private Odd GetOdd(string id)
        {
            IEnumerable <string> ids = new List <string>()
            {
                id
            };
            EntitiesByIdQuery <Odd> oddByIdQuery = new EntitiesByIdQuery <Odd>(ids);
            Odd odd = oddByIdHandler.Handle(oddByIdQuery).FirstOrDefault();

            return(odd);
        }
 public Result <bool> Handle(DeleteChapterCommand command)
 {
     return(chapterOfUnpublishedCourseQueryHandler.Handle(
                new GetChapterQuery(command.ChapterId, allowPublishedCourse: false))
            .OnSuccess((chapter) =>
     {
         dbContext.Chapters.Remove(chapter);
         dbContext.SaveChanges();
         return Result.Ok(true);
     }));
 }
Пример #3
0
        private CoachListModel GetListData()
        {
            var model = new CoachListModel
            {
                CoachList = _listCoachQuery.Handle(new GetCoachListQuery()
                {
                })
            };

            return(model);
        }
Пример #4
0
    public Foo[] Handle(GetFoos query)
    {
        var result = _cache.Load <Foo[]>(query.FooTypeCode);

        if (result == null)
        {
            _cache.Store <Foo[]>(query.FooTypeCode, result = _queryHandler.Handle(query));
        }

        return(result);
    }
        /// <summary>
        /// Handles a message that has failed processing
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="context">The context.</param>
        /// <param name="exception">The exception.</param>
        public ReceiveMessagesErrorResult MessageFailedProcessing(IReceivedMessageInternal message, IMessageContext context,
                                                                  Exception exception)
        {
            //message failed to process
            if (context.MessageId == null || !context.MessageId.HasValue)
            {
                return(ReceiveMessagesErrorResult.NoActionPossible);
            }

            var info =
                _configuration.TransportConfiguration.RetryDelayBehavior.GetRetryAmount(exception);
            string exceptionType = null;

            if (info.ExceptionType != null)
            {
                exceptionType = info.ExceptionType.ToString();
            }

            var bSendErrorQueue = false;

            if (string.IsNullOrEmpty(exceptionType) || info.MaxRetries <= 0)
            {
                bSendErrorQueue = true;
            }
            else
            {
                //determine how many times this exception has been seen for this message
                var metadata = _queryGetMetaData.Handle(new GetMetaDataQuery((RedisQueueId)context.MessageId));
                var retries  = metadata.ErrorTracking.GetExceptionCount(exceptionType);
                if (retries >= info.MaxRetries)
                {
                    bSendErrorQueue = true;
                }
                else
                {
                    context.Set(_headers.IncreaseQueueDelay, new RedisQueueDelay(info.Times[retries]));
                    metadata.ErrorTracking.IncrementExceptionCount(exceptionType);
                    _saveMetaData.Handle(new SaveMetaDataCommand((RedisQueueId)context.MessageId, metadata));
                }
            }

            if (!bSendErrorQueue)
            {
                return(ReceiveMessagesErrorResult.Retry);
            }

            _commandMoveRecord.Handle(
                new MoveRecordToErrorQueueCommand((RedisQueueId)context.MessageId));
            //we are done doing any processing - remove the messageID to block other actions
            context.SetMessageAndHeaders(null, context.Headers);
            _log.ErrorException("Message with ID {0} has failed and has been moved to the error queue", exception,
                                message.MessageId);
            return(ReceiveMessagesErrorResult.Error);
        }
Пример #6
0
        public TResult Handle(TQuery query)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var result = decorated.Handle(query);

            stopwatch.Stop();
            Logger.Info("TIMED: Querry executed in {0}ms", stopwatch.ElapsedMilliseconds);
            return(result);
        }
Пример #7
0
        public NorthwindStore.Domain.Product GetProductById(string id)
        {
            var query = new ProductQuery()
            {
                ID = "products/55"
            };

            var result = _productQueryHandler.Handle(query);

            return(result.Data);
        }
        public Result <CourseDto> Handle(UpdateCourseCommand command)
        {
            return(GetCourseById(command.Id)
                   .OnSuccess((course) => uniqueCourseNameHandler.Handle(new CourseNameIsUniqueQuery(command.Id, command.Name))
                              .OnSuccess(() =>
            {
                course = mapper.Map(command, course);

                dbContext.SaveChanges();
                return Result.Ok(mapper.Map <CourseDto>(course));
            })));
        }
