Esempio n. 1
0
        private IEnumerable <Query> FindQueriesInNamespaceToExecute(
            Guid resKey,
            string nmspace,
            ParameterNames parameters)
        {
            var exactQuery = _baseQueries.Where(k => k.QueryInfo.ResourceKey == resKey
                                                &&
                                                _parameterComparer.Equals(k.QueryInfo.Namespace, nmspace) &&
                                                k.QueryInfo.ArgCount == parameters.Count &&
                                                parameters == k.QueryInfo.Arguments).ToArray();



            return(exactQuery);
        }
Esempio n. 2
0
        public void Send <TMessage>(Expression <Func <TSaga, bool> > filter, ISagaPolicy <TSaga, TMessage> policy, TMessage message, Action <TSaga> consumerAction)
            where TMessage : class
        {
            IEnumerable <TSaga> existingSagas = _collection.Where(filter).ToList();

            if (SendMessageToExistingSagas(existingSagas, policy, consumerAction, message, RemoveSaga))
            {
                return;
            }

            SendMessageToNewSaga(policy, message, saga =>
            {
                lock (_collection)
                    _collection.Add(saga);

                consumerAction(saga);
            }, RemoveSaga);
        }
Esempio n. 3
0
 public void SimpleTest2()
 {
     Queries.Debug = true;
     Queries.TimesWasHere = 0;
     var collection = new IndexedCollection<KeyValuePair<int, int>>(k => k.Key) { new KeyValuePair<int, int>(1, 3), new KeyValuePair<int, int>(5, 2), new KeyValuePair<int, int>(5, 3) };
     var items = collection.Where(k => k.Key == 5 && k.Value == 3).ToArray();
     Assert.AreEqual(1, Queries.TimesWasHere);
     Assert.AreEqual(1, items.Length);
     Assert.AreEqual(5, items[0].Key);
     Assert.AreEqual(3, items[0].Value);
 }
Esempio n. 4
0
        public void SimpleTest1()
        {
            Queries.Debug        = true;
            Queries.TimesWasHere = 0;
            var collection = new IndexedCollection <KeyValuePair <int, int> >(k => k.Key)
            {
                new KeyValuePair <int, int>(1, 3), new KeyValuePair <int, int>(5, 2)
            };
            var items = collection.Where(k => k.Key == 5).ToArray();

            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(2, items[0].Value);
        }
