internal static TenantConfigurationLongRunningOperation CreateLongRunningOperation(
            string operationName,
            TenantLongRunningOperationResponse longRunningResponse)
        {
            if (string.IsNullOrWhiteSpace(operationName))
            {
                throw new ArgumentNullException("operationName");
            }

            if (longRunningResponse == null)
            {
                throw new ArgumentNullException("longRunningResponse");
            }

            var result = new TenantConfigurationLongRunningOperation
            {
                OperationName = operationName,
                OperationLink = longRunningResponse.OperationStatusLink ?? string.Empty,
                RetryAfter = TimeSpan.FromSeconds(longRunningResponse.RetryAfter)
            };

            var tenantConfigurationLongRunningResponse = longRunningResponse as TenantConfigurationLongRunningOperationResponse;
            if (tenantConfigurationLongRunningResponse != null && tenantConfigurationLongRunningResponse.OperationResult != null)
            {
                result.OperationResult = new PsApiManagementOperationResult(tenantConfigurationLongRunningResponse.OperationResult);
            }

            return result;
        }
        /// <summary>
        /// TODO: Revert to standard long running operation once /operationResults endpoint start returning 
        /// 202 Code for not Completed Operation.
        /// </summary>
        /// <see cref="https://msdn.microsoft.com/en-us/library/azure/dn781420.aspx#GetOperation"/>
        protected TenantConfigurationLongRunningOperation WaitForOperationToComplete(TenantConfigurationLongRunningOperation longRunningOperation)
        {
            do
            {
                var retryAfter = longRunningOperation.RetryAfter == null || longRunningOperation.RetryAfter.Value < LongRunningOperationDefaultTimeout ?
                    LongRunningOperationDefaultTimeout : longRunningOperation.RetryAfter.Value;

                WriteProgress(longRunningOperation);

                TestMockSupport.Delay(retryAfter);

                // the operation link is present in the first call to Operation. 
                // The next calls to /operationResults do not return Location header, hence preserving this value across calls
                // this is the service side bug.
                var operationStatusLink = longRunningOperation.OperationLink;

                longRunningOperation = Client.GetLongRunningOperationStatus(longRunningOperation);
                longRunningOperation.OperationLink = operationStatusLink;

                WriteVerboseWithTimestamp(Resources.VerboseGetOperationStateTimeoutMessage,
                   longRunningOperation.OperationResult.State);
            } while (longRunningOperation.OperationResult.State == TenantConfigurationState.InProgress);

            return longRunningOperation;
        }
Beispiel #3
0
        internal static TenantConfigurationLongRunningOperation CreateLongRunningOperation(
            string operationName,
            TenantLongRunningOperationResponse longRunningResponse)
        {
            if (string.IsNullOrWhiteSpace(operationName))
            {
                throw new ArgumentNullException("operationName");
            }

            if (longRunningResponse == null)
            {
                throw new ArgumentNullException("longRunningResponse");
            }

            var result = new TenantConfigurationLongRunningOperation
            {
                OperationName = operationName,
                OperationLink = longRunningResponse.OperationStatusLink ?? string.Empty,
                RetryAfter    = TimeSpan.FromSeconds(longRunningResponse.RetryAfter)
            };

            var tenantConfigurationLongRunningResponse = longRunningResponse as TenantConfigurationLongRunningOperationResponse;

            if (tenantConfigurationLongRunningResponse != null && tenantConfigurationLongRunningResponse.OperationResult != null)
            {
                result.OperationResult = new PsApiManagementOperationResult(tenantConfigurationLongRunningResponse.OperationResult);
            }

            return(result);
        }
 protected void WriteProgress(TenantConfigurationLongRunningOperation operation)
 {
     WriteProgress(new ProgressRecord(0, operation.OperationName, operation.Status.ToString()));
 }