public async Task <ActionResult <string> > Get(int id)
        {
            /*
             * try {
             *  //using var p = new RequestResponsePair<GetConfigurationRequest, GetConfigurationResponse>();
             *  //var response2 = await p.ExecuteAsync(
             *  //    new GetConfigurationRequest(),
             *  //    this._MedaitorAccess,
             *  //    null,
             *  //    this.HttpContext.RequestAborted
             *  //    );
             *  var request = new GetConfigurationRequest();
             *  var medaitorAccess = this._MedaitorAccess;
             *  using var client = medaitorAccess.GetMedaitorClient();
             *  using var connected = await client.ConnectAsync(request, this.HttpContext.RequestAborted);
             *  var response = await connected.WaitForAsync(null, this.HttpContext.RequestAborted);
             *  return response.ConvertResponseToActionResult<GetConfigurationResponse, string>((r) => r.Result?.FirstOrDefault());
             * } catch (System.Exception error) {
             *  return this.StatusCode(500, error.Message);
             * }
             */
            var request = new GetConfigurationRequest();

            return(await RequestResponseHelper <GetConfigurationRequest, GetConfigurationResponse> .
                   ExecuteToActionResultAsync <string>(
                       this.GetMedaitorClient(),
                       ActivityId.NewId(),
                       request,
                       (r) => r.Result?.FirstOrDefault(),
                       null,
                       this.HttpContext.RequestAborted
                       ));
        }
