internal void RemoveCredential(AlternateServiceAccountCredential credential)
 {
     this.DoRegistryOperation(false, delegate(RegistryKey key)
     {
         credential.Remove(key);
     }, new Func <string, LocalizedString>(DirectoryStrings.FailedToWriteAlternateServiceAccountConfigToRegistry));
     this.credentials.Remove(credential);
     credential.Dispose();
 }
        internal AlternateServiceAccountCredential AddCredential(PSCredential credential)
        {
            AlternateServiceAccountCredential newCredential = AlternateServiceAccountCredential.Create(TimeSpan.FromMilliseconds((double)(10 * this.credentials.Count)), credential);

            this.DoRegistryOperation(false, delegate(RegistryKey key)
            {
                newCredential.SaveToRegistry(key);
            }, new Func <string, LocalizedString>(DirectoryStrings.FailedToWriteAlternateServiceAccountConfigToRegistry));
            this.credentials.Insert(0, newCredential);
            return(newCredential);
        }
        private static AlternateServiceAccountConfiguration LoadFromRegistry(string machineName, bool decryptPasswords)
        {
            AlternateServiceAccountConfiguration result = new AlternateServiceAccountConfiguration(machineName);

            result.DoRegistryOperation(true, delegate(RegistryKey rootKey)
            {
                result.credentials.AddRange(AlternateServiceAccountCredential.LoadFromRegistry(rootKey, decryptPasswords));
            }, new Func <string, LocalizedString>(DirectoryStrings.FailedToReadAlternateServiceAccountConfigFromRegistry));
            result.credentials.Sort();
            return(result);
        }