Пример #1
0
 protected void UpdateJoinedEvent(Guid accountId, Guid componentId, EventCacheWriteObject oldEvent, Event newEvent)
 {
     oldEvent.Importance = newEvent.Importance;
     oldEvent.Count      = AddCount(oldEvent.Count, newEvent.Count);
     oldEvent.ActualDate = newEvent.ActualDate;
     oldEvent.Message    = newEvent.Message; // сообщение обновлять надо, чтобы в личном кабинете можно было смотреть последнее сообщение проверки
     if (newEvent.EndDate > oldEvent.EndDate)
     {
         oldEvent.EndDate = newEvent.EndDate;
     }
     oldEvent.LastUpdateDate = DateTime.Now;
 }
Пример #2
0
        protected IEventCacheReadObject CreateOrJoinSimpleEvent(
            Guid componentId,
            Event eventObj,
            Guid?oldEventId,
            TimeSpan joinInterval,
            Guid accountId,
            out bool isEventNew)
        {
            IEventCacheReadObject rLastEvent = null;

            if (oldEventId.HasValue)
            {
                rLastEvent = AllCaches.Events.Find(new AccountCacheRequest()
                {
                    AccountId = accountId,
                    ObjectId  = oldEventId.Value
                });
            }
            else
            {
                var accountDbContext = Context.DbContext.GetAccountDbContext(accountId);
                var repository       = accountDbContext.GetEventRepository();
                var lastEvent        = repository.GetForJoin(eventObj);
                if (lastEvent != null)
                {
                    rLastEvent = AllCaches.Events.GetForRead(lastEvent, accountId);
                }
            }

            if (rLastEvent != null)
            {
                var request = new AccountCacheRequest()
                {
                    AccountId = accountId,
                    ObjectId  = rLastEvent.Id
                };
                if (AllCaches.Events.ExistsInStorage(request))
                {
                    using (var wLastEvent = AllCaches.Events.Write(request))
                    {
                        bool canJoin = EventHelper.CanJoinSimpleEvents(wLastEvent, eventObj, joinInterval);
                        if (canJoin)
                        {
                            // Можно склеивать
                            UpdateJoinedEvent(accountId, componentId, wLastEvent, eventObj);
                            isEventNew = false;
                            wLastEvent.BeginSave();
                            return(wLastEvent);
                        }
                    }
                }
            }


            // Создадим новое
            {
                var accountDbContext = Context.DbContext.GetAccountDbContext(accountId);
                var eventRepository  = accountDbContext.GetEventRepository();
                isEventNew = true;
                eventRepository.Add(eventObj);
                accountDbContext.SaveChanges();
                var wEvent = EventCacheWriteObject.CreateForUpdate(eventObj, accountId);
                AllCaches.Events.AddOrGet(wEvent);
                return(wEvent);
            }
        }