Пример #9
0
        private TeamDetailModel GetDetailData(int Id)
        {
            var model = new TeamDetailModel
            {
                Details = _detailTeamQuery.Handle(new GetTeamDetailsQuery()
                {
                    ID = Id
                })
            };

            return(model);
        }
Пример #10
0
        private TeamEditModel GetEditData(int id)
        {
            var model = new TeamEditModel
            {
                Command = _editTeamQuery.Handle(new GetTeamEditQuery()
                {
                    Id = id
                }),
            };

            return(model);
        }
Пример #11
0
        private CoachDetailModel GetDetailData(int Id)
        {
            var model = new CoachDetailModel
            {
                Details = _detailCoachQuery.Handle(new GetCoachDetailsQuery()
                {
                    ID = Id
                })
            };

            return(model);
        }
Пример #12
0
        public ActionResult <Envelope <PurchaseInfoDto> > GetPurchaseDetails([FromQuery] Amount amount, [FromQuery, Required] decimal?vatRate)
        {
            var query  = CreateFromInput(amount, vatRate.Value);
            var result = _getPurchaseInfoQueryHandler.Handle(query);

            if (result.IsFailure)
            {
                return(UnprocessableEntity(Envelope.Error(result.Errors)));
            }

            return(Ok(Envelope.Ok(result.Value)));
        }
        public IEnumerable <ValidationResult> Validate(UsernameCommand command)
        {
            AccountByUsernameQuery query = new AccountByUsernameQuery(command.Username);
            Account account = accountHandler.Handle(query);

            if (account != null)
            {
                yield return(new ValidationResult(
                                 nameof(command.Username),
                                 string.Format(MessageConstants.ALREADY_REGISTERED, nameof(command.Username).ToLower())));
            }
        }
 public PersonDto Get(string personName)
 {
     try
     {
         return(_getPersonQueryHandler.Handle(new GetPersonQuery(personName)));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
         throw;
     }
 }
Пример #15
0
        public async Task <IActionResult> GetHearingVenues()
        {
            var query         = new GetHearingVenuesQuery();
            var hearingVenues = await _queryHandler.Handle <GetHearingVenuesQuery, List <HearingVenue> >(query);

            var response = hearingVenues.Select(x => new HearingVenueResponse()
            {
                Id = x.Id, Name = x.Name
            }).ToList();

            return(Ok(response));
        }
        public async Task CreateEmailNotificationAsync(CreateEmailNotificationCommand notificationCommand, Dictionary <string, string> parameters)
        {
            var template = await _queryHandler.Handle <GetTemplateByNotificationTypeQuery, Template>(new GetTemplateByNotificationTypeQuery(notificationCommand.NotificationType));

            await _commandHandler.Handle(notificationCommand);

            var requestParameters = parameters.ToDictionary(x => x.Key, x => (dynamic)x.Value);

            var emailNotificationResponse = await SendEmailAsyncRetry(notificationCommand.ContactEmail, template.NotifyTemplateId.ToString(), requestParameters, notificationCommand.NotificationId.ToString());

            await _commandHandler.Handle(new UpdateNotificationSentCommand(notificationCommand.NotificationId, emailNotificationResponse.id, emailNotificationResponse.content.body));
        }
 public PersonDto GetIncludeSoftDelete(string personName)
 {
     try
     {
         return(_getPersonsIncludeingDeltedQueryHandler.Handle(new GetPersonWithDeletedQuery(personName)));
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
         throw;
     }
 }
 public TResult Handle(TQuery query)
 {
     try
     {
         return(_decorated.Handle(query));
     }
     catch (Exception e)
     {
         _logger.Log("Error occured during query: " + query.GetType().Name, e);
         throw;
     }
 }
 private async Task <GetMessagesQueryResponse> GetMessages(string userId)
 {
     return(await _getMessagesQuery.Handle(new GetMessagesQuery()
     {
         UserId = userId,
         SearchProperties = new SearchProperties
         {
             Offset = 0,
             Limit = 100
         }
     }));
 }
