private static int Execute(CommonOptions commonOptions,
            string from,
            string to,
            string output,
            bool idempotent,
            string context,
            string environment)
        {
            var sql = new OperationExecutor(commonOptions, environment)
                .ScriptMigration(from, to, idempotent, context);

            if (string.IsNullOrEmpty(output))
            {
                ConsoleCommandLogger.Output(sql);
            }
            else
            {
                ConsoleCommandLogger.Verbose("Writing SQL script to '" + output + "'".Bold().Black());
                File.WriteAllText(output, sql, Encoding.UTF8);

                ConsoleCommandLogger.Output("Done");
            }

            return 0;
        }
Пример #2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ScaffoldContext" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>connectionString</c>--The connection string to the database.</para>
        ///     <para><c>provider</c>--The provider to use.</para>
        ///     <para><c>outputDir</c>--The directory to put files in. Paths are relative to the project directory.</para>
        ///     <para><c>outputDbContextDir</c>--The directory to put DbContext file in. Paths are relative to the project directory.</para>
        ///     <para><c>dbContextClassName</c>--The name of the DbContext to generate.</para>
        ///     <para><c>schemaFilters</c>--The schemas of tables to generate entity types for.</para>
        ///     <para><c>tableFilters</c>--The tables to generate entity types for.</para>
        ///     <para><c>useDataAnnotations</c>--Use attributes to configure the model (where possible). If false, only the fluent API is used.</para>
        ///     <para><c>overwriteFiles</c>--Overwrite existing files.</para>
        ///     <para><c>useDatabaseNames</c>--Use table and column names directly from the database.</para>
        ///     <para><c>modelNamespace</c>--Specify to override the namespace of the generated entity types.</para>
        ///     <para><c>contextNamespace</c>--Specify to override the namespace of the generated DbContext class.</para>
        ///     <para><c>noPluralize</c>--Don't use the pluralizer.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public ScaffoldContext(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var connectionString      = (string)args["connectionString"] !;
            var provider              = (string)args["provider"] !;
            var outputDir             = (string?)args["outputDir"];
            var outputDbContextDir    = (string?)args["outputDbContextDir"];
            var dbContextClassName    = (string?)args["dbContextClassName"];
            var schemaFilters         = (IEnumerable <string>)args["schemaFilters"] !;
            var tableFilters          = (IEnumerable <string>)args["tableFilters"] !;
            var modelNamespace        = (string?)args["modelNamespace"];
            var contextNamespace      = (string?)args["contextNamespace"];
            var useDataAnnotations    = (bool)args["useDataAnnotations"] !;
            var overwriteFiles        = (bool)args["overwriteFiles"] !;
            var useDatabaseNames      = (bool)args["useDatabaseNames"] !;
            var suppressOnConfiguring = (bool)(args["suppressOnConfiguring"] ?? false);
            var noPluralize           = (bool)(args["noPluralize"] ?? false);

            Execute(
                () => executor.ScaffoldContextImpl(
                    provider, connectionString, outputDir, outputDbContextDir, dbContextClassName,
                    schemaFilters, tableFilters, modelNamespace, contextNamespace, useDataAnnotations,
                    overwriteFiles, useDatabaseNames, suppressOnConfiguring, noPluralize));
        }
Пример #3
0
        public async Task TaskCanceledByUserShouldNotRetry()
        {
            try
            {
                this.AddHttpResponse(new HttpResponseMessageAbstraction(HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), "<Okay />"));
                var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
                using (CancellationTokenSource source = new CancellationTokenSource())
                {
                    var context = new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token);
                    source.Cancel();
                    var val = await
                              OperationExecutor.ExecuteOperationWithRetry(
                        () => this.DoClientSend(factory.Create()),
                        this.GetRetryPolicy(),
                        context,
                        new Logger());

                    Assert.IsNotNull(val.ExecutionOutput);
                }
                Assert.Fail("Should have thrown an operation cancelled exception");
            }
            catch (OperationCanceledException tex)
            {
                Assert.IsNotNull(tex.CancellationToken);
                Assert.IsTrue(tex.CancellationToken.IsCancellationRequested);
            }
        }
        private static int Execute(CommonOptions commonOptions,
            string environment,
            Action<IEnumerable<Type>> reportResultsAction)
        {
            var contextTypes = new OperationExecutor(commonOptions, environment)
                .GetContextTypes();

            reportResultsAction(contextTypes);

            return 0;
        }
