コード例 #1
0
        internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle)
        {
            IntPtr errorInfo = (IntPtr)0;

            if (!Partitions.Contains(partition))
            {
                throw new ArgumentException(SR.ServerNotAReplica, "partition");
            }

            // we want to return the dn instead of DNS guid
            // call DsReplicaSyncAllW
            IntPtr functionPtr = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW");

            if (functionPtr == (IntPtr)0)
            {
                throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
            }
            UnsafeNativeMethods.DsReplicaSyncAllW dsReplicaSyncAllW = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(functionPtr, typeof(UnsafeNativeMethods.DsReplicaSyncAllW));

            int result = dsReplicaSyncAllW(handle, partition, (int)option | DS_REPSYNCALL_ID_SERVERS_BY_DN, syncAllFunctionPointer, (IntPtr)0, ref errorInfo);

            try
            {
                // error happens during the synchronization
                if (errorInfo != (IntPtr)0)
                {
                    SyncFromAllServersOperationException e = ExceptionHelper.CreateSyncAllException(errorInfo, false);
                    if (e == null)
                    {
                        return;
                    }
                    else
                    {
                        throw e;
                    }
                }
                else
                {
                    // API does not return error infor occurred during synchronization, but result is not success.
                    if (result != 0)
                    {
                        throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(result, false));
                    }
                }
            }
            finally
            {
                // release the memory
                if (errorInfo != (IntPtr)0)
                {
                    UnsafeNativeMethods.LocalFree(errorInfo);
                }
            }
        }
コード例 #2
0
        internal void SyncReplicaAllHelper(IntPtr handle, SyncReplicaFromAllServersCallback syncAllFunctionPointer, string partition, SyncFromAllServersOptions option, SyncUpdateCallback callback, LoadLibrarySafeHandle libHandle)
        {
            IntPtr intPtr = (IntPtr)0;

            if (this.Partitions.Contains(partition))
            {
                IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(libHandle, "DsReplicaSyncAllW");
                if (procAddress != (IntPtr)0)
                {
                    UnsafeNativeMethods.DsReplicaSyncAllW delegateForFunctionPointer = (UnsafeNativeMethods.DsReplicaSyncAllW)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(UnsafeNativeMethods.DsReplicaSyncAllW));
                    int num = delegateForFunctionPointer(handle, partition, (int)option | 4, syncAllFunctionPointer, (IntPtr)0, ref intPtr);
                    try
                    {
                        if (intPtr == (IntPtr)0)
                        {
                            if (num != 0)
                            {
                                throw new SyncFromAllServersOperationException(ExceptionHelper.GetErrorMessage(num, false));
                            }
                        }
                        else
                        {
                            SyncFromAllServersOperationException syncFromAllServersOperationException = ExceptionHelper.CreateSyncAllException(intPtr, false);
                            if (syncFromAllServersOperationException != null)
                            {
                                throw syncFromAllServersOperationException;
                            }
                        }
                    }
                    finally
                    {
                        if (intPtr != (IntPtr)0)
                        {
                            UnsafeNativeMethods.LocalFree(intPtr);
                        }
                    }
                    return;
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromErrorCode(Marshal.GetLastWin32Error());
                }
            }
            else
            {
                throw new ArgumentException(Res.GetString("ServerNotAReplica"), "partition");
            }
        }