Example #1
0
        private void _objects_SelectedIndexChanged(object sender, EventArgs e)
        {
            _annotationLayoutControlItem.Visible = false;
            ChangeCustomActionStatus?.Invoke("RemoveReviewNote", false);
            RemoveButtons();

            if (_objects.SelectedItems.Count == 1 && _objects.SelectedItems[0].Tag is IPropertiesContainer container)
            {
                _selected        = container;
                _properties.Item = _selected;
                ChangeCustomActionStatus?.Invoke("AddReviewNote", true);

                _right.SuspendLayout();
                var reviewNotes = _schemaManager.GetAnnotations(container)?
                                  .Where(x => x is ReviewNote).ToArray();
                if (reviewNotes?.Any() ?? false)
                {
                    foreach (var reviewNote in reviewNotes)
                    {
                        AddButton(reviewNote);
                    }
                }

                _right.ResumeLayout();
            }
            else
            {
                _selected        = null;
                _properties.Item = null;
                ChangeCustomActionStatus?.Invoke("AddReviewNote", false);
            }
        }
 public static bool HasNotesWithText(this IPropertiesContainer container, [NotNull] AnnotationsPropertySchemaManager schemaManager, string filter)
 {
     return(string.IsNullOrWhiteSpace(filter) ||
            (schemaManager.GetAnnotations(container)?
             .Any(x => x.Text != null && x.Text.ToLower().Contains(filter.ToLower()) ||
                  (x is TopicToBeClarified topic &&
                   (topic.Answers?.Any(y => y.Text != null && y.Text.ToLower().Contains(filter.ToLower())) ?? false))) ?? false));
 }
        private int Count(IPropertiesContainer container)
        {
            var result = 0;

            if (container != null)
            {
                result = _schemaManager.GetAnnotations(container)?.Count(x => x is Highlight) ?? 0;
            }

            return(result);
        }
        private int Count(IPropertiesContainer container)
        {
            var result = 0;

            if (container != null)
            {
                result = _schemaManager.GetAnnotations(container)?.Count(x => (x is TopicToBeClarified topic) && !topic.Answered) ?? 0;
            }

            return(result);
        }
Example #5
0
        private int Count(IPropertiesContainer container)
        {
            var result = 0;

            if (container != null)
            {
                result = _schemaManager.GetAnnotations(container)?
                         .Count(x => !(x is AnnotationAnswer || x is Highlight || x is ReviewNote || x is TopicToBeClarified)) ?? 0;
            }

            return(result);
        }
Example #6
0
        private void _objects_SelectedIndexChanged(object sender, EventArgs e)
        {
            _annotationLayoutControlItem.Visible = false;
            ChangeCustomActionStatus?.Invoke("RemoveNotes", false);
            ChangeCustomActionStatus?.Invoke("RemoveTopic", false);
            ChangeCustomActionStatus?.Invoke("RemoveHighlight", false);
            RemoveButtons();

            if (_objects.SelectedItems.Count == 1 && _objects.SelectedItems[0].Tag is IPropertiesContainer container)
            {
                _selected        = container;
                _properties.Item = _selected;
                ChangeCustomActionStatus?.Invoke("AddTopic", true);
                ChangeCustomActionStatus?.Invoke("AddHighlight", true);

                _right.SuspendLayout();
                var annotations = _schemaManager.GetAnnotations(container)?.ToArray();

                var notes = annotations?
                            .Where(x => !(x is TopicToBeClarified || x is Highlight || x is ReviewNote)).ToArray();
                if (notes?.Any() ?? false)
                {
                    foreach (var note in notes)
                    {
                        AddButton(note);
                    }
                    ChangeCustomActionStatus?.Invoke("AddNotes", false);
                }
                else
                {
                    ChangeCustomActionStatus?.Invoke("AddNotes", true);
                }

                var topicsToBeClarified = annotations?.Where(x => x is TopicToBeClarified).ToArray();
                if (topicsToBeClarified?.Any() ?? false)
                {
                    foreach (var topic in topicsToBeClarified)
                    {
                        AddButton(topic);
                    }
                }

                var highlights = annotations?.Where(x => x is Highlight).ToArray();
                if (highlights?.Any() ?? false)
                {
                    foreach (var highlight in highlights)
                    {
                        AddButton(highlight);
                    }
                }

                var reviewNotes = annotations?.Where(x => x is ReviewNote).ToArray();
                if (reviewNotes?.Any() ?? false)
                {
                    foreach (var reviewNote in reviewNotes)
                    {
                        AddButton(reviewNote);
                    }
                }

                _right.ResumeLayout();
            }
            else
            {
                _selected        = null;
                _properties.Item = null;
                ChangeCustomActionStatus?.Invoke("AddNotes", false);
                ChangeCustomActionStatus?.Invoke("AddTopic", false);
                ChangeCustomActionStatus?.Invoke("AddHighlight", false);
            }
        }
