Ejemplo n.º 1
0
        public bool Execute(IIdentity identity)
        {
            bool result = false;

            if (identity is IEntity entity && entity.Model is IThreatModel model)
            {
                var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                if (propertyType != null)
                {
                    var property = entity.GetProperty(propertyType);
                    if (property is IPropertyIdentityReference identityReference &&
                        identityReference.Value is IDiagram diagram)
                    {
                        result = true;
                        var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                        if (factory != null)
                        {
                            OpenPanel?.Invoke(factory, diagram);
                        }
                    }
                }
            }

            if (!result)
            {
                ShowWarning?.Invoke("The Entity is not associated to any Diagram.");
            }

            return(result);
        }
        public MainWindow()
        {
            InitializeComponent();
            var style = new StyleLib();

            style.LoadStyles();
            OpenPanel.SetStyles(style, mainC);
        }
Ejemplo n.º 3
0
        private void OnOpenDiagram(IDiagram diagram)
        {
            var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");

            if (factory != null && diagram != null)
            {
                OpenPanel?.Invoke(factory, diagram);
            }
        }
Ejemplo n.º 4
0
        private void OpenDiagram(Guid diagramId)
        {
            var diagram = _model.GetDiagram(diagramId);
            var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");

            if (factory != null && diagram != null)
            {
                OpenPanel?.Invoke(factory, diagram);
            }
        }
Ejemplo n.º 5
0
 private void _superTooltip_MarkupLinkClick(object sender, MarkupLinkClickEventArgs e)
 {
     if (Guid.TryParse(e.HRef, out var id))
     {
         var diagram = _model.GetDiagram(id);
         var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
         if (factory != null && diagram != null)
         {
             OpenPanel?.Invoke(factory, diagram);
         }
     }
 }
