예제 #1
0
        public static string GetLogString(ResultObject obj)
        {
            StringBuilder logMsg = new StringBuilder();

            logMsg.AppendLine("[" + obj.TimeStampString +  "] MethodName : " + obj.MethodInfo );
            logMsg.AppendLine(", IsSuccess : " + obj.IsSuccess);

            if (!obj.IsSuccess)
            {
                logMsg.AppendLine(", ErrorMsg : " + obj.ErrorMessage);
                logMsg.AppendLine(", InternalErrorMsg : " + obj.ErrorMessageInternal);
            }

            return logMsg.ToString();
        }
예제 #2
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;
            }
        }
예제 #3
0
        public ResultObject ReconnectReader(ReaderInfo objReaderInfo)
        {
            LoggerAgent.Trace("Entering...");

            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderService.ReconnectReader ";
            try
            {
                //param validation
                if (objReaderInfo == null)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ReconnectReader Error : Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                if (objReaderInfo.ReaderId <= 0)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ReconnectReader Error : ReaderId is invalid. Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                var reader = dicReaders[objReaderInfo.ReaderId];
                reader.Reconnect(pollCycle, true);

                objRes.IsSuccess = true;

            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to ReconnectReader " + objReaderInfo.ReaderId.ToString();
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();

                LoggerAgent.Error("Error in Reconnecting reader, ReaderId = " + objReaderInfo.ReaderId.ToString(), ex);
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            //reset the methodinfo
            objRes.MethodInfo = "ReaderService.ReconnectReader ";

            LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
            LoggerAgent.Trace("Leaving...");

            return objRes;
        }
예제 #4
0
        public ResultObject ModifyReader(ReaderInfo objReaderInfo)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderService.ModifyReader ";
            try
            {
                //param validation
                if (objReaderInfo ==  null)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ModifyReader Error : Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                if (objReaderInfo.ReaderId <= 0)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ModifyReader Error : ReaderId is invalid. Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                ReaderDA objReaderDA = new ReaderDA();
                objRes = objReaderDA.ModifyReader(objReaderInfo);
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to modify reader " + objReaderInfo.ReaderId.ToString();
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            //reset the methodinfo
            objRes.MethodInfo = "ReaderService.ModifyReader ";

            LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
            LoggerAgent.Trace("Leaving...");
            return objRes;
        }
예제 #5
0
        //public ResultObject GetReaderDetails(int readerId)
        public ReaderInfo GetReaderDetails(int readerId)
        {
            LoggerAgent.Trace("Entering...");

            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderService.GetReaderDetails ";
            ReaderInfo rdrInfo = null;
            lock (objLock)
            {
                try
                {
                    RFIDMotorolaReader motoRdr;
                    motoRdr = dicReaders.ContainsKey(readerId) && dicReaders[readerId] != null ? dicReaders[readerId] : null;
                    //rdrInfo = dicReaders.ContainsKey(readerId) && dicReaders[readerId] != null ? dicReaders[readerId].ReaderInfo : null;

                    rdrInfo = motoRdr.ReaderInfo;

                    objRes.IsSuccess = true;

                }
                catch (Exception ex)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "Failed to get reader details.";
                    objRes.ErrorMessageInternal = "Error : " + ex.ToString();

                    LoggerAgent.Error("Failed to get reader details for readerId = " + readerId.ToString(), ex);
                }
            }

            objRes.ResultData["ReaderInfo"] = rdrInfo;
            objRes.TimeStampString = DateTime.Now.ToString();

            LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
            LoggerAgent.Trace("Leaving...");
            return rdrInfo;
        }