Пример #20
0
 public HttpResponseMessage Resolve(string url)
 {
     return(Get(() =>
     {
         var configuration = _findByUrl.Handle(new FindConfigurationByUrl(url));
         if (configuration != null)
         {
             MergeSettings(configuration);
         }
         return configuration;
     }));
 }
        public TResult Handle(IUserContext userContext, TQuery query)
        {
            var sw = new Stopwatch();

            var result = _decorated.Handle(userContext, query);

            sw.Stop();

            _logger.LogInformation($"Query {nameof(query)} elapsed:{sw.Elapsed}.");

            return(result);
        }
        public async Task <QueryResult <TResponse> > Handle(TQuery query, RequestContext context)
        {
            validator.Context = context;

            var validationResult = await validator.ValidateAsync(query);

            return(validationResult.IsValid
                ? await decoratedRequestHandler.Handle(query, context)
                : new QueryResult <TResponse>(validationResult
                                              .Errors.Select(x => new ValidationFailure(x.ErrorCode, x.ErrorMessage))
                                              .ToArray()));
        }
Пример #23
0
        private PlayerDetailModel GetDetailData(int Id)
        {
            var model = new PlayerDetailModel
            {
                Details = _detailPlayerQuery.Handle(new GetPlayerDetailsQuery()
                {
                    ID = Id
                })
            };

            return(model);
        }
Пример #24
0
        public async Task SendNotification(UpDateStatoRichiestaCommand richiesta)
        {
            const bool notificaChangeState             = true;
            var        sintesiRichiesteAssistenzaQuery = new SintesiRichiesteAssistenzaQuery
            {
                Filtro = new FiltroRicercaRichiesteAssistenza
                {
                    idOperatore = richiesta.IdOperatore
                },
                CodiciSede = new string[] { richiesta.CodiceSede }
            };
            var boxRichiesteQuery = new BoxRichiesteQuery()
            {
                CodiciSede = new string[] { richiesta.CodiceSede }
            };
            var boxInterventi = _boxRichiesteHandler.Handle(boxRichiesteQuery).BoxRichieste;

            var boxMezziQuery = new BoxMezziQuery()
            {
                CodiciSede = new string[] { richiesta.CodiceSede }
            };
            var boxMezzi = _boxMezziHandler.Handle(boxMezziQuery).BoxMezzi;

            var boxPersonaleQuery = new BoxPersonaleQuery()
            {
                CodiciSede = new string[] { richiesta.CodiceSede }
            };
            var boxPersonale = _boxPersonaleHandler.Handle(boxPersonaleQuery).BoxPersonale;

            var sintesiRichiesteAssistenzaMarkerQuery = new SintesiRichiesteAssistenzaMarkerQuery()
            {
                CodiciSedi = new string[] { richiesta.CodiceSede }
            };

            var listaSintesiMarker = (List <SintesiRichiestaMarker>)_sintesiRichiesteAssistenzaMarkerHandler.Handle(sintesiRichiesteAssistenzaMarkerQuery).SintesiRichiestaMarker;
            var ChamataUpd         = listaSintesiMarker.LastOrDefault(sintesi => sintesi.Id == richiesta.IdRichiesta);

            var SintesiRichiesta = _getSintesiById.GetSintesi(ChamataUpd.Codice);

            richiesta.Chiamata = SintesiRichiesta;

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("ModifyAndNotifySuccess", richiesta);

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("ChangeStateSuccess", notificaChangeState);

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("NotifyGetBoxInterventi", boxInterventi);

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("NotifyGetBoxMezzi", boxMezzi);

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("NotifyGetBoxPersonale", boxPersonale);

            await _notificationHubContext.Clients.Group(richiesta.CodiceSede).SendAsync("NotifyGetRichiestaUpDateMarker", ChamataUpd);
        }
Пример #25
0
        public static T Fetch <T>(this IManagedConnection runner, IQueryHandler <T> handler, IIdentityMap map, QueryStatistics stats, ITenant tenant)
        {
            var command = CommandBuilder.ToCommand(tenant, handler);

            return(runner.Execute(command, c =>
            {
                using (var reader = command.ExecuteReader())
                {
                    return handler.Handle(reader, map, stats);
                }
            }));
        }
