コード例 #1
0
        public List <CoetLogInfoEntity> GetLog(string startDateTime, string endDateTime, string logType)
        {
            try
            {
                string execSql           = string.Empty;
                string typeWhereTemplate = string.Empty;

                string sqlTemplate = @"select Type, JsonInfo, SendIP, SendName, Createdt 
                                       from {0} where Createdt between @startDateTime and @endDateTime";

                if (logType == "ALL")
                {
                    typeWhereTemplate = "and 1 = 1";
                }
                else
                {
                    typeWhereTemplate = string.Format("and Type = '{0}'", logType);
                }

                sqlTemplate = string.Format("{0} {1}", sqlTemplate, typeWhereTemplate);

                DateTime sDate = Convert.ToDateTime(startDateTime);
                DateTime eDate = Convert.ToDateTime(endDateTime);

                if (sDate.Year != eDate.Year || sDate.Month != eDate.Month)
                {
                    string stableName = LogTable.GetLogTName(sDate);
                    string etableName = LogTable.GetLogTName(eDate);

                    execSql = string.Format("{0} union {1}",
                                            string.Format(sqlTemplate, stableName),
                                            string.Format(sqlTemplate, etableName));
                }
                else
                {
                    string tableName = LogTable.GetLogTName(sDate);
                    execSql = string.Format(sqlTemplate, tableName);
                }

                return(DBOperate.ExecuteDataList <CoetLogInfoEntity>(execSql, new { startDateTime = startDateTime, endDateTime = endDateTime }));
            }
            catch (Exception ex)
            {
                CoetLocalLog.Error(ex.ToString());
                return(new List <CoetLogInfoEntity>());
            }
        }
コード例 #2
0
 public static List <T> ExecuteDataList <T>(string sql, object param)
 {
     try
     {
         if (string.IsNullOrEmpty(connectStr))
         {
             connectStr = GetConnectStr();
         }
         List <T> list = null;
         using (MySqlConnection con = new MySqlConnection(connectStr))
         {
             list = con.Query <T>(sql, param).AsList();
         }
         return(list);
     }
     catch (Exception ex)
     {
         CoetLocalLog.Error(ex.ToString());
         throw ex;
     }
 }
コード例 #3
0
 public static int ExecuteNonQuery(string sql, object param)
 {
     try
     {
         if (string.IsNullOrEmpty(connectStr))
         {
             connectStr = GetConnectStr();
         }
         int result = 0;
         using (MySqlConnection con = new MySqlConnection(connectStr))
         {
             result = con.Execute(sql, param);
         }
         return(result);
     }
     catch (Exception ex)
     {
         CoetLocalLog.Error(ex.ToString());
         throw ex;
     }
 }
コード例 #4
0
        public int SaveLog(List <CoetLogInfoEntity> logInfoList)
        {
            try
            {
                string tableName = LogTable.GetCurrentLogTName();

                int executeCount = 0;
                int levelCount   = 200;
                int partCount    = 1;

                if (logInfoList.Count > levelCount)
                {
                    partCount = logInfoList.Count / levelCount;
                }
                List <List <CoetLogInfoEntity> > partList = CoetArry.splitList(logInfoList, partCount);

                foreach (var part in partList)
                {
                    StringBuilder sb = new StringBuilder();

                    foreach (var item in part)
                    {
                        sb.AppendFormat(@"insert into {0}(Type, JsonInfo, SendIP, SendName, IdentificationId, Createdt) value('{1}', '{2}', '{3}', '{4}', '{5}', now());",
                                        tableName, item.Type, item.JsonInfo, item.SendIP, item.SendName, Guid.NewGuid().ToString());
                    }

                    executeCount += DBOperate.ExecuteNonQuery(sb.ToString(), new { });
                }

                return(executeCount);
            }
            catch (Exception ex)
            {
                CoetLocalLog.Error(ex.ToString());
                return(0);
            }
        }
コード例 #5
0
    static void Main(string[] args)
    {
        CoetLocalLog.StartSave();
        CoetLocalLog.Info("Begin Start CoetServer....");

        var conf = new ConfigurationBuilder()
                   .AddJsonFile("AppConfig.json")
                   .Build();

        string listenIP    = conf.GetSection("AppConfig:Listen:IP").Value;
        int    logPort     = int.Parse(conf.GetSection("AppConfig:Listen:LogPort").Value);
        int    analysePort = int.Parse(conf.GetSection("AppConfig:Listen:AnalysePort").Value);

        AutoResetEvent autoReset = new AutoResetEvent(false);

        Server LogServer = new Server
        {
            Services = { CoetLog.BindService(new LogHandlers()) },
            Ports    = { new ServerPort(listenIP, logPort, ServerCredentials.Insecure) }
        };

        LogServer.Start();

        CoetLocalLog.Info("LogServer Started");

        Server AnalyseServer = new Server
        {
            Services = { CoetAnalyse.BindService(new AnalyseHandlers()) },
            Ports    = { new ServerPort(listenIP, analysePort, ServerCredentials.Insecure) }
        };

        AnalyseServer.Start();

        CoetLocalLog.Info("AnalyseServer Started");

        autoReset.WaitOne();
    }