/// <summary> /// This method checks if the given block syntaxes are too long based on the configured limits. If so, the block syntax /// and the corresponding limit configuration is put together in an instance of <see cref="CodeBlockOccurrence">LongCodeBlockOccurrence</see>. /// </summary> /// <param name="codeBlocks">The list of block syntaxes that will be analyzed.</param> private void AnalyzeCodeBlockOccurrences(IEnumerable <BlockSyntax> codeBlocks) { if (codeBlocks == null) { throw new ArgumentNullException(nameof(codeBlocks)); } _codeBlockOccurrences.Clear(); foreach (var codeBlock in codeBlocks) { string methodName = string.Empty; int linesOfCode = 0; GetMethodNameAndLineCount(codeBlock, out methodName, out linesOfCode); var feedbacks = _feedbackMachine.RequestFeedbackForMethodCodeBlock(methodName, linesOfCode); var occurence = new CodeBlockOccurrence(codeBlock, feedbacks); _codeBlockOccurrences.Add(occurence); } }
/// <summary> /// This method creates the visual for a code block background and moves it to the correct position. /// </summary> /// <param name="adornmentBounds">The bounds of the rectangular adornment.</param> /// <param name="codeBlockOccurence">The occurence of the code block for which the visual will be created.</param> /// <returns>Returns the image that is the visual adornment (code block background).</returns> private Image CreateAndPositionCodeBlockBackgroundVisual(Rect adornmentBounds, CodeBlockOccurrence codeBlockOccurence) { if (adornmentBounds == null) { throw new ArgumentNullException(nameof(adornmentBounds)); } if (codeBlockOccurence == null) { throw new ArgumentNullException(nameof(codeBlockOccurence)); } var backgroundGeometry = new RectangleGeometry(adornmentBounds); var feedback = codeBlockOccurence.Feedbacks.Where(f => f is DrawColoredBackgroundFeedback).FirstOrDefault() as DrawColoredBackgroundFeedback; var backgroundColor = Color.FromArgb(feedback.BackgroundColor.A, feedback.BackgroundColor.R, feedback.BackgroundColor.G, feedback.BackgroundColor.B); var backgroundBrush = new SolidColorBrush(backgroundColor); backgroundBrush.Freeze(); var outlineColor = Color.FromArgb(feedback.OutlineColor.A, feedback.OutlineColor.R, feedback.OutlineColor.G, feedback.OutlineColor.B); var outlinePenBrush = new SolidColorBrush(outlineColor); outlinePenBrush.Freeze(); var outlinePen = new Pen(outlinePenBrush, 0.5); outlinePen.Freeze(); var drawing = new GeometryDrawing(backgroundBrush, outlinePen, backgroundGeometry); drawing.Freeze(); var drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); var image = new Image { Source = drawingImage }; Canvas.SetLeft(image, adornmentBounds.Left); Canvas.SetTop(image, adornmentBounds.Top); return(image); }