Ejemplo n.º 1
0
 protected override void ProcessRecord()
 {
     if (this.ParameterSetName == "ByFilters" && string.IsNullOrEmpty(this.Host) && string.IsNullOrEmpty(this.User))
     {
         this.ThrowTerminatingError(VMware.VimAutomation.Sdk.Util10Ps.ErrorHandling.ExceptionHelper.VimExceptionToErrorRecord(VMware.VimAutomation.Sdk.Util10.ErrorHandling.ExceptionHelper.CreateClientSideException("Core_RemoveCredentialStoreItem_ProcessRecord_InvalidArguemnt", VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.ErrorCategory.InvalidArgument, (object)null, (Exception)null, typeof(ViError), VMware.VimAutomation.ViCore.Cmdlets.ResourceHelper.ResourceService, (string)null)));
     }
     CredentialStoreItem[] credentialStoreItemArray;
     if (this.ParameterSetName == "ByCredentialItemObject")
     {
         credentialStoreItemArray = this._items;
     }
     else if (this.ParameterSetName == "ByFilters")
     {
         List <CredentialStoreItemImpl> list = new List <CredentialStoreItemImpl>();
         FileInfo         file            = string.IsNullOrEmpty(this.File) ? (FileInfo)null : new FileInfo(this.File);
         ICredentialStore credentialStore = (ICredentialStore)null;
         try
         {
             credentialStore = CredentialStoreFactory.CreateCredentialStore(file);
             WildcardPattern wildcardPattern1 = new WildcardPattern("*", WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
             if (!string.IsNullOrEmpty(this.Host))
             {
                 wildcardPattern1 = new WildcardPattern(this.Host, WildcardOptions.Compiled | WildcardOptions.IgnoreCase);
             }
             WildcardPattern wildcardPattern2 = new WildcardPattern("*", WildcardOptions.Compiled);
             if (!string.IsNullOrEmpty(this.User))
             {
                 wildcardPattern2 = new WildcardPattern(this.User, WildcardOptions.Compiled);
             }
             foreach (string str1 in credentialStore.GetHosts())
             {
                 if (wildcardPattern1.IsMatch(str1))
                 {
                     foreach (string str2 in credentialStore.GetUsernames(str1))
                     {
                         if (wildcardPattern2.IsMatch(str2))
                         {
                             string password = new string(credentialStore.GetPassword(str1, str2));
                             list.Add(new CredentialStoreItemImpl(str1, str2, password, this.File));
                         }
                     }
                 }
             }
         }
         finally
         {
             if (credentialStore != null)
             {
                 credentialStore.Close();
             }
         }
         credentialStoreItemArray = (CredentialStoreItem[])list.ToArray();
     }
     else
     {
         credentialStoreItemArray = new CredentialStoreItem[0];
     }
     foreach (CredentialStoreItem credentialStoreItem in credentialStoreItemArray)
     {
         if (this.ShouldProcess(string.Format(VMware.VimAutomation.ViCore.Cmdlets.ResourceHelper.ResourceService.GetString("Core_RemoveCredentialStoreItem_ProcessRecord_Action"), (object)credentialStoreItem.Host, (object)credentialStoreItem.User)))
         {
             FileInfo         file            = string.IsNullOrEmpty(credentialStoreItem.File) ? (FileInfo)null : new FileInfo(credentialStoreItem.File);
             ICredentialStore credentialStore = (ICredentialStore)null;
             try
             {
                 credentialStore = CredentialStoreFactory.CreateCredentialStore(file);
                 credentialStore.RemovePassword(credentialStoreItem.Host, credentialStoreItem.User);
             }
             finally
             {
                 if (credentialStore != null)
                 {
                     credentialStore.Close();
                 }
             }
         }
     }
 }