Esempio n. 1
0
        public IActionResult Index(Guid id)
        {
            var response = requestDispatcher.Dispatch <GetSurveyAnswerPageRequest, GetSurveyAnswerPageResponse>(new GetSurveyAnswerPageRequest {
                SurveyAnswerId = id, PageNumber = 1
            });

            var model = GetModel(response, id);

            return(View(model));
        }
 public async Task Dispatch(ChatContext context, CancellationToken cancellationToken)
 {
     using (container.BeginExecutionContextScope())
     {
         await inner.Dispatch(context, cancellationToken);
     }
 }
Esempio n. 3
0
        public IActionResult Index()
        {
            var response = requestDispatcher.Dispatch <ListSurveysRequest, ListSurveysResponse>(new ListSurveysRequest());

            return(View(new HomeViewModel {
                Title = "Home Page", Surveys = response.Surveys
            }));
        }
Esempio n. 4
0
        public IActionResult Index(Guid id)
        {
            var response = requestDispatcher.Dispatch <GetSurveyRequest, GetSurveyResponse>(new GetSurveyRequest {
                SurveyId = id
            });

            var model = new SurveyModel {
                Title = response.Survey.Name, Survey = response.Survey
            };

            return(View(model));
        }
 public async Task <HttpResponse> DispatchRequest(HttpRequest request)
 {
     try
     {
         var task = Dispatcher.Dispatch(request);
         return(task == null?HttpResponse.NotFound() : await task);
     }
     catch (Exception e)
     {
         return(Server.ActionExceptionHandler(e));
     }
 }
        public async Task <CommandResponse> Execute(Message message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            try
            {
                logger.LogDebug($"{message.Content}");
                var parameters = message.Content.Split(" ").Skip(1);
                if (parameters.Any())
                {
                    string  nationName = string.Join(" ", parameters);
                    Request request    = new Request(RequestType.GetBasicNationStats, ResponseFormat.XmlResult, DataSourceType.NationStatesAPI);
                    request.Params.Add("nationName", Helpers.ToID(nationName));
                    await _dispatcher.Dispatch(request).ConfigureAwait(false);

                    await request.WaitForResponse(token).ConfigureAwait(false);

                    if (request.Status == RequestStatus.Canceled)
                    {
                        return(await FailCommand(message.Channel, "Request/Command has been canceled. Sorry :(").ConfigureAwait(false));
                    }
                    else if (request.Status == RequestStatus.Failed)
                    {
                        return(await FailCommand(message.Channel, request.FailureReason).ConfigureAwait(false));
                    }
                    else
                    {
                        CommandResponse commandResponse = ParseResponse(request);
                        await message.Channel.WriteToAsync(message.Channel.IsPrivate, commandResponse).ConfigureAwait(false);

                        return(commandResponse);
                    }
                }
                else
                {
                    return(await FailCommand(message.Channel, "No parameter passed.").ConfigureAwait(false));
                }
            }
            catch (InvalidOperationException e)
            {
                logger.LogError(e.ToString());
                return(await FailCommand(message.Channel, "Could not execute command. Something went wrong :(").ConfigureAwait(false));
            }
            catch (TaskCanceledException e)
            {
                logger.LogError(e.ToString());
                return(await FailCommand(message.Channel, "Request/Command has been canceled. Sorry :(").ConfigureAwait(false));
            }
        }
Esempio n. 7
0
        private async void HandleRequest(RtspRequest request)
        {
            RtspListener listener = null;

            if (_listeners.TryGetValue(request.RemoteEndpoint.ToString(), out listener))
            {
                await Task.Run(() =>
                {
                    try
                    {
                        int receivedCseq = request.CSeq;
                        request.Context  = new RequestContext(listener);
                        var response     = _dispatcher.Dispatch(request);

                        if (response != null)
                        {
                            if (response.HasBody)
                            {
                                response.Headers[RtspHeaders.Names.CONTENT_LENGTH] = response.Body.Length.ToString();
                            }

                            response.Headers[RtspHeaders.Names.CSEQ] = receivedCseq.ToString();
                            listener.SendResponse(response);

                            // Remove listener on teardown.
                            // VLC will terminate the connection and the listener will stop itself properly.
                            // Some clients will send Teardown but keep the connection open, in this type scenario we'll close it.
                            if (request.Method == RtspRequest.RtspMethod.TEARDOWN)
                            {
                                listener.Stop();
                                _listeners.Remove(listener.Endpoint.ToString());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LOG.Error(e, $"Caught exception while procesing RTSP request from {request.URI}");

                        listener.SendResponse(RtspResponse.CreateBuilder()
                                              .Status(RtspResponse.Status.InternalServerError)
                                              .Build());
                    }
                });
            }
            else
            {
                LOG.Error($"Unable to process request because no active connection was found for {request.URI}");
            }
        }
Esempio n. 8
0
        public DeleteOrderResult Execute(DeleteOrderRequest request)
        {
            var result = new DeleteOrderResult();

            /*lets assume that deleting an order is a complex process which involves several steps
             * in those types of situations the outermost handler(this one for example) becomes more of a composite
             * or order of operation coordinator.  The overall process can be completed by child handlers*/

            //handlers that could be considered "general use" such as basic crud operations can be re-used by composite handlers such as this one

            //see if we can cancel the shipping
            var cancelShippingResult =
                _dispatcher.Dispatch <CancelOrderShippingRequest, CancelOrderShippingResult>(
                    new CancelOrderShippingRequest(request.OrderId));


            var refundCustomerResult =
                _dispatcher.Dispatch <RefundCustomerRequest, RefundCustomerResult>(
                    new RefundCustomerRequest(request.OrderId));

            //keep adding handlers as needed to handle the complexity in order to keep from a single handler getting too big

            return(result);
        }
Esempio n. 9
0
        public IHttpActionResult Post(AddOrderRequest request)
        {
            var result = _dispatcher.Dispatch <AddOrderRequest, AddOrderResult>(request);

            return(Ok(result));
        }
Esempio n. 10
0
 public Task Dispatch(DashboardContext context)
 {
     return(_dispatcher.Dispatch(RequestDispatcherContext.FromDashboardContext(context)));
 }
 public async Task <ActionResult <GetCustomersResult> > Get(GetCustomerRequest request)
 {
     return(await _requestDispatcher.Dispatch <GetCustomerRequest, GetCustomersResult>(request));
 }