コード例 #1
0
 public static void SyncComponentStates(MultiValuedProperty <string> adComponentStates)
 {
     if (adComponentStates != null)
     {
         using (RegistryKey localMachine = Registry.LocalMachine)
         {
             foreach (string value in adComponentStates)
             {
                 ServerComponentStates.ItemEntry itemEntry;
                 if (ServerComponentStates.TryParseRemoteStateString(value, out itemEntry))
                 {
                     string subkey = string.Format("{0}\\{1}", "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\ServerComponentStates", itemEntry.Component);
                     using (RegistryKey registryKey = localMachine.CreateSubKey(subkey))
                     {
                         bool         flag   = true;
                         object       value2 = registryKey.GetValue(itemEntry.Requester);
                         ServiceState serviceState;
                         DateTime     t;
                         if (value2 != null && registryKey.GetValueKind(itemEntry.Requester) == RegistryValueKind.String && ServerComponentStates.TryParseLocalStateString(value2 as string, out serviceState, out t) && itemEntry.Timestamp <= t)
                         {
                             flag = false;
                         }
                         if (flag)
                         {
                             ServerComponentStates.LogTransition(itemEntry.Component, itemEntry.Requester, itemEntry.State);
                             string value3 = ServerComponentStates.FormLocalString(itemEntry.State, itemEntry.Timestamp);
                             registryKey.SetValue(itemEntry.Requester, value3, RegistryValueKind.String);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
        public static void UpdateLocalState(string targetServerFqdn, string requester, string component, ServiceState state)
        {
            if (!ServerComponentStates.IsValidName(component))
            {
                throw new ArgumentException(DirectoryStrings.ComponentNameInvalid);
            }
            if (!ServerComponentStates.IsValidName(requester))
            {
                throw new ArgumentException(DirectoryStrings.RequesterNameInvalid);
            }
            string subkey = string.Format("{0}\\{1}", "SOFTWARE\\Microsoft\\ExchangeServer\\v15\\ServerComponentStates", component);

            using (RegistryKey localMachineKey = ServerComponentStates.GetLocalMachineKey(targetServerFqdn))
            {
                using (RegistryKey registryKey = localMachineKey.CreateSubKey(subkey))
                {
                    ServerComponentStates.LogTransition(component, requester, state);
                    registryKey.SetValue(requester, ServerComponentStates.FormLocalString(state, DateTime.UtcNow));
                }
            }
        }