/
ReplicationCursor.cs
82 lines (65 loc) · 2.53 KB
/
ReplicationCursor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Runtime.InteropServices;
namespace System.DirectoryServices.ActiveDirectory
{
public class ReplicationCursor
{
private readonly string? _serverDN;
private readonly DateTime _syncTime;
private readonly bool _advanced;
private string? _sourceServer;
private readonly DirectoryServer _server = null!;
private ReplicationCursor() { }
internal ReplicationCursor(DirectoryServer server, string partition, Guid guid, long filter, long time, IntPtr dn)
{
PartitionName = partition;
SourceInvocationId = guid;
UpToDatenessUsn = filter;
// convert filetime to DateTime
_syncTime = DateTime.FromFileTime(time);
// get the dn
_serverDN = Marshal.PtrToStringUni(dn);
_advanced = true;
_server = server;
}
internal ReplicationCursor(DirectoryServer server, string partition, Guid guid, long filter)
{
PartitionName = partition;
SourceInvocationId = guid;
UpToDatenessUsn = filter;
_server = server;
}
public string PartitionName { get; } = null!;
public Guid SourceInvocationId { get; }
public long UpToDatenessUsn { get; }
public string? SourceServer
{
get
{
// get the source server name if we are on win2k, or above win2k and serverDN is not NULL (means KCC translation is successful)
if (!_advanced || (_advanced && _serverDN != null))
{
_sourceServer = Utils.GetServerNameFromInvocationID(_serverDN, SourceInvocationId, _server);
}
return _sourceServer;
}
}
public DateTime LastSuccessfulSyncTime
{
get
{
if (_advanced)
return _syncTime;
else
{
// win2k client machine does not support this
if ((Environment.OSVersion.Version.Major == 5) && (Environment.OSVersion.Version.Minor == 0))
throw new PlatformNotSupportedException(SR.DSNotSupportOnClient);
else
throw new PlatformNotSupportedException(SR.DSNotSupportOnDC);
}
}
}
}
}