Пример #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GetContextTypes" /> class.
        /// </summary>
        /// <remarks>
        ///     No arguments are currently supported by <paramref name="args" />.
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public GetContextTypes(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            Execute(executor.GetContextTypesImpl);
        }
        private static int Execute(CommonOptions commonOptions,
            string context,
            string environment,
            Action<IEnumerable<MigrationInfo>> reportResultsAction)
        {
            var migrations = new OperationExecutor(commonOptions, environment)
                .GetMigrations(context);

            reportResultsAction(migrations);

            return 0;
        }
Пример #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ScriptDbContext" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public ScriptDbContext(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var contextType = (string?)args["contextType"];

            Execute(() => executor.ScriptDbContextImpl(contextType));
        }
Пример #8
0
        public SwitchOperationsToDifferentDatabase()
        {
            using (var documentStore = new DocumentStore())
            {
                #region for_database_3
                OperationExecutor operations = documentStore.Operations.ForDatabase("otherDatabase");
                #endregion

                #region for_database_4
                MaintenanceOperationExecutor maintenanceOperations = documentStore.Maintenance.ForDatabase("otherDatabase");
                #endregion
            }
        }
Пример #9
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="RemoveMigration" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        ///     <para><c>force</c>--Don't check to see if the migration has been applied to the database.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public RemoveMigration(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var contextType = (string?)args["contextType"];
            var force       = (bool)args["force"] !;

            Execute(() => executor.RemoveMigrationImpl(contextType, force));
        }
        // Method = "GET", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/~/{resourceType}/{resourceName}"
        public async Task <IHttpResponseMessageAbstraction> GetClusterResourceDetail(string resourceId, string resourceType, string location)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessGetClusterResourceDetail(this.CreateClient(), resourceId, resourceType, location),
                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);
        }
Пример #11
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="OptimizeContext" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>outputDir</c>--The directory to put files in. Paths are relative to the project directory.</para>
        ///     <para><c>modelNamespace</c>--Specify to override the namespace of the generated model.</para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public OptimizeContext(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var outputDir      = (string?)args["outputDir"];
            var modelNamespace = (string?)args["modelNamespace"];
            var contextType    = (string?)args["contextType"];

            Execute(() => executor.OptimizeContextImpl(outputDir, modelNamespace, contextType));
        }
Пример #12
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="GetMigrations" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        ///     <para>
        ///         <c>connectionString</c>--The connection string to the database. Defaults to the one specified in
        ///         <see cref="O:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext" /> or
        ///         <see cref="DbContext.OnConfiguring" />.
        ///     </para>
        ///     <para><c>noConnect</c>--Don't connect to the database.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public GetMigrations(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var contextType      = (string?)args["contextType"];
            var connectionString = (string?)args["connectionString"];
            var noConnect        = (bool)(args["noConnect"] ?? true);

            Execute(() => executor.GetMigrationsImpl(contextType, connectionString, noConnect));
        }
        // Method = "PUT", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> CreateContainer(string dnsName, string location, string clusterPayload, int schemaVersion = 2)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                    () => this.CreateResource(this.CreateClient(), dnsName, "containers", location, clusterPayload, schemaVersion),
                    this.context.RetryPolicy,
                    this.context,
                    this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content) { HelpLink = HelpLinkForException };
            }

            return result.ExecutionOutput;
        }
        // Method = "DELETE", UriTemplate = "{subscriptionId}/cloudservices/{cloudServiceName}/resources/{resourceProviderNamespace}/{resourceType}/{resourceName}"
        public async Task<IHttpResponseMessageAbstraction> DeleteContainer(string dnsName, string location)
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                    () => this.ProcessDeleteContainer(this.CreateClient(), dnsName, location),
                    this.context.RetryPolicy,
                    this.context,
                    this.context.Logger);

            if (result.ExecutionOutput.StatusCode != HttpStatusCode.Accepted)
            {
                throw new HttpLayerException(result.ExecutionOutput.StatusCode, result.ExecutionOutput.Content) { HelpLink = HelpLinkForException };
            }

            return result.ExecutionOutput;
        }
        // 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;
        }
