public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            var             itemAsLayoutContent = item as LayoutContent;
            IPanelViewModel vm      = item as IPanelViewModel;
            IPanelFactory   factory = vm?.ParentFactory;

            if (factory != null)
            {
                var template = new DataTemplate();
                FrameworkElementFactory spFactory = new FrameworkElementFactory(factory.ViewType);

                spFactory.SetValue(Control.DataContextProperty, vm);
                template.VisualTree = spFactory;
                return(template);
            }

            if (item is MarkerPaneViewModel)
            {
                return(MarkersPaneTemplate);
            }

            if (item is ProjectPaneViewModel)
            {
                return(ProjectPaneTemplate);
            }

            return(base.SelectTemplate(item, container));
        }
Ejemplo n.º 2
0
        public void CreatePanelFactoryTest()
        {
            Type          expect = typeof(Sample_Crunch.StandardPanels.TimePlotFactory);
            IPanelFactory lfp    = PluginFactory.CreatePanelFactory(expect);

            Assert.IsInstanceOfType(lfp, expect);
        }
Ejemplo n.º 3
0
        private bool AddInstance([NotNull] IPanelFactory <Form> factory, IIdentity identity)
        {
            bool result = false;

            Guid id        = identity?.Id ?? Guid.Empty;
            var  factoryId = factory.GetExtensionId();

            if (_instances.TryGetValue(factoryId, out var instances))
            {
                if ((factory.Behavior == InstanceMode.Single && instances.Count == 0) ||
                    (factory.Behavior == InstanceMode.SinglePerObject && !instances.Contains(id)))
                {
                    instances.Add(id);
                    result = true;
                }
            }
            else
            {
                instances = new List <Guid> {
                    id
                };
                _instances[factoryId] = instances;
                result = true;
            }

            return(result);
        }
Ejemplo n.º 4
0
        private void InternalAddDocument(IPanelModel document)
        {
            IPanelFactory   factory = PluginFactory.FindPanelFactory(document);
            IPanelViewModel vm      = factory.CreateViewModel(this, document);

            this.Documents.Add(vm);
        }
Ejemplo n.º 5
0
        private void InternalAddAnchorable(PaneModel pane)
        {
            IPanelFactory   factory = PluginFactory.FindPanelFactory(pane);
            IPanelViewModel vm      = factory.CreateViewModel(this, pane);

            this.Anchorables.Add(vm);
        }
Ejemplo n.º 6
0
        public DirectoryScoperPanel(IDirectoryScoperViewModel viewModel, IPanelFactory panelFactory)
        {
            DataContext = viewModel;

            XamlReader.Load(this);

            Content = panelFactory.GetFolderPanel();
        }
Ejemplo n.º 7
0
        private void Execute_NewPluginCommand(IPanelFactory factory)
        {
            IPanelModel model = factory.CreateModel();

            if (string.IsNullOrEmpty(model.Title) || string.IsNullOrEmpty(model.FactoryReference))
            {
                throw new InvalidOperationException("Invalid plugin plugin title or factory reference. Contact plugin author!");
            }
            this.Project.ProjectModel.Documents.Add(model);
        }
Ejemplo n.º 8
0
        public void FindPanelFactoryTest()
        {
            PluginFactory.Reset();
            PluginFactory.LoadPlugins(pluginPath);
            Type          factoryType = typeof(Sample_Crunch.StandardPanels.TimePlotFactory);
            var           factory     = PluginFactory.CreatePanelFactory(factoryType);
            var           model       = factory.CreateModel();
            IPanelFactory lfp         = PluginFactory.FindPanelFactory(model);

            IsTypenameSame(lfp.GetType(), factoryType);
        }
Ejemplo n.º 9
0
 private void ClosePanels(IPanelFactory factory)
 {
     foreach (var form in MdiChildren)
     {
         if (form is PanelContainerForm panelContainerForm &&
             panelContainerForm.Tag is IPanelFactory panelFactory &&
             panelFactory.GetExtensionId() == factory.GetExtensionId())
         {
             form.Close();
         }
     }
 }
