Example #1
0
        public override void ExecuteCmdlet()
        {
            if (this.ParameterSetName.Equals(GetByResourceIdParameterSet))
            {
                this.ResourceGroupName = ResourceIdHandler.GetResourceGroupName(ResourceId);
                this.Name = ResourceIdHandler.GetResourceName(ResourceId);
            }

            if (this.ParameterSetName.Equals(GetByInputObjectParameterSet))
            {
                this.ResourceGroupName = InputObject.ResourceGroup;
                this.Name = InputObject.JobResource.Name;
            }



            // Initiate to delete job
            if (ShouldProcess(this.Name, string.Format(Resource.DeletingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName)))
            {
                JobsOperationsExtensions.Delete(
                    DataBoxManagementClient.Jobs,
                    ResourceGroupName,
                    Name);

                if (PassThru)
                {
                    WriteObject(true);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            if (this.ParameterSetName.Equals("GetByResourceIdParameterSet"))
            {
                this.ResourceGroupName = ResourceIdHandler.GetResourceGroupName(ResourceId);
                this.Name = ResourceIdHandler.GetResourceName(ResourceId);
            }

            if (Name != null && string.IsNullOrWhiteSpace(Name))
            {
                throw new PSArgumentNullException("Name");
            }

            IEnumerable <UnencryptedCredentials> result = DataBoxManagementClient.Jobs.ListCredentials(ResourceGroupName, Name);

            WriteObject(result);
        }
        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);
            }
        }