/// <summary>
        /// Selects a template from the Tab.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="container">The container.</param>
        /// <returns></returns>
        public override DataTemplate SelectTemplate(object model, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
            var tabModel             = model as ITabModel;

            ITabPlugin plugin =
                MarbleController.TabTemplateSelectorPlugins.FirstOrDefault(
                    p => p.TabModel.Keyword == tabModel.Keyword);

            if (plugin != null)
            {
                try
                {
                    DataTemplate template = plugin.SelectTemplate(tabModel, element);
                    if (template != null)
                    {
                        return(template);
                    }
                }

                #region Exception Handling

                catch (Exception ex)
                {
                    TraceSourceMonitorHelper.Error("Fail to select template for tab, plugins: {0}, \r\n\terror = {1}",
                                                   plugin.TabModel.Keyword, ex);
                    return(null);
                }

                #endregion Exception Handling
            }
            return(element.FindResource("DiagramsTemplate") as DataTemplate);
        }
Example #2
0
        /// <summary>
        /// Stops the plugin and removes all its functionality available in the bot.
        /// Changes the status from <see cref="PluginStatus.Active"/> to <see cref="PluginStatus.Ready"/> when successful or <see cref="PluginStatus.Error"/> otherwise.
        /// </summary>
        public void Stop()
        {
            if (Status != PluginStatus.Active)
            {
                return;
            }

            switch (corePluginType)
            {
            case PluginType.None:
                break;

            case PluginType.Plugin:
                mainBot.CommandManager.UnregisterCollection(this);
                mainBot.RightsManager.UnregisterRights(ExposedRights);
                ExposedCommands = null;
                pluginObject.Dispose();
                pluginObject = null;
                break;

            case PluginType.Factory:
                mainBot.FactoryManager.RemoveFactory(factoryObject);
                break;

            default:
                throw Util.UnhandledDefault(corePluginType);
            }

            Status = PluginStatus.Ready;
        }
Example #3
0
        /// <summary>
        /// Starts the plugin to have all its functionality available in the bot.
        /// This call requires this plugin to be in the <see cref="PluginStatus.Ready"/> state.
        /// Changes the status to <see cref="PluginStatus.Active"/> when successful or <see cref="PluginStatus.Error"/> otherwise.
        /// </summary>
        public void Start()
        {
            if (Status != PluginStatus.Ready)
            {
                throw new InvalidOperationException("This plugin has not yet been prepared");
            }

            try
            {
                switch (corePluginType)
                {
                case PluginType.None:
                    break;

                case PluginType.Plugin:
                    pluginObject = (ITabPlugin)Activator.CreateInstance(coreType);
                    var comBuilds = CommandManager.GetCommandMethods(pluginObject);
                    ExposedCommands = CommandManager.GetBotCommands(comBuilds).ToList();
                    mainBot.RightsManager.RegisterRights(ExposedRights);
                    mainBot.CommandManager.RegisterCollection(this);
                    pluginObject.Initialize(mainBot);
                    break;

                case PluginType.Factory:
                    factoryObject = (IFactory)Activator.CreateInstance(coreType);
                    mainBot.FactoryManager.AddFactory(factoryObject);
                    break;

                default:
                    throw Util.UnhandledDefault(corePluginType);
                }
            }
            catch (MissingMethodException mmex)
            {
                Log.Write(Log.Level.Error, "Plugins and Factories needs a parameterless constructor ({0}).", mmex.Message);
                Status = PluginStatus.Error;
                return;
            }

            Status = PluginStatus.Active;
        }
 public LoadedTabPlugin(ITabPlugin tabPlugin, TabLoadContext loadContext)
 {
     TabPlugin = tabPlugin;
     Context   = loadContext;
 }
Example #5
0
 public PluginObjects(ITabPlugin plugin, PluginCommandBag bag, CommandManager commandManager)
 {
     Bag            = bag;
     Plugin         = plugin;
     CommandManager = commandManager;
 }
Example #6
0
 public LoadedTabPlugin(ITabPlugin tabPlugin, TabLoadContext loadContext)
 {
     TabPlugin = tabPlugin;
     Context = loadContext;
 }