Esempio n. 1
0
        private void LazyInit()
        {
            int num = 30;

            try
            {
                if (!Monitor.TryEnter(this.syncLock, TimeSpan.FromSeconds((double)num)))
                {
                    throw new ServerComponentApiException(DirectoryStrings.ServerComponentReadTimeout(num));
                }
                if (!this.m_lastKnownADComponentStatesAreSet)
                {
                    MultiValuedProperty <string> adStates = null;
                    Exception ex = ServerComponentStateManager.RunADOperationNoThrow(delegate
                    {
                        adStates = ServerComponentStateManager.ReadLocalServerComponentStatesFromAD();
                    });
                    if (ex != null)
                    {
                        ServerComponentStateManager.Tracer.TraceError <Exception>(0L, "LazyInit failed: {0}", ex);
                    }
                    this.SetAdStates(adStates);
                }
            }
            finally
            {
                if (Monitor.IsEntered(this.syncLock))
                {
                    Monitor.Exit(this.syncLock);
                }
            }
        }
        private static List <ServerComponentStates.ItemEntry> GetReconciledStates(string targetServerFqdn, MultiValuedProperty <string> adComponentStates, ServerComponentStateSources sourcesToUse, string component, out List <ServerComponentStates.ItemEntry> localStates, out List <ServerComponentStates.ItemEntry> remoteStates)
        {
            localStates  = null;
            remoteStates = null;
            List <ServerComponentStates.ItemEntry> localStatesTemp = null;
            List <ServerComponentStates.ItemEntry> result          = null;

            if (sourcesToUse.HasFlag(ServerComponentStateSources.Registry))
            {
                Exception ex = ServerComponentStateManager.RunLocalRegistryOperationNoThrow(delegate
                {
                    localStatesTemp = ServerComponentStates.GetLocalStates(targetServerFqdn, component);
                });
                if (ex != null && !sourcesToUse.HasFlag(ServerComponentStateSources.AD))
                {
                    throw new ServerComponentApiException(DirectoryStrings.ServerComponentLocalRegistryError(ex.ToString()), ex);
                }
                localStates = localStatesTemp;
                result      = localStatesTemp;
            }
            if (sourcesToUse.HasFlag(ServerComponentStateSources.AD))
            {
                remoteStates = ServerComponentStates.GetRemoteStates(adComponentStates, component);
                result       = remoteStates;
            }
            if (localStates != null && remoteStates != null)
            {
                result = ServerComponentStates.ReconcileStates(localStates, remoteStates);
            }
            return(result);
        }
Esempio n. 3
0
        public static void SyncAdState()
        {
            MultiValuedProperty <string> adStates = null;
            Exception ex = ServerComponentStateManager.RunADOperationNoThrow(delegate
            {
                adStates = ServerComponentStateManager.ReadLocalServerComponentStatesFromAD();
                ServerComponentStateManager.UseAdStates(adStates);
            });

            if (ex != null)
            {
                ServerComponentStateManager.Tracer.TraceError <Exception>(0L, "SyncAdState failed to read from AD: {0}", ex);
                throw new ServerComponentApiException(DirectoryStrings.ServerComponentReadADError(ex.ToString()), ex);
            }
            Exception ex2 = ServerComponentStateManager.RunLocalRegistryOperationNoThrow(delegate
            {
                ServerComponentStates.SyncComponentStates(adStates);
            });

            if (ex2 != null)
            {
                ServerComponentStateManager.Tracer.TraceError <Exception>(0L, "SyncAdState failed in ServerComponentStates.SyncComponentStates: {0}", ex2);
                throw new ServerComponentApiException(DirectoryStrings.ServerComponentLocalRegistryError(ex2.ToString()), ex2);
            }
        }
Esempio n. 4
0
        private static void RunLocalRegistryOperation(Action codeToRun)
        {
            Exception ex = ServerComponentStateManager.RunLocalRegistryOperationNoThrow(codeToRun);

            if (ex != null)
            {
                throw new ServerComponentApiException(DirectoryStrings.ServerComponentLocalRegistryError(ex.ToString()), ex);
            }
        }
Esempio n. 5
0
        public static ServiceState GetDefaultState(string componentId)
        {
            ServerComponentEnum serverComponent;

            if (!Enum.TryParse <ServerComponentEnum>(componentId, true, out serverComponent))
            {
                throw new ArgumentException(DirectoryStrings.ComponentNameInvalid);
            }
            return(ServerComponentStateManager.GetDefaultState(serverComponent));
        }
Esempio n. 6
0
        public static void SetOnline(ServerComponentEnum serverComponent)
        {
            Exception ex = ServerComponentStateManager.RunLocalRegistryOperationNoThrow(delegate
            {
                ServerComponentStates.UpdateLocalState(null, ServerComponentRequest.HealthApi.ToString(), serverComponent.ToString(), ServiceState.Active);
            });

            if (ex != null)
            {
                ServerComponentStateManager.Tracer.TraceError <ServerComponentEnum, Exception>(0L, "SetOnline({0}) failed: {1}", serverComponent, ex);
                throw new ServerComponentApiException(DirectoryStrings.ServerComponentLocalRegistryError(ex.ToString()), ex);
            }
        }
Esempio n. 7
0
        public static ServiceState GetEffectiveState(ServerComponentEnum serverComponent, bool onlineByDefault)
        {
            MultiValuedProperty <string> adStates = null;

            try
            {
                adStates = ServerComponentStateManager.Instance.GetAdStates();
            }
            catch (ServerComponentApiException arg)
            {
                ServerComponentStateManager.Tracer.TraceError <ServerComponentApiException>(0L, "GetEffectiveState ignoring failure to get adStates. Ex was {0}", arg);
            }
            ServiceState compState = ServiceState.Inactive;

            ServerComponentStateManager.RunLocalRegistryOperation(delegate
            {
                compState = ServerComponentStates.ReadEffectiveComponentState(null, adStates, ServerComponentStates.GetComponentId(serverComponent), onlineByDefault ? ServiceState.Active : ServiceState.Inactive);
            });
            return(compState);
        }
Esempio n. 8
0
        public static ServiceState GetEffectiveState(ServerComponentEnum serverComponent)
        {
            ServiceState defaultState = ServerComponentStateManager.GetDefaultState(serverComponent);

            return(ServerComponentStateManager.GetEffectiveState(serverComponent, defaultState != ServiceState.Inactive));
        }
Esempio n. 9
0
        public static bool IsOnline(ServerComponentEnum serverComponent, bool onlineByDefault)
        {
            ServiceState effectiveState = ServerComponentStateManager.GetEffectiveState(serverComponent, onlineByDefault);

            return(effectiveState == ServiceState.Active || effectiveState == ServiceState.Draining);
        }
Esempio n. 10
0
 public static bool IsOnline(ServerComponentEnum serverComponent)
 {
     return(ServerComponentStateManager.IsOnline(serverComponent, true));
 }
Esempio n. 11
0
        public static bool IsValidComponent(string componentId)
        {
            ServerComponentEnum serverComponent;

            return(Enum.TryParse <ServerComponentEnum>(componentId, true, out serverComponent) && ServerComponentStateManager.IsValidComponent(serverComponent));
        }