Exemple #1
0
        public void Add(TimeoutData timeout)
        {
            Logger.Debug("Adding timeout");

            if (timeout == null)
            {
                Logger.Debug("Timeout is null! Throwing");
                throw new ArgumentNullException("timeout");
            }

            Guid timeoutId = CombGuid.NewGuid();
            Logger.DebugFormat("Created new comb guid for timeout ID {0}", timeoutId);
            TimeoutDataEntity timeoutEntity = new TimeoutDataEntity
            {
                Destination = timeout.Destination.ToString(),
                Endpoint = timeout.OwningTimeoutManager,
                Headers = timeout.Headers.ToDictionaryString(),
                Id = timeoutId,
                SagaId = timeout.SagaId,
                State = timeout.State,
                Time = timeout.Time
            };

            using (ITimeoutDbContext dbc = _dbContextFactory.CreateTimeoutDbContext())
            {
                Logger.Debug("Saving timeout entity");
                dbc.Timeouts.Add(timeoutEntity);
                dbc.SaveChanges();
            }
        }
Exemple #2
0
        public void RemoveTimeoutBy(Guid sagaId)
        {
            Logger.DebugFormat("Removing timeout for saga ID {0}", sagaId);

            if (sagaId == Guid.Empty)
            {
                Logger.Debug("sageId is empty! Throwing");
                throw new ArgumentException("sagaId parameter cannot be empty.", "sagaId");
            }

            using (ITimeoutDbContext dbc = _dbContextFactory.CreateTimeoutDbContext())
            {
                IQueryable<TimeoutDataEntity> toDelete = dbc.Timeouts.Where(t => t.SagaId == sagaId);
                Logger.DebugFormat("{0} timeout(s) found for saga.", toDelete.Count());
                dbc.Timeouts.RemoveRange(toDelete);

                dbc.SaveChanges();
            }
        }
Exemple #3
0
        public bool TryRemove(string timeoutId)
        {
            Logger.DebugFormat("Trying to remove timeout with Id {0}.", timeoutId);

            using (ITimeoutDbContext dbc = _dbContextFactory.CreateTimeoutDbContext())
            {
                Guid timeoutGuid = Guid.Parse(timeoutId);
                TimeoutDataEntity entity = dbc.Timeouts.Find(timeoutGuid);

                if (entity == null)
                {
                    Logger.Debug("Didn't find timeout!");
                    return false;
                }

                Logger.Debug("Found timeout, removing.");
                dbc.Timeouts.Remove(entity);
                dbc.SaveChanges();
            }

            return true;
        }