public static void ProcessFiles(TesseractArgs a) { var tesseractPath = GetTesseractPath(); var maxDegreeOfParallelism = Environment.ProcessorCount; Parallel.ForEach(a.inputFiles, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, (fileName) => { var imageFile = File.ReadAllBytes(fileName); var text = ParseText(tesseractPath, imageFile, a.lang.ToString()); if (a.outputFiles != null) { TF.SaveFile(text, a.outputFiles[fileName]); } if (a.writingOnConsole) { Console.WriteLine("File:" + fileName + "\n" + text + "\n"); } }); }
/// <summary> /// A1 can be null, then will be joined default like D:\_Test\AllProjectsSearch\AllProjectsSearch\ by DefaultFolderPath() /// A2 can be slashed or backslashed. Will be appended to A1. /// To A2 will be add _Original automatically /// A3 is append after folder and folderFrom (with _Original\). can be null or SE /// /// A5 whether replace _Original in non original Folder /// </summary> /// <param name="appName"></param> /// <param name="featureOrType"></param> public static List <string> RefreshOriginalFiles(string baseFolder, object featureOrType, string modeOfFeature, bool copyFilesRecursively, bool replace_Original) { if (baseFolder == null) { baseFolder = DefaultFolderPath(); } string feature = NameOfFeature(featureOrType); FS.WithoutEndSlash(ref baseFolder); baseFolder = baseFolder + "\\" + feature; var folderFrom = baseFolder + "_Original\\"; string folder = baseFolder + "\\"; if (!string.IsNullOrEmpty(modeOfFeature)) { modeOfFeature = modeOfFeature.TrimEnd('\\') + "\\"; folderFrom += modeOfFeature; folder += modeOfFeature; } FS.GetFiles(folder, copyFilesRecursively).ToList().ForEach(d => FS.TryDeleteFile(d)); if (copyFilesRecursively) { FS.CopyAllFilesRecursively(folderFrom, folder, FileMoveCollisionOption.Overwrite); } else { FS.CopyAllFiles(folderFrom, folder, FileMoveCollisionOption.Overwrite); } var files = FS.GetFiles(folder); if (replace_Original) { const string _Original = "_Original"; for (int i = 0; i < files.Count; i++) { var item = files[i]; var item2 = item; var c = TF.ReadFile(item); // replace in content c = SH.Replace(c, _Original, string.Empty); TF.SaveFile(c, item2); if (item2.Contains(_Original)) { string newFile = item2.Replace(_Original, string.Empty); FS.MoveFile(item2, newFile, FileMoveCollisionOption.Overwrite); files[i] = newFile; } } } return(files); }
public void ReplaceManyFromStringTest() { string testString = @"Assert.Equal -> Assert.AreEqual Assert.AreEqual<*> -> CollectionAssert.AreEqual [Fact] -> [TestMethod] using Xunit; -> using Microsoft.VisualStudio.TestTools.UnitTesting;"; testString = "Assert.AreEqual<*> -> CollectionAssert.AreEqual"; string file = @"E:\Documents\vs\Projects\sunamo.Tests\sunamo.Tests.Data\ReplaceManyFromString\In_ReplaceManyFromString.cs"; var s = TF.ReadFile(file); s = SH.ReplaceManyFromString(s, testString, Consts.transformTo); TF.SaveFile(s, file); }
public static void WritingSpeed() { /* * TF.SaveFile takes 101ms * File.WriteAllText takes 8ms */ var file = @"d:\_Test\sunamo.performance\WritingSpeed\a.txt"; var content = string.Empty.PadLeft(1000000, AllChars.commat); StopwatchStatic.Start(); TF.SaveFile(content, file); StopwatchStatic.StopAndPrintElapsed("TF.SaveFile"); StopwatchStatic.Start(); File.WriteAllText(file, content); StopwatchStatic.StopAndPrintElapsed("File.WriteAllText"); }
public static void AddXmlns(string csproj, XNamespace ns, bool add) { if (add) { XDocument xml = XDocument.Load(csproj); foreach (var element in xml.Descendants().ToList()) { element.Name = ns + element.Name.LocalName; } xml.Root.SetAttributeValue("xmlns", ns.ToString()); xml.Save(csproj); } else { var text = TF.ReadFile(csproj); var xmlns = "xmlns=\"" + ns.ToString() + "\""; text = SH.ReplaceOnce(text, xmlns, string.Empty); TF.SaveFile(text, csproj); } }