Example #1
0
        public void FormatTextIntoParagraphs_EmbeddedParagraphsAreRecognized()
        {
            var content  = "This is <p>a single</p> line of text";
            var expected = $"<p>This is</p><p>a single</p><p> line of text</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #2
0
        public void LoadDocs_FormatWrappedTextIsIgnored(string openTag)
        {
            var content = @"This should be totally ignored.  It should
               `not be modified at all.`
               **All the lines should be preserved.**

               Even this one.";

            var comments = XElement.Parse(
                $@"<Docs>
                <summary>
                  Constructor with one generic parameter.
                </summary>

                <param name=""ownType"">This parameter type defined by class.</param>

                <remarks>
                  { openTag }
                    { content }
                  </format>
                </remarks>
              </Docs>");

            // Normalize the indent to match formatting.

            var expected = string.Join("\n", content.Split('\n').Select(line => line.Trim()));

            var parsed = new ECMALoader(null).LoadDocs(comments, "<<dummy>>");

            Assert.AreEqual(expected, parsed.Remarks);
        }
Example #3
0
        public void FormatTextIntoParagraphs_MultipleLinesAreWrapped()
        {
            var content  = $"This is a single line of text{ Environment.NewLine } This is a second line{ Environment.NewLine} This is a third";
            var expected = $"<p>{ content.Replace(Environment.NewLine, string.Empty) }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #4
0
        public void FormatTextIntoParagraphs_LeadingAndTrailingBlanksAreIgnoredForMultipleLines()
        {
            var content  = $"{ Environment.NewLine }{ Environment.NewLine }This is a single line of text{ Environment.NewLine } This is a second line{ Environment.NewLine} This is a third{ Environment.NewLine }{ Environment.NewLine }";
            var expected = $"<p>{ content.Replace(Environment.NewLine, string.Empty) }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #5
0
        public void FormatTextIntoParagraphs_PartialExistingParagraphsAreRecognized()
        {
            var content  = "<p>This is a single line of text";
            var expected = $"{ content }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #6
0
        public void LoadDocs_RemarksWithExamplesInXmlDocComment()
        {
            var comments = XElement.Parse(
                @"<Docs>
                <summary>
                  Constructor with one generic parameter.
                </summary>

                <param name=""ownType"">This parameter type defined by class.</param>

                <remarks>Retry policies instruct the Storage Client to retry failed requests.
                 By default, only some failures are retried. For example, connection failures and
                 throttling failures can be retried. Resource not found (404) or authentication
                 failures are not retried, because these are not likely to succeed on retry.
                 If not set, the Storage Client uses an exponential backoff retry policy, where the wait time gets
                 exponentially longer between requests, up to a total of around 30 seconds.
                 The default retry policy is recommended for most scenarios.

                 ## Examples
                   [!code-csharp[Retry_Policy_Sample](~/azure-storage-net/Test/ClassLibraryCommon/Blob/BlobUploadDownloadTest.cs#sample_RequestOptions_RetryPolicy ""Retry Policy Sample"")]
                </remarks>
              </Docs>");

            var expectedRemarks = "<p>Retry policies instruct the Storage Client to retry failed requests. By default, only some failures are retried. For example, "
                                  + "connection failures and throttling failures can be retried. Resource not found (404) or authentication failures are not retried, because these "
                                  + "are not likely to succeed on retry. If not set, the Storage Client uses an exponential backoff retry policy, where the wait time gets exponentially "
                                  + "longer between requests, up to a total of around 30 seconds. The default retry policy is recommended for most scenarios.</p>";

            var expectedExamples = "[!code-csharp[Retry_Policy_Sample](~/azure-storage-net/Test/ClassLibraryCommon/Blob/BlobUploadDownloadTest.cs#sample_RequestOptions_RetryPolicy \"Retry Policy Sample\")]";

            var parsed = new ECMALoader(null).LoadDocs(comments, "<<dummy>>");

            Assert.AreEqual(expectedRemarks, parsed.Remarks);
            Assert.AreEqual(expectedExamples, parsed.Examples);
        }
Example #7
0
 public void TestXmlIndent()
 {
     ECMALoader loader  = new ECMALoader(null);
     string     xmlFile = @"e:\mdoc\docs.xml";
     XElement   element = XElement.Load(xmlFile);
     var        docs    = loader.LoadDocs(element, xmlFile);
 }
Example #8
0
        public void FormatTextIntoParagraphs_PartialExistingParagraphsAreRecognizedForMultipleLines()
        {
            var content  = $"This is the first line of text.{ Environment.NewLine } This is the second.</p>";
            var expected = $"<p>{ content.Replace(Environment.NewLine, string.Empty) }";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #9
0
        public void LoadDocs_RemarksWithEmbeddedParagraphsInXmlDocComment()
        {
            var comments = XElement.Parse(
                @"<root>
                <summary>
                  Constructor with one generic parameter.
                </summary>

                <param name=""ownType"">This parameter type defined by class.</param>

                <remarks>
                  This is an example of the format that is used by some libraries, where
                  the lines of the remarks are broken up to increase readability.

                  <p>Because of the blank line that precedes it, this should be considered
                  a new paragraph.</p> Intellisense renders this correctly in VS, the
                  MS Docs rendering should follow suit.
                </remarks>
              </root>");

            var expected = "<p>This is an example of the format that is used by some libraries, where the lines of the remarks are broken up to increase readability.</p>"
                           + "<p>Because of the blank line that precedes it, this should be considered a new paragraph.</p><p> Intellisense renders this correctly in VS, the MS Docs rendering should follow suit.</p>";

            var parsed = new ECMALoader(null).LoadDocs(comments, "<<dummy>>");

            Assert.AreEqual(expected, parsed.Remarks);
        }
Example #10
0
        public void FormatTextIntoParagraphs_EmbeddedParagraphsAreRecognizedForMultipleLines()
        {
            var content  = $"This is the<p>first line</p> of text.{ Environment.NewLine } This <p>is the</p> second.";
            var expected = "<p>This is the</p><p>first line</p><p> of text. This</p><p>is the</p><p> second.</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #11
0
        public void FormatTextIntoParagraphs_MultipleParagraphsWithManualParagraphsAreWrapped()
        {
            var first    = $"<p>This is the first line.</p>";
            var second   = "A second paragraph.";
            var third    = "This is the third paragraph.";
            var content  = $"{ first }{ second }{ Environment.NewLine }{ Environment.NewLine }{ third }";
            var expected = $"{ first }<p>{ second }</p><p>{ third }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #12
0
        public void FormatTextIntoParagraphs_ExistingTagsArePreservedForMultipleParagraphs()
        {
            var first    = $"This is the <c>first</c> line.";
            var second   = "A <b><i>second</i> paragraph</b>.";
            var third    = "<code>This is the third paragraph.</code>";
            var content  = $"{ first }{ Environment.NewLine }{ Environment.NewLine }{ second }{ Environment.NewLine }{ Environment.NewLine }{ third }";
            var expected = $"<p>{ first }</p><p>{ second }</p><p>{ third }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #13
0
        public void FormatTextIntoParagraphs_EmbeddedParagraphsAreRecognizedForMultipleParagraphs()
        {
            var first    = "<p>This is the first paragraph.";
            var second   = "A <p>second paragraph.</p>";
            var third    = "This <p>is the third</p> paragraph.</p>";
            var content  = $"{ first }{ Environment.NewLine }{ Environment.NewLine }{ second }{ Environment.NewLine }{ Environment.NewLine }{ third }";
            var expected = "<p>This is the first paragraph.</p><p>A</p><p>second paragraph.</p><p>This</p><p>is the third</p><p> paragraph.</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #14
0
        public void FormatTextIntoParagraphs_MultipleLinesSpacesWithMultipleParagraphsAreNormalized()
        {
            var first    = $"This is the first line.{ Environment.NewLine }This is a second line.";
            var second   = $"A second paragraph.{ Environment.NewLine }With a second line.";
            var third    = "This is the third paragraph.";
            var content  = $"{ first }{ Environment.NewLine }{ Environment.NewLine }{ second }{ Environment.NewLine }{ Environment.NewLine }{ third }";
            var expected = $"<p>{ first.Replace(Environment.NewLine, " ") }</p><p>{ second.Replace(Environment.NewLine, " ") }</p><p>{ third }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #15
0
        public void FormatTextIntoParagraphs_LineIndentsAreNormalized(string indent)
        {
            var first    = "This is the first line.";
            var second   = "A second line.";
            var third    = "This is the third line.";
            var content  = $"{ indent }{first}{ Environment.NewLine }{ indent }{ second }{ Environment.NewLine }{ third }";
            var expected = $"<p>{ first } { second } { third }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #16
0
        public void FormatTextIntoParagraphs_ExtraBlanksAreIgnoredBetwenMultipleParagraphs()
        {
            var first    = $"This is the first line.{ Environment.NewLine } This is a second line.";
            var second   = "A second paragraph.";
            var third    = "This is the third paragraph.";
            var content  = $"{ Environment.NewLine }{ Environment.NewLine }{ first }{ Environment.NewLine }{ Environment.NewLine }{ Environment.NewLine }{ Environment.NewLine }{ second }{ Environment.NewLine }{ Environment.NewLine }{ Environment.NewLine }{ Environment.NewLine }{ third }{ Environment.NewLine }{ Environment.NewLine }";
            var expected = $"<p>{ first.Replace(Environment.NewLine, string.Empty) }</p><p>{ second }</p><p>{ third }</p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #17
0
        public static void Start(string[] args)
        {
            var opt = new CommandLineOptions();

            if (opt.Parse(args))
            {
                _xmlDataFolder = opt.XmlPath;
                _docsetFolder  = opt.DocsetPath;
                _outFolder     = opt.OutFolder;
                _moniker       = opt.Moniker;
                _logFile       = opt.LogFilePath;
            }

            if (string.IsNullOrEmpty(_xmlDataFolder))
            {
                WriteLine("xml path can't be null!");
                return;
            }
            if (!Directory.Exists(_docsetFolder))
            {
                WriteLine($"docset path '{_docsetFolder}' not exist");
                return;
            }

            if (string.IsNullOrEmpty(opt.LogFilePath))
            {
                _logFile = "log.txt";
            }

            if (!string.IsNullOrEmpty(opt.Moniker))
            {
                _monikers = opt.Moniker.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToHashSet();
            }

            (_repoRootFolder, _fallbackRepoRootFolder) = ECMALoader.GetRepoRootBySubPath(_xmlDataFolder);
            _fileAccessor = new FileAccessor(_repoRootFolder, _fallbackRepoRootFolder);

            WriteLine(string.Format("xml path:'{0}'", _xmlDataFolder));
            WriteLine(string.Format("docset path:'{0}'", _docsetFolder));
            WriteLine(string.Format("out path:'{0}'", _outFolder));
            WriteLine(string.Format("root path:'{0}'", _repoRootFolder));

            try
            {
                StartGenerate();
            }
            catch (Exception ex)
            {
                OPSLogger.LogSystemError(LogCode.ECMA2Yaml_InternalError, null, ex.ToString());
            }
            finally
            {
                OPSLogger.Flush(_logFile);
            }
        }
Example #18
0
        private static void AssertChange(string startText, string expected, Action <string, string> assert = null)
        {
            var actual = ECMALoader.DowngradeMarkdownHeaders(startText);

            if (assert == null)
            {
                Assert.AreEqual(expected, actual);
            }
            else
            {
                assert(expected, actual);
            }
        }
Example #19
0
        public void LoadDocs_RemarksWithSimpleXmlDocComment()
        {
            var remarks = "This is an example of the format that is used by some libraries.";

            var comments = XElement.Parse(
                $@"<Docs>
                <summary>Default constructor.</summary>
                <remarks>{ remarks }</remarks>
              </Docs>");

            var parsed = new ECMALoader(null).LoadDocs(comments, "<<dummy>>");

            Assert.AreEqual(remarks, parsed.Remarks);
        }
Example #20
0
        public virtual void LoadFromXElement(XElement p)
        {
            Name           = p.Attribute("Name")?.Value;
            VersionedNames = new List <VersionedString>()
            {
                new VersionedString(ECMALoader.LoadFrameworkAlternate(p), Name)
            };
            RefType = p.Attribute("RefType")?.Value;
            var indexStr = p.Attribute("Index")?.Value;

            if (!string.IsNullOrEmpty(indexStr) && int.TryParse(indexStr, out int i))
            {
                Index = i;
            }
        }
Example #21
0
        public void FormatTextIntoParagraphs_ParagraphsArePreservedWhenUsedInconsistentlyWithOtherTags()
        {
            var content = @"
            <p>
              Red/Blue/Yellow/Purple can become all color you want.
            </p>
            <ul>
              <li>
                Orange = Red + Yellow
              </li>
              <li>
                Purple = Red + Blue
              </li>
            </ul>";

            var expected = "<p>Red/Blue/Yellow/Purple can become all color you want.</p><p><ul> <li> Orange = Red + Yellow </li> <li> Purple = Red + Blue </li> </ul></p>";

            Assert.AreEqual(expected, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #22
0
        public void LoadDocs_RemarksWithSingleParagraphInXmlDocComment()
        {
            var comments = XElement.Parse(
                @"<Docs>
                <summary>
                  Default constructor.
                </summary>
                <remarks>
                  This is an example of the format that is used by some libraries, where
                  the lines of the remarks are broken up to increase readability for other
                  developers, but should be rendered as one paragraph for MS Docs.
                </remarks>
              </Docs>");

            var expected = "<p>This is an example of the format that is used by some libraries, where the lines of the remarks are broken up to increase readability for other developers, but should be rendered as one paragraph for MS Docs.</p>";

            var parsed = new ECMALoader(null).LoadDocs(comments, "<<dummy>>");

            Assert.AreEqual(expected, parsed.Remarks);
        }
Example #23
0
        public void FormatTextIntoParagraphs_ExistingTagsArePreserved()
        {
            var content = "This is a <code>single<code> line of text";

            Assert.AreEqual(content, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #24
0
        public static void StartGenerate()
        {
            ECMALoader loader    = new ECMALoader(_fileAccessor);
            string     xmlFolder = _xmlDataFolder.Replace(_repoRootFolder, "").Trim(Path.DirectorySeparatorChar);
            var        store     = loader.LoadFolder(xmlFolder);

            if (store == null)
            {
                return;
            }
            store.Build();
            if (OPSLogger.ErrorLogged)
            {
                WriteLine("ECMAStore.Build() met error, will quit.");
                return;
            }
            var           frameworks            = store.GetFrameworkIndex();
            List <string> requiredFrameworkList = new List <string>();

            frameworks.FrameworkAssemblies.Keys.ToList().ForEach(fw =>
            {
                if (_monikers == null || _monikers.Contains(fw))
                {
                    requiredFrameworkList.Add(fw);
                }
            });

            if (requiredFrameworkList.Count == 0)
            {
                string message = string.Empty;
                if (string.IsNullOrEmpty(_moniker))
                {
                    message = string.Format("Generated file failed since found 0 moniker.");
                }
                else
                {
                    message = string.Format("Generated file failed since found 0 moniker with filter moniker name '{0}'.", _moniker);
                }

                throw new Exception(message);
            }

            var typesByDocId = LoadTypes(store).ToDictionary(t => t.DocId, t => t);

            requiredFrameworkList.ForEach(fw =>
            {
                if (_monikers == null || _monikers.Contains(fw))
                {
                    string outPutFolder = Path.Combine(_outFolder, fw);

                    var fwAssemblyList         = frameworks.FrameworkAssemblies[fw].Values.ToList();
                    var fwTypeDocIdsByAssembly = store.TypesByUid.Values
                                                 .Where(t => t.Monikers.Contains(fw))
                                                 .SelectMany(t => t.VersionedAssemblyInfo.ValuesPerMoniker[fw].Select(asm => (asmName: asm.Name, t.DocId)))
                                                 .GroupBy(tuple => tuple.asmName)
                                                 .ToDictionary(g => g.Key, g => g.Select(t => t.DocId).ToHashSet());
                    var fwMemberDocIdsByAssembly = store.MembersByUid.Values
                                                   .Where(m => m.Monikers.Contains(fw))
                                                   .SelectMany(m => m.VersionedAssemblyInfo.ValuesPerMoniker[fw].Select(asm => (asmName: asm.Name, m.DocId)))
                                                   .GroupBy(tuple => tuple.asmName)
                                                   .ToDictionary(g => g.Key, g => g.Select(m => m.DocId).ToHashSet());

                    fwAssemblyList = fwAssemblyList.Where(asm => fwTypeDocIdsByAssembly.ContainsKey(asm.Name)).ToList();
                    fwAssemblyList.ForEach(assembly =>
                    {
                        var assemblyTypes        = fwTypeDocIdsByAssembly[assembly.Name].Where(p => typesByDocId.ContainsKey(p)).Select(docId => typesByDocId[docId]).ToList();
                        var assemblyMemberDocIds = fwMemberDocIdsByAssembly.ContainsKey(assembly.Name) ? fwMemberDocIdsByAssembly[assembly.Name] : new HashSet <string>();
                        // Order by xml
                        if (assemblyTypes.Count > 0)
                        {
                            XDocument intelligenceDoc = new XDocument(new XDeclaration("1.0", "utf-8", null));
                            var docEle      = new XElement("doc");
                            var assemblyEle = new XElement("assembly");
                            var membersEle  = new XElement("members");
                            docEle.Add(assemblyEle);
                            docEle.Add(membersEle);
                            intelligenceDoc.Add(docEle);
                            assemblyEle.SetElementValue("name", assembly.Name);

                            assemblyTypes.OrderBy(p => p.DocId).ToList().ForEach(tt =>
                            {
                                string id = tt.Uid ?? tt.DocId.Replace("T:", "");
                                if (store.TypesByUid.ContainsKey(id))
                                {
                                    var type = store.TypesByUid[id];
                                    membersEle.Add(SpecialProcessDuplicateParameters(tt.Docs, type, fw));
                                }
                                else
                                {
                                    membersEle.Add(tt.Docs);
                                }

                                if (tt.Members != null && tt.Members.Count() > 0)
                                {
                                    if (tt.Members != null && tt.Members.Count() > 0)
                                    {
                                        tt.Members.OrderBy(p => p.DocId).ToList().ForEach(m =>
                                        {
                                            if (assemblyMemberDocIds.Contains(m.DocId))
                                            {
                                                if (store.MembersByUid.ContainsKey(m.Uid))
                                                {
                                                    var member = store.MembersByUid[m.Uid];
                                                    membersEle.Add(SpecialProcessDuplicateParameters(m.Docs, member, fw));
                                                }
                                                else
                                                {
                                                    membersEle.Add(m.Docs);
                                                }
                                            }
                                        });
                                    }
                                }
                            });
                            if (membersEle.HasElements)
                            {
                                if (!Directory.Exists(outPutFolder))
                                {
                                    Directory.CreateDirectory(outPutFolder);
                                }

                                intelligenceDoc.Save(Path.Combine(outPutFolder, assembly.Name + ".xml"));
                                WriteLine($"Done generate {fw}.{assembly.Name} intellisense files.");
                            }
                        }
                    });
                }
            });

            WriteLine($"All intellisense files done.");
        }
Example #25
0
        public void FormatTextIntoParagraphs_ExistingParagraphsAreRecognized()
        {
            var content = "<p>This is a single< line of text</p>";

            Assert.AreEqual(content, ECMALoader.FormatTextIntoParagraphs(content));
        }
Example #26
0
 public void FormatTextIntoParagraphs_EmptyContentIsNotParsed(string content)
 {
     Assert.AreSame(content, ECMALoader.FormatTextIntoParagraphs(content));
 }
Example #27
0
        public void FormatTextIntoParagraphs_SingleLineIsNotWrapped()
        {
            var content = "This is a single line of text";

            Assert.AreEqual(content, ECMALoader.FormatTextIntoParagraphs(content));
        }