コード例 #1
0
        public async Task <IActionResult> SignUp([FromBody] SignUpUserCommand command)
        {
            var result = await _dispatcher.DispatchAsync(command);

            if (result.Succeeded)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
コード例 #2
0
        public async Task <APIGatewayProxyResponse> ApiGatewayProxyInvocation(APIGatewayProxyRequest apiGatewayProxyRequest, ILambdaContext context)
        {
            var targetVerbosity = Verbosity.Silent;

            if (apiGatewayProxyRequest.StageVariables.ContainsKey("verbosity"))
            {
                Enum.TryParse(apiGatewayProxyRequest.StageVariables["verbosity"], out targetVerbosity);
            }
            _lambdaLogger.Verbosity = targetVerbosity;
            _lambdaLogger.LogDebug(() => "Invoked!");
            _lambdaLogger.LogDebug(() => ApiGatewayProxyHelpers.ProxyRequestToString(apiGatewayProxyRequest));
            try
            {
                var restRequest  = CreateRestRequest(apiGatewayProxyRequest);
                var restResponse = await _dispatcher.DispatchAsync(restRequest, _lambdaLogger);

                return(CreateApiGatewayProxyResponse(restResponse));
            }
            catch (ArgumentException e)
            {
                return(new APIGatewayProxyResponse {
                    Body = _payloadConverter.SerializePayload(new { errorMessage = e.Message }), StatusCode = 405
                });
            }
        }
コード例 #3
0
        /// <summary>
        ///     Dispatches the specified entity
        /// </summary>
        /// <param name="dispatcher">The dispatcher in use</param>
        /// <param name="entity">The entity to dispatch</param>
        /// <param name="attributes">The attributes to send along with the message</param>
        /// <returns>A task that completes when the message has been acknowledged by the receiver</returns>
        public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, T entity, IEnumerable <KeyValuePair <string, string> > attributes)
        {
            var message = new ExtendedMessage <T> {
                Value = entity, Properties = attributes ?? Enumerable.Empty <KeyValuePair <string, string> >()
            };

            return(dispatcher.DispatchAsync(message, default));
        }
コード例 #4
0
        public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, T entity)
        {
            if (dispatcher == null)
            {
                throw new ArgumentNullException(nameof(dispatcher));
            }

            return(dispatcher.DispatchAsync(entity, TimeSpan.Zero));
        }
コード例 #5
0
ファイル: ValuesController.cs プロジェクト: huanent/Mediator
        public async Task <string> Mediator([FromQuery] TestCommand testCommand)
        {
            var sw = Stopwatch.StartNew();

            for (int i = 0; i < 1000000; i++)
            {
                await _dispatcher.DispatchAsync(testCommand);
            }
            sw.Stop();
            return(sw.Elapsed.ToString());
        }
コード例 #6
0
        protected override async Task OnCollectAsync(IDispatcher dispatcher)
        {
            var value = _counter.NextValue();
            var point = new MeasurementPoint(Name)
                        .AddTag("host", _counter.MachineName)
                        .AddField("value", (decimal)value)
                        .AddTimeStamp(SysTime.Now());

            var measurement = new PerformanceCounterMeasurement(point);

            await dispatcher.DispatchAsync(measurement).ForAwait();
        }
コード例 #7
0
        /// <summary>
        ///     Dispatches the specified entity
        /// </summary>
        /// <param name="dispatcher">The dispatcher in use</param>
        /// <param name="entity">The entity to dispatch</param>
        /// <param name="id">The id to use for the message</param>
        /// <returns>A task that completes when the message has been acknowledged by the receiver</returns>
        public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, T entity, string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                Throw.ArgumentNullException(nameof(id));
            }

            var message = new ExtendedMessage <T> {
                Value = entity, Id = id
            };

            return(dispatcher.DispatchAsync(message, default));
        }
コード例 #8
0
        /// <summary>
        ///     Dispatches the specified entity
        /// </summary>
        /// <param name="dispatcher">The dispatcher in use</param>
        /// <param name="entity">The entity to dispatch</param>
        /// <param name="attributes">The attributes to send along with the message</param>
        /// <param name="id">The id to use for the message</param>
        /// <returns>A task that completes when the message has been acknowledged by the receiver</returns>
        public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, T entity, IEnumerable <KeyValuePair <string, string> > attributes, string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                Throw.ArgumentNullException(nameof(id));
            }

            var message = new ExtendedMessage <T> {
                Value = entity, Properties = attributes ?? Enumerable.Empty <KeyValuePair <string, string> >(), Id = id
            };

            return(dispatcher.DispatchAsync(message, default));
        }
コード例 #9
0
        public HttpResponseMessage Post(SampleMeasurementRequest request)
        {
            _logger.Debug("Recieved SampleMeasurementRequest");

            var point = new MeasurementPoint(request.Name)
                        .AddTag("host", request.MachineName ?? Environment.MachineName)
                        .AddField("value", request.Value)
                        .AddTimeStamp(SysTime.Now());

            var measurement = new WebHookMeasurement(point);

            _dispatcher.DispatchAsync(measurement);

            return(Request.CreateResponse(HttpStatusCode.Created));
        }
