コード例 #1
0
        public void ExtractLogToFile(Stream stream, DateTime dateMin, DateTime dateMax, IList <LogLevel> logLevels)
        {
            var logs = repository.DoQuery(new NoSqlQuery <Log>()
            {
                PostFilter = log => log.SystemCreationDate > dateMin && log.SystemCreationDate < dateMax && logLevels.Contains(log.Level)
            }).OrderBy(log => log.SystemLastUpdateDate);

            StringBuilder serializedLogs = new StringBuilder();

            foreach (var log in logs)
            {
                serializedLogs.Append(JsonConvert.SerializeObject(log));
            }

            var encodedLogs = Encoding.UTF8.GetBytes(serializedLogs.ToString());

            stream.Write(encodedLogs, 0, encodedLogs.Length);
        }
コード例 #2
0
        public void DoQuery()
        {
            entityRepo.TruncateCollection();

            var entity1 = TestHelper.GetEntity1();
            var entity3 = TestHelper.GetEntity3();
            var entity4 = TestHelper.GetEntity4();

            entityRepo.InsertMany(new List <TestEntity>()
            {
                entity1, entity3, entity4
            });

            // Now we will do some queries :
            var queryOptions = QueryCreator.CreateQueryOptions <TestEntity>(2, 0, null);
            var query        = entityRepo.DoQuery(queryOptions);

            Assert.AreEqual(2, query.Count(), "Query should contain three elements");

            // Now we will add a filter method :
            queryOptions = QueryCreator.CreateQueryOptions <TestEntity>(0, 0, (filterItem) => filterItem.NumberOfChildenInt == 0);
            query        = entityRepo.DoQuery(queryOptions);
            Assert.AreEqual(1, query.Count(), "Query should contain two elements");
        }