public ProcessGenerator(ManagingLiveData module) { dispatcher = Dispatcher.CurrentDispatcher; this.processes = new ProcessInfoList(); this.updateTimer = new DispatcherTimer(); this.updateTimer.Interval = TimeSpan.FromMilliseconds(DefaultUpdateInterval); this.updateTimer.Tick += OnTimerTick; this.updateHistoryTimer = new DispatcherTimer(); this.updateHistoryTimer.Interval = TimeSpan.FromMilliseconds(DefaultUpdateHistoryInterval); this.updateHistoryTimer.Tick += OnHistoryTimerTick; this.module = module; }
public XToysProcessMessage(ProcessInfoList processList) { var simplifiedProcessList = new List <Dictionary <string, object> >(); foreach (ProcessInfo process in processList) { Dictionary <string, object> basicProcessInfo = new Dictionary <string, object>(); basicProcessInfo.Add("name", process.FileName); basicProcessInfo.Add("id", process.Id); simplifiedProcessList.Add(basicProcessInfo); } processes = simplifiedProcessList.ToArray(); }
/// <summary> /// 加载缓存 zhangdahang 2013-11-15 /// 算法思路: /// 1、从服务器获得需要更新的表(表名,版本)列表 /// 2、对比本地对应表的版本,决定是否需要更新 /// 3、对需要更新的表,获取其表中的所有记录(ID,版本)列表 /// 4、对比本地其表中的记录和版本,统计需要更新的记录集 /// 5、对需要更新的记录集中的记录进行更新,如有需要,分批更新。 /// </summary> /// <param name="status"></param> public static void LoadCache_Update(object status) { //修复Bug307 #region 准备 float step = 1; String Msg = "系统正在更新..."; IProgressCallback callBack = status as IProgressCallback; if (Yqun.Common.ContextCache.ApplicationContext.Current.ISLocalService) { if (callBack != null) { callBack.End(); } return; } DataTable ServerDataCache = null; DataTable LocalDataCache = null; //栓查版本列,如没有版本列,添加“Stcs_1”列,目前以时间作为记录版本 CompareField(); #endregion callBack.SetText(Msg); callBack.Begin(0, 100); Thread.Sleep(500); //获取服务器表集, try { ServerDataCache = GetServerDataCache(); LocalDataCache = GetLocalDataCache(); } catch (Exception ex) { Msg = string.Format("更新缓存失败,原因:“{0}”,请及时联系管理员!", ex.Message); logger.Error(Msg); if (callBack != null) { callBack.End(); } return; } step = ProgressGo(callBack, step); DataTable updateTable = GetUpdateDateTable(ServerDataCache, LocalDataCache); if (updateTable.Rows.Count == 0) { if (callBack != null) { callBack.End(); } return; } logger.Error("共有" + updateTable.Rows.Count + "表需要更新"); DataSet UpdateDB = new DataSet(); foreach (DataRow cacheRow in updateTable.Rows) { string tableName = cacheRow["tableName"].ToString(); callBack.SetText("分析表:" + tableName + "需要更新的记录"); DataTable ServerTable = GetServerDataTalbe("select ID,Scts_1 from " + tableName); if (LocalDataCache.Select("tableName ='" + tableName + "'").Length == 0) { DataRow newCacheRow = LocalDataCache.NewRow(); newCacheRow.ItemArray = cacheRow.ItemArray; LocalDataCache.Rows.Add(newCacheRow); callBack.SetText("添加新表:" + tableName); UpdateTableData(LocalDataCache.TableName, LocalDataCache); } DataTable LocalTable = GetLocalDataTable("select ID,Scts_1 from " + tableName); DataTable updateRecordTable = GetUpdateDateTable(ServerTable, LocalTable); lock (ProcessInfoList) { if (!ProcessInfoList.ContainsKey(tableName.ToLower().Trim())) { ProcessInfo pi = new ProcessInfo(); pi.CompletedRowsCount = 0; pi.TableRowsCount = updateRecordTable.Rows.Count; ProcessInfoList.Add(tableName.ToLower().Trim(), pi); } } UpdateDB.Tables.Add(updateRecordTable); } //更新 foreach (DataTable table in UpdateDB.Tables) { string tableName = table.TableName; #region 可以更新 if (table.Rows.Count == 0) { DataTable cacheTalbe = GetServerDataTalbe("select * from sys_biz_Cache where tableName='" + tableName + "'"); UpdateTableData("sys_biz_Cache", cacheTalbe); continue; } #endregion callBack.SetText("开始更新,表:" + tableName); string IDStr = ""; int index = 0; Int32 pageSize = GetPageSize(tableName); for (; index < table.Rows.Count; index++) { IDStr += "'" + table.Rows[index]["ID"].ToString() + "',"; if ((index != 0 && index % pageSize == 0) || index == table.Rows.Count - 1) { try { IDStr = IDStr.Substring(IDStr.Length - 1) == "," ? IDStr.Remove(IDStr.Length - 1) : IDStr; string sqlStr = "select * from " + tableName + " where ID in (" + IDStr + ")"; IDStr = ""; object[] parameterArr = new object[] { tableName, sqlStr, callBack, table, ServerDataCache }; //启动一个线程 ,更新本地数据据 System.Threading.Thread process = GetOneThread(); process.Start(parameterArr); } catch (Exception e) { logger.Error(e.ToString()); } } } } bool HasRunningThread = true; while (HasRunningThread) { HasRunningThread = false; lock (RunningThreads) { foreach (Thread t in RunningThreads) { if (t.ThreadState == ThreadState.Running) { HasRunningThread = true; break; } } } Thread.Sleep(50); } logger.Error("更新完成"); callBack.SetText("更新成功!"); callBack.StepTo(100); Thread.Sleep(1000); if (callBack != null) { callBack.End(); } }