Ejemplo n.º 1
0
        public bool BulkInsertLog(LogModel log)
        {
            try
            {
                string conn = @"Data Source=.\localdb;Initial Catalog=workDB;UID=sa;PWD=123456;";
                SqlConnection sqlcon = new SqlConnection(conn);
                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();

                DataTable table = this.CreateDataTable();
                this.AddModelToDataTable(table, log);
                sqlcon.Open();

                using (SqlBulkCopy bulk = new SqlBulkCopy(conn))
                {
                    bulk.BatchSize = this.logModelList.Count;
                    bulk.DestinationTableName = "CallInterfaceLog";
                    bulk.ColumnMappings.Add("ID", "ID");
                    bulk.ColumnMappings.Add("SoufunId", "SoufunId");
                    bulk.ColumnMappings.Add("OrderId", "OrderId");
                    bulk.ColumnMappings.Add("InterfaceName", "InterfaceName");
                    bulk.ColumnMappings.Add("ResponseStartTime", "ResponseStartTime");
                    bulk.ColumnMappings.Add("ResponseEndTime", "ResponseEndTime");
                    bulk.ColumnMappings.Add("Imei", "Imei");
                    bulk.ColumnMappings.Add("Appv", "Appv");
                    bulk.ColumnMappings.Add("AppType", "AppType");
                    bulk.ColumnMappings.Add("CreateTime", "CreateTime");
                    bulk.ColumnMappings.Add("InterfaceUrl", "InterfaceUrl");
                    bulk.ColumnMappings.Add("ParamsStr", "ParamsStr");
                    bulk.ColumnMappings.Add("IsDel", "IsDel");
                    bulk.ColumnMappings.Add("Status", "Status");
                    bulk.WriteToServer(table);
                }

                stopWatch.Stop();
                TimeSpan ts = stopWatch.Elapsed;
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:000}",
                                                                        ts.Hours, ts.Minutes, ts.Seconds,
                                                                        ts.Milliseconds);
                Console.WriteLine("RunTime " + elapsedTime);
                //
                table.Dispose();
                sqlcon.Close();
                sqlcon.Dispose();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return true;
        }
Ejemplo n.º 2
0
        public StringTest()
        {
            string str = "13851870675";

            //Console.WriteLine(str.IsNullOrEmpty());
            //Console.WriteLine(str.MaskPhoneNo());
            //Console.WriteLine(str.Encrypt());
            //Console.WriteLine(str.CreateSQLInsertNewEntity<BaseModel>());
            //Console.WriteLine(str.CreateSQLUpdateById<BaseModel>());

            object columnParam = new { Id=1,Name="名称",Age=10,Phone="13121135599"};
            object conditionParam = new { Id = 1, Phone =11111};

            Console.WriteLine(str.CreateSQLUpdateByProperties<BaseModel>(columnParam, conditionParam));

            string s = "Hello World!";
            this.RefStr(ref s);
            Console.WriteLine(s);

            this.OutStr(out s);
            Console.WriteLine(s);

            ToUTF8("EOP电商");

            string score = "+5";
            int ss = int.Parse(score);

            score = "-5";
            ss = int.Parse(score);
            DateTime dd = DateTime.Parse("1900/1/1");

            Console.WriteLine((decimal)ss);

            Console.WriteLine(dd.ToString("yyyy-MM-dd HH:mm"));

            byte[] a = new byte[2];
            a[0] = 0x01;
            a[1] = 0x00;

            Type t = a.GetType();

            LogModel log = new LogModel()
            {
                interfaceName =null
            };

            Console.WriteLine(string.IsNullOrEmpty(log.interfaceUrl));
        }
Ejemplo n.º 3
0
        private LogModel ParseParamListToLogModel(Dictionary<string, string> paramDict)
        {
            LogModel logModel = new LogModel();

            if (paramDict.ContainsKey("method"))
            {
                // 参数中Method
                logModel.interfaceUrl = paramDict["method"];
                // 参数中Method(同interfaceUrl)
                logModel.interfaceName = paramDict["method"];
            }

            if (paramDict.ContainsKey("RequestParamStr"))
            {
                // 请求参数get参数或post参数
                logModel.paramsStr = paramDict["RequestParamStr"];
            }

            if (paramDict.ContainsKey("timestamp"))
            {
                //  请求参数中timestamp
                logModel.createTime = paramDict["timestamp"];
            }

            if (paramDict.ContainsKey("imei"))
            {
                // 参数中的imei
                logModel.imei = paramDict["imei"];
            }

            if (paramDict.ContainsKey("appv"))
            {
                // 参数中的appv
                logModel.appv = paramDict["appv"];
            }

            if (paramDict.ContainsKey("RequestSoufunId"))
            {
                // 参数中的appv
                logModel.appv = paramDict["RequestSoufunId"];
            }

            return logModel;
        }
Ejemplo n.º 4
0
 private void AddModelToDataTable(DataTable table, LogModel model)
 {
     DataRow row = table.NewRow();
     //自增列
     //row["ID"] = logModel;
     row["SoufunId"] = string.IsNullOrEmpty(model.soufunId) ? 0L : long.Parse(model.soufunId);
     //未知字段
     //row["OrderId"] = logModel;
     row["InterfaceName"] = model.interfaceName;
     row["ResponseStartTime"] = DateTime.Now;
     row["ResponseEndTime"] = DateTime.Now;
     row["Imei"] = model.imei;
     row["Appv"] = model.appv;
     row["AppType"] = 1;
     row["CreateTime"] = string.IsNullOrEmpty(model.createTime) ? DateTime.Parse("1900/01/01") : DateTime.Parse(model.createTime.Replace("%2f", "/").Replace("%3a", ":").Replace("+", " "));
     row["InterfaceUrl"] = model.interfaceUrl;
     row["ParamsStr"] = model.paramsStr;
     row["IsDel"] = 0;
     row["Status"] = 3;
     table.Rows.Add(row);
 }