public void CompositeCodeSnippetSourceTest() { var xmlBlock1 = new XmlBlock { Name = XmlBlockTestName, Syntax = XmlBlockTestSyntax, Tags = XmlBlockTestTags, Description = XmlBlockTestDescription, Prerequisites = XmlBlockTestPrerequisites, CodeSnippets = new[] { new XmlCode { Tags = XmlSubItem1TestTags, Code = XmlSubItem1TestCode } } }; var xmlBlock2 = new XmlBlock { Name = XmlBlockTestName, Syntax = XmlBlockTestSyntax, Tags = XmlBlockTestTags, Description = XmlBlockTestDescription, Prerequisites = XmlBlockTestPrerequisites, CodeSnippets = new[] { new XmlCode { Tags = XmlSubItem2TestTags, Code = XmlSubItem2TestCode } } }; var xmlCodeSnippetSource1 = new XmlCodeSnippetSource(xmlBlock1); var xmlCodeSnippetSource2 = new XmlCodeSnippetSource(xmlBlock2); var compositeCodeSnippetSource = new CompositeCodeSnippetSource( new List<CodeSnippetSourceBase> { xmlCodeSnippetSource1, xmlCodeSnippetSource2 }); var result = compositeCodeSnippetSource.Search(new SortedSet<string>(new[] {"constructor"})); Assert.AreEqual(result.Count, 1); Assert.AreEqual(result[0].Code, "datetime(2013, 5, 7, 12, 0, 0, 0)"); Assert.AreEqual(result[0].Syntax, "python"); Assert.AreEqual(result[0].SpecificTags, new SortedSet<string>(new[] { "constructor" })); Assert.AreEqual(result[0].AllTags, new SortedSet<string>(new[] { "constructor", "datetime", "python" })); Assert.AreEqual(result[0].Context.Name, "Date and Time Data Types and Tools"); Assert.AreEqual(result[0].Context.Prerequisites, "from datatime import datetime"); Assert.AreEqual(result[0].Context.Description, "http://pandas.pydata.org/"); Assert.AreEqual(result[0].Context.Syntax, "python"); Assert.AreEqual(result[0].Context.SpecificTags, new SortedSet<string>(new[] { "datetime", "python" })); Assert.AreEqual(result[0].Context.AllTags, new SortedSet<string>(new[] { "datetime", "python" })); }
private void ProcessXmlBlock(XmlBlock xmlBlock, CodeContext parentContext) { var context = new CodeContext( xmlBlock.Name.Strip(), Split(xmlBlock.Tags), xmlBlock.Authors.Strip(), xmlBlock.Source.Strip(), xmlBlock.Syntax.Strip(), xmlBlock.Description.Strip(), xmlBlock.Prerequisites.Strip(), parentContext); if (xmlBlock.CodeSnippets != null && xmlBlock.CodeSnippets.Length > 0) foreach (var xmlChildCode in xmlBlock.CodeSnippets) ProcessXmlCode(xmlChildCode, context); if (xmlBlock.Blocks != null && xmlBlock.Blocks.Length > 0) foreach (var xmlChildBlock in xmlBlock.Blocks) ProcessXmlBlock(xmlChildBlock, context); }
/// <summary> /// Creates a code snippet source from an xml block. /// </summary> /// <param name="xmlBlock">Xml representation of a block of code snippets.</param> public XmlCodeSnippetSource(XmlBlock xmlBlock) { _codeSnippets = new List<CodeSnippet>(); if (xmlBlock != null) ProcessXmlBlock(xmlBlock, null); }
public void XmlCodeSnippetSourceTest() { var xmlBlock = new XmlBlock { Name = XmlBlockTestName, Syntax = XmlBlockTestSyntax, Tags = XmlBlockTestTags, Description = XmlBlockTestDescription, Prerequisites = XmlBlockTestPrerequisites, Blocks = new[] { new XmlBlock { Name = XmlSubBlockTestName, Tags = XmlSubBlockTestTags, Prerequisites = XmlSubBlockTestPrerequisites, CodeSnippets = new[] { new XmlCode { Tags = XmlSubItem1TestTags, Code = XmlSubItem1TestCode }, new XmlCode { Tags = XmlSubItem2TestTags, Code = XmlSubItem2TestCode } } } } }; var xmlCodeSnippetSource = new XmlCodeSnippetSource(xmlBlock, XmlBlockPath); var result = xmlCodeSnippetSource.Search(new SortedSet<string>(new[] {"now"})); Assert.AreEqual(result.Count, 1); Assert.AreEqual(result[0].Code, "datetime.now()"); Assert.AreEqual(result[0].Syntax, "python"); Assert.AreEqual(result[0].SpecificTags, new SortedSet<string>(new[] {"now"})); Assert.AreEqual(result[0].AllTags, new SortedSet<string>(new[] {"datetime", "now", "pandas", "python"})); Assert.AreEqual(result[0].Context.Name, "Date and Time Data Types and Tools"); Assert.AreEqual(result[0].Context.Prerequisites, "from datatime import datetime"); Assert.AreEqual(result[0].Context.Description, string.Empty); Assert.AreEqual(result[0].Context.Syntax, "python"); Assert.AreEqual(result[0].Context.SpecificTags, new SortedSet<string>(new[] {"datetime"})); Assert.AreEqual(result[0].Context.AllTags, new SortedSet<string>(new[] {"datetime", "pandas", "python"})); }
public void XmlBlockSerializeTest() { var xmlBlock = new XmlBlock { Name = XmlBlockTestName, Syntax = XmlBlockTestSyntax, Tags = XmlBlockTestTags, Description = XmlBlockTestDescription, Prerequisites = XmlBlockTestPrerequisites, Blocks = new[] { new XmlBlock { Name = XmlSubBlockTestName, Tags = XmlSubBlockTestTags, Prerequisites = XmlSubBlockTestPrerequisites, CodeSnippets = new[] { new XmlCode { Tags = XmlSubItem1TestTags, Code = XmlSubItem1TestCode }, new XmlCode { Tags = XmlSubItem2TestTags, Code = XmlSubItem2TestCode } } } } }; var xmlBlockString = XmlHelper.SerializeToString(xmlBlock); Assert.AreEqual(xmlBlockString, XmlBlockTestString); }
public BlockItem(XmlBlock xmlBlock) { Name = xmlBlock.Name.Strip(); Description = xmlBlock.Description.Strip(); Authors = xmlBlock.Authors.Strip(); Source = xmlBlock.Source.Strip(); Syntax = xmlBlock.Syntax.Strip(); Tags = xmlBlock.Tags.Strip(); Prerequisites = xmlBlock.Prerequisites.Strip(); }
private void BuildFromXmlBlock(XmlBlock xmlBlock) { try { LockLayout = true; IsModified = false; treeView.Nodes.Clear(); var blockItem = new BlockItem(xmlBlock); var rootNode = treeView.Nodes.Add(blockItem.ToString()); rootNode.Tag = blockItem; BuildFromXmlBlock(rootNode, xmlBlock); treeView.SelectedNode = rootNode; LockLayout = false; } catch (Exception exception) { ErrorReport.Report(exception); NewDocument(); } }
private static XmlBlock GetXmlBlock(TreeNode node) { if (!(node.Tag is BlockItem)) return null; var blockItem = node.Tag as BlockItem; var xmlBlock = new XmlBlock { Name = blockItem.Name.Strip(), Authors = blockItem.Authors.Strip(), Source = blockItem.Source.Strip(), Syntax = blockItem.Syntax.Strip(), Tags = blockItem.Tags.Strip(), Description = blockItem.Description.Strip(), Prerequisites = blockItem.Prerequisites.Strip() }; var xmlCodeList = new List<XmlCode>(); var xmlBlockList = new List<XmlBlock>(); if (node.Nodes.Count > 0) { foreach (TreeNode childNode in node.Nodes) if (childNode.Tag is CodeItem) xmlCodeList.Add(GetXmlCode(childNode)); else if (childNode.Tag is BlockItem) xmlBlockList.Add(GetXmlBlock(childNode)); if (xmlCodeList.Count > 0) xmlBlock.CodeSnippets = xmlCodeList.ToArray(); if (xmlBlockList.Count > 0) xmlBlock.Blocks = xmlBlockList.ToArray(); } return xmlBlock; }
private static void BuildFromXmlBlock(TreeNode node, XmlBlock xmlBlock) { if (xmlBlock.CodeSnippets != null && xmlBlock.CodeSnippets.Length > 0) foreach (var xmlChildCode in xmlBlock.CodeSnippets) { var childCodeItem = new CodeItem(xmlChildCode); var childCodeNode = node.Nodes.Add(childCodeItem.ToString()); childCodeNode.Tag = childCodeItem; } if (xmlBlock.Blocks != null && xmlBlock.Blocks.Length > 0) foreach (var xmlChildBlock in xmlBlock.Blocks) { var childBlockItem = new BlockItem(xmlChildBlock); var childBlockNode = node.Nodes.Add(childBlockItem.ToString()); childBlockNode.Tag = childBlockItem; BuildFromXmlBlock(childBlockNode, xmlChildBlock); } }