Example #1
0
        public virtual IActionResult Find(FindCriteria findCriteria)
        {
            var query  = new FindQuery <TModel>(findCriteria);
            var result = QueryDispatcher.Dispatch(query);

            return(Ok(result));
        }
        public virtual IActionResult Find([FromQuery] FilterQuery filterQuery)
        {
            var query  = new FindQuery <TModel>(filterQuery);
            var result = QueryDispatcher.Dispatch(query);

            return(Ok(result));
        }
        public void FindQuery_MustSet_Properties()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <Guid>();

            // Act
            var sut = new FindQuery <string, Guid>(id);

            // Assert
            Assert.Equal(id, sut.Id);
        }
Example #4
0
        /// <summary>
        /// Convert query options into DICOM study query DataSeet
        /// </summary>
        /// <param name="options">query options</param>
        /// <returns>DICOM DataSet that contains the DICOM query options</returns>
        private Dicom.DicomDataSet GetStudyQuery(QueryOptions options)
        {
            DicomDataSet query     = new DicomDataSet( );
            FindQuery    findQuery = new FindQuery( );

            query.Initialize(DicomClassType.StudyRootQueryStudy, DicomDataSetInitializeFlags.ImplicitVR | DicomDataSetInitializeFlags.LittleEndian | DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.AddMandatoryModulesOnly);

            InsertPatientInfo(options, query);
            InsertStudyInfo(options, query);

            query.InsertElementAndSetValue(DicomTag.QueryRetrieveLevel, "STUDY");
            return(query);
        }
Example #5
0
        public void IsCancelled_Reflects_StateOf_CancellationToken()
        {
            using var cts = new CancellationTokenSource();

            _query = new FindQuery <string, int>(_ => false, cts.Token);

            _query.IsCancellationRequested
            .Should().BeFalse();

            cts.Cancel();

            _query.IsCancellationRequested
            .Should().BeTrue();
        }
Example #6
0
        public static async Task <KeyValuePair <TKey, TValue>?> Find <TKey, TValue>
        (
            [NotNull] this IQueryManager <TKey, TValue> queryManager,
            [NotNull] Func <TKey, bool> isKey,
            [CanBeNull] CancellationToken cancellationToken = default
        )
        {
            var query = new FindQuery <TKey, TValue>(isKey, cancellationToken);

            if (!await queryManager.ExecuteQuery(query).ConfigureAwait(false))
            {
                return(null);
            }

            return(new KeyValuePair <TKey, TValue>(query.Key, query.Value));
        }
Example #7
0
        private SupportedAction GetAction(Message message, CommandBase <Bot, Config> command)
        {
            if (message.ForwardFrom != null)
            {
                if ((CurrentQuery != null) && (message.Date > CurrentQueryTime))
                {
                    CurrentQuery = null;
                }
                return(new ForwardAction(this, message));
            }

            if (command != null)
            {
                return(new CommandAction(this, message, command));
            }

            if (int.TryParse(message.Text, out int number))
            {
                return(new NumberAction(this, message, number));
            }

            if (Articles.Manager.TryParseArticle(message.Text, out Article article))
            {
                return(new ArticleAction(this, message, article));
            }

            if (FindQuery.TryParseFindQuery(message.Text, out FindQuery findQuery))
            {
                return(new FindQueryAction(this, message, findQuery));
            }

            if (MarkQuery.TryParseMarkQuery(message.Text, out MarkQuery markQuery))
            {
                if (message.ReplyToMessage == null)
                {
                    return(new RememberMarkAction(this, message, markQuery));
                }

                if (message.ReplyToMessage.ForwardFrom != null)
                {
                    return(new MarkAction(this, message, message.ReplyToMessage, markQuery));
                }
            }

            return(null);
        }
        public async Task <ActionResult <QuerySingleResponse <QueryCustomerModel> > > GetCustomer(int id)
        {
            var query = new FindQuery <QueryCustomerModel>()
            {
                Id = id
            };
            var customer = await _customerQueryHandler.HandleAsync(query);

            if (customer == null)
            {
                return(NotFound(new { message = "Customer not found" }));
            }
            var response = new QuerySingleResponse <QueryCustomerModel>();

            response.Data    = customer;
            response.Success = true;
            return(response);
        }
        public async Task <ActionResult <QuerySingleResponse <QueryTicketModel> > > GetTicket(int id)
        {
            var query = new FindQuery <QueryTicketModel>()
            {
                Id = id
            };
            var ticket = await _ticketQueryHandler.HandleAsync(query);

            if (ticket == null)
            {
                return(NotFound(new { message = "Ticket not found" }));
            }
            var response = new QuerySingleResponse <QueryTicketModel>();

            response.Data    = ticket;
            response.Success = true;
            return(response);
        }
