コード例 #1
0
        public Task <ResponseDTO> Handle(SearchRequestDTO request, CancellationToken cancellationToken)
        {
            ResponseDTO result = new ResponseDTO();

            try
            {
                var dicAlgorithms = GetAlgorithmsDictionary();

                ISearchAlgorithm algorithm = AlgorithmsCreator.GetAlgorithm(dicAlgorithms, request.AlgorithmKey, request.Matrix);
                var algorithmResult        = algorithm.Find(request.WordStream);

                _unitOfWork.SearchesRepository.Add(new Searches()
                {
                    UserName     = request.UserName,
                    AlgorithmKey = request.AlgorithmKey,
                    Matrix       = request.Matrix.Aggregate((x, y) => x + "," + y),
                    WordStream   = request.WordStream.Aggregate((x, y) => x + "," + y)
                });

                _unitOfWork.SaveChanges();

                result.Status = (int)eStatus.Success;
                result.Value  = algorithmResult;
            }
            catch (WordFinderCustomException ex)
            {
                result.Status  = (int)eStatus.Error;
                result.Message = ex.Message;
            }
            catch (Exception ex)
            {
                result.Status  = (int)eStatus.Error;
                result.Message = "Unexpected error";
            }

            return(Task.FromResult(result));
        }