/// <summary> 执行数据自动上传任务 /// </summary> private static void _ExcuteTask() { try { //用户登录 LoginFlag = LoginCloud(); if (LoginFlag) { ServiceAgent.ReceiveComplated += WriteDataLog; } ServiceAgent.SetParas(GlobalStaticObj_Server.Instance.CloundServerIp, GlobalStaticObj_Server.Instance.CloundServerPort); //服务传输服务 ServiceAgent.StartSendAndReceiveThread(); var startHour = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SyncStartHour")); var endHour = Convert.ToInt32(ConfigurationManager.AppSettings.Get("SyncEndHour")); while (true) { if (LoginFlag) { var currentTime = DateTime.Now; var time = long.Parse(GlobalStaticObj_Server.Instance.LastUploadTime); if (currentTime.Hour >= startHour && currentTime.Hour < endHour && time < currentTime.Ticks) { foreach (var dbName in dbList) { //if (!dbName.Contains("001")) continue; //上传本地数据 UploadDataHandler.UpLoadData(dbName, currentTime.Ticks.ToString(CultureInfo.InvariantCulture)); DataHelper.DeleteBkData(dbName, time.ToString(CultureInfo.InvariantCulture)); } //备份上传时间 GlobalStaticObj_Server.Instance.LastUploadTime = time.ToString(CultureInfo.InvariantCulture); //写入 ConfigManager.SaveConfig(ConfigConst.UploadTime, GlobalStaticObj_Server.Instance.LastUploadTime, ConfigConst.ConfigPath); MessageBox.Show("云平台数据上传完成!"); } Thread.Sleep(60 * 60 * 1000); dbList = GetDbList(); } else { Thread.Sleep(waitSecond * 1000); } } } catch (Exception ex) { GlobalStaticObj_Server.CloudPadLogService.WriteLog("云平台", ex); } }
/// <summary> 执行数据自动上传任务 /// </summary> private static void _ExcuteTask() { //用户登录 LoginFlag = LoginCloud(); if (LoginFlag) { ServiceAgent.ReceiveComplated += new ServiceAgent.ReceiveComplate(WriteDataLog); } ServiceAgent.SetParas(GlobalStaticObj_Server.Instance.CloundServerIp, GlobalStaticObj_Server.Instance.CloundServerPort); //服务传输服务 ServiceAgent.StartSendAndReceiveThread(); while (true) { if (LoginFlag) { long time = long.Parse(GlobalStaticObj_Server.Instance.LastUploadTime); DateTime currentTime = GlobalStaticObj_Server.Instance.CurrentDateTime; //currentTime = DateTime.Now; if (currentTime.Hour > 22 && currentTime.Hour < 23 && time < currentTime.Ticks) { time = currentTime.Ticks; foreach (string dbName in dbList) { //上传本地数据 UploadDataHandler.UpLoadData(dbName, time.ToString()); //备份上传时间 GlobalStaticObj_Server.Instance.LastUploadTime = time.ToString(); //写入 ConfigManager.SaveConfig(ConfigConst.UploadTime, GlobalStaticObj_Server.Instance.LastUploadTime, ConfigConst.ConfigPath); } } Thread.Sleep(60 * 60 * 1000); dbList = GetDbList(); } else { Thread.Sleep(waitSecond * 1000); } } }
/// <summary> 开始任务 /// </summary> public static void StartTest(long time) { GlobalStaticObj_Server.Instance.LastUploadTime = time.ToString(); GlobalStaticObj_Server.Instance.FileLastUploadTime = time.ToString(); if (thread == null) { status = DataSources.EnumTaskStatus.Not_Started; thread = new Thread(new ThreadStart(_ExcuteTaskTest)); thread.IsBackground = true; } if (fileThread == null) { fileThread = new Thread(new ThreadStart(_ExcuteFileTaskTest)); fileThread.IsBackground = true; } if (threadHeartBeat == null) { threadHeartBeat = new Thread(new ThreadStart(_HeartBeatThread)); threadHeartBeat.IsBackground = true; } if (status == DataSources.EnumTaskStatus.Not_Started) { //服务传输服务 ServiceAgent.StartSendAndReceiveThread(); //附件传输服务 FileAgent.StartSendAndReceiveThread(); //获取帐套信息 dbList = GetDbList(); dbListFile.Clear(); _dbList.Clear(); foreach (string db in dbList) { dbListFile.Add(db); _dbList.Add(db); } status = DataSources.EnumTaskStatus.Runing; thread.Start(); fileThread.Start(); threadHeartBeat.Start(); } }