Beispiel #1
0
 private void FreshRegion_Thread()
 {
     while (true)
     {
         try
         {
             Thread.Sleep(1000);
             if (_CurrentRegion == null)
             {
                 continue;
             }
             var con = new CardEventSearchCondition()
             {
                 EventTime = new DateTimeRange()
                 {
                     Begin = _LastDateTime, End = DateTime.Now
                 }
             };
             List <CardEvent> events = new CardEventClient(AppSettings.Current.ConnStr).GetItems(con, true).QueryObjects;
             if (events != null && events.Count > 0)
             {
                 events = (from it in events orderby it.EventTime ascending select it).ToList();
                 foreach (var item in events)
                 {
                     _CurrentRegion.HandleCardEvent(item);
                 }
                 _LastDateTime = events.Max(it => it.EventTime);
             }
         }
         catch (ThreadAbortException)
         {
             break;
         }
         catch (Exception)
         {
         }
     }
 }
 private void FreshRegion_Thread()
 {
     while (true)
     {
         try
         {
             Thread.Sleep(1000);
             if (_CurrentRegion == null)
             {
                 continue;
             }
             var con = new CardEventSearchCondition()
             {
                 EventTime = new DateTimeRange()
                 {
                     Begin = _FirstTime ? DateTime.Now.AddDays(-2) : DateTime.Now.AddMinutes(-30), //第一次获取两天之前的记录
                     End   = DateTime.Now.AddMinutes(30)                                           //这里获取事件的时间为当前时间再往前半个小时
                 }
             };
             _LastCardEvent = null;
             List <CardEvent> events = new CardEventClient(_Url).GetItems(con, true).QueryObjects;
             if (events != null && events.Count > 0)
             {
                 events = (from it in events orderby it.EventTime ascending select it).ToList();
                 foreach (var item in events)
                 {
                     if (!_CurrentRegion.IsMyDoor(item.DoorID))
                     {
                         continue;
                     }
                     if (!_LastEvents.Exists(it => it.EventTime == item.EventTime && it.UserID == item.UserID))
                     {
                         _LastEvents.Add(item);
                         if (!_FirstTime && IsMyDoor(item.DoorName))
                         {
                             _LastCardEvent = item;
                         }
                         _CurrentRegion.HandleCardEvent(item);
                     }
                 }
                 if (_LastCardEvent != null)
                 {
                     GetPersonDetail(_LastCardEvent.UserID);
                 }
             }
             if (_FirstTime)
             {
                 _FirstTime = false;
             }
             _LastEvents.RemoveAll(it => it.EventTime < con.EventTime.Begin);
             if (_CurrentRegion.PersonChanged)
             {
                 _CurrentRegion.PersonChanged = false;
                 this.RunOnUiThread(() => FreshRegion());
             }
         }
         catch (ThreadAbortException)
         {
             break;
         }
         catch (Exception)
         {
         }
     }
 }