private static string ComputeHash(PathInfo p1) { using (var md5 = MD5.Create()) { using (var stream = System.IO.File.OpenRead(p1.FullPath)) { var hash = md5.ComputeHash(stream); FileProcessed?.Invoke(null, EventArgs.Empty); return(BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant()); } } }
public FileProcessed GenerateFileProcessed(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("FilePath is a required field, please, fill it."); } _logger.Info($"Starting to generate a fileProcessed of '{filePath}'"); var fileProcessed = new FileProcessed { FilePath = filePath, FileName = Path.GetFileName(filePath), Dictionary = _fileProcessor.CountWordsOfFile(filePath) }; _logger.Info($"Finish to generate a fileProcessed of '{filePath}' with name={fileProcessed.FileName}"); return(fileProcessed); }
private void onFileProcessed(string filename) { FileProcessed?.Invoke(this, new FileProcessedEventArgs(filename)); }
/// <summary> /// Implements the template on the provided path /// </summary> /// <param name="ImplementationPath">The path to implement the template on</param> /// <param name="Data">Data to replace on the files while preprocessing</param> /// <returns>void</returns> public async Task ImplementAsync(String ImplementationPath, IDictionary <String, String> Data) { ImplementationPath = Path.GetFullPath(ImplementationPath); // Checks if the implementation folder exists Directory.CreateDirectory(ImplementationPath); // List all files and ignores the ones that should be var files = GetFiles(TPath, TConfig.ignore .Concat(new String[1] { "template.json" })); // Copies all files to their targets var copier = new FileCopier( ); copier.FileCopied += Copier_FileCopied; await copier.CopyFilesAsync( files.Select(file => Path.Combine(TPath, file)), files.Select(file => Path.Combine(ImplementationPath, file)) ); // List files to process var processable = GetFiles(ImplementationPath, TConfig.ignore .Concat(TConfig.processIgnore) .Concat(new String[1] { "template.json" })); // Processes the files for (var i = 0; i < processable.Length; i++) { ProcessFile(Path.Combine(ImplementationPath, processable[i]), Data); FileProcessed?.Invoke(processable[i], i, processable.Length); } foreach (var command in TConfig.setupTasks) { TaskRunning?.Invoke(command); Process task = null; try { task = Process.Start(new ProcessStartInfo { FileName = command.Before(' '), Arguments = command.After(' '), WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = false, UseShellExecute = true, LoadUserProfile = true, WorkingDirectory = ImplementationPath }); // Runs the process for 5 minutes in max task.WaitForExit(TConfig.tasksTimeout); if (task.ExitCode != 0) { throw new Exception($"Exit code was not 0: {task.ExitCode}."); } var elapsed = task.ExitTime - task.StartTime; if (elapsed.TotalMilliseconds >= TConfig.tasksTimeout - 2) { throw new Exception($"Process achieved the timeout: {elapsed.ToString ( )}"); } } catch (Exception ex) { TaskInterrupted?.Invoke(command, ex); } finally { task.Close( ); task.Dispose( ); } } }
public override string ToString() { return("{0} [{1} classes]".format(FileProcessed.fileName(), Classes.size())); }
private void NewFileProcessedMsg(Object o, FileProcessed e) { qtyFilesLabel.Invoke(new Action <Int32>(num => qtyFilesLabel.Text = num.ToString()), ((FileSearcher)o).NumFiles); timeLabel.Invoke(new Action <String>(str => timeLabel.Text = str), ((FileSearcher)o).Time.ToString().Substring(0, 11)); currFileLabel.Invoke(new Action <String>(str => currFileLabel.Text = str), e.FileName); }