Microsoft.Azure.Commands.KeyVault.AddAzureKeyVaultCertificateContact.ProcessRecord C# (CSharp) Method

ProcessRecord() protected method

protected ProcessRecord ( ) : void
return void
        protected override void ProcessRecord()
        {
            if (ShouldProcess(EmailAddress, Properties.Resources.AddCertificateContact))
            {
                Contacts existingContacts;

                try
                {
                    existingContacts = this.DataServiceClient.GetCertificateContacts(VaultName);
                }
                catch (KeyVaultErrorException exception)
                {
                    if (exception.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
                    {
                        throw;
                    }

                    existingContacts = null;
                }

                List<Contact> newContactList;

                if (existingContacts == null ||
                    existingContacts.ContactList == null)
                {
                    newContactList = new List<Contact>();
                }
                else
                {
                    newContactList = new List<Contact>(existingContacts.ContactList);
                }

                if (newContactList.FindIndex(
                    contact => (string.Compare(contact.EmailAddress, EmailAddress, StringComparison.OrdinalIgnoreCase) == 0)) != -1)
                {
                    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Provided email address '{0}' already exists.", EmailAddress));
                }

                newContactList.Add(new Contact { EmailAddress = EmailAddress });

                var resultantContacts = this.DataServiceClient.SetCertificateContacts(VaultName, new Contacts { ContactList = newContactList });

                if (PassThru.IsPresent)
                {
                    this.WriteObject(KeyVaultCertificateContact.FromKVCertificateContacts(resultantContacts));
                }
            }
        }
    }
AddAzureKeyVaultCertificateContact