/
ReplicationFailureCollection.cs
70 lines (54 loc) · 2.29 KB
/
ReplicationFailureCollection.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
using System.Runtime.InteropServices;
namespace System.DirectoryServices.ActiveDirectory
{
public class ReplicationFailureCollection : ReadOnlyCollectionBase
{
private readonly DirectoryServer _server;
private readonly Hashtable _nameTable;
internal ReplicationFailureCollection(DirectoryServer server)
{
_server = server;
Hashtable tempNameTable = new Hashtable();
_nameTable = Hashtable.Synchronized(tempNameTable);
}
public ReplicationFailure this[int index] => (ReplicationFailure)InnerList[index]!;
public bool Contains(ReplicationFailure failure)
{
if (failure == null)
throw new ArgumentNullException(nameof(failure));
return InnerList.Contains(failure);
}
public int IndexOf(ReplicationFailure failure)
{
if (failure == null)
throw new ArgumentNullException(nameof(failure));
return InnerList.IndexOf(failure);
}
public void CopyTo(ReplicationFailure[] failures, int index)
{
InnerList.CopyTo(failures, index);
}
private int Add(ReplicationFailure failure) => InnerList.Add(failure);
internal void AddHelper(DS_REPL_KCC_DSA_FAILURES failures, IntPtr info)
{
// get the count
int count = failures.cNumEntries;
IntPtr addr = (IntPtr)0;
for (int i = 0; i < count; i++)
{
addr = IntPtr.Add(info, sizeof(int) * 2 + i * Marshal.SizeOf(typeof(DS_REPL_KCC_DSA_FAILURE)));
ReplicationFailure managedFailure = new ReplicationFailure(addr, _server, _nameTable);
// in certain scenario, KCC returns some failure records that we need to process it first before returning
if (managedFailure.LastErrorCode == 0)
{
// we change the error code to some generic one
managedFailure.lastResult = Interop.Errors.ERROR_DS_UNKNOWN_ERROR;
}
Add(managedFailure);
}
}
}
}