Ejemplo n.º 10
0
        public PlotPaneViewModel(IProjectViewModel project, IPanelFactory factory, TimePlotModel paneModel)
            : base(factory, paneModel)
        {
            // The project in main.Project and the project actually loading the panel is not the same here when loading project from file.
            this.projectVM = project;
            this.paneModel = paneModel;
            PlotModel      = new PlotModel();
            SetUpModel();

            this.PlotModel.Title = paneModel.Title;

            project.Files.CollectionChanged   += Files_CollectionChanged;
            project.Markers.CollectionChanged += Markers_CollectionChanged;
        }
Ejemplo n.º 11
0
        public FolderPanel(IFolderViewModel viewModel, IPanelFactory panelFactory)
        {
            _panelFactory = panelFactory;

            DataContext = viewModel;

            XamlReader.Load(this);

            _panelFactory = panelFactory;

            DataContext = viewModel;

            InitializeEvents();

            GridLayoutPanel.Content = ContentGridLayout;
        }
Ejemplo n.º 12
0
        private void AddPanel([NotNull] IPanelFactory <Form> factory, IIdentity identity)
        {
            bool found = false;

            var formId = GetFormId(factory, identity);

            if (identity is IDiagram diagram)
            {
                found = DisplayForm(formId);
            }

            if (!found)
            {
                ExceptionlessClient.Default.CreateFeatureUsage(factory.GetExtensionLabel()).Submit();
                var panel = factory.Create(identity, out IActionDefinition action);
                var form  = CreateForm(factory, panel, action, formId);
                form.Closed += OnFormClosed;
            }
        }
Ejemplo n.º 13
0
        private void DeletePanel([NotNull] IPanelFactory factory, [NotNull] IPanel panel)
        {
            foreach (var item in _panelsListButtons.Values)
            {
                var subItems = item.SubItems.OfType <BaseItem>().ToArray();
                foreach (BaseItem subItem in subItems)
                {
                    if (subItem.Tag is IActionDefinition action &&
                        panel is IPanel <Form> formPanel &&
                        formPanel.PanelContainer is PanelContainerForm containerForm)
                    {
                        var actionForm = FindForm(action);
                        if (actionForm == containerForm)
                        {
                            subItem.Click -= Button_Click;
                            item.SubItems.Remove(subItem);

                            if (action is INotifyPropertyChanged childButtonAction)
                            {
                                childButtonAction.PropertyChanged -= OnChildButtonActionPropertyChanged;
                            }

                            _childParentActions.Remove(action.Id);
                            break;
                        }
                    }
                }

                if (!item.SubItems.OfType <BaseItem>().Any() &&
                    item.Tag is IActionDefinition itemAction)
                {
                    item.Enabled = itemAction.Enabled;
                }
            }

            (panel as IPanel <Form>)?.PanelContainer?.Close();
        }
Ejemplo n.º 14
0
        private void CreatePanel([NotNull] IPanelFactory factory, IIdentity identity)
        {
            if (factory is IPanelFactory <Form> formFactory)
            {
                switch (factory.Behavior)
                {
                case InstanceMode.Multiple:
                    AddPanel(formFactory, identity);
                    break;

                default:
                    if (AddInstance(formFactory, identity))
                    {
                        AddPanel(formFactory, identity);
                    }
                    else
                    {
                        DisplayForm(GetFormId(formFactory, identity));
                    }

                    break;
                }
            }
        }
Ejemplo n.º 15
0
 private void ShowPanel(IPanelFactory factory, IPanel panel)
 {
     (panel as IPanel <Form>)?.PanelContainer?.Focus();
 }
Ejemplo n.º 16
0
 private void CreatePanel([NotNull] IPanelFactory factory, [NotNull] IIdentity identity)
 {
     OpenPanel?.Invoke(factory, identity);
 }
Ejemplo n.º 17
0
        public MainForm(IPanelFactory panelFactory, IMainFormViewModel viewModel)
        {
            XamlReader.Load(this);

            Content = panelFactory.GetDirectoryScoperPanel();
        }
 public ulong RegisterPanelFactory(IPanelFactory factory)
 {
     return Constants.E_SUCCESS;
 }
Ejemplo n.º 19
0
 public TimePlotViewModel(IProjectViewModel project, IPanelFactory factory, TimePlotModel paneModel)
     : base(project, factory, paneModel)
 {
     project.PropertyChanged += ProjectVM_PropertyChanged;
     project.FilesRealigned  += Project_FilesRealigned;
 }
