Beispiel #1
0
        public IEnumerable <DomainResult> GetForTracking(string trackingId)
        {
            var retry     = 5;
            var sleepTime = 50;

            DomainResult[] results = { new DomainResult {
                                           ResultCode = ResultCode.OK
                                       } };
            while (retry > 0)
            {
                try
                {
                    results = _persistanceStore.GetAll <DomainResult>().Where(x => x.TrackingId == trackingId).ToArray();
                    retry   = 0;
                    break;
                }
                catch (Exception e)
                {
                    _logger.DebugFormat("Failed to read trackingId {0}, {1}", trackingId, e.Message);
                    if (--retry == 0)
                    {
                        _logger.Error(e.ToString());
                        return(new DomainResult[] { new DomainResult {
                                                        ResultCode = ResultCode.OK
                                                    } });
                    }
                    else
                    {
                        Thread.Sleep(sleepTime);
                        sleepTime *= 2;
                    }
                }
            }

            return(results);
        }
Beispiel #2
0
        public IEnumerable <DomainEvent> Get(Guid aggregateId, int fromVersion)
        {
            var aggregates = _persistanceStore.GetAll <PersistedDomainEvent>().Where(x => x.EventId == aggregateId.ToString() && x.Version >= fromVersion);

            return(aggregates.OrderBy(x => x.Version).Select(x => x.Source).ToList());
        }
        public void TestAllObjectsCanBeRetrievedAtOnce()
        {
            var persistedObject = new PersistedString {
                Content = "content", Id = "Id"
            };
            var persistedObject2 = new PersistedString {
                Content = "content2", Id = "Id2"
            };

            PersistanceStore.Save <PersistedString>(new[] { persistedObject, persistedObject2 });
            var saved = PersistanceStore.GetAll <PersistedString>().ToArray();

            Assert.AreEqual(2, saved.Count());
            Assert.IsTrue(saved.Any(x => x.Id == "Id" && Equals(x.Content, "content")));
            Assert.IsTrue(saved.Any(x => x.Id == "Id" && Equals(x.GetContent <string>(), "content")));
            Assert.IsTrue(saved.Any(x => x.Id == "Id2" && Equals(x.Content, "content2")));
            Assert.IsTrue(saved.Any(x => x.Id == "Id2" && Equals(x.GetContent <string>(), "content2")));
        }