private static void WinSaveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { string[] sqls = null; lock (WinInfos) { if (WinInfos.Count == 0) { return; } sqls = new string[WinInfos.Count]; int i = 0; while (WinInfos.Count > 0) { WinInfo info = WinInfos.Dequeue(); sqls[i++] = info.GetSQL(); } } ThreadPool.QueueUserWorkItem(new WaitCallback( delegate(object obj) { //string[] sqls = (string[])obj; SQLiteTool.Command(WinInfo.DB_FILE, sqls); Logger.Debug("save wins record:" + sqls.Length); } )); }
private void WinSaveTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (!Program.Config.RecordWin) { return; } List <WinInfo> tmpList = new List <WinInfo>(); MutexWinInfo.WaitOne(); tmpList.AddRange(WinInfos); WinInfos.Clear(); MutexWinInfo.ReleaseMutex(); int count = tmpList.Count; if (count > 0) { string[] sqls = new string[count]; for (int i = 0; i < count; i++) { sqls[i] = tmpList[i].GetSQL(); } ThreadPool.QueueUserWorkItem(new WaitCallback( delegate(object obj) { //string[] sqls = (string[])obj; SQLiteTool.Command(Program.Config.WinDbName, sqls); Logger.WriteLine("save wins record:" + sqls.Length); } )); } }
static void IconInputDatabase() { string fileFolder = @"D:\Code\CJ\水上公安\HarborPoliceSolution\HarborPoliceWebApp\Content\police"; string dbFileName = @"D:\Code\CJ\水上公安\HarborPoliceSolution\HarborPoliceWebApp\App_Data\HarborPolice.db"; string sql = "INSERT INTO icon (id,data,enabled,time,remark) VALUES(:id,:data,:enabled,:time,:remark)"; SQLiteConnection connection = SQLiteTool.GetConnection(dbFileName); if (connection == null) { Console.WriteLine("sqlite connection error"); return; } if (connection.State == ConnectionState.Closed) { connection.Open(); } DirectoryInfo directoryInfo = new DirectoryInfo(fileFolder); foreach (FileInfo fileInfo in directoryInfo.GetFiles()) { if (fileInfo.Extension == ".png" || fileInfo.Extension == ".jpg") { byte[] imageData = ImageTool.ImageToBytes(fileInfo.FullName); Dictionary <string, object> paramters = new Dictionary <string, object>(); paramters.Add("id", Guid.NewGuid().ToString().ToLower()); paramters.Add("data", imageData); paramters.Add("enabled", 1); paramters.Add("time", DateTime.Now); paramters.Add("remark", null); bool success = SQLiteTool.ExecuteNonQuery(connection, sql, paramters); if (success) { Console.WriteLine("success:" + fileInfo.FullName); } else { Console.WriteLine("failure:" + fileInfo.FullName); } } } connection.Close(); }