Example #10
0
    /*
     * public static FindQuery FindPath(Drone drone, byte[,] map, int endx, int endy, bool debug = false, bool simpleDebug = false)
     * {
     *      int id = instance.findQueries.FindIndex(q => q.drone == drone);
     *      if (id > -1)
     *              instance.findQueries.RemoveAt(id);
     *      FindQuery query = FindPath(map, (int)drone.transform.position.x, (int)drone.transform.position.y, endx, endy, debug, simpleDebug);
     *      query.drone = drone;
     *      return query;
     * }
     */

    public static FindQuery FindPath(bool[,] map, int startx, int starty, int endx, int endy, bool debug = false, bool simpleDebug = false)
    {
        if (startx == endx && starty == endy)
        {
            return(null);
        }

        FindQuery query = new FindQuery {
            map      = map,
            startx   = startx,
            starty   = starty,
            endx     = endx,
            endy     = endy,
            mapSizeX = map.GetLength(0),
            mapSizeY = map.GetLength(1),
            open     = new List <Position> {
                new Position {
                    x = startx, y = starty
                }
            },
            closed      = new List <Position>(),
            current     = null,
            currentId   = -1,
            totalSteps  = 0,
            path        = null,
            drone       = null,
            debug       = debug,
            simpleDebug = simpleDebug,
            stopwatch   = new System.Diagnostics.Stopwatch()
        };

        instance.findQueries.Add(query);

        if (query.debug && !query.simpleDebug)
        {
            query.stopwatch.Start();
        }

        return(query);
    }
        /// <inheritdoc/>
        public async Task <TReturn> Handle(FindQuery <TReturn, TKey> request, CancellationToken cancellationToken)
        {
            try
            {
                request.ValidateModel();

                var result = await repository.FindAsync(request.Id);

                if (result != null)
                {
                    return(mapper.Map <TReturn>(result)
                           ?? throw new InvalidOperationException($"Mapping {typeof(TEntity)} to {typeof(TReturn)}"));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                throw;
            }
        }
Example #12
0
 public FindStudent(int i)
 {
     fq  = new FindQuery();
     stu = fq.find(i);
 }
 public async Task <QueryCustomerModel> HandleAsync(FindQuery <QueryCustomerModel> findQuery)
 {
     return(await _unitOfWork.CustomerRepository.FindCustomerAsync(findQuery.Id));
 }
Example #14
0
 public FindQueryAction(Bot.Bot bot, Message message, FindQuery query) : base(bot, message) => _query = query;
        /// <summary>
        /// Initializes a new instance of the <see cref="FindHandlerFixtures"/> class.
        /// </summary>
        /// <param name="testType">Type of test to emulate.</param>
        public FindHandlerFixtures(TestTypeEnum testType)
        {
            var fixture = new Fixture();

            TestType = testType;

            ReadOnlyRepository = new Mock <IReadOnlyRepository <string, Guid> >();

            Mapper = new Mock <IMapper>();

            switch (TestType)
            {
            case TestTypeEnum.Ok:
            {
                Query       = new FindQuery <string, Guid>(fixture.Create <Guid>());
                QueryResult = fixture.Create <string>();
                Entity      = fixture.Create <string>();

                ReadOnlyRepository.Setup(
                    f => f.FindAsync(It.Is <Guid>(m => m == Query.Id)))
                .ReturnsAsync(Entity)
                .Verifiable();

                Mapper.Setup(
                    f => f.Map <string>(It.Is <string>(m => m == Entity)))
                .Returns(QueryResult)
                .Verifiable();

                break;
            }

            case TestTypeEnum.RepositoryThrowsInvalidOperationException:
            {
                Query = new FindQuery <string, Guid>(fixture.Create <Guid>());

                ReadOnlyRepository.Setup(
                    f => f.FindAsync(It.Is <Guid>(m => m == Query.Id)))
                .Throws <InvalidOperationException>()
                .Verifiable();

                break;
            }

            case TestTypeEnum.MapReturnsNull:
            {
                Query       = new FindQuery <string, Guid>(fixture.Create <Guid>());
                QueryResult = fixture.Create <string>();
                Entity      = fixture.Create <string>();

                ReadOnlyRepository.Setup(
                    f => f.FindAsync(It.Is <Guid>(m => m == Query.Id)))
                .ReturnsAsync(Entity)
                .Verifiable();

                Mapper.Setup(
                    f => f.Map <string>(It.Is <string>(m => m == Entity)))
                .Returns(null as string)
                .Verifiable();

                break;
            }

            default:
            {
                throw new ArgumentOutOfRangeException($"Unknown test type: {testType}");
            }
            }
        }
Example #16
0
 public async Task <QueryTicketModel> HandleAsync(FindQuery <QueryTicketModel> findQuery)
 {
     return(await _unitOfWork.TicketRepository.FindTicketAsync(findQuery.Id));
 }