public static MultiValuedProperty <string> UpdateRemoteState(MultiValuedProperty <string> componentStates, string requester, string component, ServiceState state)
        {
            if (!ServerComponentStates.IsValidName(component))
            {
                throw new ArgumentException(DirectoryStrings.ComponentNameInvalid);
            }
            if (!ServerComponentStates.IsValidName(requester))
            {
                throw new ArgumentException(DirectoryStrings.RequesterNameInvalid);
            }
            MultiValuedProperty <string> multiValuedProperty = new MultiValuedProperty <string>();

            if (componentStates != null)
            {
                foreach (string text in componentStates)
                {
                    ServerComponentStates.ItemEntry itemEntry;
                    if (ServerComponentStates.TryParseRemoteStateString(text, out itemEntry) && (!string.Equals(itemEntry.Component, component, StringComparison.OrdinalIgnoreCase) || !string.Equals(itemEntry.Requester, requester, StringComparison.OrdinalIgnoreCase)))
                    {
                        multiValuedProperty.Add(text);
                    }
                }
            }
            multiValuedProperty.Add(string.Format("1:{0}:{1}:{2}:{3}", new object[]
            {
                component,
                requester,
                (int)state,
                DateTime.UtcNow.Ticks
            }));
            return(multiValuedProperty);
        }
 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);
                         }
                     }
                 }
             }
         }
     }
 }
        private static List <ServerComponentStates.ItemEntry> GetRemoteStates(MultiValuedProperty <string> componentStates, string component)
        {
            List <ServerComponentStates.ItemEntry> list = new List <ServerComponentStates.ItemEntry>();

            if (componentStates == null)
            {
                return(list);
            }
            foreach (string value in componentStates)
            {
                ServerComponentStates.ItemEntry itemEntry;
                if (ServerComponentStates.TryParseRemoteStateString(value, out itemEntry) && string.Equals(itemEntry.Component, component, StringComparison.OrdinalIgnoreCase))
                {
                    list.Add(itemEntry);
                }
            }
            return(list);
        }