protected override void VisitValue( XElement element, XAttribute attribute, MSBuildElementSyntax resolvedElement, MSBuildAttributeSyntax resolvedAttribute, ValueInfo info, string value, int offset) { if (!IsTargetsFile && !IsPropsFile) { if (info.DefaultValue != null && string.Equals(info.DefaultValue, value, StringComparison.OrdinalIgnoreCase)) { Document.Diagnostics.Add( CoreDiagnostics.HasDefaultValue, attribute?.Span ?? element.OuterSpan, ImmutableDictionary <string, object> .Empty.Add("Info", info), DescriptionFormatter.GetKindNoun(info), info.Name, info.DefaultValue); } } //NOTE: doing this here means we can't check for deprecated constructs that don't have values, but there aren't any yet CheckDeprecated(info, (INamedXObject)attribute ?? element); // we skip calling base, and instead parse the expression with more options enabled // so that we can warn if the user is doing something likely invalid var kind = MSBuildCompletionExtensions.InferValueKindIfUnknown(info); var options = kind.GetExpressionOptions() | ExpressionOptions.ItemsMetadataAndLists; var node = ExpressionParser.Parse(value, options, offset); VisitValueExpression(element, attribute, resolvedElement, resolvedAttribute, info, kind, node); }
public void ClearTextAndSymbols() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual, expected; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionFormatter.ClearTextAndSymbols(description); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); expected = @" | | | | | | ( 1) | | | | | | | | | ( 11) | | | | | | | | | ( 22) | : | ( 4) | | | | | | | | | ( 15) | : | ( 5) | | | | | | | | | ( 18) | | | | | | | | | ( 6) | : | "; Assert.AreEqual(expected, actual); }
// Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version. internal void CheckRenderMapStandardChange(string filename, Id <Course> id, DescriptionKind kind, string newDescStandard) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(filename); symbolDB.Standard = eventDB.GetEvent().descriptionStandard; eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_default", kind)); undomgr.BeginCommand(71231, "change standard"); symbolDB.Standard = newDescStandard; ChangeEvent.UpdateDescriptionToMatchStandard(eventDB, symbolDB); undomgr.EndCommand(71231); description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, 1); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_std_" + newDescStandard, kind)); }
// Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version. internal void CheckRenderBitmap(string filename, Id <Course> id, DescriptionKind kind, int numColumns = 1) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(filename); eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); Bitmap bmNew = DescriptionBrowser.RenderToBitmap(symbolDB, description, kind, numColumns); if (numColumns > 1) { TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_" + numColumns + "col", kind)); } else { TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind)); } }
public static (MSBuildDiagnosticDescriptor, object[]) GetExpressionError(ExpressionError error, ValueInfo info) { (MSBuildDiagnosticDescriptor, object[]) Return(MSBuildDiagnosticDescriptor desc, params object[] args) => (desc, args); return(error.Kind switch { ExpressionErrorKind.MetadataDisallowed => Return(MetadataDisallowed, DescriptionFormatter.GetKindNoun(info), info.Name), ExpressionErrorKind.EmptyListEntry => Return(EmptyListValue), ExpressionErrorKind.ExpectingItemName => Return(ExpectingItemName), ExpressionErrorKind.ExpectingRightParen => Return(ExpectingChars1, ')'), ExpressionErrorKind.ExpectingRightParenOrPeriod => Return(ExpectingChars2, ')', '.'), ExpressionErrorKind.ExpectingPropertyName => Return(ExpectingPropertyName), ExpressionErrorKind.ExpectingMetadataName => Return(ExpectingMetadataName), ExpressionErrorKind.ExpectingMetadataOrItemName => Return(ExpectingMetadataOrItemName), ExpressionErrorKind.ExpectingRightAngleBracket => Return(ExpectingChars1, '>'), ExpressionErrorKind.ExpectingRightParenOrDash => Return(ExpectingChars2, ')', '-'), ExpressionErrorKind.ItemsDisallowed => Return(ItemsDisallowed, DescriptionFormatter.GetKindNoun(info), info.Name), ExpressionErrorKind.ExpectingMethodOrTransform => Return(ExpectingFunctionOrTransform), ExpressionErrorKind.ExpectingMethodName => Return(ExpectingFunctionName), ExpressionErrorKind.ExpectingLeftParen => Return(ExpectingChars1, '('), ExpressionErrorKind.ExpectingRightParenOrComma => Return(ExpectingChars2, ')', ','), ExpressionErrorKind.ExpectingRightParenOrValue => Return(ExpectingRightParenOrValue), ExpressionErrorKind.ExpectingValue => Return(ExpectingValue), ExpressionErrorKind.CouldNotParseNumber => Return(CouldNotParseNumber), ExpressionErrorKind.IncompleteValue => Return(IncompleteValue), ExpressionErrorKind.ExpectingBracketColonColon => Return(ExpectingChars1, "]::"), ExpressionErrorKind.ExpectingClassName => Return(ExpectingClassName), ExpressionErrorKind.ExpectingClassNameComponent => Return(IncompleteClassName), ExpressionErrorKind.IncompleteString => Return(IncompleteString), ExpressionErrorKind.IncompleteProperty => Return(IncompleteProperty), _ => throw new System.Exception($"Unhandled ExpressionErrorKind '{error.Kind}'") });
protected override void VisitValue( XElement element, XAttribute attribute, MSBuildElementSyntax resolvedElement, MSBuildAttributeSyntax resolvedAttribute, ITypedSymbol valueDescriptor, string value, int offset) { if (!IsTargetsFile && !IsPropsFile && valueDescriptor is IHasDefaultValue hasDefault) { if (hasDefault.DefaultValue != null && string.Equals(hasDefault.DefaultValue, value, StringComparison.OrdinalIgnoreCase)) { Document.Diagnostics.Add( CoreDiagnostics.HasDefaultValue, attribute?.Span ?? element.OuterSpan, ImmutableDictionary <string, object> .Empty.Add("Info", valueDescriptor), DescriptionFormatter.GetKindNoun(valueDescriptor), valueDescriptor.Name, hasDefault.DefaultValue); } } if (valueDescriptor is IDeprecatable deprecatable) { CheckDeprecated(deprecatable, (INamedXObject)attribute ?? element); } // we skip calling base, and instead parse the expression with more options enabled // so that we can warn if the user is doing something likely invalid var kind = MSBuildCompletionExtensions.InferValueKindIfUnknown(valueDescriptor); var options = kind.GetExpressionOptions() | ExpressionOptions.ItemsMetadataAndLists; var node = ExpressionParser.Parse(value, options, offset); VisitValueExpression(element, attribute, resolvedElement, resolvedAttribute, valueDescriptor, kind, node); }
public static async Task <object> GetInfoTooltipElement(MSBuildRootDocument doc, BaseInfo info, MSBuildResolveResult rr, CancellationToken token) { object nameElement = GetNameElement(info); if (nameElement == null) { return(null); } var imageElement = GetImageElement(info); if (imageElement != null) { nameElement = new ContainerElement( ContainerElementStyle.Wrapped | ContainerElementStyle.VerticalPadding, imageElement, nameElement ); } var elements = new List <object> { nameElement }; switch (info.Description.DisplayElement) { case ISymbol symbol: await AddSymbolDescriptionElements(symbol, elements.Add, token); break; case object obj: elements.Add(obj); break; default: var descStr = DescriptionFormatter.GetDescription(info, doc, rr); if (!string.IsNullOrEmpty(descStr)) { elements.Add( new ClassifiedTextElement( new ClassifiedTextRun(PredefinedClassificationTypeNames.NaturalLanguage, descStr) ) ); } break; } var seenIn = GetSeenInElement(info, doc); if (seenIn != null) { elements.Add(seenIn); } return(elements.Count == 1 ? elements[0] : new ContainerElement(ContainerElementStyle.Stacked | ContainerElementStyle.VerticalPadding, elements)); }
public void HitTestRegular() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalBox, 5, 5, 4, new RectangleF(165, 205, 40, 40)); CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalBox, 9, 9, 7, new RectangleF(285, 365, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.Directive, 4, 4, 0, new RectangleF(5, 165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(328, 147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalText, 9, 9, -1, new RectangleF(85, 365, 240, 40)); CheckHitTest(descriptionRenderer, new Point(59, 302), HitTestKind.NormalBox, 7, 7, 1, new RectangleF(45, 285, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.DirectiveText, 4, 4, -1, new RectangleF(5, 165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(328, 147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalBox, 5, 5, 4, new RectangleF(165, 205, 40, 40)); CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalBox, 9, 9, 7, new RectangleF(285, 365, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.Directive, 4, 4, 0, new RectangleF(5, 165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(431, 56), HitTestKind.None, 1, 1, -1, new RectangleF(325, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(333, 131), HitTestKind.NormalText, 3, 3, -1, new RectangleF(325, 125, 200, 40)); CheckHitTest(descriptionRenderer, new Point(491, 252), HitTestKind.DirectiveText, 6, 6, -1, new RectangleF(325, 245, 200, 40)); CheckHitTest(descriptionRenderer, new Point(527, 433), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 520, 40)); }
public void HitTestAllControls() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(68, 999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(311, 12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(16, 82), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(178, 76), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(182, 234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(60, 942), HitTestKind.DirectiveText, 23, 23, -1, new RectangleF(5, 925, 320, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(380, 76), HitTestKind.None, 1, 1, -1, new RectangleF(325, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(68, 999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40)); CheckHitTest(descriptionRenderer, new Point(398, 554), HitTestKind.NormalText, 13, 13, -1, new RectangleF(325, 525, 200, 40)); CheckHitTest(descriptionRenderer, new Point(401, 934), HitTestKind.DirectiveText, 23, 23, -1, new RectangleF(325, 925, 200, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262, 745), HitTestKind.OtherTextLine, 18, 18, 0, new RectangleF(5, 725, 520, 40)); }
public void HitTestScore() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(5))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40)); CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(228, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(311, 12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40)); CheckHitTest(descriptionRenderer, new Point(16, 112), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(178, 116), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(182, 234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(228, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 520, 40)); CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(380, 116), HitTestKind.None, 2, 2, -1, new RectangleF(325, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(398, 594), HitTestKind.NormalText, 14, 14, -1, new RectangleF(325, 565, 200, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(451, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 520, 40)); }
public static string GetMessage(this ExpressionErrorKind errorKind, ValueInfo info, out bool isWarning) { isWarning = false; switch (errorKind) { case ExpressionErrorKind.MetadataDisallowed: return($"{Name()} does not allow metadata"); case ExpressionErrorKind.EmptyListEntry: isWarning = true; return($"Empty list value"); case ExpressionErrorKind.ExpectingItemName: return($"Expecting item name"); case ExpressionErrorKind.ExpectingRightParen: return($"Expecting ')'"); case ExpressionErrorKind.ExpectingRightParenOrPeriod: return($"Expecting ')' or '.'"); case ExpressionErrorKind.ExpectingPropertyName: return($"Expecting property name"); case ExpressionErrorKind.ExpectingMetadataName: return($"Expecting metadata name"); case ExpressionErrorKind.ExpectingMetadataOrItemName: return($"Expecting metadata or item name"); case ExpressionErrorKind.ExpectingRightAngleBracket: return($"Expecting '>'"); case ExpressionErrorKind.ExpectingApos: return($"Expecting single quote"); case ExpressionErrorKind.ExpectingRightParenOrDash: return($"Expecting '-' or ')'"); case ExpressionErrorKind.ItemsDisallowed: return($"{Name()} does not allow metadata"); default: return($"Invalid expression: {errorKind}"); } string Name() => DescriptionFormatter.GetTitleCaseKindName(info); }
public void HitTestMultiLine() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent6.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, CourseId(1))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); }
public static TooltipInformation CreateTooltipInformation(MSBuildRootDocument doc, BaseInfo info, MSBuildResolveResult rr) { var formatter = new DescriptionMarkupFormatter(doc); var nameMarkup = formatter.GetNameMarkup(info); if (nameMarkup.IsEmpty) { return(null); } var desc = DescriptionFormatter.GetDescription(info, doc, rr); return(new TooltipInformation { SignatureMarkup = nameMarkup.AsMarkup(), SummaryMarkup = desc.AsMarkup(), FooterMarkup = formatter.GetSeenInMarkup(info).AsMarkup() }); }
// Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version. internal void CheckRenderBitmapPixelAtATime(Id <Course> id, DescriptionKind kind) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(false); Bitmap bmNew = RenderToBitmapPixelAtATime(symbolDB, description, kind); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind)); }
private DescriptionLine[] GetDescription() { CourseItem courseItem = (CourseItem)(listBoxCourses.SelectedItem); Id <Course> id; if (courseItem == null) { id = Id <Course> .None; } else { id = courseItem.id; } courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForUI); return(descFormatter.CreateDescription(false)); }
public string GetNameMarkup(BaseInfo info) { var color = GetColor(keywordColorId); var label = DescriptionFormatter.GetTitle(info); if (label.kind == null) { return(null); } string modifiers = null; if (info is ValueInfo vi) { var tdesc = vi.GetTypeDescription(); if (tdesc.Count > 0) { modifiers = $" : {string.Join (", ", tdesc)}"; } } return($"{label.kind} <span foreground=\"{color}\">{Escape (label.name)}</span>{modifiers}"); }
public override Task RegisterCodeFixesAsync(MSBuildFixContext context) { foreach (var diag in context.Diagnostics) { if (!(diag.Properties.TryGetValue("Info", out var val) && val is VariableInfo info)) { continue; } switch (context.XDocument.FindAtOffset(diag.Span.Start)) { case XElement el: context.RegisterCodeFix(new RemoveRedundantElementAction(el, DescriptionFormatter.GetKindNoun(info)), diag); break; case XAttribute att: context.RegisterCodeFix(new RemoveRedundantAttributeAction(att, DescriptionFormatter.GetKindNoun(info)), diag); break; } } return(Task.CompletedTask); }
// Test the course description formatter with a given file and course private void TestCourseFormatter(string testFileName, CourseDesignator courseDesignator, bool createKey, string expected) { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual; eventDB.Load(TestUtil.GetTestFile(testFileName)); eventDB.Validate(); CourseView courseView; courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); DescriptionLine[] description = descFormatter.CreateDescription(createKey); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); Assert.AreEqual(expected, actual); }
public void DisplayAllCourses() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); CourseView courseView; DescriptionFormatter descFormatter; DescriptionLine[] description; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe")); eventDB.Validate(); foreach (Id <Course> courseId in QueryEvent.SortedCourseIds(eventDB)) { CourseDesignator designator; if (QueryEvent.HasVariations(eventDB, courseId)) { var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First(); designator = new CourseDesignator(courseId, variationInfo); } else { designator = new CourseDesignator(courseId); } courseView = CourseView.CreateViewingCourseView(eventDB, designator); descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); description = descFormatter.CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out); Console.WriteLine(); } courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls); descFormatter = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting); description = descFormatter.CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out); }
void CheckDeprecated(ValueInfo info, INamedXObject namedObj) { if (info.IsDeprecated) { if (string.IsNullOrEmpty(info.DeprecationMessage)) { Document.Diagnostics.Add( CoreDiagnostics.Deprecated, namedObj.NameSpan, DescriptionFormatter.GetKindNoun(info), info.Name); } else { Document.Diagnostics.Add( CoreDiagnostics.DeprecatedWithMessage, namedObj.NameSpan, DescriptionFormatter.GetKindNoun(info), info.Name, info.DeprecationMessage ); } } }
public void ScoreCourseFormatterNoScore() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual, expected; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent5.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, Designator(5)); DescriptionLine[] description = new DescriptionFormatter(courseView, symbolDB, DescriptionFormatter.Purpose.ForPrinting).CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); expected = @" | Sample Event 1 | [Sample Event 1] | Score more! | [Score more!] |Score 4 |155 points | [155 points] ( 1) |start| | | 2.8| 8.5| | | | [Start: open bare rock] ( 17) | 1| 302| | 1.14| | |11.1S| | [S side of pit] ( 2) | 2| 31| 0.3| 2.4| | 2m| | | [Upper boulder, 2m high] ( 7) | 3| 189| | 1.8| 1.8| 10.2| | | [Small gully junction] ( 11) | 4| 191| | 5.2| 5.2| 10.1|11.15| | [Between path crossings] ( 8) | 5| 210| | 5.11| 5.20| |11.15| | [Between building and statue] ( 20) | 6| 305| | 2.7| | 6x7| | 12.4| [Stony ground, 6m by 7m (manned)] ( 5) | 7| GO| 0.1N| 5.5| 5.2| 10.1|11.1N| 12.3| [N side of N power line and path crossing (radio)] ( 4) | 8| 32| | 3.7| | | | 12.1| [very marshy spot] ( 16) | 9| 301| | 1.14| 8.4| 3.0| | | [Overgrown pit, 3m deep] ( 18) | 10| 303| | 1.3| | 4| | | [Reentrant, 4m deep] ( 19) | 11| 304| 0.1S| | 8.5| | | | [S ] "; Assert.AreEqual(expected, actual); }
public static string GetMessage(this ExpressionErrorKind errorKind, ValueInfo info, out bool isWarning) { isWarning = false; switch (errorKind) { case ExpressionErrorKind.MetadataDisallowed: return($"{Name ()} does not allow metadata"); case ExpressionErrorKind.EmptyListEntry: isWarning = true; return($"Empty list value"); case ExpressionErrorKind.ExpectingItemName: return($"Expecting item name"); case ExpressionErrorKind.ExpectingRightParen: return($"Expecting ')'"); case ExpressionErrorKind.ExpectingRightParenOrPeriod: return($"Expecting ')' or '.'"); case ExpressionErrorKind.ExpectingPropertyName: return($"Expecting property name"); case ExpressionErrorKind.ExpectingMetadataName: return($"Expecting metadata name"); case ExpressionErrorKind.ExpectingMetadataOrItemName: return($"Expecting metadata or item name"); case ExpressionErrorKind.ExpectingRightAngleBracket: return($"Expecting '>'"); case ExpressionErrorKind.ExpectingRightParenOrDash: return($"Expecting '-' or ')'"); case ExpressionErrorKind.ItemsDisallowed: return($"{Name ()} does not allow metadata"); case ExpressionErrorKind.ExpectingMethodOrTransform: return($"Expecting item function or transform"); case ExpressionErrorKind.ExpectingMethodName: return("Expecting method name"); case ExpressionErrorKind.ExpectingLeftParen: return("Expecting '('"); case ExpressionErrorKind.ExpectingRightParenOrComma: return("Expecting ')' or ','"); case ExpressionErrorKind.ExpectingRightParenOrValue: return("Expecting ',' or value"); case ExpressionErrorKind.ExpectingValue: return("Expecting value"); case ExpressionErrorKind.CouldNotParseNumber: return("Invalid numeric value"); case ExpressionErrorKind.IncompleteValue: return("Incomplete value"); case ExpressionErrorKind.ExpectingBracketColonColon: return("Expecting ']::'"); case ExpressionErrorKind.ExpectingClassName: return("Expecting class name"); case ExpressionErrorKind.ExpectingClassNameComponent: return("Incomplete class name"); case ExpressionErrorKind.IncompleteString: return("Incomplete string"); case ExpressionErrorKind.IncompleteProperty: return("Incomplete property"); default: return($"Invalid expression: {errorKind}"); } string Name() => DescriptionFormatter.GetTitleCaseKindName(info); }
//note: the value is unescaped, so offsets within it are not valid void VisitPureLiteral(ValueInfo info, MSBuildValueKind kind, string value, int offset) { IReadOnlyList <ConstantInfo> knownVals = info.Values ?? kind.GetSimpleValues(false); if (knownVals != null && knownVals.Count != 0) { foreach (var kv in knownVals) { if (string.Equals(kv.Name, value, StringComparison.OrdinalIgnoreCase)) { return; } } AddErrorWithArgs(CoreDiagnostics.UnknownValue, DescriptionFormatter.GetKindNoun(info), info.Name, value); return; } switch (kind) { case MSBuildValueKind.Guid: case MSBuildValueKind.ProjectKindGuid: if (!Guid.TryParseExact(value, "B", out _)) { AddErrorWithArgs(CoreDiagnostics.InvalidGuid, value); } break; case MSBuildValueKind.Int: if (!long.TryParse(value, out _)) { AddErrorWithArgs(CoreDiagnostics.InvalidInteger, value); } break; case MSBuildValueKind.Bool: if (!bool.TryParse(value, out _)) { AddErrorWithArgs(CoreDiagnostics.InvalidBool, value); } break; case MSBuildValueKind.Url: if (!Uri.TryCreate(value, UriKind.Absolute, out _)) { AddErrorWithArgs(CoreDiagnostics.InvalidUrl, value); } break; case MSBuildValueKind.Version: if (!Version.TryParse(value, out _)) { AddErrorWithArgs(CoreDiagnostics.InvalidVersion, value); } break; /* * FIXME: these won't work as-is, as inference will add them to the schema * case MSBuildValueKind.TargetName: * if (Document.GetSchemas ().GetTarget (value) == null) { * AddErrorWithArgs (CoreDiagnostics.UndefinedTarget, value); * } * break; * case MSBuildValueKind.PropertyName: * if (Document.GetSchemas ().GetProperty (value) == null) { * AddErrorWithArgs (CoreDiagnostics.UnknownProperty, value); * } * break; * case MSBuildValueKind.ItemName: * if (Document.GetSchemas ().GetItem (value) == null) { * AddErrorWithArgs (CoreDiagnostics.UnknownProperty, value); * } * break; */ case MSBuildValueKind.Lcid: if (int.TryParse(value, out int lcid) && lcid > 0) { try { CultureInfo.GetCultureInfo(lcid); } catch (CultureNotFoundException) { AddErrorWithArgs(CoreDiagnostics.UnknownLcid, value); } } else { AddErrorWithArgs(CoreDiagnostics.InvalidLcid, value); } break; case MSBuildValueKind.TargetFramework: if (!FrameworkInfoProvider.Instance.IsFrameworkShortNameValid(value)) { AddErrorWithArgs(CoreDiagnostics.UnknownTargetFramework, value); } break; case MSBuildValueKind.TargetFrameworkIdentifier: if (!FrameworkInfoProvider.Instance.IsFrameworkIdentifierValid(value)) { AddErrorWithArgs(CoreDiagnostics.UnknownTargetFrameworkIdentifier, value); } break; case MSBuildValueKind.TargetFrameworkVersion: { if (!Version.TryParse(value.TrimStart('v', 'V'), out Version fxv)) { AddErrorWithArgs(CoreDiagnostics.InvalidVersion, value); break; } fxv = new Version(Math.Max(fxv.Major, 0), Math.Max(fxv.Minor, 0), Math.Max(fxv.Revision, 0), Math.Max(fxv.Build, 0)); if (Document is MSBuildRootDocument d && d.Frameworks.Count > 0) { bool foundMatch = false; foreach (var fx in d.Frameworks) { if (FrameworkInfoProvider.AreVersionsEquivalent(fx.Version, fxv) && FrameworkInfoProvider.Instance.IsFrameworkVersionValid(fx.Framework, fxv)) { foundMatch = true; } } if (!foundMatch) { AddErrorWithArgs(CoreDiagnostics.UnknownTargetFrameworkVersion, value, d.Frameworks[0].Framework); } } break; } case MSBuildValueKind.TargetFrameworkProfile: { if (Document is MSBuildRootDocument d && d.Frameworks.Count > 0) { bool foundMatch = false; foreach (var fx in d.Frameworks) { if (fx.Profile == value && FrameworkInfoProvider.Instance.IsFrameworkProfileValid(fx.Framework, fx.Version, value)) { foundMatch = true; } } if (!foundMatch) { AddErrorWithArgs(CoreDiagnostics.UnknownTargetFrameworkProfile, value, d.Frameworks[0].Framework, d.Frameworks[0].Version); } } break; } } void AddError(MSBuildDiagnosticDescriptor d) => Document.Diagnostics.Add(d, new TextSpan(offset, value.Length)); void AddErrorWithArgs(MSBuildDiagnosticDescriptor d, params object[] args) => Document.Diagnostics.Add(d, new TextSpan(offset, value.Length), args); }
protected override void VisitValueExpression( XElement element, XAttribute attribute, MSBuildElementSyntax resolvedElement, MSBuildAttributeSyntax resolvedAttribute, ValueInfo info, MSBuildValueKind kind, ExpressionNode node) { bool allowExpressions = kind.AllowExpressions(); bool allowLists = kind.AllowListsOrCommaLists(); if (node is ListExpression list) { if (!allowLists) { Document.Diagnostics.Add( CoreDiagnostics.UnexpectedList, new TextSpan(list.Nodes[0].End, list.End - list.Nodes[0].End), ImmutableDictionary <string, object> .Empty.Add("Name", info.Name), DescriptionFormatter.GetKindNoun(info), info.Name); } if (!allowExpressions) { var expr = list.Nodes.FirstOrDefault(n => !(n is ExpressionText)); if (expr != null) { AddExpressionWarning(expr); } } } else if (node is ExpressionText lit) { VisitPureLiteral(info, kind, lit.GetUnescapedValue(), lit.Offset); } else { if (!allowExpressions) { AddExpressionWarning(node); } } foreach (var n in node.WithAllDescendants()) { switch (n) { case ExpressionError err: var(desc, args) = CoreDiagnostics.GetExpressionError(err, info); Document.Diagnostics.Add(desc, new TextSpan(err.Offset, Math.Max(1, err.Length)), args); break; case ExpressionMetadata meta: case ExpressionProperty prop: case ExpressionItem item: //TODO: can we validate property/metadata/items refs? //maybe warn if they're not used anywhere outside of this expression? //TODO: deprecation squiggles in expressions break; } } void AddExpressionWarning(ExpressionNode n) => Document.Diagnostics.Add(CoreDiagnostics.UnexpectedExpression, new TextSpan(n.Offset, n.Length), DescriptionFormatter.GetKindNoun(info), info.Name); }
// Test the course description formatter with a given file and course private void TestCourseFormatter(string testFileName, CourseDesignator courseDesignator, bool createKey, string expected) { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual; eventDB.Load(TestUtil.GetTestFile(testFileName)); eventDB.Validate(); CourseView courseView; courseView = CourseView.CreateViewingCourseView(eventDB, courseDesignator); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(createKey); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); Assert.AreEqual(expected, actual); }
public void HitTestScore() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(5))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(178,51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40)); CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(228,534), HitTestKind.OtherTextLine, 13, 13,0, new RectangleF(5, 525, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(311, 12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 320, 40)); CheckHitTest(descriptionRenderer, new Point(16, 112), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(178, 116), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(182, 234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(228, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(178, 51), HitTestKind.SecondaryTitle, 1, 1, 0, new RectangleF(5, 45, 520, 40)); CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(116, 93), HitTestKind.Header, 2, 2, 0, new RectangleF(5, 85, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 118), HitTestKind.Header, 2, 2, 1, new RectangleF(125, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(380, 116), HitTestKind.None, 2, 2, -1, new RectangleF(325, 85, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 137), HitTestKind.NormalBox, 3, 3, 0, new RectangleF(5, 125, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(398, 594), HitTestKind.NormalText, 14, 14, -1, new RectangleF(325, 565, 200, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(451, 534), HitTestKind.OtherTextLine, 13, 13, 0, new RectangleF(5, 525, 520, 40)); }
public void HitTestMultiLine() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent6.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, CourseId(1))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 320, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 320, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80)); CheckHitTest(descriptionRenderer, new Point(13, 51), HitTestKind.Title, 0, 1, 0, new RectangleF(5, 5, 520, 80)); CheckHitTest(descriptionRenderer, new Point(178, 101), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(178, 141), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(178, 181), HitTestKind.SecondaryTitle, 2, 4, 0, new RectangleF(5, 85, 520, 120)); CheckHitTest(descriptionRenderer, new Point(116, 213), HitTestKind.Header, 5, 5, 0, new RectangleF(5, 205, 120, 40)); }
public void DescriptionEquals() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("coursesymbols\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); CourseObj courseobj1 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); description = descFormatter.CreateDescription(false); CourseObj courseobj2 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj3 = (CourseObj) courseobj1.Clone(); CourseObj courseobj4 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 3), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj5 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 1.0F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj6 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Text, 1); undomgr.BeginCommand(12, "move control"); ChangeEvent.ChangeControlLocation(eventDB, ControlId(11), new PointF(4, 8)); undomgr.EndCommand(12); description = descFormatter.CreateDescription(false); CourseObj courseobj7 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); undomgr.BeginCommand(13, "change description"); ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.4"); undomgr.EndCommand(13); description = descFormatter.CreateDescription(false); CourseObj courseobj8 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); undomgr.BeginCommand(13, "change description"); // change description back ChangeEvent.ChangeDescriptionSymbol(eventDB, ControlId(11), 1, "5.2"); undomgr.EndCommand(13); description = descFormatter.CreateDescription(false); CourseObj courseobj9 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 1); CourseObj courseobj10 = new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F, symbolDB, description, DescriptionKind.Symbols, 2); Assert.AreEqual(courseobj1, courseobj2); Assert.AreEqual(courseobj1, courseobj3); Assert.AreNotEqual(courseobj1, courseobj4); Assert.AreNotEqual(courseobj1, courseobj5); Assert.AreNotEqual(courseobj1, courseobj6); Assert.AreEqual(courseobj1, courseobj7); Assert.AreNotEqual(courseobj1, courseobj8); Assert.AreEqual(courseobj1, courseobj9); Assert.AreNotEqual(courseobj9, courseobj10); }
public DisplayText GetNameMarkup(BaseInfo info) { var keywordColor = GetColor(keywordColorId); var varColor = GetColor(varColorID); var label = DescriptionFormatter.GetTitle(info); if (label.kind == null) { return(null); } var sb = new StringBuilder(); void AppendColor(string value, string color) { sb.Append("<span foreground=\""); sb.Append(color); sb.Append("\">"); sb.Append(value); sb.Append("</span>"); } AppendColor(label.kind, keywordColor); sb.Append(" "); sb.Append(label.name); string typeInfo = null; if (info is ValueInfo vi) { var tdesc = vi.GetTypeDescription(); if (tdesc.Count > 0) { typeInfo = string.Join(" ", tdesc); } } if (info is FunctionInfo fi) { typeInfo = fi.ReturnTypeString; if (!fi.IsProperty) { sb.Append("("); bool first = true; foreach (var p in fi.Parameters) { if (first) { first = false; } else { sb.Append(", "); } sb.Append(p.Name); sb.Append(" : "); AppendColor(p.Type, varColor); } sb.Append(")"); } } if (typeInfo != null) { sb.Append(" : "); AppendColor(typeInfo, varColor); } return(new DisplayText(sb.ToString(), true)); }
public void ActiveDescription() { bool success = controller.LoadInitialFile(TestUtil.GetTestFile("selectionmgr\\sampleevent1.coursescribe"), true); Assert.IsTrue(success); selectionMgr.ActiveTab = 3; Assert.AreEqual("SampleCourse4", selectionMgr.ActiveCourseView.CourseName); StringWriter writer = new StringWriter(); string actual, expected; DescriptionFormatter.DumpDescription(ui.symbolDB, selectionMgr.ActiveDescription, writer); actual = writer.ToString(); expected = @" | Sample Event 1 | [Sample Event 1] |SampleCourse4 |4.7 km |175 m | [Length 4.7 km, climb 175 m] ( 1) |start| | | 2.8| 8.5| | | | [Start: open bare rock] ( 11) | 1| 191| | 5.2| 5.2| 10.1|11.15| | [Between path crossings] ( 22) | 13.4: | [Mandatory passage] ( 4) | 2| 32| | 3.7| | | | 12.1| [very marshy spot] ( 15) | 13.3: | [Mandatory crossing point] ( 5) | 3| GO| 0.1N| 5.5| 5.2| 10.1|11.1N| 12.3| [N side of N power line and path crossing (radio)] ( 18) | 4| 303| | 1.3| | 4| | | [Reentrant, 4m deep] ( 6) | 14.2: 1420 m | [Navigate 1420 m to finish funnel] "; Assert.AreEqual(expected, actual); selectionMgr.ActiveTab = 0; Assert.AreEqual("All controls", selectionMgr.ActiveCourseView.CourseName); writer = new StringWriter(); DescriptionFormatter.DumpDescription(ui.symbolDB, selectionMgr.ActiveDescription, writer); actual = writer.ToString(); expected = @" | Sample Event 1 | [Sample Event 1] |All controls |17 controls | [17 controls] ( 1) |start| | | 2.8| 8.5| | | | [Start: open bare rock] ( 23) |start| |0.2NW| 1.7| | 2.5| | | [Start: NW gully, 2.5m deep] ( 2) | | 31| 0.3| 2.4| | 2m| | | [Upper boulder, 2m high] ( 4) | | 32| | 3.7| | | | 12.1| [very marshy spot] ( 12) | | 74| | 2.4| |0.5/2.5|11.15| | [Between boulders, 0.5m to 2.5m high] ( 7) | | 189| | 1.8| 1.8| 10.2| | | [Small gully junction] ( 10) | | 190| | 5.1| 5.5| 10.1|11.1N| | [N side of road and power line crossing] ( 11) | | 191| | 5.2| 5.2| 10.1|11.15| | [Between path crossings] ( 8) | | 210| | 5.11| 5.20| |11.15| | [Between building and statue] ( 9) | | 211| | 3.7| 3.7|4x4|5x6|11.15| | [Between marshes, 4m by 4m and 5m by 6m] ( 13) | | 290| 0.1N| 5.2| | 10.2| | | [N path junction] ( 14) | | 291| | 1.10| 2.4| | | | [Knoll and boulder] ( 16) | | 301| | 1.14| 8.4| 3.0| | | [Overgrown pit, 3m deep] ( 17) | | 302| | 1.14| | |11.1S| | [S side of pit] ( 18) | | 303| | 1.3| | 4| | | [Reentrant, 4m deep] ( 19) | | 304| 0.1S| | 8.5| | | | [S ] ( 20) | | 305| | 2.7| | 6x7| | 12.4| [Stony ground, 6m by 7m (manned)] ( 21) | | 306| | | | | | | [] ( 5) | | GO| 0.1N| 5.5| 5.2| 10.1|11.1N| 12.3| [N side of N power line and path crossing (radio)] ( 6) | 14.2: | [Navigate to finish funnel] ( 24) | 14.1: | [Follow tapes to finish] ( 3) | 13.3: | [Mandatory crossing point] ( 15) | 13.3: | [Mandatory crossing point] ( 22) | 13.4: | [Mandatory passage] "; Assert.AreEqual(expected, actual); writer = new StringWriter(); }
public void ClearTextAndSymbols() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual, expected; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionFormatter.ClearTextAndSymbols(description); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); expected = @" | | | | | | ( 1) | | | | | | | | | ( 11) | | | | | | | | | ( 22) | : | ( 4) | | | | | | | | | ( 15) | : | ( 5) | | | | | | | | | ( 18) | | | | | | | | | ( 6) | : | "; Assert.AreEqual(expected, actual); }
// Create a description course object to use in testing. DescriptionCourseObj CreateDescriptionCourseObj(CourseAppearance appearance, int numColumns = 1) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("coursesymbols\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(3))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); return new DescriptionCourseObj(Id<Special>.None, new PointF(-4, 4), 0.9F / numColumns, symbolDB, description, DescriptionKind.Symbols, numColumns); }
public ClassifiedTextElement GetNameElement(ISymbol info) { var label = DescriptionFormatter.GetTitle(info); if (label.kind == null) { return(null); } var runs = new List <ClassifiedTextRun> (); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Keyword, label.kind)); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.WhiteSpace, " ")); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Identifier, label.name)); string typeInfo = null; if (info is VariableInfo vi) { var tdesc = vi.GetTypeDescription(); if (tdesc.Count > 0) { typeInfo = string.Join(" ", tdesc); } } if (info is FunctionInfo fi) { typeInfo = fi.ReturnTypeString; if (!fi.IsProperty) { runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, "(")); bool first = true; foreach (var p in fi.Parameters) { if (first) { first = false; } else { runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, ", ")); } runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.SymbolReference, p.Name)); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, " : ")); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Type, p.Type)); } runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, ")")); } } if (typeInfo != null) { runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Other, " : ")); runs.Add(new ClassifiedTextRun(PredefinedClassificationTypeNames.Type, typeInfo)); } return(new ClassifiedTextElement(runs)); }
public void HitTestAllControls() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259,78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38,97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5,85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226,260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205,245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(68,999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262,745), HitTestKind.OtherTextLine, 18, 18,0, new RectangleF(5, 725, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(311,12), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(16,82), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(178,76), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(182,234), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85,205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(60,942), HitTestKind.DirectiveText, 23, 23,-1, new RectangleF(5,925, 320, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262,745), HitTestKind.OtherTextLine, 18, 18,0, new RectangleF(5, 725, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(143, 22), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(434, 25), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(116, 53), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(259, 78), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(380, 76), HitTestKind.None, 1, 1, -1, new RectangleF(325,45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(38, 97), HitTestKind.NormalBox, 2, 2, 0, new RectangleF(5, 85, 40, 40)); CheckHitTest(descriptionRenderer, new Point(226, 260), HitTestKind.NormalBox, 6, 6, 5, new RectangleF(205, 245, 40, 40)); CheckHitTest(descriptionRenderer, new Point(68, 999), HitTestKind.Directive, 24, 24, 0, new RectangleF(5, 965, 320, 40)); CheckHitTest(descriptionRenderer, new Point(398,554), HitTestKind.NormalText, 13, 13, -1, new RectangleF(325,525, 200, 40)); CheckHitTest(descriptionRenderer, new Point(401, 934), HitTestKind.DirectiveText, 23, 23, -1, new RectangleF(325, 925, 200, 40)); CheckHitTest(descriptionRenderer, new Point(3, 184), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(262,745), HitTestKind.OtherTextLine, 18, 18,0, new RectangleF(5, 725, 520, 40)); }
// Render the given course id (0 = all controls) and kind to a map, and compare it to the saved version. internal void CheckRenderMap(string filename, Id<Course> id, DescriptionKind kind, int numColumns = 1) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(filename); eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, DesignatorFromCourseId(eventDB, id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(kind == DescriptionKind.Symbols); Bitmap bmNew = RenderToMapThenToBitmap(symbolDB, description, kind, numColumns); if (numColumns > 1) TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_ocad_" + numColumns + "col", kind)); else TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "_ocad", kind)); }
public void HitTestRegular() { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(CourseId(4))); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB); descriptionRenderer.Description = description; descriptionRenderer.CellSize = 40; descriptionRenderer.Margin = 5; descriptionRenderer.DescriptionKind = DescriptionKind.Symbols; CheckHitTest(descriptionRenderer, new Point(201,36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(79,50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145,80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175,216), HitTestKind.NormalBox, 5, 5,4, new RectangleF(165,205, 40, 40)); CheckHitTest(descriptionRenderer, new Point(285,365), HitTestKind.NormalBox, 9, 9,7, new RectangleF(285, 365, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81,193), HitTestKind.Directive, 4, 4,0, new RectangleF(5,165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(328,147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.Text; CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 320, 40)); CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalText, 5, 5, -1, new RectangleF(85, 205, 240, 40)); CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalText, 9, 9, -1, new RectangleF(85, 365, 240, 40)); CheckHitTest(descriptionRenderer, new Point(59, 302), HitTestKind.NormalBox, 7, 7, 1, new RectangleF(45,285, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.DirectiveText, 4, 4, -1, new RectangleF(5, 165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(328, 147), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 320, 40)); descriptionRenderer.DescriptionKind = DescriptionKind.SymbolsAndText; CheckHitTest(descriptionRenderer, new Point(201, 36), HitTestKind.Title, 0, 0, 0, new RectangleF(5, 5, 520, 40)); CheckHitTest(descriptionRenderer, new Point(79, 50), HitTestKind.Header, 1, 1, 0, new RectangleF(5, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(145, 80), HitTestKind.Header, 1, 1, 1, new RectangleF(125, 45, 120, 40)); CheckHitTest(descriptionRenderer, new Point(289, 60), HitTestKind.Header, 1, 1, 2, new RectangleF(245, 45, 80, 40)); CheckHitTest(descriptionRenderer, new Point(175, 216), HitTestKind.NormalBox, 5, 5, 4, new RectangleF(165, 205, 40, 40)); CheckHitTest(descriptionRenderer, new Point(285, 365), HitTestKind.NormalBox, 9, 9, 7, new RectangleF(285, 365, 40, 40)); CheckHitTest(descriptionRenderer, new Point(81, 193), HitTestKind.Directive, 4, 4, 0, new RectangleF(5, 165, 320, 40)); CheckHitTest(descriptionRenderer, new Point(431, 56), HitTestKind.None, 1, 1, -1, new RectangleF(325, 45, 200, 40)); CheckHitTest(descriptionRenderer, new Point(333, 131), HitTestKind.NormalText, 3, 3, -1, new RectangleF(325, 125, 200, 40)); CheckHitTest(descriptionRenderer, new Point(491,252), HitTestKind.DirectiveText, 6, 6, -1, new RectangleF(325, 245, 200, 40)); CheckHitTest(descriptionRenderer, new Point(527,433), HitTestKind.None, -1, -1, -1, new RectangleF(0, 0, 0, 0)); CheckHitTest(descriptionRenderer, new Point(255, 427), HitTestKind.OtherTextLine, 10, 10, 0, new RectangleF(5, 405, 520, 40)); }
public void DisplayAllCourses() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); CourseView courseView; DescriptionFormatter descFormatter; DescriptionLine[] description; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent1.coursescribe")); eventDB.Validate(); foreach (Id<Course> courseId in QueryEvent.SortedCourseIds(eventDB)) { CourseDesignator designator; if (QueryEvent.HasVariations(eventDB, courseId)) { var variationInfo = QueryEvent.GetAllVariations(eventDB, courseId).First(); designator = new CourseDesignator(courseId, variationInfo); } else { designator = new CourseDesignator(courseId); } courseView = CourseView.CreateViewingCourseView(eventDB, designator); descFormatter = new DescriptionFormatter(courseView, symbolDB); description = descFormatter.CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out); Console.WriteLine(); } courseView = CourseView.CreateViewingCourseView(eventDB, CourseDesignator.AllControls); descFormatter = new DescriptionFormatter(courseView, symbolDB); description = descFormatter.CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, Console.Out); }
// Render the given course id (0 = all controls) and kind to a bitmap, and compare it to the saved version. internal void CheckRenderBitmapPixelAtATime(Id<Course> id, DescriptionKind kind) { SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); CourseView courseView; eventDB.Load(TestUtil.GetTestFile("descriptions\\sampleevent1.coursescribe")); eventDB.Validate(); courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); DescriptionLine[] description = descFormatter.CreateDescription(false); Bitmap bmNew = RenderToBitmapPixelAtATime(symbolDB, description, kind); TestUtil.CheckBitmapsBase(bmNew, DescriptionBrowser.GetBitmapFileName(eventDB, id, "", kind)); }
public void ScoreCourseFormatterNoScore() { UndoMgr undomgr = new UndoMgr(5); EventDB eventDB = new EventDB(undomgr); SymbolDB symbolDB = new SymbolDB(Util.GetFileInAppDirectory("symbols.xml")); StringWriter writer = new StringWriter(); string actual, expected; eventDB.Load(TestUtil.GetTestFile("descformatter\\sampleevent5.coursescribe")); eventDB.Validate(); CourseView courseView = CourseView.CreateViewingCourseView(eventDB, Designator(5)); DescriptionLine[] description = new DescriptionFormatter(courseView, symbolDB).CreateDescription(false); DescriptionFormatter.DumpDescription(symbolDB, description, writer); actual = writer.ToString(); expected = @" | Sample Event 1 | [Sample Event 1] | Score more! | [Score more!] |Score 4 |155 points | [155 points] ( 1) |start| | | 2.8| 8.5| | | | [Start: open bare rock] ( 17) | 1| 302| | 1.14| | |11.1S| | [S side of pit] ( 2) | 2| 31| 0.3| 2.4| | 2m| | | [Upper boulder, 2m high] ( 7) | 3| 189| | 1.8| 1.8| 10.2| | | [Small gully junction] ( 11) | 4| 191| | 5.2| 5.2| 10.1|11.15| | [Between path crossings] ( 8) | 5| 210| | 5.11| 5.20| |11.15| | [Between building and statue] ( 20) | 6| 305| | 2.7| | 6x7| | 12.4| [Stony ground, 6m by 7m (manned)] ( 5) | 7| GO| 0.1N| 5.5| 5.2| 10.1|11.1N| 12.3| [N side of N power line and path crossing (radio)] ( 4) | 8| 32| | 3.7| | | | 12.1| [very marshy spot] ( 16) | 9| 301| | 1.14| 8.4| 3.0| | | [Overgrown pit, 3m deep] ( 18) | 10| 303| | 1.3| | 4| | | [Reentrant, 4m deep] ( 19) | 11| 304| 0.1S| | 8.5| | | | [S ] "; Assert.AreEqual(expected, actual); }
private DescriptionLine[] GetDescription() { CourseItem courseItem = (CourseItem)(listBoxCourses.SelectedItem); CourseView courseView; Id<Course> id; if (courseItem == null) id = Id<Course>.None; else id = courseItem.id; courseView = CourseView.CreateViewingCourseView(eventDB, new CourseDesignator(id)); DescriptionFormatter descFormatter = new DescriptionFormatter(courseView, symbolDB); return descFormatter.CreateDescription(customKeyCheckBox.Checked); }
protected override void VisitValueExpression( XElement element, XAttribute attribute, MSBuildElementSyntax resolvedElement, MSBuildAttributeSyntax resolvedAttribute, ValueInfo info, MSBuildValueKind kind, ExpressionNode node) { bool allowExpressions = kind.AllowExpressions(); bool allowLists = kind.AllowListsOrCommaLists(); if (node is ListExpression list) { if (!allowLists) { Document.Diagnostics.Add( CoreDiagnostics.UnexpectedList, new TextSpan(list.Nodes[0].End, list.End - list.Nodes[0].End), ImmutableDictionary <string, object> .Empty.Add("Name", info.Name), DescriptionFormatter.GetKindNoun(info), info.Name); } if (!allowExpressions) { var expr = list.Nodes.FirstOrDefault(n => !(n is ExpressionText)); if (expr != null) { AddExpressionWarning(expr); } } } else if (node is ExpressionText lit) { VisitPureLiteral(info, kind, lit.GetUnescapedValue(), lit.Offset); } else { if (!allowExpressions) { AddExpressionWarning(node); } } foreach (var n in node.WithAllDescendants()) { switch (n) { case ExpressionError err: var(desc, args) = CoreDiagnostics.GetExpressionError(err, info); Document.Diagnostics.Add(desc, new TextSpan(err.Offset, Math.Max(1, err.Length)), args); break; case ExpressionMetadata meta: var metaItem = meta.GetItemName(); if (!string.IsNullOrEmpty(metaItem) && !IsMetadataUsed(metaItem, meta.MetadataName, ReferenceUsage.Write)) { Document.Diagnostics.Add( CoreDiagnostics.UnwrittenMetadata, meta.Span, ImmutableDictionary <string, object> .Empty .Add("ItemName", metaItem) .Add("Name", meta.MetadataName) .Add("Spans", new [] { new TextSpan(meta.MetadataNameOffset, meta.MetadataName.Length) }), metaItem, meta.MetadataName ); } break; case ExpressionPropertyName prop: if (!IsPropertyUsed(prop.Name, ReferenceUsage.Write)) { Document.Diagnostics.Add( CoreDiagnostics.UnwrittenProperty, prop.Span, ImmutableDictionary <string, object> .Empty .Add("Name", prop.Name) .Add("Spans", new[] { new TextSpan(prop.Offset, prop.Length) }), prop.Name ); } break; case ExpressionItemName item: if (!IsItemUsed(item.Name, ReferenceUsage.Write)) { Document.Diagnostics.Add( CoreDiagnostics.UnwrittenItem, item.Span, ImmutableDictionary <string, object> .Empty .Add("Name", item.Name) .Add("Spans", new[] { new TextSpan(item.Offset, item.Length) }), item.Name ); } //TODO: deprecation squiggles in expressions break; } } void AddExpressionWarning(ExpressionNode n) => Document.Diagnostics.Add(CoreDiagnostics.UnexpectedExpression, new TextSpan(n.Offset, n.Length), DescriptionFormatter.GetKindNoun(info), info.Name); }