コード例 #1
0
        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);
        }
コード例 #2
0
        private static void LogTransition(string component, string requester, ServiceState state)
        {
            if (state != ServiceState.Active)
            {
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_ServerComponentStateSetOffline, Environment.MachineName, new object[]
                {
                    component,
                    requester,
                    state.ToString()
                });
                return;
            }
            bool flag = false;
            List <ServerComponentStates.ItemEntry> list        = null;
            List <ServerComponentStates.ItemEntry> localStates = ServerComponentStates.GetLocalStates(null, ServerComponentStates.ServerWideOfflineComponentId);

            foreach (ServerComponentStates.ItemEntry itemEntry in localStates)
            {
                if (itemEntry.State != ServiceState.Active && !string.Equals(itemEntry.Requester, requester, StringComparison.OrdinalIgnoreCase))
                {
                    flag = true;
                    break;
                }
            }
            if (!flag && !string.Equals(component, ServerComponentStates.ServerWideOfflineComponentId, StringComparison.OrdinalIgnoreCase))
            {
                list = ServerComponentStates.GetLocalStates(null, component);
                foreach (ServerComponentStates.ItemEntry itemEntry2 in list)
                {
                    if (itemEntry2.State != ServiceState.Active && !string.Equals(itemEntry2.Requester, requester, StringComparison.OrdinalIgnoreCase))
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag)
            {
                DateTime dateTime = DateTime.UtcNow;
                foreach (ServerComponentStates.ItemEntry itemEntry3 in localStates)
                {
                    if (itemEntry3.State != ServiceState.Active && itemEntry3.Timestamp < dateTime)
                    {
                        dateTime = itemEntry3.Timestamp;
                    }
                }
                if (list != null)
                {
                    foreach (ServerComponentStates.ItemEntry itemEntry4 in list)
                    {
                        if (itemEntry4.State != ServiceState.Active && itemEntry4.Timestamp < dateTime)
                        {
                            dateTime = itemEntry4.Timestamp;
                        }
                    }
                }
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_ServerComponentStateSetOnline, Environment.MachineName, new object[]
                {
                    component,
                    requester,
                    dateTime
                });
            }
        }