protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { string newPath = ReplaceUtil.Replace(m_Parameters.NewPath, file); string message = "Success"; FileInfo result = null; try { string dirPath = Path.GetDirectoryName(newPath); Directory.CreateDirectory(dirPath); if (m_Parameters.Overwrite || !File.Exists(newPath)) { result = file.CopyTo(newPath, m_Parameters.Overwrite); } } catch (Exception ex) { RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); message = ex.Message; } if (result == null) { return(new ProcessingResult(ProcessingResultType.Failure, message ?? "Failure", new FileInfo[0])); } return(new ProcessingResult(ProcessingResultType.Success, "Success", new FileInfo[] { new FileInfo(newPath) })); }
public override void LocalInit() { base.LocalInit(); m_Filename = ReplaceUtil.Replace(m_Parameters.Filename, (FileInfo)null); TextWriter tw = new StreamWriter(m_Filename); string lineEnding = TextUtil.GetNewline(m_Parameters.LineEndings); tw.NewLine = lineEnding; m_CsvWriter = new CsvWriter(tw); List <string> headers = new List <string>(); switch (m_Parameters.PathFormat) { case PathFormat.FullPath: headers.Add("Filename"); break; case PathFormat.NameThenDirectory: headers.Add("Filename"); headers.Add("Path"); break; case PathFormat.DirectoryThenName: headers.Add("Path"); headers.Add("Filename"); break; } headers.Add("Matches"); string[] columnHeaders = HeaderUtil.GetUniqueHeaders(headers, RunInfo.Condition, RunInfo.FieldSources); foreach (string header in columnHeaders) { m_CsvWriter.WriteField(header); } m_CsvWriter.NextRecord(); }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { string directoryPath = ReplaceUtil.Replace(m_Parameters.DirectoryPath, file); ProcessingResultType resultType = ProcessingResultType.Failure; string message = "Failed to create directory"; try { if (Directory.Exists(directoryPath)) { resultType = ProcessingResultType.Success; message = "Directory already exists"; } else if (!File.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); resultType = ProcessingResultType.Success; message = "Directory created"; } } catch (Exception ex) { RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); message = ex.Message; } return(new ProcessingResult(resultType, message, new FileInfo[0])); }
private void DoPlay() { var director = GameObject.Instantiate(prefab); var map = new Dictionary <AnimationPlayableAsset, AnimationClip>(); ReplaceUtil.ReplaceAll(director, clip, map); director.Play(); ReplaceUtil.RestoreAsset(map); director.stopped += (obj) => { GameObject.Destroy(obj.gameObject); }; }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { string outputFilename = ReplaceUtil.Replace(m_Parameters.FileName, file); if (!m_Parameters.OverwriteExistingFile && File.Exists(outputFilename)) { return(new ProcessingResult(ProcessingResultType.Failure, "File exists", new FileInfo[0])); } Encoding encoding = TextUtil.DetectEncoding(file); string tmpFile = Path.GetTempFileName(); bool endsWithNewLine = TextUtil.FileEndsWithNewline(file, encoding); using (StreamWriter writer = TextUtil.CreateStreamWriterWithAppropriateEncoding( tmpFile, encoding, m_Parameters.OutputEncoding)) { writer.NewLine = TextUtil.GetNewline(file, m_Parameters.LineEndings); using (StreamReader reader = TextUtil.CreateStreamReaderWithAppropriateEncoding(file, encoding)) { string text = m_Parameters.Text ?? string.Empty; if (m_Parameters.PrependOrAppend == PrependAppend.Prepend) { WriteLines(writer, text); } bool writtenAnyFromFile = false; while (!reader.EndOfStream) { if (writtenAnyFromFile) { writer.WriteLine(); } writer.Write(reader.ReadLine()); writtenAnyFromFile = true; } // Add a trailing line ending if the original file ended in one if (endsWithNewLine) { writer.WriteLine(); } if (m_Parameters.PrependOrAppend == PrependAppend.Append) { WriteLines(writer, text); } } } return(GetProcessingResultFromCopyAndDeleteTempFile(file, outputFilename, tmpFile, m_Parameters.OverwriteExistingFile, m_Parameters.MoveOriginalToRecycleBin)); }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { string outputFilename = ReplaceUtil.Replace(m_Parameters.FileName, file); if (!m_Parameters.OverwriteExistingFile && File.Exists(outputFilename)) { return(new ProcessingResult(ProcessingResultType.Failure, "File exists", new FileInfo[0])); } Encoding encoding = TextUtil.DetectEncoding(file); string tmpFile = Path.GetTempFileName(); bool endsWithNewLine = TextUtil.FileEndsWithNewline(file, encoding); using (StreamWriter writer = TextUtil.CreateStreamWriterWithAppropriateEncoding( tmpFile, encoding, m_Parameters.OutputEncoding)) { writer.NewLine = TextUtil.GetNewline(file, m_Parameters.LineEndings); using (StreamReader reader = TextUtil.CreateStreamReaderWithAppropriateEncoding( file, encoding)) { bool keep = m_Parameters.FilterType == LineFilterType.KeepMatchingLines; bool anyWritten = false; while (!reader.EndOfStream) { string line = reader.ReadLine(); bool matches = m_Regex.IsMatch(line); if (matches == keep) { if (anyWritten) { writer.WriteLine(); } writer.Write(line); anyWritten = true; } } if (endsWithNewLine) { writer.WriteLine(); } } } return(GetProcessingResultFromCopyAndDeleteTempFile(file, outputFilename, tmpFile, m_Parameters.OverwriteExistingFile, m_Parameters.MoveOriginalToRecycleBin)); }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { try { string comandLine = ReplaceUtil.Replace(m_Parameters.CommandLine, file); Process process = System.Diagnostics.Process.Start("cmd", "/c " + comandLine); if (m_Parameters.WaitForTaskToFinish) { process.WaitForExit(); } } catch (Exception ex) { RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); return(new ProcessingResult(ProcessingResultType.Failure, ex.Message, new FileInfo[] { file })); } return(new ProcessingResult(ProcessingResultType.Success, "Success", new FileInfo[] { file })); }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { ProcessingResultType resultType = ProcessingResultType.Success; string message = "Success"; string newPath = ReplaceUtil.Replace(m_Parameters.FileName, file); FileInfo[] resultFiles = new FileInfo[0]; if (File.Exists(newPath)) { if (m_Parameters.UpdateModificationDateIfExists) { try { File.SetLastWriteTime(newPath, DateTime.Now); resultFiles = new FileInfo[] { new FileInfo(newPath) }; message = "Successfully updated file modification date"; } catch (Exception ex) { resultType = ProcessingResultType.Failure; message = $"Failed to update file modification date: {ex.Message}"; RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); } } } else { try { File.Create(newPath).Close(); resultFiles = new FileInfo[] { new FileInfo(newPath) }; message = "Successfully created file"; } catch (Exception ex) { resultType = ProcessingResultType.Failure; message = $"Failed to create file: {ex.Message}"; RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); } } return(new ProcessingResult(resultType, message, resultFiles)); }
protected internal override ProcessingResult Process(FileInfo file, string[] values, CancellationToken token) { int width; int height; bool isBitmap = false; string outPath = null; FileInfo[] generatedFiles = new FileInfo[0]; ProcessingResultType resultType = ProcessingResultType.Failure; string message = "Success"; Bitmap b = null; try { b = new Bitmap(file.FullName); isBitmap = true; } catch (Exception ex) { resultType = ProcessingResultType.NotApplicable; } if (isBitmap) { try { if (m_Parameters.ResizeBy == MediaDimension.Width) { width = m_Parameters.Size; height = (int)Math.Round((double)b.Height * width / b.Width); } else { height = m_Parameters.Size; width = (int)Math.Round((double)b.Width * height / b.Height); } using (Bitmap bout = new Bitmap(b, new Size(width, height))) { outPath = ReplaceUtil.Replace(m_Parameters.NewPath, file); ImageFormat format = ImageFormat.Jpeg; switch (m_Parameters.Format) { case ImageSaveFormat.Bitmap: format = ImageFormat.Bmp; break; case ImageSaveFormat.Exif: format = ImageFormat.Exif; break; case ImageSaveFormat.Gif: format = ImageFormat.Gif; break; case ImageSaveFormat.Jpeg: format = ImageFormat.Jpeg; break; case ImageSaveFormat.Png: format = ImageFormat.Png; break; case ImageSaveFormat.Tiff: format = ImageFormat.Tiff; break; } if (m_Parameters.Overwrite || !File.Exists(outPath)) { string outDirPath = Path.GetDirectoryName(outPath); Directory.CreateDirectory(outDirPath); bout.Save(outPath, format); resultType = ProcessingResultType.Success; generatedFiles = new FileInfo[] { new FileInfo(outPath) }; } else { resultType = ProcessingResultType.Failure; message = "Target file exists"; generatedFiles = new FileInfo[0]; } } } catch (Exception ex) { RunInfo.ExceptionInfos.Enqueue(new ExceptionInfo(ex, file)); message = ex.Message; resultType = ProcessingResultType.Failure; } finally { b?.Dispose(); } } return(new ProcessingResult(resultType, message, generatedFiles)); }