public void InsertNullTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.Name; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.Field, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert a non-null element // FieldElement field1 = new FieldElement(); field1.Name = "newField"; sortedInserter.InsertElement(regionElement, field1); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element was not inserted at the correct index."); // // Insert a null element // FieldElement field2 = null; sortedInserter.InsertElement(regionElement, field2); Assert.AreEqual(1, regionElement.Children.Count, "Element should not have been inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); }
private static void HandleRegion(RegionElement region) { if (GlobalSettings.VisitorSettings.WriteLogs) { ItitLogFile(); } var reportDir = CreateReportFolder(region); var dataCollector = new DataCollector(); List <YandexPage> yaPages; if (!GlobalSettings.VisitorSettings.DeserializeMode) { yaPages = dataCollector.CollectRequestResults(reportDir, region); Serialize(yaPages, Path.Combine(reportDir, "yaPages.xml")); } else { yaPages = DeSerialize(); } var report = new RivalListReport(yaPages); var printer = new RivalListReportPrinter(report, Path.Combine(reportDir, "RivalListReport-{0}.html")); printer.Print(GlobalSettings.VisitorSettings.RivalsOnPage); var rivalReport = new RivalReport2(yaPages, reportDir, region); rivalReport.Print(reportDir); }
private static CaptionRegion MapToCaptionRegion(RegionElement regionElement) { var endTime = regionElement.End.TotalSeconds >= TimeSpan.MaxValue.TotalSeconds ? TimeSpan.MaxValue : TimeSpan.FromSeconds(regionElement.End.TotalSeconds); var captionRegion = new CaptionRegion { Id = regionElement.Id, Begin = TimeSpan.FromSeconds(regionElement.Begin.TotalSeconds), End = endTime, Style = TimedTextStyleParser.MapStyle(regionElement, null) }; foreach (TimedTextElementBase element in regionElement.Children) { TimedTextElement child = BuildTimedTextElements(element, null); if (child != null && child.CaptionElementType == TimedTextElementType.Animation) { captionRegion.Animations.Add(child as TimedTextAnimation); } } return(captionRegion); }
private static CaptionElement MapToCaption(PElement pElement, RegionElement region) { var captionElement = BuildTimedTextElements(pElement, region); captionElement.Id = pElement.Id ?? Guid.NewGuid().ToString(); return(captionElement as CaptionElement); }
/// <summary> /// Creates a clone of this instance. /// </summary> /// <returns>Clone of the instance.</returns> protected override CodeElement DoClone() { RegionElement clone = new RegionElement(); clone._directivesEnabled = _directivesEnabled; return(clone); }
private YandexPage GetResultPage(QueryElement query, IWebDriver driver, RegionElement region) { //var driver = WebDriverProvider.GetWebDriver(); var yaPage = new YandexPage(driver, query, region); //driver.Close(); return(yaPage); }
public void InsertByTypeElementTypeDescendingTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.Type; sortBy.Direction = SortDirection.Descending; SortedInserter sortedInserter = new SortedInserter(ElementType.Type, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert an element with a mid value. // TypeElement type1 = new TypeElement(); type1.Name = "Type1"; type1.Type = TypeElementType.Structure; sortedInserter.InsertElement(regionElement, type1); // // Insert an element that should be sorted toward the end // TypeElement type2 = new TypeElement(); type2.Name = "Type2"; type2.Type = TypeElementType.Class; sortedInserter.InsertElement(regionElement, type2); // // Insert an element that should be sorted toward the middle // TypeElement type3 = new TypeElement(); type3.Name = "Type3"; type3.Type = TypeElementType.Interface; sortedInserter.InsertElement(regionElement, type3); // // Insert an element that should be sorted toward the beginning // TypeElement type4 = new TypeElement(); type4.Name = "Type4"; type4.Type = TypeElementType.Enum; sortedInserter.InsertElement(regionElement, type4); Assert.AreEqual(4, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(type4), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(type3), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(type1), "Element is not at the correct index."); Assert.AreEqual(3, regionElement.Children.IndexOf(type2), "Element is not at the correct index."); }
public static string CreateReportFolder(RegionElement region) { var path = region == null? Path.Combine("Reports", _startDateTime.ToString("yyyy-MM-dd_HH-mm-ss")) : Path.Combine("Reports", _startDateTime.ToString("yyyy-MM-dd_HH-mm-ss"), region.Region); Directory.CreateDirectory(path); return(path); }
public YandexPage(IWebDriver driver, QueryElement query, RegionElement region) { this._driver = driver; _region = region; Query = query.Query; Frequency = query.Frequency; QueryGroup = query.Group; SearchRequest(); ResultItems = GetResultItems(); }
public RivalReport2(List <YandexPage> yaPages, string reportDir, RegionElement region) { _htmlRootTemplate = File.ReadAllText("HTMLTemplates/ReportRoot.html"); _htmlRowTemplate = File.ReadAllText("HTMLTemplates/ReportRow.html"); _yaPages = yaPages; _reportDir = reportDir; _region = region; Companies = CompaniesProvider.GetCompanies(yaPages); }
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { RegionElement region = (RegionElement)e.Node.Tag; if (OnSelectRegion != null) { OnSelectRegion(region); } Close(); }
/// <summary> /// Writes a begin region directive. /// </summary> /// <param name="element">Region element.</param> protected override void WriteRegionBeginDirective(RegionElement element) { StringBuilder builder = new StringBuilder(DefaultBlockLength); builder.Append(CSharpSymbol.Preprocessor); builder.Append(CSharpKeyword.Region); builder.Append(' '); builder.Append(element.Name); WriteIndented(builder.ToString()); }
public void DefaultArrangeNoUsingMoveTest() { CodeConfiguration configuration = CodeConfiguration.Default.Clone() as CodeConfiguration; configuration.Formatting.Usings.MoveTo = CodeLevel.None; CodeArranger arranger = new CodeArranger(configuration); ReadOnlyCollection <ICodeElement> arranged = arranger.Arrange(_testElements); // // Verify using statements were grouped and sorted correctly // Assert.AreEqual(3, arranged.Count, "An unexpected number of root elements were returned from Arrange."); RegionElement regionElement = arranged[0] as RegionElement; Assert.IsNotNull(regionElement, "Expected a region element."); Assert.AreEqual("Header", regionElement.Name); GroupElement groupElement = arranged[1] as GroupElement; Assert.IsNotNull(groupElement, "Expected a group element."); Assert.AreEqual("Namespace", groupElement.Name, "Unexpected group name."); Assert.AreEqual(1, groupElement.Children.Count, "Group contains an unexpected number of child elements."); groupElement = groupElement.Children[0] as GroupElement; Assert.IsNotNull(groupElement, "Expected a group element."); Assert.AreEqual("System", groupElement.Name, "Unexpected group name."); Assert.AreEqual(7, groupElement.Children.Count, "Group contains an unexpected number of child elements."); string lastUsingName = null; foreach (CodeElement groupedElement in groupElement.Children) { UsingElement usingElement = groupedElement as UsingElement; Assert.IsNotNull(usingElement, "Expected a using element."); string usingName = usingElement.Name; if (lastUsingName != null) { Assert.AreEqual( -1, lastUsingName.CompareTo(usingName), "Expected using statements to be sorted by name."); } } // // Verify the namespace arrangement // NamespaceElement namespaceElement = arranged[2] as NamespaceElement; Assert.IsNotNull(namespaceElement, "Expected a namespace element."); }
public void InsertByTypeTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.Type; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.Method, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert an element with a mid alphabet return type. // MethodElement method1 = new MethodElement(); method1.Name = "DoSomething"; method1.Type = "Nullable<DateTime>"; sortedInserter.InsertElement(regionElement, method1); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(method1), "Element was not inserted at the correct index."); // // Insert an element that should be sorted toward the end // MethodElement method2 = new MethodElement(); method2.Name = "DoSomething"; method2.Type = "Type"; sortedInserter.InsertElement(regionElement, method2); Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(method1), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(method2), "Element is not at the correct index."); // // Insert an element that should be sorted toward the beginning // MethodElement method3 = new MethodElement(); method3.Name = "DoSomething"; method3.Type = "IEnumerable"; sortedInserter.InsertElement(regionElement, method3); Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(method3), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(method1), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(method2), "Element is not at the correct index."); }
public void InsertByElementTypeTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.ElementType; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.NotSpecified, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert an element with a middle access. // ConstructorElement constructor = new ConstructorElement(); constructor.Name = "SomeClass"; constructor.Access = CodeAccess.Public; sortedInserter.InsertElement(regionElement, constructor); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element was not inserted at the correct index."); // // Insert an element that should be sorted toward the end // MethodElement methodElement = new MethodElement(); methodElement.Name = "SomeMethod"; methodElement.Access = CodeAccess.Public; sortedInserter.InsertElement(regionElement, methodElement); Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index."); // // Insert an element that should be sorted toward the beginning // FieldElement fieldElement = new FieldElement(); fieldElement.Name = "someField"; fieldElement.Access = CodeAccess.Private; sortedInserter.InsertElement(regionElement, fieldElement); Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(fieldElement), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(constructor), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index."); }
private void RecursionAddChildren(RegionElement item, TreeNode node) { if (item.Children.Count > 0) { foreach (RegionElement child in item.Children) { TreeNode childNode = new TreeNode(child.RegionName); childNode.Tag = child; RecursionAddChildren(child, childNode); node.Nodes.Add(childNode); } } }
public void DefaultArrangeEnumerationTest() { List <ICodeElement> codeElements = new List <ICodeElement>(); UsingElement usingElement = new UsingElement(); usingElement.Name = "System"; TypeElement enumElement = new TypeElement(); enumElement.Type = TypeElementType.Enum; enumElement.Access = CodeAccess.Public; enumElement.Name = "TestEnum"; enumElement.BodyText = "Value1 = 1,\r\nValue2 = 2"; NamespaceElement namespaceElement = new NamespaceElement(); namespaceElement.Name = "TestNamespace"; namespaceElement.AddChild(usingElement); namespaceElement.AddChild(enumElement); codeElements.Add(namespaceElement); CodeArranger arranger = new CodeArranger(CodeConfiguration.Default); ReadOnlyCollection <ICodeElement> arranged = arranger.Arrange(codeElements.AsReadOnly()); Assert.AreEqual(1, arranged.Count, "After arranging, an unexpected number of elements were returned."); NamespaceElement namespaceElementTest = arranged[0] as NamespaceElement; Assert.IsNotNull(namespaceElementTest, "Expected a namespace element."); Assert.AreEqual(2, namespaceElementTest.Children.Count, "After arranging, an unexpected number of namespace elements were returned."); Assert.AreEqual(ElementType.Using, namespaceElement.Children[0].ElementType); RegionElement regionElement = namespaceElementTest.Children[1] as RegionElement; Assert.IsNotNull(regionElement, "Expected a region element."); Assert.AreEqual("Enumerations", regionElement.Name, "Unexpected region name."); Assert.AreEqual(1, regionElement.Children.Count, "After arranging, an unexpected number of region elements were returned."); TypeElement typeElement = regionElement.Children[0] as TypeElement; Assert.IsNotNull(typeElement, "Expected a type element."); Assert.AreEqual(TypeElementType.Enum, typeElement.Type, "Unexpected type element type."); Assert.AreEqual(enumElement.Name, typeElement.Name, "Unexpected type element name."); }
/// <summary> /// Writes an end region directive. /// </summary> /// <param name="element">Region element.</param> protected override void WriteRegionEndDirective(RegionElement element) { StringBuilder builder = new StringBuilder(DefaultBlockLength); builder.Append(CSharpSymbol.Preprocessor); builder.Append(CSharpKeyword.EndRegion); if (Configuration.Formatting.Regions.EndRegionNameEnabled) { builder.Append(' '); builder.Append(element.Name); } WriteIndented(builder.ToString()); }
public List <YandexPage> CollectRequestResults(string reportDir, RegionElement region) { var queryCount = _settings.Queries.Count; if (region != null) { Logger.WriteGreen(region.Region + " - " + region.Code); } Logger.WriteWhite("Начало обработки запросов. Кол-во: " + queryCount); var delay = _settings.DelayInSeconds * 1000; var yaPages = new List <YandexPage>(); IWebDriver driver = null; //TODO. Управление временем жизни браузера более красиво. if (!GlobalSettings.VisitorSettings.NewBrowserForQuery) { driver = WebDriverProvider.GetWebDriver(); } for (int i = 0; i < _settings.Queries.Count; i++) { //TODO. Управление временем жизни браузера более красиво. if (GlobalSettings.VisitorSettings.NewBrowserForQuery) { driver = WebDriverProvider.GetWebDriver(); } var queryElement = _settings.Queries[i]; Logger.WriteWhite(string.Format("({0} из {1}){2}", i + 1, queryCount, queryElement.Query)); var query = queryElement; yaPages.Add(GetResultPage(query, driver, region)); // TODO. Хотел реализовать скриншот экрана. // Не получилось - хром делает скриншот только отображаемого экрана. Фаерфокс умеет делать скриншот всей страницы. //MakeScreenshot("", driver, i, queryElement); Thread.Sleep(delay); } if (!GlobalSettings.VisitorSettings.NewBrowserForQuery) { //TODO. Управление временем жизни браузера более красиво. driver.Close(); } return(yaPages); }
public void InsertByNameTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.Name; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.Field, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert an element with a mid alphabet name. // FieldElement field1 = new FieldElement(); field1.Name = "newField"; sortedInserter.InsertElement(regionElement, field1); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element was not inserted at the correct index."); // // Insert an element that should be sorted toward the end // FieldElement field2 = new FieldElement(); field2.Name = "zooField"; sortedInserter.InsertElement(regionElement, field2); Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); // // Insert an element that should be sorted toward the beginning // FieldElement field3 = new FieldElement(); field3.Name = "booField"; sortedInserter.InsertElement(regionElement, field3); Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field3), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); }
public void InsertByAccessTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.Access; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.Field, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // Insert an element with a middle access. // FieldElement field1 = new FieldElement(); field1.Access = CodeAccess.Protected | CodeAccess.Internal; sortedInserter.InsertElement(regionElement, field1); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element was not inserted at the correct index."); // // Insert an element that should be sorted toward the end // FieldElement field2 = new FieldElement(); field2.Access = CodeAccess.Public; sortedInserter.InsertElement(regionElement, field2); Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); // // Insert an element that should be sorted toward the beginning // FieldElement field3 = new FieldElement(); field3.Access = CodeAccess.Private; sortedInserter.InsertElement(regionElement, field3); Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field3), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); }
/// <summary> /// 检查当前文件中是否存在相同的region名字,如果不存在则返回-1,否则返回该region的末尾位置 /// </summary> /// <param name="regionName"></param> /// <param name="classElement"></param> /// <returns></returns> private int CheckExistRegionName(string regionName, CodeElement classElement) { VSCodeModel codeModel = new VSCodeModel(); List <RegionElement> regions = codeModel.GetAllRegionsInClass(classElement); RegionElement re = regions.Where(o => o.RegionName == regionName).FirstOrDefault(); if (re == null) { return(-1); } else { return(re.EndLine - 1); } }
/// <summary> /// Arranges an element, delegating the responsibility to the first arranger /// encountered who can process the request. /// </summary> /// <param name="parentElement">Parent code element.</param> /// <param name="codeElement">Code element to arrange.</param> public void ArrangeElement(ICodeElement parentElement, ICodeElement codeElement) { bool arranged = false; // Region elements are ignored. Only process their children. RegionElement regionElement = codeElement as RegionElement; if (regionElement != null) { List <ICodeElement> regionChildren = new List <ICodeElement>(regionElement.Children); regionElement.ClearChildren(); foreach (ICodeElement regionChildElement in regionChildren) { ArrangeElement(parentElement, regionChildElement); } } else { foreach (IElementArranger arranger in _arrangers) { if (arranger.CanArrange(parentElement, codeElement)) { arranger.ArrangeElement(parentElement, codeElement); arranged = true; break; } } if (!arranged) { if (parentElement != null) { parentElement.AddChild(codeElement); } else { throw new InvalidOperationException( string.Format( Thread.CurrentThread.CurrentCulture, "Cannot arrange element of type {0} with name '{1}'.", codeElement.GetType().Name, codeElement.Name)); } } } }
public void InsertByNoneTest() { SortBy sortBy = new SortBy(); sortBy.By = ElementAttributeType.None; sortBy.Direction = SortDirection.Ascending; SortedInserter sortedInserter = new SortedInserter(ElementType.Field, sortBy); // // Create a parent element // RegionElement regionElement = new RegionElement(); Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children."); // // With no criteria specified, elements should just be inserted // at the end of the collection. // FieldElement field1 = new FieldElement(); field1.Name = "zooField"; sortedInserter.InsertElement(regionElement, field1); Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element was not inserted at the correct index."); FieldElement field2 = new FieldElement(); field1.Name = "newField"; sortedInserter.InsertElement(regionElement, field2); Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); FieldElement field3 = new FieldElement(); field1.Name = "booField"; sortedInserter.InsertElement(regionElement, field3); Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent."); Assert.AreEqual(0, regionElement.Children.IndexOf(field1), "Element is not at the correct index."); Assert.AreEqual(1, regionElement.Children.IndexOf(field2), "Element is not at the correct index."); Assert.AreEqual(2, regionElement.Children.IndexOf(field3), "Element is not at the correct index."); }
private void treeView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (treeView1.SelectedNode != null) { RegionElement region = (RegionElement)treeView1.SelectedNode.Tag; if (OnSelectRegion != null) { OnSelectRegion(region); } Close(); } } if (e.KeyCode == Keys.Escape) { Close(); } }
public void DefaultArrangeUsingsInRegionTest() { CodeArranger arranger = new CodeArranger(CodeConfiguration.Default); List <ICodeElement> codeElements = new List <ICodeElement>(); RegionElement regionElement = new RegionElement(); regionElement.Name = "Using Directives"; UsingElement usingElement1 = new UsingElement(); usingElement1.Name = "System"; regionElement.AddChild(usingElement1); UsingElement usingElement2 = new UsingElement(); usingElement2.Name = "System.Text"; regionElement.AddChild(usingElement2); codeElements.Add(regionElement); ReadOnlyCollection <ICodeElement> arranged = arranger.Arrange(codeElements.AsReadOnly()); // // Verify using statements were stripped from the region // Assert.AreEqual(1, arranged.Count, "An unexpected number of root elements were returned from Arrange."); GroupElement groupElement = arranged[0] as GroupElement; Assert.IsNotNull(groupElement, "Expected a group element."); Assert.AreEqual("Namespace", groupElement.Name); groupElement = groupElement.Children[0] as GroupElement; Assert.IsNotNull(groupElement, "Expected a group element."); Assert.AreEqual("System", groupElement.Name); foreach (ICodeElement arrangedElement in groupElement.Children) { Assert.IsTrue(arrangedElement is UsingElement, "Expected a using element."); } }
/// <summary> /// Arranges the child element. /// </summary> /// <param name="codeElement">The code element.</param> /// <param name="childElement">The child element.</param> private void ArrangeChildElement(ICodeElement codeElement, ICodeElement childElement) { // // Region elements are ignored. Only process their children. // RegionElement regionElement = childElement as RegionElement; if (regionElement != null) { List <ICodeElement> regionChildren = new List <ICodeElement>(regionElement.Children); regionElement.ClearChildren(); foreach (ICodeElement regionChildElement in regionChildren) { _childrenArranger.ArrangeElement(codeElement, regionChildElement); } } else { _childrenArranger.ArrangeElement(codeElement, childElement); } }
private void form_OnSelectRegion(RegionElement region) { VSTextView textView = new VSTextView(VSTextView.ActiveTextView); TextSpan ts = textView.GetSelectedSpan(); string cutStr = textView.GetText(ts.iStartLine, 0, ts.iEndLine + 1, 0); //if (!cutStr.StartsWith("\r\n")) //{ // cutStr = "\r\n" + cutStr; //} //if (!cutStr.EndsWith("\r\n")) //{ // cutStr = cutStr + "\r\n"; //} //判断要移动的文本和region的关系 if (ts.iStartLine > region.EndLine) { //要移动的文本在region下面,此时需要先删除再插入。才能让传过来的insertLine有效 textView.DeleteText(ts.iStartLine, 0, ts.iEndLine + 1, 0); textView.InsertText(cutStr, region.EndLine, 0); InsertBlankLineAroundInsert(region.EndLine, ts.iEndLine - ts.iStartLine); } else if (ts.iEndLine < region.StartLine) { //文本在region上面,先插入再删除 textView.InsertText(cutStr, region.EndLine, 0); textView.DeleteText(ts.iStartLine, 0, ts.iEndLine + 1, 0); //文本删除后,因为region要往上移动,所以这里的region实际位置发生了变化 InsertBlankLineAroundInsert(region.EndLine - (ts.iEndLine - ts.iStartLine) - 1, ts.iEndLine - ts.iStartLine); } else { MessageBox.Show("Selected text has intersection with this region, can't handle request."); } }
private static CaptionRegion MapToCaptionRegion(RegionElement regionElement) { var endTime = regionElement.End.TotalSeconds >= TimeSpan.MaxValue.TotalSeconds ? TimeSpan.MaxValue : TimeSpan.FromSeconds(regionElement.End.TotalSeconds); var captionRegion = new CaptionRegion { Id = regionElement.Id, Begin = TimeSpan.FromSeconds(regionElement.Begin.TotalSeconds), End = endTime, Style = TimedTextStyleParser.MapStyle(regionElement, null), TunneledData = regionElement.Root.Images.ToDictionary(ie => ie.Key, ie => new TunneledData() { Data = ie.Value.Data, Encoding = ie.Value.Encoding, MimeType = ie.Value.ImageType }) }; foreach (TimedTextElementBase element in regionElement.Children) { TimedTextElement child = BuildTimedTextElements(element, null); if (child != null && child.CaptionElementType == TimedTextElementType.Animation) { #if HACK_XAMLTYPEINFO var children = captionRegion.Animations as MediaMarkerCollection <TimedTextAnimation>; #else var children = captionRegion.Animations; #endif children.Add(child as TimedTextAnimation); } } return(captionRegion); }
/// <summary> /// Writes an ending region directive. /// </summary> /// <param name="element">The region element.</param> protected abstract void WriteRegionEndDirective(RegionElement element);
/// <summary> /// Creates a clone of this instance. /// </summary> /// <returns>Clone of the instance.</returns> protected override CodeElement DoClone() { RegionElement clone = new RegionElement(); clone._directivesEnabled = _directivesEnabled; return clone; }