Ejemplo n.º 20
0
 public MapPlotPaneViewModel(IProjectViewModel project, IPanelFactory factory, TimePlotModel paneModel)
     : base(project, factory, paneModel)
 {
 }
Ejemplo n.º 21
0
        private string GetFormId([NotNull] IPanelFactory <Form> factory, IIdentity identity)
        {
            Guid id = identity?.Id ?? Guid.Empty;

            return(GetFormId(factory, id));
        }
Ejemplo n.º 22
0
 private string GetFormId([NotNull] IPanelFactory <Form> factory, Guid identityId)
 {
     return($"{factory.GetExtensionId()}_{identityId.ToString()}");
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Add plugins from path. Can be called multiple times to include several paths.
        /// </summary>
        /// <param name="pluginPath">The path to include plugins from.</param>
        public static List <Exception> LoadPlugins(string pluginPath)
        {
            if (!Directory.Exists(pluginPath))
            {
                throw new DirectoryNotFoundException("The plugin directory (" + Path.GetFullPath(pluginPath) + ") could not be found!");
            }

            // Save any exception and continue loading next dll
            List <Exception> exList = new List <Exception>();

            foreach (var dll in Directory.EnumerateFiles(pluginPath, "*.dll"))
            {
                var domain = AppDomain.CurrentDomain;
                domain.ReflectionOnlyAssemblyResolve += MyInterceptMethod;
                string name = Path.GetFileName(dll);
                try
                {
                    Assembly nextAssembly = Assembly.Load(File.ReadAllBytes(dll));
                    var      info         = new PluginInfo(string.Format("{0} v{1}", nextAssembly.GetName().Name, nextAssembly.GetName().Version), dll);

                    foreach (var type in nextAssembly.GetTypes())
                    {
                        foreach (var item in type.GetInterfaces())
                        {
                            if (item.Name == nameof(IParserFactory) && !type.IsGenericType && !type.IsInterface)
                            {
                                IParserFactory factory = PluginFactory.CreateParserFactory(type);
                                ParserFactories.Add(factory);

                                ParserPluginAttribute attr = type.GetCustomAttribute <ParserPluginAttribute>(false);
                                if (attr != null)
                                {
                                    info.AddItem(new PluginInfo.ItemInfo()
                                    {
                                        Name = string.Format("{0} ({1})", attr.Title, attr.FileType), Type = PluginInfo.ItemType.Parser
                                    });
                                }
                            }
                            else if (item.Name == nameof(IAnalyzer) && !type.IsGenericType && !type.IsInterface)
                            {
                                AnalyzerPluginAttribute attr = type.GetCustomAttribute <AnalyzerPluginAttribute>(false);
                                Analyzers.Add(type);
                                info.AddItem(new PluginInfo.ItemInfo()
                                {
                                    Name = type.Name, Type = PluginInfo.ItemType.Analyzer
                                });
                            }
                            else if (item.Name == nameof(IPanelFactory) && !type.IsGenericType && !type.IsInterface)
                            {
                                IPanelFactory factory = PluginFactory.CreatePanelFactory(type);
                                PanelFactories.Add(factory);
                                info.AddItem(new PluginInfo.ItemInfo()
                                {
                                    Name = factory.Title, Type = PluginInfo.ItemType.Display
                                });
                            }
                        }
                    }

                    // Add assembly item is containing any plugin
                    if (info.Items.Count > 0)
                    {
                        Info.Add(info);
                    }
                }
                catch (ReflectionTypeLoadException ex)
                {
                    Exception exL = ex.LoaderExceptions[0];
                    if (exL is TypeLoadException)
                    {
                        exList.Add(new PluginLoadException("Plugin " + name + " could not load from " + pluginPath + "! Please contact plugin author.", exL));
                    }
                    else
                    {
                        exList.Add(new PluginLoadException("Plugin " + name + " could not load! Please contact plugin author.", ex.LoaderExceptions[0]));
                    }
                }
                catch (Exception ex)
                {
                    exList.Add(new PluginLoadException("Plugin " + name + " could not load! Please contact plugin author.", ex));
                }
                finally
                {
                    domain.ReflectionOnlyAssemblyResolve -= MyInterceptMethod;
                }
            } // End of file loop

            return(exList);
        }
Ejemplo n.º 24
0
 public PanelViewModel(IPanelFactory factory, T model)
 {
     this.factory = factory;
     this.model   = model;
 }
Ejemplo n.º 25
0
 private void CreatePanel([NotNull] IPanelFactory factory, [NotNull] IIdentity identity)
 {
     _panelForEntityRequired?.Invoke(factory, identity);
 }
Ejemplo n.º 26
0
        private PanelContainerForm CreateForm([NotNull] IPanelFactory <Form> factory,
                                              [NotNull] IPanel <Form> panel, [NotNull] IActionDefinition action, [Required] string formId)
        {
            PanelContainerForm result = null;

            if (panel is UserControl control)
            {
                result = new PanelContainerForm
                {
                    Name   = action.Id.ToString("N"),
                    Tag    = factory,
                    FormId = formId
                };
                panel.PanelContainer = result;

                if (panel is IDesktopAlertAwareExtension desktopAlertAwareExtension)
                {
                    desktopAlertAwareExtension.ShowMessage += DesktopAlertAwareExtensionOnShowMessage;
                    desktopAlertAwareExtension.ShowWarning += DesktopAlertAwareExtensionOnShowWarning;
                }

                if (panel is IExecutionModeSupport executionModePanel)
                {
                    executionModePanel.SetExecutionMode(_executionMode);
                }

                if (panel is IShowDiagramPanel <Form> showDiagram)
                {
                    if (showDiagram.Diagram == null)
                    {
                        var diagram = _model?.AddDiagram();
                        if (diagram != null)
                        {
                            result.Text = diagram.Name;
                            ((INotifyPropertyChanged)diagram).PropertyChanged += OnDiagramNameChanged;

                            showDiagram.SetDiagram(diagram);

                            if (factory is IMainRibbonExtension mainRibbonExtension)
                            {
                                AddChildButton(mainRibbonExtension, action);
                            }
                        }

                        result.FormId = GetFormId(factory, diagram);
                    }
                    else
                    {
                        result.Text = showDiagram.Diagram.Name;
                        ((INotifyPropertyChanged)showDiagram.Diagram).PropertyChanged += OnDiagramNameChanged;

                        if (factory is IMainRibbonExtension mainRibbonExtension &&
                            AddChildButton(mainRibbonExtension, action) != null)
                        {
                            MinimalLoadMainRibbonExtension(mainRibbonExtension);
                        }

                        result.FormId = GetFormId(factory, showDiagram.Diagram);
                    }
                }

                if (panel is IShowThreatModelPanel <Form> showThreatModel)
                {
                    result.Text = action.Label;
                    showThreatModel.SetThreatModel(_model);

                    if (factory is IMainRibbonExtension mainRibbonExtension)
                    {
                        AddChildButton(mainRibbonExtension, action);
                    }
                }

                if (panel is IStaticPanel <Form> staticPanel)
                {
                    result.Text = action.Label;

                    if (factory is IMainRibbonExtension mainRibbonExtension)
                    {
                        AddChildButton(mainRibbonExtension, action);
                    }
                }

                if (panel is ICustomRibbonExtension ribbonExtension)
                {
                    result.InitializeRibbon(ribbonExtension, _mergeIndex);
                }
                else
                {
                    result.HideRibbon();
                }

                if (panel is IPanelOpenerExtension panelCreationRequiredExtension)
                {
                    panelCreationRequiredExtension.OpenPanel += CreatePanel;
                }

                result.Panel = panel;
                DisplayChild(result);
                control.Visible = true;
            }

            return(result);
        }
Ejemplo n.º 27
0
 public XYPlotPaneViewModel(IProjectViewModel project, IPanelFactory factory, TimePlotModel paneModel)
     : base(project, factory, paneModel)
 {
     project.PropertyChanged += ProjectVM_PropertyChanged;
 }
Ejemplo n.º 28
0
        public static IPanelFactory CreatePanelFactory(Type type)
        {
            IPanelFactory factory = (IPanelFactory)Activator.CreateInstance(type);

            return(factory);
        }