public override void ExecuteCmdlet()
        {
            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                if (ParameterSetName == JobFilterSet)
                {
                    JobId = Job.JobId;
                }

                WriteDebug("Stopping job with ID: " + JobId);

                var cancelResponse = ServiceClientAdapter.CancelJob(JobId);

                var operationStatus = TrackingHelpers.GetOperationResult(
                    cancelResponse,
                    operationId => ServiceClientAdapter.GetCancelJobOperationResult(operationId));

                if (operationStatus.Response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new Exception(string.Format(Resources.JobCouldNotCancelJob,
                                                      cancelResponse.Response.StatusCode.ToString()));
                }
                else
                {
                    WriteObject(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(JobId)));
                }
            });
        }
コード例 #2
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == JobFilterSet)
            {
                JobId = Job.JobId;
            }

            ExecutionBlock(() =>
            {
                base.ExecuteCmdlet();

                ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId);
                string vaultName         = resourceIdentifier.ResourceName;
                string resourceGroupName = resourceIdentifier.ResourceGroupName;

                WriteDebug("Stopping job with ID: " + JobId);

                var cancelResponse = ServiceClientAdapter.CancelJob(
                    JobId,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName);

                var operationStatus = TrackingHelpers.GetOperationResult(
                    cancelResponse,
                    operationId => ServiceClientAdapter.GetCancelJobOperationResult(
                        operationId,
                        vaultName: vaultName,
                        resourceGroupName: resourceGroupName));

                if (operationStatus.Response.StatusCode != HttpStatusCode.NoContent)
                {
                    throw new Exception(string.Format(Resources.JobCouldNotCancelJob,
                                                      cancelResponse.Response.StatusCode.ToString()));
                }
                else
                {
                    WriteObject(JobConversions.GetPSJob(ServiceClientAdapter.GetJob(
                                                            JobId,
                                                            vaultName: vaultName,
                                                            resourceGroupName: resourceGroupName)));
                }
            }, ShouldProcess(JobId, "Stop"));
        }