private LoggerListViewViewModel() { bool isRun = true; //每毫秒从日志Stack中读取弹出的日志,以便于海量日志不会在毫秒级内发生阻塞。 //考虑到NKnife.NLog.WinForm组件是为了显示,这样的设计不会导致逻辑的问题。 var thread = new Thread(() => { while (isRun) { if (!_stack.IsEmpty) { CustomLogInfo[] infos = new CustomLogInfo[_stack.Count]; _stack.TryPopRange(infos); //弹出Stack中的所有的日志 LogInfos.AddRange(infos); //触发ListView显示最新的日志 SizeCollection(LogInfos, (int)MaxViewCount); //将ViewModel中的绑定集合缩小到指定大小,触发减少显示 Thread.Sleep(1); } } }); thread.Name = $"{nameof(LoggerListView)}_ReadLog_Thread"; thread.IsBackground = true; thread.Start(); Application.ApplicationExit += (s, e) => { isRun = false; _stack.Clear(); }; }
/// <summary> /// Send the selected file in the FTP /// </summary> /// <param name="_fileInfo"></param> public void UploadFileToFTP(LogInfos _fileInfo) { _fileInfo.IsLoading = true; WebClient _sendToFTP = new WebClient(); _sendToFTP.UploadFileCompleted += ((object sender, UploadFileCompletedEventArgs e) => _fileInfo.IsLoading = false); _sendToFTP.Credentials = new NetworkCredential("u89869971-jv2", "&piiC2017"); _sendToFTP.UploadFileAsync(new Uri("ftp://home689765717.1and1-data.host/cata/" + _fileInfo.LogName), WebRequestMethods.Ftp.UploadFile, Path.Combine(SavingPath, _fileInfo.LogName)); }
/// <summary> /// Return all file names /// </summary> /// <returns></returns> public void GetAllLocalFilesNames() { if (!Directory.Exists(SavingPath)) { Directory.CreateDirectory(SavingPath); } AllLocalFilesLog.Clear(); string[] _directories = Directory.GetFiles(SavingPath, "*.cata"); for (int i = 0; i < _directories.Length; i++) { LogInfos _infos = new LogInfos(Path.GetFileName(_directories[i])); AllLocalFilesLog.Add(_infos); } }
public RowValues(string row, int lineNumber) { if (SelectedSolvisControlVersion < 132) { if (lineNumber == 1) { Infos = new LogInfos(); } sensors = new double[24]; actors = new double[20]; HasValues = true; ConvertSoFile(row); } else { switch (lineNumber) { case 1: Infos = new LogInfos(row); break; case 2: case 3: case 4: case 5: Infos.SetNextLogInfo(row, lineNumber); break; default: HasValues = true; sensors = new double[30]; actors = new double[22]; ConvertMiFile(row); break; } } }