示例#1
0
 public void AddEvent(EventInfo info, bool onlyNew)
 {
     //本地添加事件不产生订阅
     using (var ef = new ServiceDBContext())
     {
         if (onlyNew)
         {
             if (ef.EventInfo.Count(r => r.Type == info.Type && r.Time == info.Time) > 0)
             {
                 return;
             }
         }
         ef.EventInfo.Add(info);
         ef.SaveChanges();
     }
 }
示例#2
0
 internal int Add4Cloud(List <ServiceInfo> data)
 {
     //新增或更新,仅在CLOUD模式下
     if (GlobalConfig.Instance.Client == "CLOUD")
     {
         using (var ef = new ServiceDBContext())
         {
             var client  = data.First().Client;
             var oldList = ef.ServiceInfo.Where(r => r.Client == client).ToList();
             ef.ServiceInfo.RemoveRange(oldList);
             ef.ServiceInfo.AddRange(data);
             return(ef.SaveChanges());
         }
     }
     else
     {
         return(0);
     }
 }
示例#3
0
        public int AddEvent4Cloud(List <EventInfo> infoList)
        {
            using (var ef = new ServiceDBContext())
            {
                int c = 0;
                foreach (var info in infoList)
                {
                    if (!ef.EventInfo.Any(r => r.Id == info.Id))
                    {
                        ef.EventInfo.Add(info);
                        c++;
#if DEBUG
                    }
                    //补足推送记录
                    if (!ef.EventPushRecord.Any(r => r.Event == info.Id))
                    {
#endif
                        //根据订阅规则生成待推送记录
                        var sub = ef.ClientEventSubscriber.Include(r => r.EventSubscriber).Where(r => r.Client == info.Client && r.EventSubscriber.IsEnable).ToList();
                        sub.ForEach(s =>
                        {
                            ef.EventPushRecord.Add(new EventPushRecord()
                            {
                                Id         = Guid.NewGuid(),
                                Pushed     = false,
                                PushTime   = DateTime.Now,
                                Event      = info.Id,
                                Subscriber = s.Subscriber
                            });
                        });
                    }
                }
                ef.SaveChanges();
                return(c);
            }
        }