/// <summary> /// Move source file to pool /// </summary> /// <param name="filePath"></param> /// <returns></returns> public SpoolFile MoveIn(string filePath) { var spoolFile = new SpoolFile(_configuration.Name, Index); try { var ext = FilePathUtil.GetPathExtension(filePath); var path = GenerateFilePath(ext); spoolFile.Path = path; //直接移动 File.Move(filePath, path); //Write queue _pendingQueue.Enqueue(spoolFile); //是否写满了(需要按照待处理的文件数量+处理中的数量进行计算,避免当关闭自动归还功能时,磁盘下的文件还有大量的堆积) if (_pendingQueue.Count + _progressingDict.Count > _configuration.TrainMaxFileCount) { var info = BuildInfo(); var args = new TrainWriteOverEventArgs() { Train = info, }; OnWriteOver?.Invoke(this, args); } return(spoolFile); } catch (Exception ex) { _logger.LogError("Move file to train failed, FilePool:'{0}',Train:'{1}',FilePath:'{2}',Exception:{3}.", _configuration.Name, Index, filePath, ex.Message); throw ex; } }
private void spoolList_DoubleClick(object sender, EventArgs e) { if (spoolList.SelectedItems.Count == 1) { ListViewItem selection = spoolList.SelectedItems[0]; if (selection.Tag != null) { new Thread((ThreadStart) delegate { SpoolFile spool = selection.Tag as SpoolFile; string SpoolFile = spool.Download(); if (SpoolFile != "") { this.Invoke((MethodInvoker) delegate { Editor.OpenLocalSource(SpoolFile, Language.None, spool.getName(), true); }); } else { MessageBox.Show("Spool file was not downloaded. Please check the spool file exists."); } }).Start(); } } }
/// <summary> /// Load train files /// </summary> private void LoadFiles() { var directoryInfo = new DirectoryInfo(Path); var files = directoryInfo.GetFiles(); foreach (var file in files) { var spoolFile = new SpoolFile() { FilePool = _configuration.Name, TrainIndex = Index, Path = file.FullName }; _pendingQueue.Enqueue(spoolFile); } }
/// <summary> /// Write file /// </summary> /// <param name="stream"></param> /// <param name="fileExt"></param> /// <returns></returns> public async ValueTask <SpoolFile> WriteFileAsync(Stream stream, string fileExt) { var spoolFile = new SpoolFile(_configuration.Name, Index); try { var path = GenerateFilePath(fileExt); spoolFile.Path = path; //Write file await WriteInternalAsync(stream, path); //Write queue _pendingQueue.Enqueue(spoolFile); //是否写满了(需要按照待处理的文件数量+处理中的数量进行计算,避免当关闭自动归还功能时,磁盘下的文件还有大量的堆积) if (_pendingQueue.Count + _progressingDict.Count > _configuration.TrainMaxFileCount) { var info = BuildInfo(); var args = new TrainWriteOverEventArgs() { Train = info, }; OnWriteOver?.Invoke(this, args); } return(spoolFile); } catch (Exception ex) { _logger.LogError("Write file to train failed, FilePool:'{0}',Train:'{1}',FileExt:'{2}',Exception:{3}.", _configuration.Name, Index, fileExt, ex.Message); throw ex; } finally { //流释放 stream?.Close(); stream?.Dispose(); } }