Exemplo n.º 1
0
        /// <summary>
        /// visits the directory, recursivery
        /// </summary>
        /// <param name="basePath"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public static async IAsyncEnumerable <Fsentry> VisitAsync(string basePath, [EnumeratorCancellation] CancellationToken ct = default)
        {
            var q = new DirsFilesStack();

            await q.EnumAndPushAsync(basePath, Filepath.Empty, ct);

            while (q.HasMore)
            {
                var entry = q.Pop();

                yield return(entry);

                if (entry.Event != FsentryEvent.EnterDir)
                {
                    continue;
                }

                q.PushLeavingDir(entry);

                if (entry.Command == FsentryCommand.Advance)
                {
                    var name        = Filepath.Parse(Path.GetFileName(entry.FullPathString));
                    var relativeDir = entry.RelativePath.Parent.Combine(name.Items);
                    await q.EnumAndPushAsync(entry.FullPathString, relativeDir, ct);
                }
                else                 // skip requested
                {
                    // nop. skip.
                }
            }
        }
Exemplo n.º 2
0
        //// This function demonstrates that we can add a comment to (nearly) every paragraph if we like.
        public static void AddToEveryPara(Document doc)
        {
            ConsoleC.WriteLine(ConsoleColor.White, "Trying to write a comment on all the paragraphs!");

            //// Load the default instance of Document class.
            // Document doc = LoadDocument.Default();

            for (int i = 1; i < doc.Paragraphs.Count; i++)
            {
                // Add a comment.
                try
                {
                    object text = "This is a comment on Paragraph " + i + ".";
                    doc.Comments.Add(doc.Paragraphs[i].Range, ref text);
                    ConsoleC.WriteLine(ConsoleColor.Green, "Added a comment on Paragraph " + i + "!");
                }
                catch (Exception ex)
                {
                    ConsoleC.WriteLine(ConsoleColor.Red, "Failed to add a comment to Paragraph " + i + " — " + ex.ToString());
                }
            }

            //Save to a new file.
            doc.SaveAs2(Filepath.Full().Replace(".docx", "_2.docx"));
        }
Exemplo n.º 3
0
        public void Test_Empty()
        {
            var path = Filepath.Parse("");

            Assert.IsTrue(path.Prefix is PathPrefix.Empty);
            Assert.AreEqual("", path.ToString());
        }
Exemplo n.º 4
0
        public void Test_Simple_Afile()
        {
            var path = Filepath.Parse("file.txt");

            Assert.IsFalse(path.Absolute);
            Assert.AreEqual("file.txt", path.ToString("/"));
        }
Exemplo n.º 5
0
        public string ExtractSeriesName(MediaFile ie)
        {
            reset();
            this.ie = ie;
            // Read plain configurationFilePath
            string filename = System.IO.Path.GetFileNameWithoutExtension(ie.Filename);

            filename = NameCleanup.RemoveReleaseGroupTag(filename);
            folders  = Filepath.extractFoldernamesFromPath(ie.FilePath.Path);
            if (ie.inSeasonFolder() && folders.Length > 2)
            {
                if (!Regex.IsMatch(folders[folders.Length - 2], pathBlacklist, RegexOptions.IgnoreCase))
                {
                    return(folders[folders.Length - 2]);
                }
            }
            extractNameFromSeasonsFolder();
            extractNameFromString(filename);
            if (folders.Length != 0)
            {
                extractNameFromString(folders[folders.Length - 1]);
            }
            fallbackFolderNames();
            name = NameCleanup.Postprocessing(name);
            if (name == null)
            {
                return("");
            }
            return(name);
        }
Exemplo n.º 6
0
        private void Update(EvaluationContext context)
        {
            var content  = Content.GetValue(context);
            var filepath = Filepath.GetValue(context);

            if (content != _lastContent)
            {
                Log.Debug("Writing file " + filepath);
                try
                {
                    File.WriteAllText(filepath, content);
                }
                catch (Exception e)
                {
                    Log.Error($"Failed to write file {filepath}:" + e.Message);
                }

                _lastContent = content;
            }
            else
            {
                Log.Debug("Just updating???");
            }

            Result.Value      = Content.GetValue(context);
            OutFilepath.Value = filepath;    // Forward so it can be triggered
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                if (File.Exists(args[0]))
                {
                    args[0] = Filepath.goUpwards(args[0], 1);
                }
                if (!Directory.Exists(args[0]))
                {
                    AttachConsole(ATTACH_PARENT_PROCESS);
                    Console.Out.WriteLine();
                    Console.Out.WriteLine("Series Renamer command line argument(s):");
                    Console.Out.WriteLine("\"Series Renamer.exe [Path]\": Opens the program in the folder [Path].");
                    Console.Out.WriteLine("\"Series Renamer.exe /help\": Displays this help message.");
                    return;
                }
            }

            Console.Out.WriteLine("");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1.Instance = new Form1(args);
            Application.Run(Form1.Instance);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            //// Load a document we can play with.
            Document doc = LoadDocument.Default();

            DocumentCheckSpelling.DocCheckSpelling(doc);

            // InlineLists.RunTests();



            InlineLists.DetectAll(doc);

            // Comments.AddToEveryPara(doc);

            Headers.DetectHeaders(doc);
            Headers.DetectLineSpacingAfterBullets(doc);

            Language.LanguageChecker(doc);

            //// Save to a new file.
            doc.SaveAs2(Filepath.Full().Replace(".docx", "_2.docx"));

            //// Keep the console open even when the program has finished.
            ConsoleC.WriteLine(ConsoleColor.Green, "\nThe program has finished.");
            Console.ReadLine();
        }
