예제 #1
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2014/3/20 14:52:55</remarks>
        public bool Update(LogInfoEntity entity, DbTransaction trans)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_LogInfo_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@AppId", DbType.Int32, entity.AppId);
            database.AddInParameter(commandWrapper, "@TerminalIP", DbType.AnsiString, entity.TerminalIP);
            database.AddInParameter(commandWrapper, "@ModuleId", DbType.Int32, entity.ModuleId);
            database.AddInParameter(commandWrapper, "@FunctionId", DbType.Int32, entity.FunctionId);
            database.AddInParameter(commandWrapper, "@Message", DbType.AnsiString, entity.Message);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Int32)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
예제 #2
0
        public void Update(SynCheckedDataInfoEntity entity)
        {
            LogInfoEntity log = new LogInfoEntity()
            {
                AccountName = entity.AccountName, Operation = GetOperation(), ErrorDate = DateTime.Now, Tag = entity.DealWithId
            };

            try
            {
                string fileContent = string.Empty;
                string filePath    = PathHelper.GetDirectoryName("Files") + entity.FileName;

                using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    using (StreamReader sr = new StreamReader(fs, Encoding.Default))
                    {
                        fileContent = sr.ReadToEnd();
                    }
                }

                if (string.IsNullOrWhiteSpace(fileContent) == false)
                {
                    string[] rows = fileContent.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                    if (rows.Length > 1)
                    {
                        // 第一行是标题,从第2行开始读
                        for (int i = 1; i < rows.Length; i++)
                        {
                            string   row    = rows[i];
                            string[] fields = row.Split('\t');
                            DealRowData(fields, entity);
                        }
                        // 读取完成,删除缓存、数据库数据、文件
                        DataHelper.RemoveSynCheckedDataInfo(entity);
                        File.Delete(filePath);

                        log.ErrorMsg = "同步完成";
                        ParamHelper.wcfLog.Add(log);
                    }
                    else
                    {
                        // 只有标题,没有谁数据,删掉文件和记录
                        DataHelper.RemoveSynCheckedDataInfo(entity);
                        File.Delete(filePath);

                        log.ErrorMsg = "因为没有数据而删除";
                        ParamHelper.wcfLog.Add(log);
                    }
                }
            }
            catch (Exception ex)
            {
                log.ErrorMsg = ex.Message;
                // 找不到文件删除记录
                DataHelper.RemoveSynCheckedDataInfo(entity);
                ParamHelper.wcfLog.Add(log);
            }
        }
예제 #3
0
        public static void AddLog(LogInfoEntity entity)
        {
            string strIsLog = ConfigurationManager.AppSettings["IsLog"].ToString();
            bool   isLog    = bool.Parse(strIsLog);

            if (isLog)
            {
                ParamHelper.wcfLog.Add(entity);
            }
        }
예제 #4
0
        public void LogInfoToEntityTest()
        {
            LogInfoEntity converted = mapper.ToEntity(log);

            Assert.AreEqual(log.Id, converted.Id);
            Assert.AreEqual(log.Message, converted.Messagge);
            Assert.AreEqual(log.LogType, converted.LogType);
            Assert.AreEqual(log.Username, converted.Username);
            Assert.AreEqual(log.Date, converted.Date);
        }
예제 #5
0
        public static void AddLog(string errorMsg, string accountName = "System", string operation = null, string tag = null)
        {
            LogInfoEntity entity = new LogInfoEntity();

            entity.AccountName = accountName;
            entity.ErrorMsg    = errorMsg;
            entity.ErrorDate   = DateTime.Now;
            entity.Operation   = operation;
            entity.Tag         = tag;

            AddLog(entity);
        }
예제 #6
0
        /// <summary>
        /// 将IDataReader的当前记录读取到LogInfoEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public LogInfoEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new LogInfoEntity();

            obj.Idx        = (System.Int32)reader["Idx"];
            obj.AppId      = (System.Int32)reader["AppId"];
            obj.TerminalIP = (System.String)reader["TerminalIP"];
            obj.ModuleId   = (System.Int32)reader["ModuleId"];
            obj.FunctionId = (System.Int32)reader["FunctionId"];
            obj.Message    = (System.String)reader["Message"];
            obj.RowTime    = (System.DateTime)reader["RowTime"];

            return(obj);
        }
예제 #7
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>LogInfoEntity</returns>
        /// <remarks>2014/3/20 14:52:55</remarks>
        public LogInfoEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_LogInfo_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, idx);


            LogInfoEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
예제 #8
0
 public void Initialize()
 {
     mapper = new LogInfoMapper();
     entity = new LogInfoEntity()
     {
         Id       = 1,
         Messagge = "User logged using API",
         LogType  = LogType.LOGIN,
         Username = "******",
         Date     = DateTime.Now
     };;
     log = new LogInfo()
     {
         Id       = 1,
         Message  = "User logged using API",
         LogType  = LogType.LOGIN,
         Username = "******",
         Date     = DateTime.Now
     };
 }
예제 #9
0
 static void SaveInfo(string functionName, string message, string zoneId = "")
 {
     try
     {
         var systeminfologEntity = new LogInfoEntity()
         {
             AppId      = ShareUtil.AppId,
             TerminalIP = _terminalIP,
             FunctionId = FunctionAppCache.Instance.GetFunctionId(functionName),
             ModuleId   = 1,
             Message    = message,
             RowTime    = DateTime.Now
         };
         LogInfoMgr.Insert(systeminfologEntity, null, zoneId);
     }
     catch (Exception ex)
     {
         LogHelper.Insert(ex);
     }
 }
예제 #10
0
 /// <summary>
 /// Update
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 /// <remarks>2014/3/20 14:52:55</remarks>
 public bool Update(LogInfoEntity entity)
 {
     return(Update(entity, null));
 }
예제 #11
0
 /// <summary>
 /// Insert
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="trans">The trans.</param>
 /// <returns></returns>
 /// <remarks>2014/3/20 14:52:55</remarks>
 public bool Insert(LogInfoEntity entity)
 {
     return(Insert(entity, null));
 }
예제 #12
0
        public static void AddLog(LogInfoEntity entity)
        {
            var db = CoreDBContext.GetContext();

            db.Set <LogInfoEntity>().Add(entity);
        }
예제 #13
0
        public static bool Update(LogInfoEntity logInfoEntity, DbTransaction trans = null)
        {
            var provider = new LogInfoProvider();

            return(provider.Update(logInfoEntity, trans));
        }
예제 #14
0
        public static bool Insert(LogInfoEntity logInfoEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new LogInfoProvider(zoneId);

            return(provider.Insert(logInfoEntity, trans));
        }