Example #1
0
 public void InitService(ETC.ETCSetting etc)
 {
     ETC.ETCService s = null;
     if (!_Services.ContainsKey(etc.GetType()))
     {
         s                        = new ETC.ETCService();
         s.OnReadCard            += new EventHandler <OpenCardEventArgs>(s_OnReadCard);
         s.OnPaying              += new EventHandler <OpenCardEventArgs>(s_OnPaying);
         s.OnPaidOk              += new EventHandler <OpenCardEventArgs>(s_OnPaidOk);
         s.OnPaidFail            += new EventHandler <OpenCardEventArgs>(s_OnPaidFail);
         s.OnError               += new EventHandler <OpenCardEventArgs>(s_OnError);
         _Services[etc.GetType()] = s;
     }
     else
     {
         s = _Services[etc.GetType()] as ETC.ETCService;
     }
     s.Setting = etc;
     _Services[etc.GetType()].Init();
 }
Example #2
0
 public static ETCSetting GetSetting()
 {
     try
     {
         if (_CurSetting == null)
         {
             var items = ETCDevice.GetAllDevices();
             if (items != null && items.Length > 0)
             {
                 _CurSetting         = new ETCSetting();
                 _CurSetting.Devices = new List <ETCDeviceInfo>();
                 _CurSetting.Devices.AddRange(items);
                 var original = new SysParaSettingsBll(AppSettings.CurrentSetting.ParkConnect).GetSetting <ETCSetting>();
                 if (original != null && original.Devices != null)
                 {
                     if (original.ReadSameCardInterval > 0)
                     {
                         _CurSetting.ReadSameCardInterval = original.ReadSameCardInterval;
                     }
                     foreach (var item in items)
                     {
                         var o = original.Devices.SingleOrDefault(it => it.LaneNo == item.LaneNo);
                         item.EntranceID    = o != null ? o.EntranceID : 0;
                         item.DisableReader = o != null ? o.DisableReader : true;
                         item.DisableRSU    = o != null ? o.DisableRSU : true;
                     }
                 }
             }
             else
             {
                 _CurSetting = new SysParaSettingsBll(AppSettings.CurrentSetting.ParkConnect).GetSetting <ETCSetting>();
             }
         }
     }
     catch (Exception ex)
     {
         Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
     }
     return(_CurSetting);
 }
Example #3
0
        private void ReaderRead_Thread()
        {
            string   lastCard = null;
            DateTime lastDT   = DateTime.Now;

            try
            {
                Thread.Sleep(2000);
                while (true)
                {
                    try
                    {
                        var r = ReaderRead();
                        if (r != null && r.ErrorCode == 0)
                        {
                            var w = r as GetCardInfoResponse;
                            if (GlobalSettings.Current.Get <Dictionary <int, CardEventReport> >().ContainsKey(EntranceID))
                            {
                                lastCard = GlobalSettings.Current.Get <Dictionary <int, CardEventReport> >()[EntranceID].CardID;
                                lastDT   = GlobalSettings.Current.Get <Dictionary <int, CardEventReport> >()[EntranceID].EventDateTime;
                            }
                            if (w.CardNo == lastCard && CalInterval(lastDT, DateTime.Now) < ETCSetting.GetSetting().ReadSameCardInterval)
                            {
                                continue;
                            }
                            if (this.OnReadCardInfo != null)
                            {
                                this.OnReadCardInfo(this, new ReadCardInfoEventArgs()
                                {
                                    CardInfo = w
                                });
                            }
                            Thread.Sleep(1000);
                            State = 0;
                        }
                        else
                        {
                            var msg = ErrorDescr(r.ErrorCode);
                            if (!string.IsNullOrEmpty(msg) && this.OnError != null)
                            {
                                OpenCardEventArgs args = new OpenCardEventArgs()
                                {
                                    Entrance  = Ralid.Park.BLL.ParkBuffer.Current.GetEntrance(EntranceID),
                                    LastError = msg,
                                };
                                this.OnError(this, args);
                            }
                            Thread.Sleep(500);  //如果某一个函数调用失败,则休眠一段时间,避免循环太快
                        }
                    }
                    catch (Exception)
                    {
                        Thread.Sleep(500); //如果某一个函数调用失败,则休眠一段时间,避免循环太快
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
        }