public void OnTransactionExecutionFailed(OperationExecutionResult errorCode, string error)
        {
            State = OperationExecutionState.Failed;

            TransactionFinishMoment = DateTime.UtcNow;

            Result = errorCode;
            Error  = error;
        }
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices"
        public async Task <IHttpResponseMessageAbstraction> ListCloudServices()
        {
            OperationExecutionResult <IHttpResponseMessageAbstraction> result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessListCloudServices(this.CreateClient()),
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
            }

            return(result.ExecutionOutput);
        }
Exemple #3
0
        public static OperationExecutionErrorCode MapToOperationExecutionErrorCode(this OperationExecutionResult source)
        {
            switch (source)
            {
            case OperationExecutionResult.UnknownError:
                return(OperationExecutionErrorCode.Unknown);

            case OperationExecutionResult.AmountIsTooSmall:
                return(OperationExecutionErrorCode.AmountTooSmall);

            case OperationExecutionResult.RebuildingRejected:
                return(OperationExecutionErrorCode.RebuildingRejected);

            default:
                throw new ArgumentOutOfRangeException(nameof(source), source, null);
            }
        }
Exemple #4
0
        internal async Task <IHttpResponseMessageAbstraction> PerformRequest()
        {
            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
                OperationExecutionResult <IHttpResponseMessageAbstraction> result = await
                                                                                    OperationExecutor.ExecuteOperationWithRetry(
                    () => this.DoClientSend(factory.Create()),
                    this.GetRetryPolicy(),
                    new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token),
                    new Logger());

                if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted && result.ExecutionOutput.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content, result.Attempts, result.TotalTime);
                }

                return(result.ExecutionOutput);
            }
        }
Exemple #5
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="args">List of arguments</param>
        /// <param name="operationResult">Operation result to write in</param>
        /// <param name="helpFormatter">Formatter object in case we need to write help</param>
        internal void ExecuteInternal(string[] args, OperationExecutionResult operationResult, IHelpFormatter helpFormatter = null)
        {
            var parsedArguments = ValidateInternal(args, operationResult);

            if (!operationResult.Valid)
            {
                CommandParser.PrintHelpInternal(Configuration, this, helpFormatter, operationResult.Messages);
                return;
            }

            try
            {
                operationResult.Messages.Add(new Operation.Messages.Progress(String.Format(Resources.ExecutingCommand, Name)));

                // Create instance of reflected type
                var target = (object)null;
                if (!MethodInfo.IsStatic)
                {
                    // No check, if it crashes it crashes
                    operationResult.Messages.Add(new Operation.Messages.Warning(String.Format(Resources.CreatingDefaultInstance, MethodInfo.DeclaringType)));
                    target = Activator.CreateInstance(MethodInfo.DeclaringType, true);
                }

                // Get values
                var allParameters = SystemParameters.Concat(Parameters).OrderBy(i => i.ParameterInfo.Position);
                var values        = allParameters.Select(i =>
                {
                    if (typeof(InputArguments).GetTypeInfo().IsAssignableFrom(i.ParameterInfo.ParameterType))
                    {
                        return(parsedArguments);
                    }
                    else if (typeof(OperationResult).GetTypeInfo().IsAssignableFrom(i.ParameterInfo.ParameterType))
                    {
                        return(operationResult);
                    }
                    else if (typeof(Array).GetTypeInfo().IsAssignableFrom(i.ParameterInfo.ParameterType))
                    {
                        var finalType   = i.ParameterInfo.ParameterType.GetElementType();
                        var objectArray = parsedArguments.GetValue(i)
                                          .Select(j => Convert.ChangeType(j, finalType))
                                          .ToArray();
                        var arr = Array.CreateInstance(finalType, objectArray.Length);
                        Array.Copy(objectArray, arr, objectArray.Length);
                        return(arr);
                    }
                    else
                    {
                        return(Convert.ChangeType(parsedArguments.GetValue(i)[0], i.ParameterInfo.ParameterType));
                    }
                })
                                    .ToArray();

                operationResult.Output = MethodInfo.Invoke(target, values);
            }
            catch (Exception e)
            {
                throw new CommandLineEngineException(Resources.ErrorExecutingCommand, operationResult, e);
            }
            finally
            {
                CommandParser.PrintDebug(operationResult.Messages);
            }
        }