public override void ExecuteCmdlet()
        {
            try
            {
                var allSACs = StorSimpleClient.GetAllStorageAccountCredentials();
                if (StorageAccountName == null)
                {
                    WriteObject(allSACs, true);
                    WriteVerbose(string.Format(Resources.SACGet_StatusMessage, allSACs.Count, allSACs.Count > 1 ? "s" : string.Empty));
                    return;
                }

                var sac = allSACs.Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (sac == null)
                {
                    throw new ArgumentException(string.Format(Resources.SACNotFoundWithName, StorageAccountName));
                }
                else
                {
                    WriteVerbose(string.Format(Resources.SACFoundWithName, StorageAccountName));
                    WriteObject(sac);
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        public override void ExecuteCmdlet()
        {
            ConfirmAction(Force.IsPresent,
                          Resources.RemoveWarningACR,
                          Resources.RemoveConfirmationACR,
                          string.Empty,
                          () =>
            {
                try
                {
                    StorageAccountCredentialResponse existingSac = null;
                    string sacName = null;

                    switch (ParameterSetName)
                    {
                    case StorSimpleCmdletParameterSet.IdentifyByName:
                        var allSACs = StorSimpleClient.GetAllStorageAccountCredentials();
                        existingSac = allSACs.Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                        sacName     = StorageAccountName;
                        break;

                    case StorSimpleCmdletParameterSet.IdentifyByObject:
                        existingSac = SAC;
                        sacName     = SAC.Name;
                        break;
                    }
                    if (existingSac == null)
                    {
                        WriteObject(null);
                        WriteVerbose(string.Format(Resources.SACNotFoundWithName, sacName));
                        return;
                    }

                    var serviceConfig = new ServiceConfiguration()
                    {
                        AcrChangeList        = new AcrChangeList(),
                        CredentialChangeList = new SacChangeList()
                        {
                            Added   = new List <StorageAccountCredential>(),
                            Deleted = new[] { existingSac.InstanceId },
                            Updated = new List <StorageAccountCredential>()
                        }
                    };

                    if (WaitForComplete.IsPresent)
                    {
                        WriteVerbose("About to run a task to remove your Storage Access Credential!");
                        var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                        HandleSyncTaskResponse(taskStatus, "delete");
                    }
                    else
                    {
                        WriteVerbose("About to create a task to remove your Storage Access Credential!");
                        var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                        HandleAsyncTaskResponse(taskResponse, "delete");
                    }
                }
                catch (Exception exception)
                {
                    this.HandleException(exception);
                }
            });
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                var allSACs     = StorSimpleClient.GetAllStorageAccountCredentials();
                var existingSac = allSACs.Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault();
                if (existingSac == null)
                {
                    throw new ArgumentException(string.Format(Resources.SACNotFoundWithName, StorageAccountName));
                }

                string encryptedKey;
                string thumbprint;
                string endpoint = GetEndpointFromHostname(existingSac.Hostname);
                if (!ValidateAndEncryptStorageCred(StorageAccountName, StorageAccountKey, endpoint, out encryptedKey, out thumbprint))
                {
                    return;
                }

                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList        = new AcrChangeList(),
                    CredentialChangeList = new SacChangeList()
                    {
                        Added   = new List <StorageAccountCredential>(),
                        Deleted = new List <string>(),
                        Updated = new[]
                        {
                            new StorageAccountCredential()
                            {
                                InstanceId  = existingSac.InstanceId,
                                CloudType   = existingSac.CloudType,
                                Hostname    = existingSac.Hostname,
                                Login       = existingSac.Login,
                                Password    = encryptedKey ?? existingSac.Password,
                                UseSSL      = UseSSL ?? existingSac.UseSSL,
                                VolumeCount = existingSac.VolumeCount,
                                Name        = existingSac.Name,
                                IsDefault   = existingSac.IsDefault,
                                PasswordEncryptionCertThumbprint = thumbprint,
                                Location = existingSac.Location
                            },
                        }
                    }
                };

                if (WaitForComplete.IsPresent)
                {
                    WriteVerbose("About to run a task to update your Storage Access credential!");
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "update");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var updatedSac = StorSimpleClient.GetAllStorageAccountCredentials()
                                         .Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(updatedSac);
                    }
                }
                else
                {
                    WriteVerbose("About to create a task to update your Storage Access credential!");
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "update");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                string endpoint = string.IsNullOrEmpty(Endpoint) ? StorSimpleConstants.DefaultStorageAccountEndpoint : Endpoint;

                //validate storage account credentials
                bool   storageAccountPresent;
                string encryptedKey;
                string thumbprint;
                string location = GetStorageAccountLocation(StorageAccountName, out storageAccountPresent);
                if (!storageAccountPresent ||
                    !ValidateAndEncryptStorageCred(StorageAccountName, StorageAccountKey, endpoint, out encryptedKey, out thumbprint))
                {
                    return;
                }

                var serviceConfig = new ServiceConfiguration()
                {
                    AcrChangeList        = new AcrChangeList(),
                    CredentialChangeList = new SacChangeList()
                    {
                        Added = new[]
                        {
                            new StorageAccountCredential()
                            {
                                CloudType = CloudType.Azure,
                                Hostname  = GetHostnameFromEndpoint(endpoint),
                                Login     = StorageAccountName,
                                Password  = encryptedKey,
                                PasswordEncryptionCertThumbprint = thumbprint,
                                UseSSL   = UseSSL,
                                Name     = StorageAccountName,
                                Location = location
                            },
                        },
                        Deleted = new List <string>(),
                        Updated = new List <StorageAccountCredential>()
                    }
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.ConfigureService(serviceConfig);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdSac = StorSimpleClient.GetAllStorageAccountCredentials()
                                         .Where(x => x.Name.Equals(StorageAccountName, StringComparison.InvariantCultureIgnoreCase));
                        WriteObject(createdSac);
                    }
                }
                else
                {
                    var taskResponse = StorSimpleClient.ConfigureServiceAsync(serviceConfig);
                    HandleAsyncTaskResponse(taskResponse, "create");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }