Exemplo n.º 1
0
        private static NativeMethods.InteropDsRolePrimaryDomainInfoBasic GetPrimaryDomainInformation(string serverFqdn = null)
        {
            SafeDsRolePrimaryDomainInfoLevelHandle safeDsRolePrimaryDomainInfoLevelHandle = null;
            int num = 0;

            NativeMethods.InteropDsRolePrimaryDomainInfoBasic result;
            try
            {
                int num2;
                for (;;)
                {
                    num2 = NativeMethods.DsRoleGetPrimaryDomainInformation(serverFqdn, NativeMethods.DsRolePrimaryDomainInfoBasic, out safeDsRolePrimaryDomainInfoLevelHandle);
                    if (num2 == 0)
                    {
                        goto IL_8A;
                    }
                    if (num2 != 1723)
                    {
                        goto IL_73;
                    }
                    if (num >= NativeHelpers.MaxCallRetry)
                    {
                        break;
                    }
                    num++;
                    Thread.Sleep(num * NativeHelpers.CallRetryBaseSleepTime);
                }
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_RPC_SERVER_TOO_BUSY, "DsRoleGetPrimaryDomainInformation", new object[]
                {
                    "DsRoleGetPrimaryDomainInformation",
                    1723
                });
                throw new ADTransientException(DirectoryStrings.ExceptionDomainInfoRpcTooBusy);
IL_73:
                throw new CannotGetDomainInfoException(DirectoryStrings.CannotGetDomainInfo(num2.ToString("X")));
IL_8A:
                NativeMethods.InteropDsRolePrimaryDomainInfoBasic interopDsRolePrimaryDomainInfoBasic = new NativeMethods.InteropDsRolePrimaryDomainInfoBasic();
                Marshal.PtrToStructure(safeDsRolePrimaryDomainInfoLevelHandle.DangerousGetHandle(), interopDsRolePrimaryDomainInfoBasic);
                if (string.IsNullOrEmpty(interopDsRolePrimaryDomainInfoBasic.domainNameDns))
                {
                    throw new CannotGetDomainInfoException(DirectoryStrings.CannotGetUsefulDomainInfo);
                }
                result = interopDsRolePrimaryDomainInfoBasic;
            }
            finally
            {
                if (safeDsRolePrimaryDomainInfoLevelHandle != null)
                {
                    safeDsRolePrimaryDomainInfoLevelHandle.Dispose();
                }
            }
            return(result);
        }
 internal static extern int DsRoleGetPrimaryDomainInformation(string server, int infoLevel, out SafeDsRolePrimaryDomainInfoLevelHandle buffer);