Esempio n. 1
0
        public ResultObject AddReader(ReaderInfo objReaderInfo)
        {
            lock (objLock)
            {
                LoggerAgent.Trace("Entering...");

                ResultObject objRes = new ResultObject();
                objRes.MethodInfo = "ReaderService.AddReader ";

                try
                {

                    // -- Adding reader to DB ----
                    ReaderDA objReaderDA = new ReaderDA();
                    objRes = objReaderDA.AddReader(objReaderInfo);

                    if (objRes.IsSuccess == false)
                    {
                        return objRes;
                    }

                    // --- Connecting to actual reader ---
                    RFIDMotorolaReader rdrObject = null;
                    try
                    {
                        rdrObject = new RFIDMotorolaReader(objReaderInfo, 1000, readerPulseMonitor_InMin);
                        objRes.IsSuccess = rdrObject.Connect(pollCycle, true);
                    }
                    catch (Exception ex)
                    {
                        objRes.IsSuccess = false;
                        objRes.ErrorMessage = "Unable to connect to Reader. IP Address " + objReaderInfo.IPAddress;
                        objRes.ErrorMessageInternal = "Error : " + ex.ToString();
                    }

                    //Reader-Service collection will cache actual reader.
                    dicReaders[objReaderInfo.ReaderId] = rdrObject;

                    //Set result object: - /*set online status*/
                    objReaderInfo.IsOnline = objRes.IsSuccess;
                    //Set readerInfo in result object
                    // NOTE: ReaderId key is already SET by DAL call.
                    // objRes.ResultData["ReaderInfo"] = objReaderInfo;
                    objRes.MethodInfo = "ReaderService.AddReader ";
                    objRes.TimeStampString = DateTime.Now.ToString();

                    LoggerAgent.Debug("Reader status:  "
                        + " Reader IP:Port = " + rdrObject.ReaderInfo.IPAddress + ":"  + rdrObject.ReaderInfo.PortNo.ToString()
                        + ", IsOnline = " + rdrObject.ReaderInfo.IsOnline.ToString() );
                }
                catch (Exception ex)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "Unable to Add Reader. IP Address " + objReaderInfo.IPAddress;
                    objRes.ErrorMessageInternal = "Error : " + ex.ToString();

                    LoggerAgent.Error("Error : Failed to AddReader. " + objRes.ErrorMessage, ex);
                }
                finally
                {
                    LoggerAgent.Trace("Leaving...");
                }

                LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
                return objRes;
            }
        }
Esempio n. 2
0
        private void MonitoringTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            monitoringTimer.Stop();
            try
            {
                foreach (var reader in currentGroup.Readers)
                {
                    if (dicReaders.ContainsKey(reader.ReaderId))
                    {
                        RFIDMotorolaReader rdr = dicReaders[reader.ReaderId];
                        if (null != rdr)
                        {
                            if (!rdr.ReaderInfo.IsOnline)
                            {
                                try { rdr.Reconnect(pollCycle, true); }
                                catch
                                {
                                    // Log Reader is offline
                                    rdr.ReaderInfo.IsOnline = false;
                                }
                            }

                        }
                        else
                        {
                            lock (objLock)
                            {

                                RFIDMotorolaReader rdrObject = null;
                                try
                                {
                                    rdrObject = new RFIDMotorolaReader(reader, 1000, readerPulseMonitor_InMin);
                                    rdrObject.Connect(pollCycle, true);
                                }
                                catch
                                { //Log Reader is offline
                                    reader.IsOnline = false;
                                }

                                dicReaders[reader.ReaderId] = rdrObject;
                            }
                        }
                    }
                    else
                    {
                        lock (objLock)
                        {

                            RFIDMotorolaReader rdrObject = null;
                            try
                            {
                                rdrObject = new RFIDMotorolaReader(reader, 1000, readerPulseMonitor_InMin);
                                rdrObject.Connect(pollCycle, true);
                            }
                            catch
                            { //Log Reader is offline
                                reader.IsOnline = false;
                            }

                            dicReaders[reader.ReaderId] = rdrObject;
                        }
                    }
                }
            }
            catch { }
            finally
            {
                monitoringTimer.Start();
            }
        }
Esempio n. 3
0
        private bool InitService()
        {
            bool isInitDone = false;
            try
            {
                // Get Reader Group Details
                iReaderGroupID = int.Parse(ConfigurationManager.AppSettings["ReaderGroupID"]);

                ReaderGroupDA rdrGrpDataAccess = new ReaderGroupDA();
                currentGroup = rdrGrpDataAccess.GetReaderGroup(iReaderGroupID);

                if (!int.TryParse(ConfigurationManager.AppSettings["PollCycle"], out pollCycle))
                    pollCycle = 10000;

                //ReaderPulseMonitor_InMin
                if (!int.TryParse(ConfigurationManager.AppSettings["ReaderPulseMonitor_InMin"], out readerPulseMonitor_InMin))
                    readerPulseMonitor_InMin = 30;

                // Initialize all readers
                Parallel.ForEach(currentGroup.Readers,
                    rdr =>
                    {

                        RFIDMotorolaReader rdrObject = null;
                        try
                        {
                            rdrObject = new RFIDMotorolaReader(rdr, 1000, readerPulseMonitor_InMin);
                            rdrObject.Connect(pollCycle, true);

                        }
                        catch
                        { //Log Reader is offline }
                            rdr.IsOnline = false;
                        }

                        lock (objLock)
                        {
                            dicReaders[rdr.ReaderId] = rdrObject;
                        }
                    });

                monitoringTimer = new System.Timers.Timer(5000);
                monitoringTimer.Elapsed += MonitoringTimer_Elapsed;
                monitoringTimer.Start();

                isInitDone = true;
            }
            catch (Exception ex)
            {
                isInitDone = false;
                LoggerAgent.Error("Error in init reader service.", ex);
            }
            finally
            {
                LoggerAgent.Trace("Leaving...");
            }

            return isInitDone;
        }