Example #1
0
        public void TestMaketagFromString()
        {
            string f       = @"../../catlmodule-class.md";
            string content = File.ReadAllText(f);
            string yml     = YMLMeister.GetYmlBlock(content);

            Debug.WriteLine("-----Get All tags-----");
            var matches = YMLMeister.GetAllTags(yml);

            Debug.WriteLine("<---output ends here");
            var tags = new List <Tag>();

            foreach (string m in matches)
            {
                var t = new Tag(m);
                tags.Add(t);
                Debug.WriteLine("tag name is: " + t.TagName);
                foreach (var i in t.TagValues)
                {
                    Debug.WriteLine("   " + i);
                }
            }
            Debug.WriteLine("make tags from those same tuples:");
            foreach (var v in tags)
            {
                Debug.WriteLine(v.ToString());
            }
        }
Example #2
0
        public void TestSinglelineValue()
        {
            string f       = @"../../abstract-classes-cpp.md";
            string content = File.ReadAllText(f);
            string tag     = "ms.assetid";

            Assert.IsFalse(YMLMeister.IsMultilineValue(content, tag));
        }
Example #3
0
        public void TestTagPos()
        {
            string f       = @"../../abstract-classes-cpp.md";
            string content = File.ReadAllText(f);
            string tag     = "title";
            int    i       = YMLMeister.GetTagStartPos(content, tag);

            Assert.AreEqual(i, 5);
        }
Example #4
0
        public void TestMultilineValue()
        {
            YMLMeister YMLMeister = new YMLMeister();
            string     f          = @"../../abstract-classes-cpp.md";
            string     content    = File.ReadAllText(f);
            string     tag        = "helpviewer_keywords";

            Assert.IsTrue(YMLMeister.IsMultilineValue(content, tag));
        }
Example #5
0
        public void TestTagEndPosSingleVal()
        {
            string f        = @"../../abstract-classes2.md";
            string content  = File.ReadAllText(f);
            string tag      = "ms.author";
            int    startPos = YMLMeister.GetTagStartPos(content, tag);
            int    endPos   = YMLMeister.GetTagValueEndPos(content, startPos);
            string s        = content.Substring(0, endPos);

            Assert.AreEqual(endPos, 112);
        }
Example #6
0
        public void TestGetValue()
        {
            string f       = @"../../abstract-classes2.md";
            string content = File.ReadAllText(f);
            string tag     = "translation.priority.ht";
            string temp    = YMLMeister.GetValue(content, tag);

            Debug.WriteLine("-------TestGetValue----------");
            Debug.Write(temp);
            Debug.WriteLine("-------");
        }
Example #7
0
        public void TestTagEndPosMultiLine()
        {
            string f        = @"../../abstract-classes2.md";
            string content  = File.ReadAllText(f);
            string tag      = "translation.priority.ht";
            int    startPos = YMLMeister.GetTagStartPos(content, tag);
            //int lineEnd = content.IndexOf("\n", startPos);
            int    endPos = YMLMeister.GetTagValueEndPos(content, startPos);
            string s      = content.Substring(startPos, endPos - startPos);

            Assert.AreEqual(s.Length, 197);
        }
Example #8
0
        public void TestSuffix()
        {
            string f       = @"../../abstract-classes3.md";
            string content = File.ReadAllText(f);
            string tag     = "ms.author";

            Debug.WriteLine("-----Suffix for ms.author-----");
            string result = YMLMeister.GetSuffix(content, tag);

            Debug.Write(result);
            Debug.WriteLine("-------------");
        }
Example #9
0
        public void TestOutputforGetTagAndValue()
        {
            string f       = @"../../abstract-classes2.md";
            string content = File.ReadAllText(f);
            string tag     = "translation.priority.ht";
            string val     = YMLMeister.GetTagAndValue(content, tag);

            Debug.Write(val);

            tag = "ms.author";
            val = YMLMeister.GetTagAndValue(content, tag);
            Debug.Write(val);
        }