Exemplo n.º 9
0
        public static Word.Document Default()
        {
            try
            {
                object fileName = Filepath.Full();

                Word.Application wordApp = new Word.Application {
                    Visible = true
                };

                Document aDoc = wordApp.Documents.Open(ref fileName, ReadOnly: false, Visible: true);

                aDoc.Activate();
                Word.Application wordObject = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

                Application word = (Microsoft.Office.Interop.Word.Application)wordObject;
                word.Visible        = true;
                word.ScreenUpdating = false;

                return(word.ActiveDocument);
            }
            catch
            {
                throw new Exception("Error loading default document!");
            }
        }
Exemplo n.º 10
0
 public void Test_Canonicalize()
 {
     {
         var path = Filepath.Parse("./../dir/.../xxx/../file.txt");
         Assert.AreEqual("dir/.../file.txt", path.Canonicalize().ToString("/"));
     }
 }
Exemplo n.º 11
0
        static void Xmp1(string[] args)
        {
            var inputPath = (1 <= args.Length)
                                        ? args[0]
                                        : Directory.GetCurrentDirectory();

            var filepath = Filepath.Parse(inputPath);

            Console.WriteLine($"input path = {filepath}");

            Console.WriteLine("=======================================================");
            Console.WriteLine($"     prefix : {filepath.Prefix}");
            Console.WriteLine($"is absolute?: {filepath.IsAbsolute}");

            for (var i = 0; i < filepath.Items.Count; i++)
            {
                Console.WriteLine($"     item {i} : {filepath.Items[i]}");
            }

            Console.WriteLine("=======================================================");
            Console.WriteLine($"  last item : {filepath.LastItem}");
            Console.WriteLine($"    has ext?: {filepath.HasExtension}");
            Console.WriteLine($"  last item without ext: {filepath.LastItemWithoutExtension}");
            Console.WriteLine($"  extension : {filepath.Extension}");
        }
Exemplo n.º 12
0
        private string GenerateFullPath()
        {
            var checkedFilePath = Filepath.TrimEnd(new char['\\']) + "\\";
            var checkedFileName = Filename.EndsWith(".xml") ? Filename : Filename + ".xml";

            return(checkedFilePath + checkedFileName);
        }
Exemplo n.º 13
0
        public void Test_Simple_0()
        {
            var path = Filepath.Parse("/");

            Assert.IsTrue(path.Absolute);
            Assert.AreEqual("/", path.ToString("/"));
            Assert.AreEqual("\\", path.ToString("\\"));
        }
Exemplo n.º 14
0
        public void Test_Simple_WithBackSlashes()
        {
            var path = Filepath.Parse(@"a/\/b///c/\/\/");

            Assert.IsFalse(path.IsAbsolute);
            Assert.AreEqual(3, path.Items.Count);
            Assert.AreEqual("c", path.Items[2]);
        }
Exemplo n.º 15
0
 public override string ToString()
 {
     if (!Filepath.Contains("."))
     {
         Filepath += "." + DefaultFileExtension;
     }
     return($"{Type},{Layer},{Origin},\"{Filepath.Replace('\\', '/')}\",{StartPosition.X.ToString(Constants.CULTUREINFO)},{StartPosition.Y.ToString(Constants.CULTUREINFO)}");
 }
Exemplo n.º 16
0
 private static Filepath GetTempDir() =>
 Filepath.Parse(System.IO.Path.GetTempPath())
 .Combine(_AsItems("FsentryTestDir_" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "_" + NextTempDirSeq()))
 .Canonicalize()
 .Also(self => {                           // 安全そうなパスであることをできるだけチェック
     Assert.IsTrue(self.IsAbsolute);
     Assert.IsTrue(2 <= self.Items.Count);
 });
Exemplo n.º 17
0
        public void Test_Simple_2()
        {
            var path = Filepath.Parse(@"a/\/b///c/\/\/");

            Assert.IsFalse(path.Absolute);
            Assert.AreEqual(3, path.Items.Length);
            Assert.AreEqual("c", path.Items[2]);
        }
Exemplo n.º 18
0
        public bool IsHost()
        {
            //Does file name end with ".Tests.csproj"
            return(Filepath.EndsWith(".Tests.csproj") ||
                   Text.Contains("349c5851-65df-11da-9384-00065b846f21") || //IsWebApp/Site/MVC/WebRole
                   IsInHostPath(Filepath));

            // is in services.json
        }
