Ejemplo n.º 1
0
        /// <summary>
        /// Lists all the jobs available under the given resource group.
        /// </summary>
        private static void ListJobsByResourceGroup()
        {
            //Initializes a new instance of the DataBoxManagementClient class
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            IPage <JobResource> jobPageList = null;
            List <JobResource>  jobList     = new List <JobResource>();
            string resourceGroupName        = "<resource-group-name>";

            do
            {
                // Lists all the jobs available under resource group.
                if (jobPageList == null)
                {
                    jobPageList = JobsOperationsExtensions.ListByResourceGroup(dataBoxManagementClient.Jobs, resourceGroupName);
                }
                else
                {
                    jobPageList = JobsOperationsExtensions.ListByResourceGroupNext(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);
            }
        }