Ejemplo n.º 6
0
        public bool Execute(IIdentity identity)
        {
            bool result = false;

            if (identity is IEntity entity && entity.Model is IThreatModel model)
            {
                using (var dialog = new DiagramSelectionDialog(entity))
                {
                    if (dialog.ShowDialog(Form.ActiveForm) == DialogResult.OK)
                    {
                        var diagram = dialog.Diagram;
                        if (diagram == null)
                        {
                            diagram = model.AddDiagram(dialog.DiagramName);
                        }

                        if (diagram != null)
                        {
                            var schemaManager = new AssociatedDiagramPropertySchemaManager(model);
                            var propertyType  = schemaManager.GetAssociatedDiagramIdPropertyType();
                            if (propertyType != null)
                            {
                                var property = entity.GetProperty(propertyType);
                                if (property == null)
                                {
                                    property = entity.AddProperty(propertyType, diagram.Id.ToString("N"));
                                }
                                else
                                {
                                    property.StringValue = diagram.Id.ToString("N");
                                }

                                result = true;
                                DiagramAssociationHelper.NotifyDiagramAssociation(entity, diagram);
                                var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                                if (factory != null)
                                {
                                    OpenPanel?.Invoke(factory, diagram);
                                    ShowMessage?.Invoke("Diagram has been associated successfully.");
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
    public void EnableCanvas(bool value)
    {
        isEnabled = value;
        GetComponent <Canvas>().enabled = isEnabled;
        GotoPosition();

        if (!isEnabled)
        {
            ClosePanel?.Invoke();
        }
        else
        {
            OpenPanel?.Invoke();
        }

        //any other stuff required for disabling/enabling canvas goes here
    }
        public void ExecuteCustomAction([NotNull] IActionDefinition action)
        {
            string text    = null;
            bool   warning = false;

            try
            {
                switch (action.Name)
                {
                case "AddDataFlow":
                    //text = "Add Data Flow";
                    //_model.AddEntity<IDataStore>();
                    break;

                case "RemoveDataFlow":
                    var selected = _grid.GetSelectedCells()?.OfType <GridCell>()
                                   .Select(x => x.GridRow)
                                   .Distinct()
                                   .ToArray();

                    if (_currentRow != null)
                    {
                        if ((selected?.Length ?? 0) > 1)
                        {
                            var outcome = MessageBox.Show(Form.ActiveForm,
                                                          $"You have selected {selected.Length} Flows. Do you want to remove them all?\nPlease click 'Yes' to remove all selected Flows,\nNo to remove only the last one you selected, '{_currentRow?.Tag?.ToString()}'.\nPress Cancel to abort.",
                                                          "Remove Flows", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,
                                                          MessageBoxDefaultButton.Button3);
                            switch (outcome)
                            {
                            case DialogResult.Yes:
                                bool removed = true;
                                foreach (var row in selected)
                                {
                                    bool r = false;
                                    if (row.Tag is IDataFlow flow)
                                    {
                                        r = _model.RemoveDataFlow(flow.Id);
                                    }

                                    removed &= r;

                                    if (r && row == _currentRow)
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                    }
                                }

                                if (removed)
                                {
                                    text = "Remove Flows";
                                }
                                else
                                {
                                    warning = true;
                                    text    = "One or more Flows cannot be removed.";
                                }
                                break;

                            case DialogResult.No:
                                if (_currentRow != null && _currentRow.Tag is IDataFlow flow2)
                                {
                                    if (_model.RemoveDataFlow(flow2.Id))
                                    {
                                        _properties.Item = null;
                                        _currentRow      = null;
                                        text             = "Remove Flow";
                                    }
                                    else
                                    {
                                        warning = true;
                                        text    = "The Flow cannot be removed.";
                                    }
                                }
                                break;
                            }
                        }
                        else if (_currentRow != null && _currentRow.Tag is IDataFlow dataFlow &&
                                 MessageBox.Show(Form.ActiveForm,
                                                 $"You are about to remove Flow '{dataFlow.Name}'. Are you sure?",
                                                 "Remove Flow", MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
                                                 MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            if (_model.RemoveDataFlow(dataFlow.Id))
                            {
                                _properties.Item = null;
                                text             = "Remove Flow";
                            }
                            else
                            {
                                warning = true;
                                text    = "The Flow cannot be removed.";
                            }
                        }
                    }
                    break;

                case "FindDataFlow":
                    bool found = false;
                    if (_currentRow != null && _currentRow.Tag is IDataFlow dataFlow2)
                    {
                        var diagrams = _model.Diagrams?.ToArray();
                        if (diagrams?.Any() ?? false)
                        {
                            foreach (var diagram in diagrams)
                            {
                                var flow = diagram.GetLink(dataFlow2.Id);
                                if (flow != null)
                                {
                                    found = true;
                                    var factory = ExtensionUtils.GetExtensionByLabel <IPanelFactory>("Diagram");
                                    if (factory != null)
                                    {
                                        OpenPanel?.Invoke(factory, diagram);
                                    }
                                    break;
                                }
                            }
                        }
                    }

                    if (!found)
                    {
                        warning = true;
                        text    = "The Flow has not been found in any Diagram.";
                    }
                    break;

                case "Refresh":
                    LoadModel();
                    break;
                }

                if (warning)
                {
                    ShowWarning?.Invoke(text);
                }
                else if (text != null)
                {
                    ShowMessage?.Invoke($"{text} has been executed successfully.");
                }
            }
            catch
            {
                ShowWarning?.Invoke($"An error occurred during the execution of the action.");
                throw;
            }
        }
Ejemplo n.º 9
0
 public void InvokeOpenPanel()
 {
     Debug.Log("Invoking Succesfull");
     OpenPanel?.Invoke();
 }
Ejemplo n.º 10
0
 private void ButtonCreateTag_Click(object sender, RoutedEventArgs e)
 {
     //tell parent control to open panel
     OpenPanel?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 11
0
 public void Initialize(OpenPanel openPanel, string path, string plantName)
 {
     this.plantName.text = plantName;
     this.openPanel      = openPanel;
     this.path           = path;
 }
Ejemplo n.º 12
0
 private void CreatePanel([NotNull] IPanelFactory factory, [NotNull] IIdentity identity)
 {
     OpenPanel?.Invoke(factory, identity);
 }