Пример #1
0
        /// <summary>
        /// This method cancels the specified job.
        /// </summary>
        private static void CancelJob()
        {
            string resourceGroupName = "<resource-group-name>";
            string jobName           = "<job-name>";
            string reason            = "<reason>";

            // Initializes a new instance of the DataBoxManagementClient class.
            DataBoxManagementClient dataBoxManagementClient = InitializeDataBoxClient();

            // Gets information about the specified job.
            JobResource jobResource = JobsOperationsExtensions.Get(
                dataBoxManagementClient.Jobs,
                resourceGroupName,
                jobName);

            if (jobResource.IsCancellable != null &&
                (bool)jobResource.IsCancellable)
            {
                CancellationReason cancellationReason = new CancellationReason(reason);

                // Initiate cancel job
                JobsOperationsExtensions.Cancel(
                    dataBoxManagementClient.Jobs,
                    resourceGroupName,
                    jobName,
                    cancellationReason);
            }
        }
        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 cancel job
            if (ShouldProcess(this.Name, string.Format(Resource.CancellingDataboxJob + this.Name + Resource.InResourceGroup + this.ResourceGroupName)))
            {
                JobsOperationsExtensions.Cancel(
                    DataBoxManagementClient.Jobs,
                    ResourceGroupName,
                    Name,
                    Reason);
            }

            if (PassThru)
            {
                WriteObject(true);
            }
        }