예제 #6
0
        public ResultObject AddReader(ReaderInfo readerInfo)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.AddReader ";
            string insertSql =
                                    "INSERT INTO [RF].[Reader] " +
                                                 " ([ReaderGroupID] " +
                                                 ", [ReaderTypeID] " +
                                                 ", [ReaderName] " +
                                                 ", [ReaderDescription] " +
                                                 ", [IPAddress] " +
                                                 ", [PortNo] " +
                                                 ", [MACAddress] " +
                                                 ", [AntennaPower] " +
                                                 ", [ReaderPower] " +
                                                 ", [LocationRef] " +
                                                 ", [LocationDescription] " +
                                                 ", [IsDeleted]  " +
                                                 ", [CreateDateTime]  " +
                                                 ", [UpdateDateTime] ) " +
                                                 " VALUES " +
                                                 "(@ReaderGroupID " +
                                                 ", @ReaderTypeID " +
                                                 ", @ReaderName " +
                                                 ", @ReaderDescription " +
                                                 ", @IPAddress " +
                                                 ", @PortNo " +
                                                 ", @MACAddress " +
                                                 ", @AntennaPower " +
                                                 ", @ReaderPower " +
                                                 ", @LocationRef " +
                                                 ", @LocationDescription " +
                                                 ", @IsDeleted " +
                                                 ", @CreateDateTime " +
                                                 ", @UpdateDateTime ); ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = insertSql;

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? "  " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, (float)1.0); // readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, 0);
                    dbhelper.AddParameter("@CreateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to add reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            //try to return readerId for newly added reader
            ResultObject internalResultObject = new ResultObject();
            internalResultObject = GetReaderByReaderName(readerInfo.ReaderName);

            //Assign readerId to main result object with key "ReaderId"
            objRes.ResultData["ReaderId"] = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
               readerInfo.ReaderId  = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
            objRes.ResultData["ReaderInsertSql"] = insertSql;
            objRes.TimeStampString = DateTime.Now.ToString();

            return objRes;
        }
예제 #7
0
        public ResultObject ModifyReader(ReaderInfo readerInfo, bool isdeleted = false)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.ModifyReader ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = "UPDATE [RF].[Reader] " +
                                                   "SET [ReaderGroupID] = @ReaderGroupID " +
                                                    ", [ReaderTypeID] = @ReaderTypeID " +
                                                    ", [ReaderName] = @ReaderName " +
                                                    ", [ReaderDescription] = @ReaderDescription  " +
                                                    ", [IPAddress] = @IPAddress  " +
                                                    ", [PortNo] = @PortNo  " +
                                                    ", [MACAddress] = @MACAddress " +
                                                    ", [AntennaPower] = @AntennaPower " +
                                                    ", [ReaderPower] = @ReaderPower  " +
                                                    ", [LocationRef] = @LocationRef  " +
                                                    ", [LocationDescription] = @LocationDescription  " +
                                                    ", [IsDeleted] = @IsDeleted " +
                                                    ", [UpdateDateTime] = @UpdateDateTime " +
                                                    " WHERE ReaderID = @ReaderID ;";

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? " " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, isdeleted ? 1 : 0);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@ReaderID", SqlDbType.Int, readerInfo.ReaderId);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                    objRes.ResultData["ReaderId"] = readerInfo.ReaderId;
                    //objRes.ResultData["ReaderInfo"] = readerInfo;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to modify reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }
예제 #8
0
        public ResultObject GetReaderByReaderName(string readerName)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderDA.GetReaderByReaderName ";
            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = "SELECT [ReaderID],[ReaderGroupID],[ReaderTypeID],[ReaderName],[ReaderDescription],[IPAddress],[PortNo],[MACAddress],[AntennaPower],[ReaderPower],[LocationRef],[LocationDescription],[IsDeleted]  FROM [RF].[Reader] WHERE [ReaderName] = '" + readerName + "'";
                    DataSet dsReaders = dbhelper.ExcuteDatset(dbhelper.Command);

                    if (dsReaders.Tables.Count == 0 || dsReaders.Tables[0].Rows.Count == 0)
                    {
                        //throw new Exception("Reader not found");
                        objRes.IsSuccess = false;
                        objRes.ErrorMessage = "Reader not found";
                        objRes.ErrorMessageInternal = "Empty data table returned by DAL for supplied readerName = " + readerName;
                    }

                    List<ReaderInfo> readersInfo = DbHelper.DataTableToList<ReaderInfo>(dsReaders.Tables[0]).ToList();

                    objRes.IsSuccess = true;
                    objRes.ResultData["ReaderInfo"] = readersInfo.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to get ReaderInfo from database on supplied readerName = " + readerName;
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }
예제 #9
0
        public ResultObject ExeSP(int readerId, string tagIds)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderDA.ExeSP ";

            string spName = "[RF].[spProcessTags]";
            try
            {
                using (var dbhelper = new DbHelper())
                {
                    dbhelper.Command.CommandType = System.Data.CommandType.StoredProcedure;
                    dbhelper.Command.CommandText = spName;
                    dbhelper.AddParameter("@ReaderId", SqlDbType.VarChar, readerId);
                    dbhelper.AddParameter("@tags", SqlDbType.VarChar, tagIds);

                    dbhelper.ExecuteNoneQuery();
                }

                objRes.IsSuccess = true;
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to execute sp for processing tags.";
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }