public override void ExecuteCmdlet()
{
this.WriteVerbose("Vault Settings File path: " + this.Path);
ASRVaultCreds asrVaultCreds = null;
if (File.Exists(this.Path))
{
try
{
this.WriteWarningWithTimestamp(
string.Format(
Properties.Resources.CmdletWillBeDeprecatedSoon,
this.MyInvocation.MyCommand.Name));
var serializer = new DataContractSerializer(typeof(ASRVaultCreds));
using (var s = new FileStream(
this.Path,
FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
asrVaultCreds = (ASRVaultCreds)serializer.ReadObject(s);
}
}
catch (XmlException xmlException)
{
throw new XmlException(
string.Format(Properties.Resources.InvalidXml, xmlException));
}
catch (SerializationException serializationException)
{
throw new SerializationException(
string.Format(Properties.Resources.InvalidXml, serializationException));
}
}
else
{
throw new FileNotFoundException(
Properties.Resources.VaultSettingFileNotFound,
this.Path);
}
// Validate required parameters taken from the Vault settings file.
if (string.IsNullOrEmpty(asrVaultCreds.ResourceName))
{
throw new ArgumentException(
Properties.Resources.ResourceNameNullOrEmpty,
asrVaultCreds.ResourceName);
}
if (string.IsNullOrEmpty(asrVaultCreds.CloudServiceName))
{
throw new ArgumentException(
Properties.Resources.CloudServiceNameNullOrEmpty,
asrVaultCreds.CloudServiceName);
}
try
{
RecoveryServicesClient.ValidateVaultSettings(
asrVaultCreds.ResourceName,
asrVaultCreds.CloudServiceName);
Utilities.UpdateVaultSettings(asrVaultCreds);
this.WriteObject(new ASRVaultSettings(
asrVaultCreds.ResourceName,
asrVaultCreds.CloudServiceName));
}
catch (Exception exception)
{
this.HandleException(exception);
}
}
}