Пример #26
0
        public ComposizionePartenzaAvanzataResult GetMarkerComposizionePartenzaAvanzataFromId(FiltriComposizionePartenza filtro)
        {
            var codiceSede = Request.Headers["codicesede"];

            var partenzaAvanzataQuery = new ComposizionePartenzaAvanzataQuery()
            {
                Filtro     = filtro,
                CodiceSede = codiceSede
            };

            return(_handler.Handle(partenzaAvanzataQuery));
        }
Пример #27
0
 public TResult Handle(TQuery query)
 {
     try
     {
         return(_decorated.Handle(query));
     }
     catch (Exception e)
     {
         _logger.LogError($"Query <{typeof(TQuery)}> failed with exception - <{e.Message}>.");
         throw;
     }
 }
Пример #28
0
        public async Task <IActionResult> GetPersonByUsername(string username)
        {
            if (!username.IsValidEmail())
            {
                ModelState.AddModelError(nameof(username), $"Please provide a valid {nameof(username)}");
                return(BadRequest(ModelState));
            }

            var query  = new GetPersonByUsernameQuery(username);
            var person = await _queryHandler.Handle <GetPersonByUsernameQuery, Person>(query);

            if (person == null)
            {
                return(NotFound());
            }

            var mapper   = new PersonToResponseMapper();
            var response = mapper.MapPersonToResponse(person);

            return(Ok(response));
        }
        public async Task <IActionResult> AddEndPointToHearingAsync(Guid hearingId, AddEndpointRequest addEndpointRequest)
        {
            if (hearingId == Guid.Empty)
            {
                ModelState.AddModelError(nameof(hearingId), $"Please provide a valid {nameof(hearingId)}");
                return(BadRequest(ModelState));
            }

            var result = await new AddEndpointRequestValidation().ValidateAsync(addEndpointRequest);

            if (!result.IsValid)
            {
                ModelState.AddFluentValidationErrors(result.Errors);
                return(BadRequest(ModelState));
            }

            try
            {
                var newEp = EndpointToResponseMapper.MapRequestToNewEndpointDto(addEndpointRequest, _randomGenerator,
                                                                                _kinlyConfiguration.SipAddressStem);

                var command = new AddEndPointToHearingCommand(hearingId, newEp);
                await _commandHandler.Handle(command);

                var hearing =
                    await _queryHandler.Handle <GetHearingByIdQuery, VideoHearing>(new GetHearingByIdQuery(hearingId));

                var endpoint = hearing.GetEndpoints().FirstOrDefault(x => x.DisplayName.Equals(addEndpointRequest.DisplayName));
                if (endpoint != null && hearing.Status == BookingStatus.Created)
                {
                    await _eventPublisher.PublishAsync(new EndpointAddedIntegrationEvent(hearingId, endpoint));
                }
            }
            catch (HearingNotFoundException exception)
            {
                return(NotFound(exception.Message));
            }

            return(NoContent());
        }
Пример #30
0
        public async Task <IActionResult> Post(FiltriComposizionePartenza filtri)
        {
            var    codiceSede   = Request.Headers["codicesede"];
            var    headerValues = Request.Headers["HubConnectionId"];
            string ConId        = headerValues.FirstOrDefault();

            var query = new ComposizioneMezziQuery()
            {
                Filtro     = filtri,
                CodiceSede = codiceSede
            };

            if (ModelState.IsValid)
            {
                try
                {
                    List <ComposizioneMezzi> composizioneMezzi = handler.Handle(query).ComposizioneMezzi;
                    return(Ok());
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains(Costanti.UtenteNonAutorizzato))
                    {
                        return(StatusCode(403, new { message = Costanti.UtenteNonAutorizzato }));
                    }
                    else if (ex.Message.Contains("404"))
                    {
                        return(StatusCode(404, new { message = "Servizio non raggiungibile. Riprovare più tardi" }));
                    }
                    else
                    {
                        return(BadRequest(new { message = ex.Message }));
                    }
                }
            }
            else
            {
                return(BadRequest());
            }
        }