Example #10
0
        public void TestGetYmlBlock()
        {
            string f       = @"../../abstract-classes3.md";
            string content = File.ReadAllText(f);
            string yml     = YMLMeister.GetYmlBlock(content);

            Debug.WriteLine("-----Get YML Block-----");
            int i = yml.Length;

            Debug.Write(yml);
            Debug.WriteLine("<---output ends here");
            //    Assert.AreEqual(result.Length, 207);
        }
Example #11
0
        public void TestReplaceSingleLine()
        {
            string f       = @"../../abstract-classes3.md";
            string content = File.ReadAllText(f);
            string tag     = "ms.author";

            Debug.WriteLine("-----Delete ms.author-----");
            var result = YMLMeister.ReplaceSingleValue(content, tag, "Donald Jr");
            int i      = result.Length;

            Debug.Write(result);
            Debug.WriteLine("<---output ends here");
            //    Assert.AreEqual(result.Length, 207);
        }
Example #12
0
        public void TestCreateTag()
        {
            string f       = @"../../abstract-classes3.md";
            string content = File.ReadAllText(f);
            string tag     = "ms.ImNew";
            string newVal  = "\"new Value\"";

            Debug.WriteLine("-----Create ms.ImNew-----");
            var result = YMLMeister.CreateTag(content, tag, newVal);
            int i      = result.Length;

            Debug.Write(result);
            Debug.WriteLine("<---output ends here");
            //    Assert.AreEqual(result.Length, 207);
        }
Example #13
0
        public void TestParseYml2()
        {
            string f       = @"../../abstract-classes3.md";
            var    content = File.ReadAllText(f);
            var    result  = YMLMeister.ParseYML2(content, null);

            foreach (var v in result)
            {
                Debug.WriteLine(v.TagName);
                foreach (var v2 in v.TagValues)
                {
                    Debug.WriteLine("   " + v2);
                }
            }
        }
Example #14
0
        public void TestGetAllTagsWithCPPBracketKeywords()
        {
            string f       = @"../../catlmodule-class.md";
            string content = File.ReadAllText(f);
            string yml     = YMLMeister.GetYmlBlock(content);

            Debug.WriteLine("-----Get All tags-----");
            var tags = YMLMeister.GetAllTags(yml);

            Debug.WriteLine("<---output ends here");
            foreach (string s in tags)
            {
                Debug.WriteLine(s);
            }
            //    Assert.AreEqual(result.Length, 207);
        }
Example #15
0
        public void TestPrefixTagSuffix()
        {
            string f       = @"../../abstract-classes3.md";
            string content = File.ReadAllText(f);
            string tag     = "ms.author";

            Debug.WriteLine("-----Prefix tag suffix for ms.author-----");
            string        prefix    = YMLMeister.GetPrefix(content, tag);
            string        tagAndval = YMLMeister.GetTagAndValue(content, tag);
            string        suffix    = YMLMeister.GetSuffix(content, tag);
            StringBuilder sb        = new StringBuilder();

            sb.Append(prefix).Append(tagAndval).Append(suffix);
            Debug.Assert(sb.ToString().Length == content.Length);
            Debug.Write(prefix + tagAndval + suffix);
            Debug.WriteLine("-------------");
        }