Example #7
0
        private void AddReviewNotesPage([NotNull] PdfDocument doc, [NotNull] PdfStandardFont font,
                                        [NotNull] IEnumerable <IPropertiesContainer> containers, [NotNull] AnnotationsPropertySchemaManager schemaManager,
                                        [NotNull] IPropertyType propertyType)
        {
            string  objectType = null;
            string  name       = null;
            string  text       = null;
            Bitmap  image      = null;
            var     y          = 0f;
            PdfPage page       = null;
            var     textSize   = SizeF.Empty;

            foreach (var container in containers)
            {
                if (container is IDataFlow flow)
                {
                    objectType = _model.GetIdentityTypeName(flow);
                    name       = flow.Name;
                    text       = $"From {_model.GetIdentityTypeName(flow.Source)} '{flow.Source.Name}' to {_model.GetIdentityTypeName(flow.Target)} '{flow.Target.Name}'";
                    image      = flow.GetImage(ImageSize.Medium);
                }
                else if (container is IThreatEvent threatEvent)
                {
                    objectType = _model.GetIdentityTypeName(threatEvent);
                    name       = threatEvent.Name;
                    text       = $"Applied to {_model.GetIdentityTypeName(threatEvent.Parent)} '{threatEvent.Parent.Name}'";
                    image      = threatEvent.GetImage(ImageSize.Medium);
                }
                else if (container is IIdentity identity)
                {
                    objectType = _model.GetIdentityTypeName(identity);
                    name       = identity.Name;
                    text       = null;
                    image      = identity.GetImage(ImageSize.Medium);
                }
                else if (container is IThreatEventMitigation threatEventMitigation)
                {
                    objectType = "Threat Event Mitigation";
                    name       = threatEventMitigation.Mitigation.Name;
                    text       = $"Associated to Threat Event '{threatEventMitigation.ThreatEvent.Name}' on '{threatEventMitigation.ThreatEvent.Parent.Name}'";
                    image      = Icons.Resources.mitigations;
                }
                else if (container is IThreatTypeMitigation threatTypeMitigation)
                {
                    objectType = "Threat Type Mitigation";
                    name       = threatTypeMitigation.Mitigation.Name;
                    text       = $"Associated to Threat Type '{threatTypeMitigation.ThreatType.Name}'";
                    image      = Icons.Resources.standard_mitigations;
                }
                else
                {
                    objectType = null;
                    name       = null;
                    text       = null;
                    image      = null;
                }

                var reviewNotes = schemaManager.GetAnnotations(container)?.OfType <ReviewNote>().ToArray();
                if (reviewNotes?.Any() ?? false)
                {
                    PdfImage img;
                    foreach (var reviewNote in reviewNotes)
                    {
                        if (y == 0 || (y > page.Graphics.ClientSize.Height - textSize.Height * 10))
                        {
                            y    = 0;
                            page = doc.Pages.Add();

                            textSize = WriteText(page, "Review Notes", new PdfStandardFont(font, font.Size, PdfFontStyle.Bold), 0, 0);
                            y        = textSize.Height + 10;
                            page.Graphics.DrawLine(PdfPens.Black, 0, y, page.Graphics.ClientSize.Width, y);
                            y += 10;
                        }

                        if (image != null && objectType != null && name != null)
                        {
                            img = PdfImage.FromImage(image);
                            page.Graphics.DrawImage(img, new RectangleF(0, y, 16, 16));
                            textSize = WriteText(page, $"{objectType}: {name}", font, 18, y + 2);
                            if (text != null)
                            {
                                y       += textSize.Height + 5;
                                textSize = WriteText(page, text, font, 18, y);
                            }
                            y       += textSize.Height + 5;
                            textSize = WriteText(page, reviewNote.Text, font, 18, y);
                            y       += textSize.Height + 5;
                            textSize = WriteText(page, $"Note created by {reviewNote.CreatedBy} on {reviewNote.CreatedOn.ToShortDateString()} and modified by {reviewNote.ModifiedBy} on {reviewNote.ModifiedOn.ToShortDateString()}", font, 18, y);

                            y += textSize.Height + 10;
                        }
                    }
                }
            }
        }