Esempio n. 5
0
        public void AdvancedTest1()
        {
            Queries.Debug        = true;
            Queries.TimesWasHere = 0;
            var collection = new IndexedCollection <TimeRange>(k => k.Value, k => k.EndTime - k.StartTime)
            {
                new TimeRange(new DateTime(2012, 2, 1), new DateTime(2012, 2, 2), 4),
                new TimeRange(new DateTime(2012, 2, 3), new DateTime(2012, 2, 4), 5),
                new TimeRange(new DateTime(2012, 2, 4), new DateTime(2012, 2, 5), 6),
                new TimeRange(new DateTime(2012, 2, 2), new DateTime(2012, 2, 6), 7),
                new TimeRange(new DateTime(2012, 2, 2), new DateTime(2012, 2, 8), 8),
                new TimeRange(new DateTime(2012, 2, 5), new DateTime(2012, 2, 10), 9),
                new TimeRange(new DateTime(2012, 2, 4), new DateTime(2012, 2, 9), 10),
                new TimeRange(new DateTime(2012, 2, 2), new DateTime(2012, 2, 3), 11),
                new TimeRange(new DateTime(2012, 2, 8), new DateTime(2012, 2, 10), 12),
            };
            var items = collection.Where(k => k.Value == 4 || k.StartTime == new DateTime(2012, 2, 2)).ToArray();

            Assert.AreEqual(0, Queries.TimesWasHere);
            Assert.AreEqual(4, items.Length);

            Queries.TimesWasHere = 0;
            items = collection.Where(k => k.Value == 4 && k.EndTime == new DateTime(2012, 2, 2)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(4, items[0].Value);

            Queries.TimesWasHere = 0;
            items = collection.Where(k => k.Value == 5 && k.StartTime != new DateTime(2012, 2, 3)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);

            Queries.TimesWasHere = 0;
            items = collection.Where(k => k.EndTime - k.StartTime == TimeSpan.FromDays(1)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(4, items.Length);
        }
		public void Should_use_indices_to_improve_query_performance()
		{
			IndexedCollection<IndexedClass> collection = new IndexedCollection<IndexedClass>();

			collection.Add(new IndexedClass {Name = "Chris"});
			collection.Add(new IndexedClass {Name = "David"});
			collection.Add(new IndexedClass {Name = "Jason"});
			collection.Add(new IndexedClass {Name = "Matt"});
			collection.Add(new IndexedClass {Name = "Terry"});
			collection.Add(new IndexedClass {Name = "Zach"});


			var result = collection.Where(x => x.Name == "Matt").First();

			Assert.AreEqual("Matt", result.Name);
		}
Esempio n. 7
0
 public void SimpleTest5()
 {
     Queries.Debug = true;
     Queries.TimesWasHere = 0;
     var collection = new IndexedCollection<KeyValuePair<object, int>>(k => k.Key)
                          {
                              new KeyValuePair<object, int>(0, 3),
                              new KeyValuePair<object, int>(null, 2),
                              new KeyValuePair<object, int>(5, 3)
                          };
     int v = 5;
     var items = collection.Where(k => k.Key != null && (int)k.Key == v && k.Value == 3).ToArray();
    // Assert.AreEqual(1, Queries.TimesWasHere);
     Assert.AreEqual(1, items.Length);
     Assert.AreEqual(5, items[0].Key);
     Assert.AreEqual(3, items[0].Value);
 //    Assert.Fail("Пока не проходит");
 }
Esempio n. 8
0
        public void SimpleTest5()
        {
            Queries.Debug        = true;
            Queries.TimesWasHere = 0;
            var collection = new IndexedCollection <KeyValuePair <object, int> >(k => k.Key)
            {
                new KeyValuePair <object, int>(0, 3),
                new KeyValuePair <object, int>(null, 2),
                new KeyValuePair <object, int>(5, 3)
            };
            int v     = 5;
            var items = collection.Where(k => k.Key != null && (int)k.Key == v && k.Value == 3).ToArray();

            // Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(5, items[0].Key);
            Assert.AreEqual(3, items[0].Value);
            //    Assert.Fail("Пока не проходит");
        }
Esempio n. 9
0
        public void SimpleTest6()
        {
            Queries.Debug        = true;
            Queries.TimesWasHere = 0;
            Func <KeyValuePair <int, int>, int> counter = k => k.Key + k.Value;
            var collection = new IndexedCollection <KeyValuePair <int, int> >(k => counter(k))
            {
                new KeyValuePair <int, int>(0, 3),
                new KeyValuePair <int, int>(2, 2),
                new KeyValuePair <int, int>(5, 3)
            };

            var items = collection.Where(k => counter(k) == 4).ToArray();

            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(2, items[0].Key);
            Assert.AreEqual(2, items[0].Value);
        }
Esempio n. 10
0
 private IEnumerable <Query> FindInCache(Guid key, string nmspace, ParameterNames parameters)
 {
     lock (_cachedQueries)
         return(_cachedQueries.Where(k => k.ResourceKey == key && k.Namespace == nmspace && k.Arguments == parameters));
 }
Esempio n. 11
0
 public static T FirstOrDefault <T>(this IndexedCollection <T> source, Expression <Func <T, bool> > query)
 {
     return(source.Where(query).FirstOrDefault());
 }
Esempio n. 12
0
 public static bool All <T>(this IndexedCollection <T> source, Expression <Func <T, bool> > query)
 {
     return(source.Where(query).Count() == source.Count);
 }
Esempio n. 13
0
 public static bool Any <T>(this IndexedCollection <T> source, Expression <Func <T, bool> > query)
 {
     return(Equals(source.Where(query).FirstOrDefault(), default(T)));
 }
Esempio n. 14
0
        public void SimpleTest6()
        {
            Queries.Debug = true;
            Queries.TimesWasHere = 0;
            Func<KeyValuePair<int, int>, int> counter = k => k.Key + k.Value;
            var collection = new IndexedCollection<KeyValuePair<int, int>>(k=>counter(k))
                                 {
                                     new KeyValuePair<int, int>(0, 3),
                                     new KeyValuePair<int, int>(2, 2),
                                     new KeyValuePair<int, int>(5, 3)
                                 };

            var items = collection.Where(k => counter(k) == 4).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(2, items[0].Key);
            Assert.AreEqual(2, items[0].Value);
        }
Esempio n. 15
0
        public void AdvancedTest1()
        {
            Queries.Debug = true;
            Queries.TimesWasHere = 0;
            var collection = new IndexedCollection<TimeRange>(k => k.Value,k=>k.EndTime - k.StartTime)
                                 {
                                     new TimeRange(new DateTime(2012,2,1),new DateTime(2012,2,2), 4 ),
                                     new TimeRange(new DateTime(2012,2,3),new DateTime(2012,2,4), 5 ),
                                     new TimeRange(new DateTime(2012,2,4),new DateTime(2012,2,5), 6 ),
                                     new TimeRange(new DateTime(2012,2,2),new DateTime(2012,2,6), 7 ),
                                     new TimeRange(new DateTime(2012,2,2),new DateTime(2012,2,8), 8 ),
                                     new TimeRange(new DateTime(2012,2,5),new DateTime(2012,2,10),9 ),
                                     new TimeRange(new DateTime(2012,2,4),new DateTime(2012,2,9), 10 ),
                                     new TimeRange(new DateTime(2012,2,2),new DateTime(2012,2,3), 11 ),
                                     new TimeRange(new DateTime(2012,2,8),new DateTime(2012,2,10), 12 ),
                                 };
            var items = collection.Where( k => k.Value == 4 || k.StartTime == new DateTime(2012, 2, 2)).ToArray();
            Assert.AreEqual(0, Queries.TimesWasHere);
            Assert.AreEqual(4, items.Length);         

            Queries.TimesWasHere = 0;
            items = collection.Where( k => k.Value == 4 && k.EndTime == new DateTime(2012, 2, 2)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);
            Assert.AreEqual(4, items[0].Value);

            Queries.TimesWasHere = 0;
            items = collection.Where( k => k.Value == 5 && k.StartTime != new DateTime(2012, 2, 3)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(1, items.Length);

            Queries.TimesWasHere = 0;
            items = collection.Where( k => k.EndTime - k.StartTime == TimeSpan.FromDays(1)).ToArray();
            Assert.AreEqual(1, Queries.TimesWasHere);
            Assert.AreEqual(4, items.Length);
        }
Esempio n. 16
0
        public Product IndexedExactMatch()
        {
            int code = _code = (_code + 1) % _maxCode;

            return(_indexed.Where(p => p.Code == code).Enumerate());
        }