コード例 #10
0
ファイル: RpcMiddleware.cs プロジェクト: anlei-fu/Jasmine
        public async Task ProcessRequest(RpcContext context)
        {
            var filterContext = _pool.Rent();

            filterContext.Init(context);

            try
            {
                await _dispatcher.DispatchAsync(context.Request.Path, filterContext);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            finally
            {
                _pool.Recycle(filterContext);
            }

            //if (next != null)
            //    await next(context);
        }
コード例 #11
0
        protected override async Task OnCollectAsync(IDispatcher dispatcher)
        {
            if (!_serviceNames.Any())
            {
                return;
            }

            var services = _searcher.Get();

            foreach (var service in services.Cast <ManagementObject>())
            {
                var svcName = (string)service.GetPropertyValue("Name");
                if (!_serviceNames.Contains(svcName))
                {
                    continue;
                }

                var state = service.GetPropertyValue("State") as string;

                var point = new MeasurementPoint(Name)
                            .AddTag("host", _host)
                            .AddTag("svcName", svcName)
                            .AddTag("displayName", (string)service.GetPropertyValue("DisplayName"))
                            .AddField("state", state)
                            .AddField("isRunning", state != null && state.ToLower() == "running")
                            .AddTimeStamp(SysTime.Now());

                if (_includeProcessInfo)
                {
                    AppendProcessInfo(service, point);
                }

                var measurement = new WinServiceStatusMeasurement(point);

                await dispatcher.DispatchAsync(measurement).ForAwait();
            }
        }
コード例 #12
0
 public Task Update([FromBody] Update _) => dispatcher.DispatchAsync();
コード例 #13
0
 /// <summary>
 ///     Dispatches the specified entity
 /// </summary>
 /// <param name="dispatcher">The dispatcher in use</param>
 /// <param name="message">The message to dispatch</param>
 /// <returns>A task that completes when the message has been acknowledged by the receiver</returns>
 public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, Message <T> message) => dispatcher.DispatchAsync(message, default);
コード例 #14
0
 /// <summary>
 ///     Dispatches the specified entity
 /// </summary>
 /// <param name="dispatcher">The dispatcher in use</param>
 /// <param name="entity">The entity to dispatch</param>
 /// <returns>A task that completes when the message has been acknowledged by the receiver</returns>
 public static Task DispatchAsync <T>(this IDispatcher <T> dispatcher, T entity) => dispatcher.DispatchAsync(entity, default);
コード例 #15
0
 /// <summary>
 /// Sends the message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 public Task SendMessageAsync(object message, CancellationToken cancellationToken) =>
 _dispatcher.DispatchAsync(_serviceProvider, message, cancellationToken);
コード例 #16
0
 public static Task DispatchAsync(this IDispatcher dispatcher, Func <Task> funcTask) =>
 dispatcher.DispatchAsync(async() =>
 {
     await funcTask().ConfigureAwait(false);
     return(true);
 });
コード例 #17
0
 public static Task DispatchAsync(this IDispatcher dispatcher, Action action) =>
 dispatcher.DispatchAsync(() =>
 {
     action();
     return(true);
 });
コード例 #18
0
 public async Task <IHttpActionResult> Post([FromBody] DataSetRequest request)
 {
     return(Ok(await _dispatcher.DispatchAsync(request)));
 }
コード例 #19
0
 protected async Task DispatchAsync <T>(T command) where T : ICommand
 {
     await _dispatcher.DispatchAsync(command);
 }
コード例 #20
0
ファイル: Store.cs プロジェクト: ForEvolve/StateR
 public Task DispatchAsync <TAction>(TAction action, CancellationToken cancellationToken = default) where TAction : IAction
 {
     return(_dispatcher.DispatchAsync(action, cancellationToken));
 }
コード例 #21
0
 protected async Task <Result> CommandAsync(ICommand command)
 {
     return(await _dispatcher.DispatchAsync(command));
 }
コード例 #22
0
        public async Task DispatcherWithExecutorDispatchAsync()
        {
            var request = new AwesomeRequest();

            var response = await _dispatcherWithExecutor.DispatchAsync(request, default);
        }
コード例 #23
0
        public async Task DynamicDispatcherDispatchAsync()
        {
            var request = new AwesomeRequest();

            var response = await _dynamicDispatcher.DispatchAsync(request, default);
        }
コード例 #24
0
 public override Task InvokeAsync(Action workItem)
 {
     return(_dispatcher.DispatchAsync(workItem));
 }
コード例 #25
0
ファイル: ValuesController.cs プロジェクト: huanent/Mediator
 public async Task <IEnumerable <string> > GetAsync([FromQuery] TestCommand command)
 {
     return(await _dispatcher.DispatchAsync(command, HttpContext.RequestAborted));
 }
コード例 #26
0
 public Task Update([FromBody] Update update)
 => dispatcher.DispatchAsync(update);