//************************************************************** // AppUpdater Constructor //************************************************************** public AppDownloader(AppUpdater appMan) { AppMan = appMan; Log = new UpdateLog(); UpdateEventArgs = new UpdateCompleteEventArgs(); DownloadEventArgs = new DownloadProgressEventArgs(); }
private void btnGo_Click(object sender, EventArgs e) { //Product deserializedProduct = JsonConvert.DeserializeObject<Product>(json); MyThreadClass myThr = new MyThreadClass(this); List<FileInfo> lstFiles = null; try { if (myThread != null && myThread.IsAlive) return; //btnGo.Enabled = false; txtLog.Text = ""; lstFiles = getFiles(); if (lstFiles == null || lstFiles.Count() == 0) return; delegateUpdateBar = new UpdateBar(methodUpdateBar); delegateUpdateLog = new UpdateLog(methodUpdatetxtLog); pBar1.Minimum = 0; pBar1.Maximum = lstFiles.Count(); pBar1.Value = 0; pBar1.Step = 1; myThread = new Thread(() => myThr.myThread(lstFiles)); myThread.Start(); } catch { throw; } finally { //btnGo.Enabled = true; } }
public virtual bool Pause(int size = 0) { ConfirmAfterPause = false; _pause = true; if (!_enablePause) { return(true); } if (_callDownloadNotice != null) { _callDownloadNotice(size); } //等待用户确认 while (_pause) { UpdateLog.DEBUG_LOG("有下载,等待用户确认"); Thread.Sleep(1000); } return(ConfirmAfterPause); }
private int downloadMapData(MapFileData fileData, string saveFilePath) { int ret = CodeDefine.RET_FAIL; try { lock (m_locker) { if (!Directory.Exists(fileData.SaveDir + "/" + fileData.Dir)) { Directory.CreateDirectory(fileData.SaveDir + "/" + fileData.Dir); } } //计算下载点,在资源包中,每个文件都有4个32字节的数据头加上文件名、md5长度,要跳过 long begin = fileData.Begin + 32 * 4 + fileData.DirLen + fileData.NameLen + fileData.Md5Len; //http的AddRange方法是闭包的,所以减一。([from, to]) long end = fileData.End - 1; //每个文件有3次下载机会 int i = _RETRAY_TIMES; while (i > 0) { i--; if (fileData.Name.Contains("RemoteVersion.xml") || fileData.Name.ToLower().Contains("localversion.xml")) { ret = CodeDefine.RET_SUCCESS; return(ret); } if (Download.UseBackupCdn(fileData.ResUrl, Download.BackupCdn)) { //使用台湾备份cdn地址 for (int cdnIndex = 0; cdnIndex < Download.BackupCdn.Length; ++cdnIndex) { string backupUrl = fileData.ResUrl.Replace(Download.BackupCdn[0], Download.BackupCdn[cdnIndex]); using (FileStream outFile = new FileStream(saveFilePath, FileMode.Create)) { ret = httpDownload(backupUrl, outFile, begin, end); if (ret >= CodeDefine.RET_SUCCESS) { break; } if (ret == CodeDefine.RET_SKIP_BY_ABORT) { return(ret); } } } if (ret >= CodeDefine.RET_SUCCESS) { break; } } else { using (FileStream outFile = new FileStream(saveFilePath, FileMode.Create)) { //UpdateLog.INFO_LOG(_TAG + " download: " + saveFilePath); ret = httpDownload(fileData.ResUrl, outFile, begin, end); if (ret >= CodeDefine.RET_SUCCESS) { break; } if (ret == CodeDefine.RET_SKIP_BY_ABORT) { return(ret); } UpdateLog.WARN_LOG(_TAG + " try download i = " + i); Thread.Sleep(_SLEEP_TIME); } } } } catch (System.Exception ex) { if (saveFilePath.Contains("ClassesResources.xml")) { ret = CodeDefine.RET_SUCCESS; } UpdateLog.ERROR_LOG(_TAG + "ThreadCallBack(object state) download fail: file= " + saveFilePath + "\n error" + ex.Message + "\n" + ex.StackTrace); UpdateLog.EXCEPTION_LOG(ex); } return(ret); }
public static void ShowLog(string text) { try { Form form = Application.OpenForms["Form1"]; if (form == null) { return; } RichTextBox W = form.Controls.Find("log_rt", true).FirstOrDefault() as RichTextBox; if (W == null) { return; } if (W.InvokeRequired) { UpdateLog ph = new UpdateLog(ShowLog); W.Invoke(ph, text); } else { if (W.Text.Length > 13000) { W.Text = W.Text.Substring(W.Text.Length - 7000); } W.SelectionStart = W.TextLength; W.SelectionLength = 0; if (text.ToUpper().Contains("ACK")) { W.SelectionColor = Color.Blue; } else if (text.ToUpper().Contains("INF")) { W.SelectionColor = Color.Green; } else if (text.ToUpper().Contains("ABS")) { W.SelectionColor = Color.Red; } else if (text.ToUpper().Contains("CAN")) { W.SelectionColor = Color.Orange; } else { W.SelectionColor = Color.Black; } W.AppendText(text + "\n"); W.ScrollToCaret(); } } catch (Exception e) { } }
public void Synchronize(log4net.ILog logger, Arguments args) { logger.Info($"\n\n*** Synchronisation of fragments started - {DateTime.Now} ***\n\n"); var updateCounter = new UpdateCounter(); var updateLog = new UpdateLog(); var updateLogFileName = Path.Combine(args.Directory.FullName, "UpdateLog.txt"); if (File.Exists(updateLogFileName)) { var data = File.ReadAllText(updateLogFileName); updateLog = JsonConvert.DeserializeObject <UpdateLog>(data); } try { if (args.Clean) { logger.Info($"\nCleaning out target directory {args.Directory.Name}..\n\n"); ClearFolder(args.Directory); } Directory.CreateDirectory(args.Directory.FullName); var contextUrl = args.Source; logger.Info("\nConnecting to SharePoint online..\n\n"); using (var spContext = new SharePointClientContext(contextUrl)) { logger.Info($"Loading fragments from site: {contextUrl}"); var syncConf = FragmentSettings.GetConfig(); var fileSync = new FileSynchroniser(); var listSync = new ListSynchroniser(); foreach (Fragment fragment in syncConf.Fragments) { try { if (fragment.Type == "library") { fileSync.Synchronise(spContext, fragment, updateCounter, updateLog, logger, args); } else if (fragment.Type == "list") { listSync.Synchronise(spContext, fragment, updateCounter, updateLog, logger, args); } else { logger.Warn($"\n\nWarning: Unsupported synchronisation settig found; type:{fragment.Type}, source:{fragment.Source}, destination:{fragment.Destination}\n\n"); } } catch (Exception ex) { logger.Error($"Failed synchronising {fragment.Source}", ex); if (args.BreakOnError) { throw; } } } } } catch (Exception ex) { logger.Error("An exception was thrown", ex); if (args.BreakOnError) { throw; } } var json = JsonConvert.SerializeObject(updateLog); System.IO.File.WriteAllText(Path.Combine(args.Directory.FullName, "UpdateLog.txt"), json); logger.Info($"\n\nSynchronisation of fragments finished - {DateTime.Now}.\n"); logger.Info($"Total documents processed {updateCounter.DocumentCount}, {updateCounter.DocumentUpdateCount} templates were updated\n"); logger.Info($"Total fragments processed {updateCounter.ListItemCount}, {updateCounter.ListItemUpdateCount} items were updated\n\n"); }
public override int Work() { if (LastFlowResult == CodeDefine.RET_SKIP_BY_BACKDOWNLOAD) { UpdateLog.DEBUG_LOG("因为是后台下载分段,跳过资源释放流程"); return(CodeDefine.RET_SUCCESS); } if (!CheckLastFlowResult()) { return(LastFlowResult); } UpdateLog.DEBUG_LOG("释放分段资源+++"); int ret = CodeDefine.RET_SUCCESS; for (int i = 0; i < _currentData.VersionModelBaseList.Count; i++) { VersionModel vModel = _currentData.VersionModelBaseList[i]; //本地分段版本号更大,则跳过 if (LocalXml.BaseResVersion.CompareTo(vModel.FromVersion) > 0) { continue; } string resourceUrl = vModel.ResourceUrl.Replace("\\", "/"); string resourceName = resourceUrl.Substring(resourceUrl.LastIndexOf("/") + 1); string localResourceFile = System.IO.Path.Combine(_storeDir, resourceName); if (!File.Exists(localResourceFile)) { UpdateLog.DEBUG_LOG("释放资源时,没有资源: " + localResourceFile); continue; } //用大小比较 FileInfo fileInfo = new FileInfo(localResourceFile); long toDownloadFileLenght = 0; if (long.TryParse(vModel.FileSize, out toDownloadFileLenght)) { if (fileInfo.Length == toDownloadFileLenght) { if (!HasTransedResource()) { UpdateLog.DEBUG_LOG("还没有转移过资源,不能做资源释放,先跳转到转移资源流程!!!"); ret = CodeDefine.RET_SKIP_BY_FORCE_TRANS_RESOURCE; break; } UpdateLog.DEBUG_LOG("释放分段资源: " + localResourceFile); UnzipResource unzip = new UnzipResource(localResourceFile, _storeDir); ret = unzip.UnzipRes(); //更新本地分段号 _localXml.BaseResVersion = vModel.ToVersion; _localXml.save(_localXml); //资源释放完了就删除下载好的资源 if (File.Exists(localResourceFile)) { File.Delete(localResourceFile); } } else { UpdateLog.DEBUG_LOG(string.Format("分段资源没下载完:{0} -> {1} ", localResourceFile, fileInfo.Length)); } } } UpdateLog.DEBUG_LOG("释放分段资源---"); return(ret); }
public UpdateLog Add(UpdateLog updateLog) { return(new UpdateLogDAL().Add(updateLog)); }
public void FinishWithError(int code) { UpdateLog.ERROR_LOG("FinishWithError : + " + code); LastFlowResult = code; Work(); }
private void requestData(HttpWebRequest myRequest, FileStream outFile) { byte[] btContent = new byte[_BUFFER]; HttpWebResponse reponse = null; Stream myStream = null; try { using (reponse = myRequest.GetResponse() as HttpWebResponse) { using (myStream = reponse.GetResponseStream()) { int intSize = 0; int readLen = 0; intSize = myStream.Read(btContent, 0, _BUFFER); while (intSize > 0) { readLen += intSize; //已下载 DownloadedSize = readLen; lock (m_locker) { MutiDownloadedSize += intSize; //中断下载 if (_isAbortOption) { UpdateLog.WARN_LOG("abort download : " + Thread.CurrentThread.Name); break; } } outFile.Write(btContent, 0, intSize); if (!myStream.CanRead) { break; } intSize = myStream.Read(btContent, 0, _BUFFER); } } } } catch (System.Exception ex) { UpdateLog.ERROR_LOG(_TAG + ex.Message + "\n" + ex.StackTrace); if (reponse != null) { UpdateLog.ERROR_LOG("Http status: " + reponse.StatusCode); } } finally { if (reponse != null) { reponse.Close(); } if (myStream != null) { myStream.Close(); } if (outFile != null) { outFile.Flush(); } } btContent = null; }
/// <summary> /// 后台更新当前场景资源 /// </summary> /// <param name="normalList"></param> /// <param name="append"></param> internal void BackDownloadCurSceneData(string[] normalList, bool append = false) { UpdateLog.WARN_LOG("Add cur scene resources"); AddDataList(normalList, DataLevel.CurScene, append); }
public async Task <bool> UpdateReadPageNumber(UpdateLog updateLog, int userid, int bookid) { return(await _repo.UpdateReadPageNumber(updateLog, userid, bookid)); }
public void Synchronise(SharePointClientContext spContext, Fragment fragment, UpdateCounter updateCounter, UpdateLog updateLog, log4net.ILog logger, Arguments args) { var list = spContext.Web.Lists.GetByTitle(fragment.Source); var items = list.GetItems(new CamlQuery()); LoadListItems(spContext, items); spContext.ExecuteQuery(); var noUpdateRequiredCount = 0; var updatedCount = 0; var destinationPath = args.Directory.FullName; if (fragment.Destination.Length > 0) { var destination = args.Directory.CreateSubdirectory(fragment.Destination); destinationPath = destination.FullName; } logger.Info($"\n\nProcessing {fragment.Source} list settings..."); GetListSettings(spContext, list, fragment.Source, destinationPath); logger.Info($"\n\nProcessing {fragment.Source} into {destinationPath}, found {items.Count} fragments"); foreach (var item in items) { if (item.FileSystemObjectType == FileSystemObjectType.Folder) { continue; } HandleListItem(spContext, logger, args, destinationPath, item, ref updatedCount, ref noUpdateRequiredCount); var fileName = GetFileNameForFieldValue(item, destinationPath); SaveItemFieldValues(logger, args.Overwrite, item, fileName, ref updatedCount, ref noUpdateRequiredCount); } logger.Info($"\nFinished processing {fragment.Source}, {noUpdateRequiredCount} items were up to date, {updatedCount} items were updated"); UpdateCounters(updateCounter, noUpdateRequiredCount, updatedCount); var log = updateLog.Updates.FirstOrDefault(x => x.Source.Equals(fragment.Source, StringComparison.InvariantCultureIgnoreCase)); if (log == null) { log = new UpdateLog.UpdateLogEntry() { Source = fragment.Source, Destination = fragment.Destination, LastModified = DateTime.Now, Version = 1 }; updateLog.Updates.Add(log); } else { log.Destination = fragment.Destination; if (updatedCount > 0) { log.LastModified = DateTime.Now; log.Version++; } } }
/// <summary> /// 释放资源 /// 文件结构 4x32 文件头 |32位记录路径长度|32位记录文件名|32位记录md5长度|32位记录文件大小| /// 然后根据这4个结构获取具体的路径、文件名、md5值、文件内容 /// </summary> /// <returns></returns> public int UnzipRes() { UpdateLog.INFO_LOG(_TAG + "unzipRes()"); int ret = CodeDefine.RET_SUCCESS; FileStream resFileStream = null; long filePostion = 0; long fileSize = 0; try { resFileStream = new FileStream(_resPath, FileMode.Open, FileAccess.Read, FileShare.Read); fileSize = resFileStream.Length; List <ResourceFileData> fileDataList = new List <ResourceFileData>(); //启动线程池 // var threadPool = new HttpThreadPool<UnzipData>(4, ThreadFunc); while (fileSize > 0 && filePostion < fileSize) { ResourceFileData fileData = new ResourceFileData(); //4x32长度的头 fileData.DirLen = int.Parse(read(resFileStream, 32, filePostion, out filePostion)); fileData.NameLen = int.Parse(read(resFileStream, 32, filePostion, out filePostion)); fileData.Md5Len = int.Parse(read(resFileStream, 32, filePostion, out filePostion)); fileData.FileSize = long.Parse(read(resFileStream, 32, filePostion, out filePostion)); //读取内容 fileData.Dir = read(resFileStream, fileData.DirLen, filePostion, out filePostion); fileData.Name = read(resFileStream, fileData.NameLen, filePostion, out filePostion); fileData.Md5 = read(resFileStream, fileData.Md5Len, filePostion, out filePostion); //跳过localversion的释放 if (fileData.Name.ToLower().Equals("localversion.xml")) { resFileStream.Seek(fileData.FileSize, SeekOrigin.Current); } else { writeFile(resFileStream, fileData.FileSize, fileData.Dir, fileData.Name); //resFileStream.Seek(fileData.FileSize, SeekOrigin.Current); //UnzipData ud = new UnzipData(fileData, filePostion, fileSize); //threadPool.addTask(ud); } filePostion += fileData.FileSize; } //等待所有文件下载完 //threadPool.waitWhileWorking(); } catch (System.Exception ex) { ret = CodeDefine.RET_FAIL_UNZIP_RES_FILE; UpdateLog.ERROR_LOG(_TAG + ex.Message + "\n" + ex.StackTrace); UpdateLog.EXCEPTION_LOG(ex); } finally { if (resFileStream != null) { resFileStream.Close(); } } return(ret); }
//解析xml public int parseResouceVersionXml(string path) { UpdateLog.INFO_LOG(_TAG + "parseResouceVersionXml(string path):" + path); int ret = CodeDefine.RET_SUCCESS; try { var sp = MonoXmlUtils.LoadXmlEx(path); if (sp == null || sp.ToXml() == null) { return(CodeDefine.RET_FAIL_PARSE_RES_XML_FILE); } var dom = sp.ToXml(); //正式流程 parse(dom, "ResourceVersion/VersionBase", NormalFollow.VersionModelBaseList); parse(dom, "ResourceVersion/VersionPatch", NormalFollow.VersionModelPatchList); NormalFollow.AppVersion = parse(dom, "ResourceVersion/CodeVersion_last/Version"); NormalFollow.ClientUrl = parse(dom, "ResourceVersion/CodeVersion_last/url"); NormalFollow.AppSize = parse(dom, "ResourceVersion/CodeVersion_last/size"); NormalFollow.Language = parse(dom, "ResourceVersion/loginSever/language"); bool enable = true; if (!Boolean.TryParse(parse(dom, "ResourceVersion/ForceUpdate"), out enable)) { enable = true; } NormalFollow.EnableForceUpdate = enable; NormalFollow.PatchVersion = GetMaxPatchVersion(NormalFollow.VersionModelPatchList); //测试流程 parse(dom, "ResourceVersion/test_tag/VersionBase", TestFollow.VersionModelBaseList); parse(dom, "ResourceVersion/test_tag/VersionPatch", TestFollow.VersionModelPatchList); TestFollow.AppVersion = parse(dom, "ResourceVersion/test_tag/app_current_version"); TestFollow.ClientUrl = parse(dom, "ResourceVersion/test_tag/app_update_url"); TestFollow.AppSize = parse(dom, "ResourceVersion/test_tag/test_size"); TestFollow.Language = parse(dom, "ResourceVersion/test_tag/language"); if (!Boolean.TryParse(parse(dom, "ResourceVersion/test_tag/ForceUpdate"), out enable)) { enable = true; } TestFollow.EnableForceUpdate = enable; TestFollow.PatchVersion = GetMaxPatchVersion(TestFollow.VersionModelPatchList); //白名单 mac地址 var macList = parseNodes(dom, "ResourceVersion/test_tag/legal_client_machine_list/legal_client_machine"); for (int i = 0; macList != null && i < macList.Length; i++) { if (macList[i] == null) { continue; } WhiteCode.Add(macList[i].Text); } //白名单 用户名 var userList = parseNodes(dom, "ResourceVersion/test_tag/legal_client_user_list/legal_client_user"); for (int i = 0; userList != null && i < userList.Length; i++) { if (userList[i] == null) { continue; } WhiteUsers.Add(userList[i].Text); } //白名单 ip地址 var ipList = parseNodes(dom, "ResourceVersion/test_tag/legal_client_ip_list/legal_client_ip"); for (int i = 0; ipList != null && i < ipList.Length; i++) { if (ipList[i] == null) { continue; } WhiteIp.Add(ipList[i].Text); } } catch (System.Exception ex) { ret = CodeDefine.RET_FAIL_PARSE_RES_XML_FILE; UpdateLog.ERROR_LOG(_TAG + ex.Message + "/n" + ex.StackTrace); UpdateLog.EXCEPTION_LOG(ex); } return(ret); }
public async Task <IActionResult> UpdateLog(UpdateLog logDetails) { logDetails.logUpdater = _httpContextAccessor.HttpContext?.User?.Claims.Where(a => a.Type == ClaimTypes.Name).FirstOrDefault()?.Value; return(Ok(await _timeLoggingRepository.UpdateLog(logDetails))); }
public int parseMapFile(string mapFile, string resUrl, string saveDir) { _saveDir = saveDir; UpdateLog.INFO_LOG(_TAG + "parseMapFile(string mapFile, string resUrl):" + mapFile + "," + resUrl); int ret = CodeDefine.RET_SUCCESS; List <MapFileData> mapFileDataList = _mapFileDataList; FileStream mapFileStream = null; try { mapFileStream = new FileStream(mapFile, FileMode.Open); long filePosition = 0; long mapFileSize = mapFileStream.Length; while (mapFileSize > 0 && filePosition != mapFileSize) { if (filePosition >= mapFileSize) { UpdateLog.ERROR_LOG("解析出错了"); return(ret); } MapFileData mapFileData = new MapFileData(); mapFileData.Begin = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); if (mapFileData.Begin == -1) { UpdateLog.WARN_LOG("解析map文件,出现异常,请检查: " + mapFile); return(ret); } mapFileData.End = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); mapFileData.DirLen = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); mapFileData.NameLen = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); mapFileData.Md5Len = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); mapFileData.FileSize = parseInt(read(mapFileStream, 10, filePosition, out filePosition)); mapFileData.Dir = read(mapFileStream, mapFileData.DirLen, filePosition, out filePosition); mapFileData.Name = read(mapFileStream, mapFileData.NameLen, filePosition, out filePosition); mapFileData.Md5 = read(mapFileStream, mapFileData.Md5Len, filePosition, out filePosition); mapFileData.ResUrl = resUrl; mapFileData.SaveDir = _saveDir; UnityEngine.Debug.Log("mapFileData.Name :" + mapFileData.Name); mapFileDataList.Add(mapFileData); } } catch (System.Exception ex) { ret = CodeDefine.RET_FAIL_PARSE_MAP_FILE; UpdateLog.ERROR_LOG(_TAG + ex.Message + "\n" + ex.StackTrace); UpdateLog.EXCEPTION_LOG(ex); } finally { if (mapFileStream != null) { mapFileStream.Close(); } } return(ret); }
public int Update(UpdateLog updateLog) { return(new UpdateLogDAL().Update(updateLog)); }
public bool UpdateNeeded(Week week) { return(!UpdateLog.ContainsKey(week) || DateTime.UtcNow - UpdateLog[week] > UpdateInterval); }
public void Update(UpdateLog log) { _context.Update(log); }
public override int Work() { if (!CheckLastFlowResult()) { return(LastFlowResult); } if (!CurrentRemoteData.EnableForceUpdate) { UpdateLog.DEBUG_LOG("Do not support force update client, skip download!!!"); return(CodeDefine.RET_SUCCESS); } UpdateLog.DEBUG_LOG("开始下载客户端+++"); int ret = CodeDefine.RET_INIT; var localXml = LocalXml; var remoteData = CurrentRemoteData; string appVersion = localXml.LocalAppVersion; string clientUrl = remoteData.ClientUrl.Replace("\\", "/"); string clientName = clientUrl.Substring(clientUrl.LastIndexOf("/") + 1); string clientPath = System.IO.Path.Combine(_storeDir, clientName); //远端有更高客户端版本,则检查下载 if (remoteData.AppVersion.CompareTo(appVersion) > 0) { if (_customDownClientFunc != null) { UpdateLog.DEBUG_LOG("使用外部方法下载客户端"); _customDownClientFunc(remoteData.ClientUrl, _storeDir); ret = CodeDefine.RET_SUCCESS; callClientDownloadFinish(true); } else { if (_ios) { callClientDownloadFinish(true); return(CodeDefine.RET_SKIP_BY_DOWNLOAD_APP); } int appSize = int.Parse(remoteData.AppSize); //下载前提醒,如果取消则直接退出当前流程 if (!Pause(appSize)) { return(CodeDefine.RET_SKIP_BY_CANCEL); } ApkStorePath = clientPath; ret = _fileDownload.DownloadUseBackCdn(clientPath, clientUrl, appSize, true); FileInfo clientFile = new FileInfo(clientPath); if (ret >= CodeDefine.RET_SUCCESS && clientFile.Length < appSize) { ret = CodeDefine.RET_FAIL_EXCEPTION_DOWNLOAD; UpdateLog.ERROR_LOG("download Client: size is not correct: " + clientFile.Length + " -> " + appSize); } callClientDownloadFinish(ret >= CodeDefine.RET_SUCCESS); } //下载成功则跳过后续流程 if (ret == CodeDefine.RET_SUCCESS) { ret = CodeDefine.RET_SKIP_BY_DOWNLOAD_APP; } UpdateLog.DEBUG_LOG("下载客户端结束"); } else { if (File.Exists(clientPath)) { File.Delete(clientPath); UpdateLog.DEBUG_LOG("删除已下载好的客户端!!!"); } ret = CodeDefine.RET_SUCCESS; } UpdateLog.DEBUG_LOG("开始下载客户端---"); return(ret); }
public static void LogUpdate(string msg) { try { Form form = Application.OpenForms["FormMonitoring"]; RichTextBox W; if (form == null) { return; } W = form.Controls.Find("Log_rt", true).FirstOrDefault() as RichTextBox; if (W == null) { return; } if (W.InvokeRequired) { UpdateLog ph = new UpdateLog(LogUpdate); W.BeginInvoke(ph, msg); } else { //W.AppendText(msg + "\n"); W.SelectionStart = W.TextLength; W.SelectionLength = 0; if (msg.ToUpper().Contains("ACK")) { W.SelectionColor = Color.Blue; } else if (msg.ToUpper().Contains("INF")) { W.SelectionColor = Color.Green; } else if (msg.ToUpper().Contains("ABS")) { W.SelectionColor = Color.Red; } else if (msg.ToUpper().Contains("CAN")) { W.SelectionColor = Color.Orange; } else { W.SelectionColor = Color.Black; } W.AppendText(msg + "\n"); W.SelectionColor = W.ForeColor; if (W.Lines.Length > 1000) { W.Select(0, W.GetFirstCharIndexFromLine(W.Lines.Length - 1000)); W.SelectedText = ""; } W.ScrollToCaret(); //EventUpdate("MAPDT", FormMain.HostControl.Events.MAPDT); //EventUpdate("PORT", FormMain.HostControl.Events.PORT); //EventUpdate("PRS", FormMain.HostControl.Events.PRS); //EventUpdate("SYSTEM", FormMain.HostControl.Events.SYSTEM); //EventUpdate("TRANSREQ", FormMain.HostControl.Events.TRANSREQ); //EventUpdate("FFU", FormMain.HostControl.Events.FFU); //EventUpdate("BF1_BYPASS", FormMain.HostControl.Events.BF1_BYPASS); //NodeManagement.Get("BF1").ByPassCheck = FormMain.HostControl.Events.BF1_BYPASS; //EventUpdate("BF2_BYPASS", FormMain.HostControl.Events.BF2_BYPASS); //NodeManagement.Get("BF2").ByPassCheck = FormMain.HostControl.Events.BF2_BYPASS; } } catch (Exception e) { } }
/// <summary> /// 执行指标测试指令 /// </summary> /// <param name="clientSocket"></param> private static void Excute(object clientSocket) { Socket client = clientSocket as Socket; byte[] ID_buffer = new byte[40]; try { UpdateLog.ClearLog(); Thread.Sleep(100); while (true) { if (client.Available > 0) { UpdateLog.Log("➤ 查询参数"); byte[] res = TransferFiles.ReceiveVarData(client); string Str_NameAndMission = Encoding.UTF8.GetString(res); string stationname = "", Commend = "", st = "", ed = ""; if (Str_NameAndMission != "GetConfig" && Str_NameAndMission != "SetConfig") { string[] array = Str_NameAndMission.Split("#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); UpdateLog.Log("站名#" + array[0]); UpdateLog.Log("指令#" + array[1]); stationname = array[0]; Commend = array[1]; st = array[2]; ed = array[3]; UpdateLog.Log("时间#" + array[2].Replace("#", " ") + " 至 " + array[3].Replace("#", " ")); } else { //若是【获去配置】或【修改配置】则只包含命令 Commend = Str_NameAndMission; } switch (Commend) { #region 基础数据 case "BaseCount": try { try { UpdateLog.Log("➤ 列车总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetTrainNum(st, ed, li.lid.ToString()); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("列车总数#" + (total)); UpdateLog.Log("数据来源#Train表"); } catch (Exception ex) { UpdateLog.Error("列车总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类列车数量"); foreach (LineInfo li in LineList) { DataTable tmp = IndexTest.GetTyainNumByTrainType(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i][0].ToString().Replace("NoTrainType", "列车类型为空") + "#" + tmp.Rows[i][1].ToString()); } } } UpdateLog.Log("数据来源#Train表"); } catch (Exception ex) { UpdateLog.Error("各类列车数量#" + ex.Message); } try { UpdateLog.Log("➤ 车厢总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetCarNumByPeriod(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "#" + tmp); total += tmp; } UpdateLog.Log("车厢总数#" + total); UpdateLog.Log("数据来源#TrainDetail表"); } catch (Exception ex) { UpdateLog.Error("车厢总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类车厢数量"); foreach (LineInfo li in LineList) { UpdateLog.Log("线路" + li.lid); DataTable tmp = IndexTest.GetCarNumByCarKind(st, ed, li.lid.ToString()); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i]["vehicletype"].ToString() + "#" + tmp.Rows[i]["KindNum"].ToString()); } } } UpdateLog.Log("数据来源#TrainDetail表"); } catch (Exception ex) { UpdateLog.Error("各类车厢数量#" + ex.Message); } try { UpdateLog.Log("➤ 图像总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Pic + li.FolderName + "\\", ".jpg"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("图像总数#" + total); UpdateLog.Log("数据来源#.jpg文件个数"); } catch (Exception ex) { UpdateLog.Error("图像总数#" + ex.Message); } try { UpdateLog.Log("➤ 走行部图像总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_ZXPic + li.FolderName + "\\", ".jpg"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("走行部图像总数#" + total); UpdateLog.Log("数据来源#.jpg文件个数"); } catch (Exception ex) { UpdateLog.Error("图像总数#" + ex.Message); } try { UpdateLog.Log("➤ 视频总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Video + li.FolderName + "\\", ".mp4"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("视频总数#" + total); UpdateLog.Log("数据来源#.mp4文件个数"); } catch (Exception ex) { UpdateLog.Error("视频总数#" + ex.Message); } try { UpdateLog.Log("➤ 声音总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Voice + li.FolderName + "\\", ".aac"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("声音总数#" + total); UpdateLog.Log("数据来源#.aac文件个数"); } catch (Exception ex) { UpdateLog.Error("声音总数#" + ex.Message); } try { UpdateLog.Log("➤ 所有预警总数"); decimal total = 0; foreach (LineInfo li in LineList) { decimal tmp = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), null, null, null); UpdateLog.Log("线路" + li.lid + "#" + tmp); total += tmp; } UpdateLog.Log("预警总数#" + total); } catch (Exception ex) { UpdateLog.Error("预警总数#" + ex.Message); } try { UpdateLog.Log("➤ 各类别预警数"); int sum_Alarm = 0, sum_Fail = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("线路" + li.lid + ""); UpdateLog.Log("===正常报警:"); DataTable alarm = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true); if (alarm != null && alarm.Rows.Count > 0) { for (int i = 0; i < alarm.Rows.Count; i++) { UpdateLog.Log(alarm.Rows[i]["ProblemType"].ToString() + "#" + alarm.Rows[i]["AlarmNum"].ToString()); sum_Alarm += int.Parse(alarm.Rows[i]["AlarmNum"].ToString()); } } UpdateLog.Log("===检测失败:"); DataTable fail = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), false); if (fail != null && fail.Rows.Count > 0) { for (int i = 0; i < fail.Rows.Count; i++) { UpdateLog.Log(fail.Rows[i]["ProblemType"].ToString() + "#" + fail.Rows[i]["AlarmNum"].ToString()); sum_Fail += int.Parse(fail.Rows[i]["AlarmNum"].ToString()); } } } UpdateLog.Log("【报警总数】#" + sum_Alarm); UpdateLog.Log("【检测失败】#" + sum_Fail); } catch (Exception ex) { UpdateLog.Error("各类别预警数" + ex.Message); } } catch (Exception ex) { UpdateLog.Error("基础数据异常#" + ex.Message); } break; #endregion #region 丢文件 case "MissFiles": try { UpdateLog.Log("➤ 丢文件检测"); foreach (LineInfo li in LineList) { UpdateLog.Log("=====【线路" + li.lid + "】====="); int Count_Dir; List <DirectoryInfo> list_MissingIndex; List <FileInfo> list_MissingPics; IndexTest.CountMissingPics(st, ed, Common.Default.Path_Pic + li.FolderName + "\\", out Count_Dir, out list_MissingIndex, out list_MissingPics); UpdateLog.Log("共检测了文件夹#" + Count_Dir); UpdateLog.Log("共丢失Index#" + list_MissingIndex.Count); UpdateLog.Log("共丢失图片#" + list_MissingPics.Count); if (list_MissingIndex.Count > 0) { UpdateLog.Log("===Index丢失明细==="); foreach (DirectoryInfo dir in list_MissingIndex) { UpdateLog.Log("Index丢失#" + dir.FullName); } } if (list_MissingPics.Count > 0) { UpdateLog.Log("===图片丢失明细==="); foreach (FileInfo fi in list_MissingPics) { UpdateLog.Log("图片丢失#" + fi.FullName); } } } } catch (Exception ex) { UpdateLog.Error(ex.Message); } try { UpdateLog.Log("➤ 丢文件检测(走形)"); foreach (LineInfo li in LineList) { UpdateLog.Log("=====【线路" + li.lid + "】====="); int Count_Dir; List <DirectoryInfo> list_MissingIndex; List <FileInfo> list_MissingPics; IndexTest.CountMissingPics(st, ed, Common.Default.Path_ZXPic + li.FolderName + "\\", out Count_Dir, out list_MissingIndex, out list_MissingPics); UpdateLog.Log("共检测了文件夹#" + Count_Dir); UpdateLog.Log("共丢失Index#" + list_MissingIndex.Count); UpdateLog.Log("共丢失图片#" + list_MissingPics.Count); if (list_MissingIndex.Count > 0) { UpdateLog.Log("===Index丢失明细==="); foreach (DirectoryInfo dir in list_MissingIndex) { UpdateLog.Log("Index丢失#" + dir.FullName); } } if (list_MissingPics.Count > 0) { UpdateLog.Log("===图片丢失明细==="); foreach (FileInfo fi in list_MissingPics) { UpdateLog.Log("图片丢失#" + fi.FullName); } } } } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 入库率 case "DBIndex": try { UpdateLog.Log("➤ 列车实时入库率"); double[] all = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "SOCKET", null); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "SOCKET", li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "入库率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } UpdateLog.Log("实时入库率(Socket)#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#实时入库列车数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮总数#" + ex.Message); } try { UpdateLog.Log("➤ 列车补入库率"); double[] all = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "INDEX", null); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetTrainInfoImportDataByFlagRatio(st, ed, "INDEX", li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "入库率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } UpdateLog.Log("补入库率(Index)#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 4, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#Index补入库列车数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("入库率#" + ex.Message); } break; #endregion #region 热轮指标 case "HotwheelIndex": try { UpdateLog.Log("➤ 热轮总数"); int total = 0; foreach (LineInfo li in LineList) { int tmp = IndexTest.GetFileNum(st, ed, Common.Default.Path_Hotwheel + li.FolderName + "\\", ".HotWheel"); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("热轮总数#" + total); UpdateLog.Log("数据来源#.HotWheel文件个数"); } catch (Exception ex) { UpdateLog.Error("热轮总数#" + ex.Message); } try { UpdateLog.Log("➤ 热轮接入率"); double[] total = new double[2]; foreach (LineInfo li in LineList) { try { double[] tmp = IndexTest.GetHotWheelFileStatisicsRatio(st, ed, li.FolderName); UpdateLog.Log("线路" + li.lid + "接入率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); total[0] += tmp[0]; total[1] += tmp[1]; } catch (Exception e) { UpdateLog.Error(e.Message); } } UpdateLog.Log("热轮接入率#" + total[0] + "/" + total[1] + " * 100 = " + (total[0] != 0 ? Math.Round((total[0]) / (total[1]), 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#接入热轮文件数/过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮接入率#" + ex.Message); } try { UpdateLog.Log("➤ 热轮匹配率"); double[] total = new double[2]; foreach (LineInfo li in LineList) { try { double[] tmp = IndexTest.GetHotWheelFileMatchRatio(st, ed, li.FolderName); UpdateLog.Log("线路" + li.lid + "匹配率#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); total[0] += tmp[0]; total[1] += tmp[1]; } catch (Exception e) { UpdateLog.Error(e.Message); } } UpdateLog.Log("热轮匹配率#" + total[0] + "/" + total[1] + " * 100 = " + (total[0] != 0 ? Math.Round((total[0]) / (total[1]), 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#匹配成功的热轮文件数/接入的热轮文件数*100%"); } catch (Exception ex) { UpdateLog.Error("热轮匹配率#" + ex.Message); } break; #endregion #region 确报指标 case "QBIndex": try { UpdateLog.Log("➤ 确报总数"); int total = 0; foreach (LineInfo li in LineList) { DataTable tmpdt = IndexTest.GetAllQBNumByPeriod(st, ed, li.lid.ToString()); int tmp = 0; int.TryParse(tmpdt.Rows[0][0]?.ToString(), out tmp); total += tmp; UpdateLog.Log("线路" + li.lid + "#" + tmp); } UpdateLog.Log("确报总数#" + total); } catch (Exception ex) { UpdateLog.Error("确报总数#" + ex.Message); } try { UpdateLog.Log("➤ 确报接入率"); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetQBRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "#" + tmp[0] + "/" + tmp[1] + " * 100 = " + (tmp[1] != 0 ? Math.Round(tmp[0] / tmp[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); } double[] all = IndexTest.GetQBRatio(st, ed, null); UpdateLog.Log("确报总接入率#" + all[0] + "/" + all[1] + " * 100 = " + (all[1] != 0 ? Math.Round(all[0] / all[1], 2, MidpointRounding.AwayFromZero) * 100 : 0) + "%"); UpdateLog.Log("公式#确报主表中的数值/非客过车总数*100%"); } catch (Exception ex) { UpdateLog.Error("确报接入率#" + ex.Message); } try { UpdateLog.Log("➤ 确报车号利用率"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetQBUseRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "利用率#" + tmp + "%"); } double all = IndexTest.GetQBUseRatio(st, ed, null); UpdateLog.Log("确报车号利用率#" + all + "%"); UpdateLog.Log("公式#确报弥补的车号数/车号识别短少的车号数*100%"); } catch (Exception ex) { UpdateLog.Error("确报车号利用率#" + ex.Message); } break; #endregion #region 车号识别率 case "CheckTrainNum": try { UpdateLog.Log("➤ 车号识别率"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetVisionCarNoRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "识别率#" + tmp + "%"); } double all = IndexTest.GetVisionCarNoRatio(st, ed, null); UpdateLog.Log("车号识别率#" + all + "%"); UpdateLog.Log("公式#车号正常车辆数/所有过车车辆数*100% [依据数据库计算]"); } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 丢轴 case "MissAxle": try { UpdateLog.Log("➤ 丢轴"); foreach (LineInfo li in LineList) { double tmp = IndexTest.GetUnusualAlexTrainRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "丢轴率#" + tmp + "%"); } double all = IndexTest.GetUnusualAlexTrainRatio(st, ed, null); UpdateLog.Log("总丢轴率#" + all + "%"); UpdateLog.Log("公式#丟轴、多轴列数/实际过车列数*100%"); UpdateLog.Log("*注#以算法返回的-11为基准,业务上发生的丢轴、多轴均视为丢轴"); } catch (Exception ex) { UpdateLog.Error(ex.Message); } break; #endregion #region 音视频生成率 case "GenerateRate_Audio_Video": try { UpdateLog.Log("➤ 音频生成率 和 视频生成率"); decimal total_audio = 0, total_video = 0, total_video2 = 0, total_Dir = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); List <string> MissingAudio, MissingVideo, MissingVideo2; int DirCount; IndexTest.GenerateRate_Audio_Video(st, ed, Common.Default.Path_Pic + li.FolderName, out MissingAudio, out MissingVideo, out MissingVideo2, out DirCount); UpdateLog.Log("检测文件夹数#" + DirCount); total_Dir += DirCount; decimal rate_audio = DirCount != 0 ? Math.Round((DirCount - MissingAudio.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_audio += DirCount - MissingAudio.Count; UpdateLog.Log("音频生成率#" + rate_audio); UpdateLog.Log("公式#音频生成率 = 生成主音频文件数/列车文件夹数*100%\r\n"); decimal rate_video = DirCount != 0 ? Math.Round((DirCount - MissingVideo.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_video += DirCount - MissingVideo.Count; UpdateLog.Log("视频生成率#" + rate_video); UpdateLog.Log("公式#视频生成率 = 生成主视频文件数/列车文件夹数*100%\r\n"); decimal rate_video2 = DirCount != 0 ? Math.Round((DirCount - MissingVideo2.Count) / Convert.ToDecimal(DirCount), 4, MidpointRounding.AwayFromZero) * 100 : 0; total_video2 += DirCount - MissingVideo2.Count; UpdateLog.Log("视频生成率(辅)#" + rate_video2); UpdateLog.Log("公式#视频生成率 = 生成主视频文件数/列车文件夹数*100%\r\n"); UpdateLog.Log("丢失音频明细"); foreach (string i in MissingAudio) { UpdateLog.Log(i); } UpdateLog.Log("丢失视频明细"); foreach (string i in MissingVideo) { UpdateLog.Log(i); } UpdateLog.Log("丢失视频明细(辅)"); foreach (string i in MissingVideo2) { UpdateLog.Log(i); } } UpdateLog.Log("音频总生成率#" + Math.Round(total_audio / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); UpdateLog.Log("视频总生成率#" + Math.Round(total_video / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); UpdateLog.Log("视频总生成率(辅)#" + Math.Round(total_video / total_Dir, 4, MidpointRounding.AwayFromZero) * 100); } catch (Exception ex) { UpdateLog.Error("音频生成率 和 视频生成率异常#" + ex.Message); } break; #endregion #region 图像检测率 case "CallRate_Image": try { UpdateLog.Log("➤ 图像检测率"); foreach (LineInfo li in LineList) { double[] tmp = IndexTest.GetImageCheckRatio(st, ed, li.lid.ToString()); UpdateLog.Log("线路" + li.lid + "检测率#" + tmp[0] + "/" + tmp[1] + "=" + tmp[2] + "%"); } double[] all_Rate = IndexTest.GetImageCheckRatio(st, ed, null); UpdateLog.Log("图像检测率#" + all_Rate[0] + "/" + all_Rate[1] + "=" + all_Rate[2] + "%"); UpdateLog.Log("公式#主服务成功调用算法的个数/所有过车图片数*100%"); } catch (Exception ex) { UpdateLog.Error("图像检测率#" + ex.Message); } break; #endregion #region 图像算法调用及时性 case "Timely_Image": try { UpdateLog.Log(IndexTest.GetTimely(st, ed)); } catch (Exception ex) { UpdateLog.Error("图像算法调用的及时性异常#" + ex.Message); } break; #endregion #region 图像报警准确率 case "AccuracyRate_Image": try { foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); decimal true_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true, true, "pic"); decimal false_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), false, true, "pic"); decimal all_pic = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), null, true, "pic"); UpdateLog.Log("➤ 真实报警率#" + true_pic + "/" + all_pic + "=" + (all_pic != 0 ? (Math.Round(true_pic / all_pic, 4) * 100) : 0) + "%"); UpdateLog.Log("➤ 误报率#" + false_pic + "/" + all_pic + "=" + (all_pic != 0 ? (Math.Round(false_pic / all_pic, 4) * 100) : 0) + "%"); UpdateLog.Log("*注#基于人工处理后数据才有意义"); } } catch (Exception ex) { UpdateLog.Error("图像报警准确率#" + ex.Message); } break; #endregion #region 视频检测率 case "CheckRate_Video": try { UpdateLog.Log("此功能暂不实现"); } catch (Exception ex) { UpdateLog.Error("视频检测率#" + ex.Message); } break; #endregion #region 视频算法调用的及时性 case "Timely_Video": try { UpdateLog.Log("此功能暂不实现"); } catch (Exception ex) { UpdateLog.Error("视频算法调用的及时性#" + ex.Message); } break; #endregion #region 9个检测项独立统计【报喜不报忧模式】 case "Custom4Client": try { UpdateLog.Log("➤ 各类检测项统计"); int total_Alarm = 0; foreach (LineInfo li in LineList) { UpdateLog.Log("【线路" + li.lid + "】"); DataTable tmp = IndexTest.GetAlarmNum(st, ed, li.lid.ToString(), true); if (tmp != null && tmp.Rows.Count > 0) { for (int i = 0; i < tmp.Rows.Count; i++) { UpdateLog.Log(tmp.Rows[i]["ProblemType"].ToString() + "#" + tmp.Rows[i]["AlarmNum"].ToString()); total_Alarm += int.Parse(tmp.Rows[i]["AlarmNum"]?.ToString()); } } } UpdateLog.Log("报警总数#" + total_Alarm); } catch (Exception ex) { UpdateLog.Error("各类别预警数" + ex.Message); } break; #endregion default: break; } TransferFiles.SendVarData(client, Encoding.UTF8.GetBytes(UpdateLog.OutputLog_IntoString(false))); break; } else { Thread.Sleep(0); continue; } } } catch (Exception ex) { ///当网络异常中断#拔网线等触发,接受为0字节,但是并不认为是异常,因此需要添加心跳机制; UpdateLog.Error("接受失败#" + ex.Message); } finally { //输出日志文件 UpdateLog.OutputLog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TOEC Index Test"), "TOEC Index Test"); //关闭套接字 client.Close(); } }
private void Version_Click(object sender, RoutedEventArgs e) { var dialog = new UpdateLog(); var task = dialog.ShowAsync(); }
/// <summary> /// 在线程中执行更新流程 /// </summary> private void updateFlowByThread() { bool continueFlow = false; CurrentFlow = null; _abortFlows = false; int resultCode = CodeDefine.RET_SUCCESS; int runFlowCount = 0; while (true && !_abortFlows) { BaseFlow oldFlow = null; continueFlow = false; runFlowCount = 0; for (int i = 0; !_abortFlows && i < _flowList.Count; ++i) { runFlowCount++; CurrentFlow = _flowList[i]; UpdateLog.DEBUG_LOG(CurrentFlow.FlowName()); CurrentFlow.OnEnter(oldFlow); resultCode = CurrentFlow.Work(); CurrentFlow.OnLeave(resultCode); //更新客户端,跳过所有流程 if (resultCode == CodeDefine.RET_SKIP_BY_DOWNLOAD_APP) { UpdateLog.DEBUG_LOG("Download Client finish, skip all left flows!!!"); break; } //需要强制释放资源,重新走更新流程 if (resultCode == CodeDefine.RET_SKIP_BY_FORCE_TRANS_RESOURCE) { FlowInstance <Flow1TransResource>().SetForceUnzip(); continueFlow = true; break; } //中断操作 if (resultCode == CodeDefine.RET_SKIP_BY_ABORT) { UpdateLog.DEBUG_LOG("Abort flow -> " + CurrentFlow.FlowName()); break; } if (resultCode == CodeDefine.RET_SKIP_BY_DISABLEDOWNLOAD) { UpdateLog.DEBUG_LOG("Not support download, skip all flows!!!"); break; } //取消操作 if (resultCode == CodeDefine.RET_SKIP_BY_CANCEL) { UpdateLog.DEBUG_LOG("Skip flow by cancel download option, exit game!!!"); break; } if (resultCode < CodeDefine.RET_SUCCESS) { break; } oldFlow = CurrentFlow; } if (!continueFlow) { break; } } if (runFlowCount != _flowList.Count) { FlowInstance <FlowFinish>().FinishWithError(resultCode); } _threadFinish = true; //重新开启 if (_restart) { UpdateLog.DEBUG_LOG("Restart update"); StartUpdate(); } else { UpdateLog.DEBUG_LOG("Finish update flow!!! " + resultCode); } }
private void unzipApk() { UpdateLog.DEBUG_LOG("Trans resource from apk!!!"); UpdateLog.DEBUG_LOG("_resourcePath=" + _resourcePath); //res开始路径,从assets开始 string APKStreamingAsset = "assets/"; //跳过的资源路径,bin目录不做拷贝 string skipResDir = "/bin/"; string apkPath = _resourcePath; if (!ForTest) { apkPath = apkPath.Replace("!/assets", ""); apkPath = apkPath.Replace("jar:file://", ""); } UpdateLog.DEBUG_LOG("apkPath=" + apkPath); UpdateLog.DEBUG_LOG("_outPath=" + _outPath); FileStream fileStream = null; try { fileStream = File.OpenRead(apkPath);// new FileStream(apkPath, FileMode.Open); ZipFile f = new ZipFile(fileStream); nReadCount = (Int32)f.Count; fileStream.Seek(0, SeekOrigin.Begin); } catch (System.Exception ex) { UpdateLog.ERROR_LOG(ex.Message); } if (fileStream == null) { UpdateLog.ERROR_LOG("文件读取失败"); return; } using (ZipInputStream s = new ZipInputStream(fileStream)) { ZipEntry entry = null; while ((entry = s.GetNextEntry()) != null) { string unRootPath = _outPath; string directoryName = Path.GetDirectoryName(entry.Name).Replace("\\", "/") + "/"; if (directoryName.Contains(skipResDir)) { ++nWriteCount; continue; } if (!directoryName.StartsWith(APKStreamingAsset)) { ++nWriteCount; continue; } string fileName = Path.GetFileName(entry.Name); // create directory; if (!string.IsNullOrEmpty(directoryName)) { unRootPath = Path.Combine(unRootPath, directoryName); unRootPath = unRootPath.Replace(APKStreamingAsset, ""); unRootPath = unRootPath.Replace('\\', '/'); if (!Directory.Exists(unRootPath)) { Directory.CreateDirectory(unRootPath); } } if (!string.IsNullOrEmpty(fileName)) { try { fileName = Path.Combine(unRootPath, fileName); fileName = fileName.Replace('\\', '/'); using (FileStream streamWriter = File.Create(fileName)) { int size = 0; int bufferSize = 512; byte[] tempBuffer = new byte[bufferSize]; while (true) { size = s.Read(tempBuffer, 0, bufferSize); if (size > 0) { streamWriter.Write(tempBuffer, 0, size); } else { break; } } streamWriter.Flush(); ++nWriteCount; streamWriter.Close(); } } catch (Exception ex) { UpdateLog.ERROR_LOG(ex.Message); UpdateLog.ERROR_LOG("文件损坏: " + entry.Name); } finally { } } else { ++nWriteCount; UpdateLog.ERROR_LOG("trans error, file name is empty: " + entry.Name); } } Thread.Sleep(50); _success = (nWriteCount == nReadCount && nWriteCount != 0); UpdateLog.DEBUG_LOG(string.Format("转移资源结束 {0}/{1}", nWriteCount, nReadCount)); } }
/// 日志回调注册 /// </summary> /// <param name="log1"></param> /// <param name="log2"></param> /// <param name="log3"></param> public void RegisterLog(DefaultLog log1, WarnLog log2, ErrorLog log3) { UpdateLog.RegisterLogCallback(log1, log2, log3); }
/// <summary> /// 设置预加载信息,用来显示进度 /// </summary> /// <param name="total"></param> /// <param name="loadedCount"></param> public void SetPreloadTotal(int total) { UpdateLog.WARN_LOG("start preload+++++++++++++"); _showPreloadRes = true; _totalPreloadRes = total; }
public void InitializeTools(ININ.Interop.IDTypeLib.II3ID Designer) { var IntegerTypeSpecifier = "::" + Designer.QueryNativeTypeName(ININ.Interop.IDTypeLib.I3IDNativeDataType.ID_INTEGER); var StringTypeSpecifier = "::" + Designer.QueryNativeTypeName(ININ.Interop.IDTypeLib.I3IDNativeDataType.ID_STRING); ININ.Interop.IDTypeLib.II3IDTool AddValues; AddValues = Designer.Tools.RegisterTool( null, //event sink - it gets called when it is created? see API guide "TSD - Add Values", //Label "ToolStepDemo", //ToolModuleName "TSD_Add", //Toolname - this should probably be unique "Implements adding a string to an integer", //Description "Tool Step Demo", //Tool Category "ToolStepDemo", //DLL Name "AddValues", //Function name (in above DLL) 3 //number of parameters ); AddValues.ParameterDefinitions.Item(0).SetAsInputComboBox(IntegerTypeSpecifier, "Operand 1", true); AddValues.ParameterDefinitions.Item(1).SetAsInputComboBox(StringTypeSpecifier, "Operand 2", true); AddValues.ParameterDefinitions.Item(2).SetAsOutput(IntegerTypeSpecifier, "Result", true); AddValues.ExitPaths.Add("Success", 3, false); AddValues.ExitPaths.Add("Convert Error", 1, true); AddValues.ExitPaths.Add("Failure", 2, true); AddValues.Commit(); ININ.Interop.IDTypeLib.II3IDTool UpdateLog; UpdateLog = Designer.Tools.RegisterTool( null, //event sink - it gets called when it is created? see API guide "TSD - Update Log", //Label "ToolStepDemo", //ToolModuleName "TSD_UpdateLog", //Toolname - this should probably be unique "Implements adding a log message with date/timestamp", //Description "Tool Step Demo", //Tool Category "ToolStepDemo", //DLL Name "updateLog", //Function name (in above DLL) 2 //number of parameters ); UpdateLog.ParameterDefinitions.Item(0).SetAsOutput(StringTypeSpecifier, "Log", true); UpdateLog.ParameterDefinitions.Item(1).SetAsInputComboBox(StringTypeSpecifier, "Message", true); UpdateLog.ExitPaths.Add("Next", 1, false); UpdateLog.Commit(); ININ.Interop.IDTypeLib.II3IDTool StockQuote; StockQuote = Designer.Tools.RegisterTool( null, //event sink - it gets called when it is created? see API guide "TSD - Stock Quote", //Label "ToolStepDemo", //ToolModuleName "TSD_StockQuote", //Toolname - this should probably be unique "Implements getting a stock quote via a web service", //Description "Tool Step Demo", //Tool Category "ToolStepDemo", //DLL Name "getStockQuote", //Function name (in above DLL) 2 //number of parameters ); StockQuote.ParameterDefinitions.Item(0).SetAsInputComboBox(StringTypeSpecifier, "Stock Symbol", true); StockQuote.ParameterDefinitions.Item(1).SetAsOutput(StringTypeSpecifier, "Stock Quote", true); StockQuote.ExitPaths.Add("Next", 1, false); StockQuote.Commit(); }
/// <summary> /// 多线程下载文件 /// </summary> /// <param name="mapFileDataList">文件列表</param> /// <returns>小于0失败</returns> public int DownloadFileByMultiThread(List <MapFileData> mapFileDataList) { int ret = CodeDefine.RET_FAIL; int allRetryTimes = _RETRAY_TIMES; Download.MutiDownloadedSize = 0; _abort = false; if (mapFileDataList == null) { ret = CodeDefine.RET_FAIL; return(ret); } while (_failDownloadFile.Count <= _MAX_ERROR_LIMIT && allRetryTimes > 0) { _currentDownloadFileCount = 0; _failDownloadFile.Clear(); _totalDownloadFileCount = mapFileDataList.Count; _threadPool = new HttpThreadPool <MapFileData>(_MAX_THREAD_COUNT, ThreadCallBack); for (int i = 0; i < mapFileDataList.Count; i++) { MapFileData fileData = mapFileDataList[i]; _threadPool.addTask(fileData); } //等待所有文件下载完 _threadPool.waitWhileWorking(); if (_abort) { UpdateLog.DEBUG_LOG("abort repaire download!!!"); _abort = false; return(CodeDefine.RET_SKIP_BY_ABORT); } //当失败文件数小于_MAX_ERROR_LIMIT,则这些文件重新加到下载队列里面 if (_failDownloadFile.Count != 0) { for (int i = 0; i < _failDownloadFile.Count; i++) { UpdateLog.DEBUG_LOG("有文件下载失败" + _failDownloadFile[i].Name); } mapFileDataList.Clear(); mapFileDataList.AddRange(_failDownloadFile); //_failDownloadFile.Clear(); ret = CodeDefine.RET_FAIL; } else { mapFileDataList.Clear(); _failDownloadFile.Clear(); ret = CodeDefine.RET_SUCCESS; break; } allRetryTimes--; } //到这里还有文件没有下载成功,则表示下载失败了 if (mapFileDataList.Count > 0) { UpdateLog.DEBUG_LOG("更新失败,有" + mapFileDataList.Count + "个文件下载失败"); } return(ret); }
public async Task <bool> UpdateReadPageNumber([FromBody] UpdateLog updateLog, int userid, int bookid) { return(await new BookService().UpdateReadPageNumber(updateLog, userid, bookid)); }