public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); // initialize values to default DateTime rangeStart = DateTime.UtcNow.AddDays(-1); DateTime rangeEnd = DateTime.UtcNow; if (From.HasValue) { rangeStart = From.Value; } if (!From.HasValue && To.HasValue) { throw new Exception(Resources.JobFromNotProvided); } if (To.HasValue) { rangeEnd = To.Value; } if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc) { throw new Exception(Resources.JobTimeFiltersShouldBeSpecifiedInUtc); } // validate filters if (rangeEnd <= rangeStart) { throw new Exception(Resources.JobToShouldBeGreaterThanFrom); } else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30)) { throw new Exception(Resources.JobAllowedDateTimeRangeExceeded); } // validate JobId and Job objects if (!string.IsNullOrEmpty(JobId)) { // if JobId and Job are provided together and they don't match then throw exception if (Job != null && JobId != Job.JobId) { throw new Exception(Resources.JobJobIdAndJobMismatch); } } else if (Job != null) { JobId = Job.JobId; } List <JobBase> result = new List <JobBase>(); WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4}", From, To, Status, Operation, BackupManagementType)); int resultCount = 0; var adapterResponse = ServiceClientAdapter.GetJobs(JobId, Status.HasValue ? Status.ToString() : null, Operation.HasValue ? Operation.ToString() : null, rangeStart, rangeEnd, BackupManagementType.HasValue ? Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null); JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); while (!string.IsNullOrEmpty(adapterResponse.ItemList.NextLink)) { if (resultCount >= JobConstants.MaximumJobsToFetch) { // trace a warning that there are more jobs and user has to refine filters. WriteWarning(Resources.JobRefineFilters); break; } string skipToken; ServiceClientHelpers.GetSkipTokenFromNextLink( adapterResponse.ItemList.NextLink, out skipToken); if (skipToken != null) { adapterResponse = ServiceClientAdapter.GetJobs(JobId, Status.HasValue ? Status.ToString() : null, Operation.HasValue ? Operation.ToString() : null, rangeStart, rangeEnd, BackupManagementType.HasValue ? Helpers.JobConversions.GetJobTypeForService(BackupManagementType.Value) : null, null, skipToken); JobConversions.AddServiceClientJobsToPSList(adapterResponse, result, ref resultCount); } else { break; } } WriteDebug("Number of jobs fetched: " + result.Count); WriteObject(result, enumerateCollection: true); }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; // initialize values to default DateTime rangeStart = DateTime.UtcNow.AddDays(-1); DateTime rangeEnd = DateTime.UtcNow; if (From.HasValue) { rangeStart = From.Value; } if (!From.HasValue && To.HasValue) { throw new Exception(Resources.JobFromNotProvided); } if (To.HasValue) { rangeEnd = To.Value; } if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc) { throw new Exception(Resources.JobTimeFiltersShouldBeSpecifiedInUtc); } // validate filters if (rangeEnd <= rangeStart) { throw new Exception(Resources.JobToShouldBeGreaterThanFrom); } else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30)) { throw new Exception(Resources.JobAllowedDateTimeRangeExceeded); } else if (rangeStart > DateTime.UtcNow) { throw new Exception(Resources.JobStartTimeShouldBeLessThanCurrent); } // validate JobId and Job objects if (!string.IsNullOrEmpty(JobId)) { // if JobId and Job are provided together and they don't match then throw exception if (Job != null && JobId != Job.JobId) { throw new Exception(Resources.JobJobIdAndJobMismatch); } } else if (Job != null) { JobId = Job.JobId; } List <JobBase> result = new List <JobBase>(); WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4} UseSecondaryRegion - {5}", From, To, Status, Operation, BackupManagementType, UseSecondaryRegion.ToString())); int resultCount = 0; if (UseSecondaryRegion.IsPresent) { ARSVault vault = ServiceClientAdapter.GetVault(resourceGroupName, vaultName); string secondaryRegion = BackupUtils.regionMap[vault.Location]; WriteDebug(" Getting CRR jobs from secondary region: " + secondaryRegion); var adapterResponse = ServiceClientAdapter.GetCrrJobs(VaultId, JobId, ServiceClientHelpers.GetServiceClientJobStatus(Status), Operation.ToString(), rangeStart, rangeEnd, ServiceClientHelpers.GetServiceClientBackupManagementType(BackupManagementType), secondaryRegion); JobConversions.AddServiceClientJobsToPSList( adapterResponse, result, ref resultCount); } else { var adapterResponse = ServiceClientAdapter.GetJobs( JobId, ServiceClientHelpers.GetServiceClientJobStatus(Status), Operation.ToString(), rangeStart, rangeEnd, ServiceClientHelpers.GetServiceClientBackupManagementType( BackupManagementType), vaultName: vaultName, resourceGroupName: resourceGroupName); JobConversions.AddServiceClientJobsToPSList( adapterResponse, result, ref resultCount); } WriteDebug("Number of jobs fetched: " + result.Count); WriteObject(result, enumerateCollection: true); }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); // initialize values to default DateTime rangeStart = DateTime.UtcNow.AddDays(-1); DateTime rangeEnd = DateTime.UtcNow; if (From.HasValue) { rangeStart = From.Value; } if (!From.HasValue && To.HasValue) { throw new Exception(Resources.JobFromNotProvided); } if (To.HasValue) { rangeEnd = To.Value; } if (rangeStart.Kind != DateTimeKind.Utc || rangeEnd.Kind != DateTimeKind.Utc) { throw new Exception(Resources.JobTimeFiltersShouldBeSpecifiedInUtc); } // validate filters if (rangeEnd <= rangeStart) { throw new Exception(Resources.JobToShouldBeGreaterThanFrom); } else if (rangeEnd.Subtract(rangeStart) > TimeSpan.FromDays(30)) { throw new Exception(Resources.JobAllowedDateTimeRangeExceeded); } else if (rangeStart > DateTime.UtcNow) { throw new Exception(Resources.JobStartTimeShouldBeLessThanCurrent); } // validate JobId and Job objects if (!string.IsNullOrEmpty(JobId)) { // if JobId and Job are provided together and they don't match then throw exception if (Job != null && JobId != Job.JobId) { throw new Exception(Resources.JobJobIdAndJobMismatch); } } else if (Job != null) { JobId = Job.JobId; } List <JobBase> result = new List <JobBase>(); WriteDebug(string.Format("Filters provided are: StartTime - {0} " + "EndTime - {1} Status - {2} Operation - {3} Type - {4}", From, To, Status, Operation, BackupManagementType)); int resultCount = 0; ServiceClientModel.JobStatus?jobStatus = null; jobStatus = Status.HasValue ? (Status.ToEnum <ServiceClientModel.JobStatus>()) : default(ServiceClientModel.JobStatus?); var adapterResponse = ServiceClientAdapter.GetJobs(JobId, Status.HasValue ? Status.ToEnum <ServiceClientModel.JobStatus>() : default(ServiceClientModel.JobStatus?), Operation.ToString(), rangeStart, rangeEnd, ServiceClientHelpers.GetServiceClientBackupManagementType( BackupManagementType)); JobConversions.AddServiceClientJobsToPSList( adapterResponse, result, ref resultCount); WriteDebug("Number of jobs fetched: " + result.Count); WriteObject(result, enumerateCollection: true); }); }