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

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

            var result = new ApiManagementLongRunningOperation
            {
                OperationName = operationName,
                OperationLink = longRunningResponse.OperationStatusLink,
                RetryAfter = TimeSpan.FromSeconds(longRunningResponse.RetryAfter),
                Status = longRunningResponse.Status,
                Error = longRunningResponse.Error != null
                    ? longRunningResponse.Error.Message
                    : null
            };

            var apiServiceLongRunnigResponse = longRunningResponse as ApiServiceLongRunningOperationResponse;
            if (apiServiceLongRunnigResponse != null && apiServiceLongRunnigResponse.Value != null)
            {
                result.ApiManagement = new PsApiManagement(apiServiceLongRunnigResponse.Value);
            }

            return result;
        }
 private static void AdjustRetryAfter(LongRunningOperationResponse longrunningResponse, int longRunningOperationInitialTimeout)
 {
     if (longRunningOperationInitialTimeout >= 0)
     {
         longrunningResponse.RetryAfter = longRunningOperationInitialTimeout;
     }
 }