public override void ExecuteCmdlet() { ExecutionBlock(() => { //Validate start time < end time base.ExecuteCmdlet(); Dictionary <System.Enum, object> parameter = new Dictionary <System.Enum, object>(); parameter.Add(GetRecoveryPointParams.Item, Item); if (this.ParameterSetName == DateTimeFilterParameterSet) { //User want list of RPs between given time range WriteDebug(String.Format("ParameterSet = DateTimeFilterParameterSet. \n" + "StartDate = {0} EndDate = {1}, Item.Name = {2}, Item.ContainerName = {3}", StartDate, EndDate, Item.Name, Item.ContainerName)); if (StartDate >= EndDate) { throw new ArgumentException(Resources.RecoveryPointEndDateShouldBeGreater); } if (StartDate.Kind != DateTimeKind.Utc || EndDate.Kind != DateTimeKind.Utc) { throw new ArgumentException(Resources.GetRPErrorInputDatesShouldBeInUTC); } parameter.Add(GetRecoveryPointParams.StartDate, StartDate); parameter.Add(GetRecoveryPointParams.EndDate, EndDate); PsBackupProviderManager providerManager = new PsBackupProviderManager(parameter, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType); var rpList = psBackupProvider.ListRecoveryPoints(); WriteDebug(String.Format("RPCount in Response = {0}", rpList.Count)); WriteObject(rpList, enumerateCollection: true); } else if (this.ParameterSetName == RecoveryPointIdParameterSet) { //User want details of a particular recovery point WriteDebug(String.Format("ParameterSet = DateTimeFilterParameterSet. \n" + "StartDate = {0} EndDate = {1}, RPId = {2}", StartDate, EndDate, RecoveryPointId)); parameter.Add(GetRecoveryPointParams.RecoveryPointId, RecoveryPointId); PsBackupProviderManager providerManager = new PsBackupProviderManager(parameter, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType); WriteObject(psBackupProvider.GetRecoveryPointDetails()); } else { throw new Exception(Resources.RecoveryPointUnsupportedParamet); } }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { //Validate start time < end time base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; // initialize values to default DateTime rangeEnd = DateTime.UtcNow; DateTime rangeStart = rangeEnd.AddDays(-30); Dictionary <Enum, object> providerParameters = new Dictionary <Enum, object>(); providerParameters.Add(VaultParams.VaultName, vaultName); providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName); providerParameters.Add(RecoveryPointParams.Item, Item); if (ParameterSetName == DateTimeFilterParameterSet || ParameterSetName == NoFilterParameterSet) { // if both start and end date are given by user if (StartDate.HasValue && EndDate.HasValue) { rangeStart = StartDate.Value; rangeEnd = EndDate.Value; } // if only start date is given by user else if (StartDate.HasValue && EndDate.HasValue == false) { rangeStart = StartDate.Value; rangeEnd = rangeStart.AddDays(30); } // if only end date is given by user else if (EndDate.HasValue && StartDate.HasValue == false) { rangeEnd = EndDate.Value; rangeStart = rangeEnd.AddDays(-30); } //User want list of RPs between given time range WriteDebug(string.Format("ParameterSet = DateTimeFilterParameterSet. \n" + "StartDate = {0} EndDate = {1}, Item.Name = {2}, Item.ContainerName = {3}", rangeStart, rangeEnd, Item.Name, Item.ContainerName)); if (rangeStart >= rangeEnd) { throw new ArgumentException(Resources.RecoveryPointEndDateShouldBeGreater); } if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc) { throw new ArgumentException(Resources.GetRPErrorInputDatesShouldBeInUTC); } if (rangeStart > DateTime.UtcNow) { throw new ArgumentException( Resources.GetRPErrorStartTimeShouldBeLessThanUTCNow); } providerParameters.Add(RecoveryPointParams.StartDate, rangeStart); providerParameters.Add(RecoveryPointParams.EndDate, rangeEnd); PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType); var rpList = psBackupProvider.ListRecoveryPoints(); WriteDebug(string.Format("RPCount in Response = {0}", rpList.Count)); WriteObject(rpList, enumerateCollection: true); } else if (ParameterSetName == RecoveryPointIdParameterSet) { //User want details of a particular recovery point WriteDebug(string.Format("ParameterSet = DateTimeFilterParameterSet. \n" + "StartDate = {0} EndDate = {1}, RPId = {2}, KeyFileDownloadLocation = {3}", StartDate, EndDate, RecoveryPointId, KeyFileDownloadLocation)); providerParameters.Add(RecoveryPointParams.RecoveryPointId, RecoveryPointId); providerParameters.Add( RecoveryPointParams.KeyFileDownloadLocation, KeyFileDownloadLocation); PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(Item.ContainerType, Item.BackupManagementType); WriteObject(psBackupProvider.GetRecoveryPointDetails()); } else { throw new Exception(Resources.RecoveryPointUnsupportedParamet); } }); }