Ejemplo n.º 1
0
        /// <summary>
        /// Load Plugin if Enabled
        /// </summary>
        /// <param name="config"></param>
        public void Plugin_Load(PluginConfiguration config)
        {
            ///Check if Enabled
            if (config.Enabled)
            {
                var plugin = Plugins.Find(x =>
                    x.Title == config.Name &&
                    x.ParentPlugin == config.Parent &&
                    x.ParentPluginCategory == config.Category
                    );
                if (plugin != null)
                {
                    try
                    {
                        // Assign event handlers
                        plugin.SendData += Plugin_SendData;

                        // Process SubPlugins
                        plugin.SubCategories = config.SubCategories;
                        Plugin_LoadSubPlugins(config);

                        // Initialize plugin
                        plugin.Initialize();

                        // If set to OpenOnStartUp then Open new Tab
                        if (plugin.OpenOnStartUp) AddTab(plugin);

                        // Create an Options page (if exists)
                        Plugin_CreateOptionsPage(plugin);
                    }
                    catch (Exception ex)
                    {
                        var mData = new Controls.Message_Center.MessageData();
                        mData.Title = "Plugin Error";
                        mData.Text = "Error during plugin load";
                        mData.AdditionalInfo = ex.Message;
                        mData.Type = TrakHound.API.Messages.MessageType.TRAKHOUND_ALERT;

                        messageCenter.AddMessage(mData);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add the 'sub' plugins to the PluginConfiguration
        /// </summary>
        /// <param name="config"></param>
        private void Plugin_LoadSubPlugins(PluginConfiguration config)
        {
            var plugin = Plugins.Find(x =>
                x.Title == config.Name &&
                x.ParentPlugin == config.Parent &&
                x.ParentPluginCategory == config.Category
                );
            if (plugin != null)
            {
                plugin.Plugins = new List<IClientPlugin>();

                if (config.SubCategories != null)
                {
                    foreach (PluginConfigurationCategory subcategory in config.SubCategories)
                    {
                        foreach (PluginConfiguration subConfig in subcategory.PluginConfigurations)
                        {
                            var subplugin = Plugins.Find(x =>
                                x.Title == subConfig.Name &&
                                x.ParentPlugin == subConfig.Parent &&
                                x.ParentPluginCategory == subConfig.Category
                                );
                            if (subplugin != null)
                            {
                                Plugin_LoadSubPlugins(subConfig);

                                plugin.Plugins.Add(subplugin);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private void config_EnabledChanged(PluginConfiguration sender)
 {
     Properties.Settings.Default.Plugin_Configurations = PluginConfigurations;
     Properties.Settings.Default.Save();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get a list of PluginConfigurations
        /// </summary>
        /// <param name="plugins"></param>
        /// <returns></returns>
        private List<PluginConfiguration> GetPluginConfigurations(List<IClientPlugin> plugins)
        {
            var result = new List<PluginConfiguration>();

            List<PluginConfiguration> configs = Properties.Settings.Default.Plugin_Configurations;

            // Get list (not actual setting)
            if (configs != null) configs = configs.ToList();
            else configs = new List<PluginConfiguration>();

            foreach (var plugin in plugins)
            {
                // See if config is already created
                var config = FindPluginConfiguration(plugin, configs);
                if (config == null)
                {
                    config = new PluginConfiguration();
                    config.Name = plugin.Title;
                    config.Description = plugin.Description;
                    config.Enabled = true;
                }

                config.SubCategories = plugin.SubCategories;

                config.EnabledChanged += config_EnabledChanged;

                config.Parent = plugin.ParentPlugin;
                config.Category = plugin.ParentPluginCategory;

                if (FindPluginConfiguration(plugin, result) == null) result.Add(config);
            }

            result = ProcessPluginConfigurations(result);

            return result;
        }
        private void SelectPage(ListButton lb)
        {
            foreach (var olb in Pages)
            {
                if (olb == lb) olb.IsSelected = true;
                else olb.IsSelected = false;
            }

            foreach (var category in SubCategories)
            {
                var config = category.PluginConfigurations.Find(x => GetPluginName(x.Name) == GetPluginName(lb.Text));
                if (config != null)
                {
                    currentPage = config;
                    break;
                }
            }

            // Set Page as PageContent
            PageContent = lb.DataObject as UserControl;

            // Save selected page
            int index = Pages.ToList().FindIndex(x => x == lb);
            if (index >= 0)
            {
                Properties.Settings.Default.DashboardSelectedPage = index;
                Properties.Settings.Default.Save();
            }

            // Load Saved Zoom Level
            ZoomLevel = MainWindow.LoadSavedPageZoomValue(lb.DataObject as IPage);
        }
 void config_EnabledChanged(PluginConfiguration config)
 {
     if (config.Enabled) Plugins_Load(config);
     else Plugins_Unload(config);
 }
        public void Plugins_Unload(PluginConfiguration config)
        {
            if (config != null)
            {
                if (!config.Enabled)
                {
                    ListButton lb = Pages.ToList().Find(x => GetPluginName(x.Text) == GetPluginName(config.Name));
                    if (lb != null)
                    {
                        Pages.Remove(lb);
                    }

                    if (config == currentPage) PageContent = null;

                    if (enabledPlugins.Contains(config)) enabledPlugins.Remove(config);
                }
            }
        }
        public void Plugins_Load(PluginConfiguration config)
        {
            if (Plugins != null)
            {
                if (!enabledPlugins.Contains(config))
                {
                    IClientPlugin plugin = Plugins.Find(x => x.Title.ToUpper() == config.Name.ToUpper());
                    if (plugin != null)
                    {
                        try
                        {
                            plugin.SubCategories = config.SubCategories;
                            plugin.SendData += Plugin_SendData;

                            plugin.Initialize();
                        }
                        catch { }

                        var bt = new ListButton();
                        if (plugin.Image != null) bt.Image = new BitmapImage(plugin.Image);
                        bt.Text = plugin.Title;
                        bt.Selected += PageSelected;
                        bt.DataObject = plugin;
                        Pages.Add(bt);

                        SortPageList();

                        enabledPlugins.Add(config);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public PluginConfiguration Copy()
        {
            var result = new PluginConfiguration();

            result.Name = Name;
            result.Description = Description;
            result.Enabled = Enabled;
            result.Parent = Parent;
            result.SubCategories = SubCategories.ToList();

            return result;
        }