Exemplo n.º 19
0
 public DalFilepath MapToDal(Filepath entity)
 {
     return(new DalFilepath
     {
         Id = entity.id,
         Path = entity.path,
         Lib_id = entity.lib_id
     });
 }
Exemplo n.º 20
0
        public void Test_Simple_Absolute_1()
        {
            var path = Filepath.Parse("/");

            Assert.IsTrue(path.Prefix is PathPrefix.Empty);
            Assert.IsTrue(path.Absolute);
            Assert.AreEqual(0, path.Items.Length);
            Assert.AreEqual("/", path.ToString("/"));
        }
Exemplo n.º 21
0
        private string Find_history_file_by_id(string id)
        {
            var filepaths = Directory.GetFiles(_path);
            var filepath  = filepaths.FirstOrDefault(fp => Filepath.Matches_id(fp, id));

            if (filepath == null)
            {
                throw new ApplicationException($"Invalid history id '{id}'!");
            }
            return(filepath);
        }
        // mandatory since ModuleCacheKey is used as a dictionnary key
        public override int GetHashCode()
        {
            int hashcode = Name.GetHashCode() ^ Flags.GetHashCode();

            if (Filepath != null)
            {
                hashcode ^= Filepath.GetHashCode();
            }

            return(hashcode);
        }
Exemplo n.º 23
0
        public string Map_name_to_id(string name)
        {
            var filepaths = Directory.GetFiles(_path);
            var filepath  = filepaths.FirstOrDefault(fp => Filepath.Matches_name(fp, name));

            if (filepath == null)
            {
                throw new ApplicationException($"Invalid history name '{name}'!");
            }
            return(Filepath.Extract_id(filepath));
        }
Exemplo n.º 24
0
 public override int GetHashCode()
 {
     unchecked
     {
         var result = Language.GetHashCode();
         result = (result * 397) ^ Name.GetHashCode();
         result = (result * 397) ^ Filepath.GetHashCode();
         result = (result * 397) ^ _internalConfigList.GetHashCode();
         return(result);
     }
 }
Exemplo n.º 25
0
 private async Task SetupPathAsync(Filepath absPath)
 {
     if (absPath.HasExtension)
     {
         System.IO.Directory.CreateDirectory(absPath.Parent.ToString());
         await System.IO.File.WriteAllTextAsync(absPath.ToString(), "some file.", System.Text.Encoding.UTF8);
     }
     else
     {
         System.IO.Directory.CreateDirectory(absPath.ToString());
     }
 }
Exemplo n.º 26
0
        public void Test_Simple_1()
        {
            var path = Filepath.Parse("a/b/c.tar.gz");

            Assert.IsTrue(path.Prefix is PathPrefix.Empty);
            Assert.IsFalse(path.Absolute);
            Assert.AreEqual(3, path.Items.Length);
            Assert.AreEqual("a", path.Items[0]);
            Assert.AreEqual("b", path.Items[1]);
            Assert.AreEqual("c.tar.gz", path.Items[2]);
            Assert.AreEqual("a/b/c.tar.gz", path.ToString("/"));
        }
Exemplo n.º 27
0
        public void Test_TraditionalDos_2()
        {
            Action <string> test_ = pathStr =>
            {
                var path = Filepath.Parse(pathStr);
                Assert.IsTrue(path.Absolute);
                Assert.AreEqual(1, path.Items.Length);
            };

            test_(@"C:\a");
            test_(@"C:\a\");
        }
Exemplo n.º 28
0
        public void Test_Combine_2()
        {
            var basepath = Filepath.Parse("relative/dir");
            var other    = Filepath.Parse("/abs/file.txt");

            var rv = basepath.Combine(other.Items);

            Assert.IsInstanceOfType(rv.Prefix, typeof(PathPrefix.None));
            Assert.IsFalse(basepath.IsAbsolute);
            Assert.AreEqual(4, rv.Items.Count);
            Assert.AreEqual("relative", rv.Items[0]);
            Assert.AreEqual("file.txt", rv.Items[3]);
        }
Exemplo n.º 29
0
        public void Test_Simple_Absolute_2()
        {
            Action <string> test_ = pathStr =>
            {
                var path = Filepath.Parse(pathStr);
                Assert.IsTrue(path.Prefix is PathPrefix.Empty);
                Assert.IsTrue(path.Absolute);
                Assert.AreEqual(3, path.Items.Length);
                Assert.AreEqual("/usr/local/bin", path.ToString("/"));
            };

            test_("/usr/local/bin");
            test_("/usr/local/bin/");             // ends with "/"
        }
Exemplo n.º 30
0
        public void Test_DosDevice_2_UNC()
        {
            var path = Filepath.Parse(@"\\.\UNC\foo\bar\baz");

            var prefix = path.Prefix as DosDevice;

            Assert.IsNotNull(prefix);
            Assert.IsTrue(prefix !.IsUnc);
            Assert.AreEqual("foo", prefix !.Server);
            Assert.AreEqual("bar", prefix !.Share);
            Assert.AreEqual(@"foo\bar", prefix.Volume);
            Assert.AreEqual(1, path.Items.Length);
            Assert.AreEqual("baz", path.Items[0]);
        }