Exemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            try
            {
                ConfirmAction(
                    Force.IsPresent,
                    string.Format(Resources.StopAzureStorSimpleJobWarningMessage, InstanceId),
                    string.Format(Resources.StopAzureStorSimpleJobMessage, InstanceId),
                    InstanceId,
                    () =>
                {
                    // Get details of the job being cancelled.
                    var deviceJobDetails = StorSimpleClient.GetDeviceJobById(InstanceId);
                    if (deviceJobDetails == null)
                    {
                        throw new ArgumentException(string.Format(Resources.NoDeviceJobFoundWithGivenIdMessage, InstanceId));
                    }

                    // Make sure the job is running and cancellable, else fail.
                    if (!(deviceJobDetails.IsJobCancellable && deviceJobDetails.Status == "Running"))
                    {
                        throw new ArgumentException(string.Format(Resources.JobNotRunningOrCancellable, InstanceId));
                    }

                    // issue call to cancel the job.
                    WriteVerbose(string.Format(Resources.StoppingDeviceJob, InstanceId));
                    var taskStatusInfo = StorSimpleClient.StopDeviceJob(deviceJobDetails.Device.InstanceId, InstanceId);
                    HandleSyncTaskResponse(taskStatusInfo, "stop");
                    if (taskStatusInfo.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        WriteVerbose(Resources.StopDeviceJobSucceeded);
                        WriteObject(deviceJobDetails);
                    }
                });
            }
            catch (Exception exception)
            {
                HandleException(exception);
            }
        }