Ejemplo n.º 2
0
        public async Task Medaitor_9Monitor()
        {
            var servicesWebApp   = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var servicesMediator = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            servicesWebApp.AddLatransMedaitor()
            .AddActivityHandler <TestActivityHandler5>()
            .Build();

            ActivityId activityId = ActivityId.NewId();

            using (var serviceProviderMediator = servicesMediator.BuildServiceProvider()) {
                using (var serviceProviderWebApp = servicesWebApp.BuildServiceProvider()) {
                    using (var scopeWebApp2 = serviceProviderWebApp.CreateScope()) {
                        var scopedProviderWebApp2 = scopeWebApp2.ServiceProvider;
                        var medaitorClient2       = scopedProviderWebApp2.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();


                        using (var scopeWebApp1 = serviceProviderWebApp.CreateScope()) {
                            var scopedProviderWebApp1 = scopeWebApp1.ServiceProvider;
                            var medaitorClient1       = scopedProviderWebApp1.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();

                            var activityExecutionConfiguration1 = scopedProviderWebApp1.GetRequiredService <ActivityExecutionConfigurationDefaults>().ForQueryCancelable;
                            var request5 = new TestRequest5()
                            {
                                A = 6, B = 7
                            };
                            var connectedClient = await medaitorClient1.ConnectAsync(
                                activityId,
                                request5,
                                activityExecutionConfiguration1,
                                CancellationToken.None);

                            //

                            //medaitorClient2.
                            //
                            var activityResponse = await connectedClient.WaitForAsync(activityExecutionConfiguration1, CancellationToken.None);

                            Assert.NotNull(activityResponse);
                            Assert.NotNull(activityResponse as OkResultActivityResponse <TestResponse5>);
                            Assert.Equal(6 * 7 + 1, ((OkResultActivityResponse <TestResponse5>)activityResponse).Result.R);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public async Task Medaitor_4WaitForAsync()
        {
            var servicesWebApp   = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var servicesMediator = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            servicesWebApp.AddLatransMedaitor()
            .AddActivityHandler <TestActivityHandler1>()
            .AddActivityHandler <TestActivityHandler2>()
            .Build();

            ActivityId activityId = ActivityId.NewId();

            using (var serviceProviderMediator = servicesMediator.BuildServiceProvider()) {
                using (var serviceProviderWebApp = servicesWebApp.BuildServiceProvider()) {
                    using (var scopeWebApp = serviceProviderWebApp.CreateScope()) {
                        var scopedProviderWebApp = scopeWebApp.ServiceProvider;
                        var medaitorClient       = scopedProviderWebApp.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();

                        var activityExecutionConfiguration = scopedProviderWebApp.GetRequiredService <ActivityExecutionConfigurationDefaults>().ForQueryCancelable;
                        var request = new TestRequest1()
                        {
                            A = 6, B = 7
                        };
                        var connectedClient = await medaitorClient.ConnectAndSendAsync(
                            activityId,
                            request,
                            activityExecutionConfiguration,
                            CancellationToken.None);

                        var activityResponse = await connectedClient.WaitForAsync(activityExecutionConfiguration, CancellationToken.None);

                        var status = await connectedClient.GetStatusAsync();

                        Assert.Equal(ActivityStatus.Completed, status.Status);
                        Assert.NotNull(activityResponse);
                        Assert.NotNull(activityResponse as OkResultActivityResponse <TestResponse1>);
                        Assert.Equal(6 * 7 + 1, ((OkResultActivityResponse <TestResponse1>)activityResponse).Result.R);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public async Task Medaitor_3ConnectAsync()
        {
            var servicesWebApp   = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var servicesMediator = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            servicesWebApp.AddLatransMedaitor()
            .AddActivityHandler <TestActivityHandler1>()
            .AddActivityHandler <TestActivityHandler2>()
            .Build();

            IMediatorClientConnected <TestRequest1> connectedClient = null;
            MediatorClientConnected <TestRequest1, TestResponse1> testConnectedClient = null;

            using (var serviceProviderMediator = servicesMediator.BuildServiceProvider()) {
                using (var serviceProviderWebApp = servicesWebApp.BuildServiceProvider()) {
                    using (var scopeWebApp = serviceProviderWebApp.CreateScope()) {
                        var scopedProviderWebApp = scopeWebApp.ServiceProvider;
                        var medaitorClient       = scopedProviderWebApp.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();

                        var request = new TestRequest1()
                        {
                            A = 6, B = 7
                        };
                        connectedClient = await medaitorClient.ConnectAndSendAsync(
                            ActivityId.NewId(),
                            request,
                            null,
                            CancellationToken.None);

                        Assert.False(connectedClient.GetActivityContext().IsDisposed);
                        Assert.NotNull(connectedClient);
                        testConnectedClient = (MediatorClientConnected <TestRequest1, TestResponse1>)connectedClient;
                        Assert.False(testConnectedClient.IsDisposed());
                    }
                }
            }
            Assert.True(testConnectedClient.IsDisposed());
        }
        public async Task <ActionResult <IEnumerable <string> > > Get()
        {
#if false
            try {
                var medaitorClient = this._MedaitorAccess.GetMedaitorClient();
                var arguments      = new GetConfigurationRequest();
                var ctxt           = medaitorClient.CreateContextByRequest(arguments);
                await medaitorClient.ExecuteAsync(ctxt, null, this.HttpContext.RequestAborted);

                return(ctxt.ReturnAsActionResult <IEnumerable <string> >());
            } catch (System.Exception error) {
                return(this.StatusCode(500, error.Message));
            }
            try {
                var request = new GetConfigurationRequest();
                using var client    = this._MedaitorAccess.GetMedaitorClient();
                using var connected = await client.ConnectAsync(request, this.HttpContext.RequestAborted);

                var response = await connected.WaitForAsync(null, this.HttpContext.RequestAborted);

                return(response.ConvertResponseToActionResult <GetConfigurationResponse, IEnumerable <string> >((r) => r.Result));
            } catch (System.Exception error) {
                return(this.StatusCode(500, error.Message));
            }
#endif
            var request = new GetConfigurationRequest();


            return(await RequestResponseHelper <GetConfigurationRequest, GetConfigurationResponse> .
                   ExecuteToActionResultAsync <IEnumerable <string> >(
                       this.GetMedaitorClient(),
                       ActivityId.NewId(),
                       request,
                       (r) => r.Result,
                       null, //ActivityWaitForSpecification.,
                       this.HttpContext.RequestAborted
                       ));
        }
Ejemplo n.º 6
0
            public override async Task ExecuteAsync(
                IActivityContext <TestRequest1> activityContext,
                CancellationToken cancellationToken)
            {
                var request  = activityContext.Request;
                var request2 = new TestRequest2()
                {
                    A = request.A, B = request.B
                };
                ActivityId activityId = ActivityId.NewId();

                using var connectedClient = await activityContext.ConnectAndSendAsync(
                          activityId,
                          request2,
                          null,   // activityExecutionConfiguration,
                          cancellationToken);

                var response2 = await connectedClient.WaitForAsync(null, cancellationToken);

                if (response2.TryGetResult <TestResponse2>(out var result2))
                {
                    var response = new TestResponse1()
                    {
                        R = result2.R + 1
                    };
                    await this.SetResponseAsync(activityContext, response);

                    return;
                }
                else
                {
                    await activityContext.SetActivityResponseAsync(response2);

                    return;
                }
            }
Ejemplo n.º 7
0
        public async Task Medaitor_6Cancel()
        {
            var servicesWebApp   = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var servicesMediator = new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            servicesWebApp.AddLatransMedaitor()
            .AddActivityHandler <TestActivityHandler6>()
            .Build();

            ActivityId activityId = ActivityId.NewId();

            using (var serviceProviderMediator = servicesMediator.BuildServiceProvider()) {
                using (var serviceProviderWebApp = servicesWebApp.BuildServiceProvider()) {
                    using (var scopeWebApp1 = serviceProviderWebApp.CreateScope()) {
                        var scopedProviderWebApp1 = scopeWebApp1.ServiceProvider;
                        var medaitorClient1       = scopedProviderWebApp1.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();

                        using (var scopeWebApp2 = serviceProviderWebApp.CreateScope()) {
                            var scopedProviderWebApp2 = scopeWebApp2.ServiceProvider;
                            var medaitorClient2       = scopedProviderWebApp2.GetRequiredService <IMediatorClientFactory>().GetMedaitorClient();

                            var activityExecutionConfiguration1 = scopedProviderWebApp2.GetRequiredService <ActivityExecutionConfigurationDefaults>().ForQueryCancelable;
                            var request6 = new TestRequest6()
                            {
                                A = 6, B = 7
                            };
                            var cts = new CancellationTokenSource();
                            var taskConnectedClient1 = medaitorClient1.ConnectAndSendAsync(
                                activityId,
                                request6,
                                activityExecutionConfiguration1,
                                cts.Token);
                            //

                            var connectedClient2 = await medaitorClient2.ConnectAsync(activityId, CancellationToken.None);

                            var status = await connectedClient2.GetStatusAsync();

                            Assert.Equal(ActivityStatus.Running, status.Status);
                            cts.Cancel();
                            IMediatorClientConnected <TestRequest6> connectedClient1;
                            try {
                                connectedClient1 = await taskConnectedClient1;
                            } catch {
                                connectedClient1 = null;
                            }
                            //
                            if (connectedClient1 is null)
                            {
                                //
                            }
                            else
                            {
                                var activityResponse = await connectedClient1.WaitForAsync(activityExecutionConfiguration1, CancellationToken.None);

                                Assert.NotNull(activityResponse);
                                Assert.True(activityResponse is CanceledActivityResponse);
                            }
                        }
                    }
                }
            }
        }