コード例 #1
0
        /// <summary>
        /// Based on the response from the service, handles the job created in the service appropriately.
        /// </summary>
        /// <param name="response">Response from service</param>
        /// <param name="operationName">Name of the operation</param>
        protected void HandleCreatedJob(
            AzureRestNS.AzureOperationResponse response,
            string operationName,
            string vaultName         = null,
            string resourceGroupName = null)
        {
            WriteDebug(Resources.TrackingOperationStatusURLForCompletion +
                       response.Response.Headers.GetAzureAsyncOperationHeader());

            var operationStatus = TrackingHelpers.GetOperationStatus(
                response,
                operationId => ServiceClientAdapter.GetProtectedItemOperationStatus(
                    operationId,
                    vaultName: vaultName,
                    resourceGroupName: resourceGroupName));

            if (response != null && operationStatus != null)
            {
                WriteDebug(Resources.FinalOperationStatus + operationStatus.Status);

                if (operationStatus.Properties != null)
                {
                    var jobExtendedInfo =
                        (OperationStatusJobExtendedInfo)operationStatus.Properties;

                    if (jobExtendedInfo.JobId != null)
                    {
                        var jobStatusResponse =
                            (OperationStatusJobExtendedInfo)operationStatus.Properties;
                        WriteObject(GetJobObject(
                                        jobStatusResponse.JobId,
                                        vaultName: vaultName,
                                        resourceGroupName: resourceGroupName));
                    }
                }

                if (operationStatus.Status == OperationStatusValues.Failed &&
                    operationStatus.Error != null)
                {
                    var errorMessage = string.Format(
                        Resources.OperationFailed,
                        operationName,
                        operationStatus.Error.Code,
                        operationStatus.Error.Message);
                    throw new Exception(errorMessage);
                }
            }
        }