Пример #16
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="UpdateDatabase" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para>
        ///         <c>targetMigration</c>--The target <see cref="Migration" />. If <see cref="Migration.InitialDatabase" />, all migrations will be
        ///         reverted. Defaults to the last migration.
        ///     </para>
        ///     <para>
        ///         <c>connectionString</c>--The connection string to the database. Defaults to the one specified in
        ///         <see cref="O:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext" /> or
        ///         <see cref="DbContext.OnConfiguring" />.
        ///     </para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public UpdateDatabase(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var targetMigration  = (string?)args["targetMigration"];
            var connectionString = (string?)args["connectionString"];
            var contextType      = (string?)args["contextType"];

            Execute(() => executor.UpdateDatabaseImpl(targetMigration, connectionString, contextType));
        }
Пример #17
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="AddMigration" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>name</c>--The name of the migration.</para>
        ///     <para>
        ///         <c>outputDir</c>--The directory (and sub-namespace) to use. Paths are relative to the project directory. Defaults to
        ///         "Migrations".
        ///     </para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> type to use.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public AddMigration(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var name        = (string)args["name"] !;
            var outputDir   = (string?)args["outputDir"];
            var contextType = (string?)args["contextType"];
            var @namespace  = (string?)args["namespace"];

            Execute(() => executor.AddMigrationImpl(name, outputDir, contextType, @namespace));
        }
        private static int Execute(CommonOptions commonOptions,
            string name,
            string outputDir,
            string context,
            string environment,
            Action<MigrationFiles> reporter)
        {
            var files = new OperationExecutor(commonOptions, environment)
                .AddMigration(name, outputDir, context);

            reporter?.Invoke(files);

            ConsoleCommandLogger.Output("Done. To undo this action, use 'dotnet ef migrations remove'");

            return 0;
        }
        // Method = "GET", UriTemplate = "/{subscriptionId}/cloudservices/{cloudServiceName}/resources/{deploymentNamespace}/~/containers/{containerName}/users/operations/{operationId}",
        public async Task <IHttpResponseMessageAbstraction> GetOperationStatus(string dnsName, string location, Guid operationId)
        {
            var start  = DateTime.UtcNow;
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () => this.ProcessGetOperationStatus(this.CreateClient(), dnsName, location, operationId),
                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);
        }
Пример #20
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ScriptMigration" /> class.
        /// </summary>
        /// <remarks>
        ///     <para>The arguments supported by <paramref name="args" /> are:</para>
        ///     <para><c>fromMigration</c>--The starting migration. Defaults to <see cref="Migration.InitialDatabase" />.</para>
        ///     <para><c>toMigration</c>--The ending migration. Defaults to the last migration.</para>
        ///     <para><c>idempotent</c>--Generate a script that can be used on a database at any migration.</para>
        ///     <para><c>noTransactions</c>--Don't generate SQL transaction statements.</para>
        ///     <para><c>contextType</c>--The <see cref="DbContext" /> to use.</para>
        /// </remarks>
        /// <param name="executor">The operation executor.</param>
        /// <param name="resultHandler">The <see cref="IOperationResultHandler" />.</param>
        /// <param name="args">The operation arguments.</param>
        public ScriptMigration(
            OperationExecutor executor,
            IOperationResultHandler resultHandler,
            IDictionary args)
            : base(resultHandler)
        {
            Check.NotNull(executor, nameof(executor));
            Check.NotNull(args, nameof(args));

            var fromMigration  = (string?)args["fromMigration"];
            var toMigration    = (string?)args["toMigration"];
            var idempotent     = (bool)args["idempotent"] !;
            var noTransactions = (bool)(args["noTransactions"] ?? false);
            var contextType    = (string?)args["contextType"];

            Execute(() => executor.ScriptMigrationImpl(fromMigration, toMigration, idempotent, noTransactions, contextType));
        }
