/// <summary> /// Lists all the jobs available under the subscription. /// </summary> private static void ListJobs() { //Initializes a new instance of the DataBoxManagementClient class DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient(); IPage <JobResource> jobPageList = null; List <JobResource> jobList = new List <JobResource>(); do { // Lists all the jobs available under the subscription. if (jobPageList == null) { jobPageList = JobsOperationsExtensions.List(dataBoxManagementClient.Jobs); } else { jobPageList = JobsOperationsExtensions.ListNext(dataBoxManagementClient.Jobs, jobPageList.NextPageLink); } jobList.AddRange(jobPageList.ToList()); } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink))); }
public override void ExecuteCmdlet() { if (this.ParameterSetName.Equals("GetByResourceIdParameterSet")) { this.ResourceGroupName = ResourceIdHandler.GetResourceGroupName(ResourceId); this.Name = ResourceIdHandler.GetResourceName(ResourceId); } if (!string.IsNullOrEmpty(this.Name)) { List <PSDataBoxJob> result = new List <PSDataBoxJob>(); result.Add(new PSDataBoxJob(JobsOperationsExtensions.Get( this.DataBoxManagementClient.Jobs, this.ResourceGroupName, this.Name, "details"))); WriteObject(result, true); } else if (!string.IsNullOrEmpty(this.ResourceGroupName)) { IPage <JobResource> jobPageList = null; List <JobResource> result = new List <JobResource>(); List <PSDataBoxJob> finalResult = new List <PSDataBoxJob>(); do { // Lists all the jobs available under resource group. if (jobPageList == null) { jobPageList = JobsOperationsExtensions.ListByResourceGroup( this.DataBoxManagementClient.Jobs, this.ResourceGroupName); } else { jobPageList = JobsOperationsExtensions.ListByResourceGroupNext( this.DataBoxManagementClient.Jobs, jobPageList.NextPageLink); } if (Completed || Cancelled || Aborted || CompletedWithError) { foreach (var job in jobPageList) { if ((Completed && job.Status == StageName.Completed) || (Cancelled && job.Status == StageName.Cancelled) || (Aborted && job.Status == StageName.Aborted) || (CompletedWithError && job.Status == StageName.CompletedWithErrors)) { result.Add(job); } } } else { result.AddRange(jobPageList.ToList()); } } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink))); foreach (var job in result) { finalResult.Add(new PSDataBoxJob(job)); } WriteObject(finalResult, true); } else { IPage <JobResource> jobPageList = null; List <JobResource> result = new List <JobResource>(); List <PSDataBoxJob> finalResult = new List <PSDataBoxJob>(); do { // Lists all the jobs available under the subscription. if (jobPageList == null) { jobPageList = JobsOperationsExtensions.List( this.DataBoxManagementClient.Jobs); } else { jobPageList = JobsOperationsExtensions.ListNext( this.DataBoxManagementClient.Jobs, jobPageList.NextPageLink); } if (Completed || Cancelled || Aborted || CompletedWithError) { foreach (var job in jobPageList) { if ((Completed && job.Status == StageName.Completed) || (Cancelled && job.Status == StageName.Cancelled) || (Aborted && job.Status == StageName.Aborted) || (CompletedWithError && job.Status == StageName.CompletedWithErrors)) { result.Add(job); } } } else { result.AddRange(jobPageList.ToList()); } } while (!(string.IsNullOrEmpty(jobPageList.NextPageLink))); foreach (var job in result) { finalResult.Add(new PSDataBoxJob(job)); } WriteObject(finalResult, true); } }