Esempio n. 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));
            }
        }
Esempio n. 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
                });
            }
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 5
0
        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());
        }
        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();
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 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));
        }
Esempio n. 10
0
        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);
        }
Esempio n. 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();
            }
        }
 public Task Update([FromBody] Update _) => dispatcher.DispatchAsync();
Esempio n. 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);
Esempio n. 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);
Esempio n. 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);
Esempio n. 16
0
 public static Task DispatchAsync(this IDispatcher dispatcher, Func <Task> funcTask) =>
 dispatcher.DispatchAsync(async() =>
 {
     await funcTask().ConfigureAwait(false);
     return(true);
 });
Esempio n. 17
0
 public static Task DispatchAsync(this IDispatcher dispatcher, Action action) =>
 dispatcher.DispatchAsync(() =>
 {
     action();
     return(true);
 });
Esempio n. 18
0
 public async Task <IHttpActionResult> Post([FromBody] DataSetRequest request)
 {
     return(Ok(await _dispatcher.DispatchAsync(request)));
 }
Esempio n. 19
0
 protected async Task DispatchAsync <T>(T command) where T : ICommand
 {
     await _dispatcher.DispatchAsync(command);
 }
Esempio n. 20
0
 public Task DispatchAsync <TAction>(TAction action, CancellationToken cancellationToken = default) where TAction : IAction
 {
     return(_dispatcher.DispatchAsync(action, cancellationToken));
 }
Esempio n. 21
0
 protected async Task <Result> CommandAsync(ICommand command)
 {
     return(await _dispatcher.DispatchAsync(command));
 }
Esempio n. 22
0
        public async Task DispatcherWithExecutorDispatchAsync()
        {
            var request = new AwesomeRequest();

            var response = await _dispatcherWithExecutor.DispatchAsync(request, default);
        }
Esempio n. 23
0
        public async Task DynamicDispatcherDispatchAsync()
        {
            var request = new AwesomeRequest();

            var response = await _dynamicDispatcher.DispatchAsync(request, default);
        }
Esempio n. 24
0
 public override Task InvokeAsync(Action workItem)
 {
     return(_dispatcher.DispatchAsync(workItem));
 }
Esempio n. 25
0
 public async Task <IEnumerable <string> > GetAsync([FromQuery] TestCommand command)
 {
     return(await _dispatcher.DispatchAsync(command, HttpContext.RequestAborted));
 }
Esempio n. 26
0
 public Task Update([FromBody] Update update)
 => dispatcher.DispatchAsync(update);