Пример #21
0
        public IHttpActionResult Operation([FromBody] OperationMessage operationMessage)
        {
            OperationConstructor constructor = new OperationConstructor(operationMessage);
            Operation            operation   = constructor.CreateOperation();

            OperationExecutor     executor     = OperationExecutor.GetInstance();
            EngineOperationResult engineResult = executor.ExecuteOperation(operation);

            if (engineResult.isSuccessful())
            {
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        public MainWindow()
        {
            inputValidator    = new InputValidator();
            memory            = new Memory();
            operationExecutor = new OperationExecutor();
            outputFormatter   = new OutputFormatter();

            InitializeComponent();

            this.PaddingTopGrid.MouseDown += new MouseButtonEventHandler(this.DragMoveWindow);
            this.ToolbarGrid.MouseDown    += new MouseButtonEventHandler(this.DragMoveWindow);

            this.btnMinimize.MouseDown += new MouseButtonEventHandler(this.MinimizeWindow);
            this.btnClose.MouseDown    += new MouseButtonEventHandler(this.CloseWindow);

            this.btnOne.Click   += new RoutedEventHandler(this.AppendCharacter);
            this.btnTwo.Click   += new RoutedEventHandler(this.AppendCharacter);
            this.btnThree.Click += new RoutedEventHandler(this.AppendCharacter);
            this.btnFour.Click  += new RoutedEventHandler(this.AppendCharacter);
            this.btnFive.Click  += new RoutedEventHandler(this.AppendCharacter);
            this.btnSix.Click   += new RoutedEventHandler(this.AppendCharacter);
            this.btnSeven.Click += new RoutedEventHandler(this.AppendCharacter);
            this.btnEight.Click += new RoutedEventHandler(this.AppendCharacter);
            this.btnNine.Click  += new RoutedEventHandler(this.AppendCharacter);
            this.btnZero.Click  += new RoutedEventHandler(this.AppendCharacter);
            this.btnDot.Click   += new RoutedEventHandler(this.AppendCharacter);

            this.btnDel.Click += new RoutedEventHandler(this.RemoveCharacter);
            this.btnCE.Click  += new RoutedEventHandler(this.ClearInput);
            this.btnC.Click   += new RoutedEventHandler(this.ClearAll);

            this.btnResult.Click     += new RoutedEventHandler(this.CalculateResult);
            this.btnChangeSign.Click += new RoutedEventHandler(this.ChangeSign);

            this.btnMC.Click += new RoutedEventHandler(this.SetMemoryState);
            this.btnMS.Click += new RoutedEventHandler(this.SetMemoryState);
            this.btnMR.Click += new RoutedEventHandler(this.SetMemoryState);

            this.btnAdd.Click        += new RoutedEventHandler(this.SetOperation);
            this.btnSubtract.Click   += new RoutedEventHandler(this.SetOperation);
            this.btnMultiply.Click   += new RoutedEventHandler(this.SetOperation);
            this.btnDivide.Click     += new RoutedEventHandler(this.SetOperation);
            this.btnInvert.Click     += new RoutedEventHandler(this.SetOperation);
            this.btnSquareRoot.Click += new RoutedEventHandler(this.SetOperation);
        }
Пример #23
0
        // Method = "GET", UriTemplate = "UriTemplate = "{subscriptionId}/resourceproviders/{resourceProviderNamespace}/Properties?resourceType={resourceType}"
        public async Task <IEnumerable <KeyValuePair <string, string> > > GetResourceProviderProperties()
        {
            var result = await OperationExecutor.ExecuteOperationWithRetry(
                () =>
            {
                Task <IHttpResponseMessageAbstraction> retval = this.ProcessGetResourceProviderPropertiesRequest(this.CreateClient());
                var x = retval.Result;
                if (x.StatusCode != HttpStatusCode.Accepted && x.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpLayerException(x.StatusCode, x.Content);
                }
                return(retval);
            },
                this.context.RetryPolicy,
                this.context,
                this.context.Logger);

            return(this.ParseCapabilities(result.ExecutionOutput.Content));
        }
Пример #24
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);
            }
        }
Пример #25
0
        public async Task TimeOutExceptionOnTheHttpCallShouldRetry()
        {
            var factory = ServiceLocator.Instance.Locate <IHttpClientAbstractionFactory>();
            OperationExecutionResult <IHttpResponseMessageAbstraction> response;

            using (CancellationTokenSource source = new CancellationTokenSource())
            {
                this.AddHttpException(new TimeoutException("The Operation Timed Out"));
                this.AddHttpResponse(new HttpResponseMessageAbstraction(HttpStatusCode.Accepted, new HttpResponseHeadersAbstraction(), "<Okay />"));
                response =
                    await
                    OperationExecutor.ExecuteOperationWithRetry(
                        () => this.DoClientSend(factory.Create()),
                        this.GetRetryPolicy(),
                        new HDInsightSubscriptionAbstractionContext(GetValidCredentials(), source.Token),
                        new Logger());
            }
            Assert.AreEqual(2, this.attempts);
            Assert.AreEqual(0, this.responses.Count);
            Assert.AreEqual(HttpStatusCode.Accepted, response.ExecutionOutput.StatusCode);
            Assert.AreEqual("<Okay />", response.ExecutionOutput.Content);
        }