Example #16
0
        public void TestPrefix()
        {
            string f        = @"../../abstract-classes-cpp.md";
            string content  = File.ReadAllText(f);
            string tag      = "ms.custom";
            string expected = "---\r\ntitle: \"Abstract Classes (C++) | Microsoft Docs\"\r\n";

            string result = YMLMeister.GetPrefix(content, tag);

            int x  = String.Compare(expected, result);
            int xx = expected.Length;
            int z  = result.Length;

            //Assert.AreEqual(x, 0);
            Assert.AreEqual(result.Length, expected.Length);
            System.Diagnostics.Debug.WriteLine(result + tag);
        }
        static void Main(string[] args)
        {
            // Load options
            var     opts           = new Options(args);
            var     currentFile    = "";
            var     currentContent = "";
            var     currentBody    = "";
            var     currentTagList = new Tags();
            Command command        = null;
            string  commandFile    = "";

            try
            {
                commandFile = File.ReadAllText(opts.ArgFile);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unable to read command file {0}", opts.ArgFile);
                Console.WriteLine(e.Message);
                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();
                System.Environment.Exit(1);
            }

            var commandRecords = commandFile.Split('\n');

            foreach (var commandRecord in commandRecords)
            {
                var trimmedCommand = commandRecord.Trim();
                if (!String.IsNullOrEmpty(trimmedCommand) && trimmedCommand != CommandBuilder.Header)
                {
                    try
                    {
                        command = new Command(trimmedCommand, opts.OptUnique);
                    }
                    catch (Exception e)
                    {
                        string warning = String.Format("Unable to read command {0} in command file {1}", trimmedCommand, opts.ArgFile);
                        MUT.MutLog.AppendWarning(warning);
                        MUT.MutLog.AppendError(e.Message);
                        continue;
                    }

                    if (!String.IsNullOrEmpty(currentFile) && currentFile != command.Filename)
                    {
                        WriteCurrentFile(opts, currentFile, currentBody, currentTagList);
                    }

                    if (currentFile != command.Filename)
                    {
                        currentFile = command.Filename;

                        try
                        {
                            currentContent = File.ReadAllText(currentFile);
                        }
                        catch (System.IO.FileNotFoundException e)
                        {
                            // Log it?
                            MUT.MutLog.AppendError(e.Message);
                            continue;
                        }
                        catch (System.IO.DirectoryNotFoundException e)
                        {
                            // Log it?
                            MUT.MutLog.AppendError(e.Message);
                            continue;
                        }
                        // param 2 only used in mdextract to specify just get one tag from each file.
                        // For apply we need to get all tags because any unchanged vals need to be written back into file
                        currentTagList = new Tags(YMLMeister.ParseYML2(currentContent, null));
                        currentBody    = currentContent.Substring(currentContent.IndexOf("---", 4) + 3);
                    }

                    switch (command.TagAction)
                    {
                    case Command.Action.create:
                        AddTagIfNotPresent(currentTagList, command);
                        break;

                    case Command.Action.delete:
                        DeleteTag(currentTagList, command);
                        break;

                    case Command.Action.overwrite:
                        OverwriteIfTagExists(currentTagList, command);
                        break;

                    case Command.Action.require:
                        OverwriteOrAddTag(currentTagList, command);
                        break;

                    case Command.Action.excise:
                        ExciseValues(currentTagList, command);
                        break;

                    case Command.Action.merge_if:
                        MergeValuesIfTagExists(currentTagList, command);
                        break;

                    case Command.Action.merge_add:
                        MergeValuesOrAddTag(currentTagList, command);
                        break;

                    default:
                        MUT.MutLog.AppendInfo(String.Format("Ignoring the {0} tag in {1}",
                                                            command.TagData.TagName, command.Filename));
                        break;
                    }
                }
            }

            if (command != null && !String.IsNullOrEmpty(currentFile))
            {
                // We're done, write the file out, if there's anything to write.
                WriteCurrentFile(opts, currentFile, currentBody, currentTagList);
            }

            // open commands file or report failure and exit
            // create objects for applies-to file, metadata collection
            // for each line in commands file
            //   load fields from line or report failure and continue
            //   if first line or filename field is not the current applies-to file
            //     if filename field is not the current applies-to file
            //       if there's an updated metadata collection
            //         write the metadata collection to the applies-to file or report failure
            //       close current applies-to file
            //     open new applies-to file or report failure and continue
            //     parse metadata collection from applies-to file or report failure and continue
            //   apply action to metadata collection or report failure and continue
            // if there's an open applies-to file
            //   if there's an updated metadata collection
            //     write the metadata collection to the applies-to file or report failure
            //   close current applies-to file
            // report complete and exit

            if (opts.Use_log)
            {
                MUT.MutLog.WriteFile(opts.Logfile());
            }

            Console.WriteLine("Mdapply: Complete.");
            // Console.ReadLine();
        }