Пример #26
0
        public IHttpActionResult Operation([FromBody] OperationMessage operationMessage)
        {
            if (operationMessage != null && operationMessage.isValid())
            {
                OperationConstructor constructor = new OperationConstructor(operationMessage);
                Operation            operation   = constructor.CreateOperation();
                OperationExecutor    executor    = OperationExecutor.GetInstance();

                EngineOperationResult engineResult = executor.ExecuteOperation(operation);

                if (engineResult.isSuccessful())
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest("Bad operation"));
                }
            }
            else
            {
                return(BadRequest("Wrong Json Format"));
            }
        }
Пример #27
0
 public void ProcessOperation()
 {
     lock (_locker)
     {
         while (OperationsToExecute.Any())
         {
             IOperation currentOperation;
             OperationsToExecute.TryDequeue(out currentOperation);
             if (currentOperation != null)
             {
                 try
                 {
                     LoggingService.LogInfo(currentOperation, String.Format(Resources.Executing_operation__id));
                     OperationExecutor.Execute(currentOperation);
                     LoggingService.LogInfo(currentOperation, String.Format(Resources.Operation_executed_without_errors));
                 }
                 catch (Exception ex)
                 {
                     LoggingService.LogException(ex, currentOperation, String.Format("Error during execution of operation"));
                 }
             }
         }
     }
 }
        private void TestWatcher()
        {
            var operation = TabController.ConfigurationService.GetOperation(TabController.Configuration, Watcher.WatcherData);

            OperationExecutor.Execute(operation);
        }
Пример #29
0
 public SynchronousFiber(OperationExecutor executor)
 {
     _executor = executor;
 }
Пример #30
0
		public SynchronousFiber(OperationExecutor executor)
		{
			_executor = executor;
		}
Пример #31
0
 public PoolFiber(OperationExecutor executor)
 {
     _executor = executor;
 }
Пример #32
0
 public PoolFiber(OperationExecutor executor)
 {
     _executor = executor;
 }
Пример #33
0
 public ThreadFiber(OperationExecutor executor)
 {
     _executor = executor;
     _thread   = CreateThread();
     _thread.Start();
 }
Пример #34
0
 public ThreadFiber(OperationExecutor executor)
 {
     _executor = executor;
     _thread = CreateThread();
     _thread.Start();
 }
Пример #35
0
        public async Task Foo()
        {
            var entityStore    = new EntityStore();
            var operationStore = new OperationStore(entityStore.Watch());

            var connection = new MockConnection();

            var humanMapper = new HumanMapper();
            var droidMapper = new DroidMapper();

            var humanHeroMapper = new HumanHeroMapper(
                entityStore,
                humanMapper,
                droidMapper);

            var droidHeroMapper = new DroidHeroMapper(
                entityStore,
                humanMapper,
                droidMapper);

            var resultDataFactory = new GetHeroResultFactory(
                entityStore,
                humanHeroMapper,
                droidHeroMapper);

            var resultBuilder = new GetHeroResultBuilder(
                entityStore,
                ExtractEntityId,
                resultDataFactory,
                new SerializerResolver(new[] { new StringSerializer() }));

            var operationExecutor = new OperationExecutor <JsonDocument, GetHeroResult>(
                connection,
                () => resultBuilder,
                operationStore,
                ExecutionStrategy.NetworkOnly);

            GetHeroResult?result = null;
            var           query  = new GetHeroQuery(operationExecutor);

            query.Watch().Subscribe(c =>
            {
                result = c.Data;
            });

            await Task.Delay(1000);

            using (entityStore.BeginUpdate())
            {
                DroidEntity entity = entityStore.GetOrCreate <DroidEntity>(new EntityId("Droid", "abc"));
                entity.Name = "C3-PO";
            }

            await Task.Delay(1000);

            Assert.NotNull(result);

            EntityId ExtractEntityId(JsonElement obj) =>
            new(
                obj.GetProperty("__typename").GetString() !,
                obj.GetProperty("id").GetString() !);
        }