Ejemplo n.º 1
0
        /// <summary>
        /// Adds a plugin into the managed collection of plugin models.
        /// </summary>
        /// <param name="pluginModel"></param>
        /// <returns></returns>
        public static bool AddPluginModel(PluginModelBase pluginModel)
        {
            try
            {
                if (pluginModel != null)
                {
                    PluginManager.mPluginModelColl.Add(pluginModel.Name, pluginModel);
                    return(true);
                }

                return(false);
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        private static void loadPluginAssembly(string assemblyFile,
                                               IMiniUMLDocument windowViewModel,
                                               IMessageBoxService msgBox)
        {
            Assembly assembly;

            try
            {
                // Load the plugin assembly.
                assembly = Assembly.LoadFrom(assemblyFile);

                // Add an instance of each PluginModel found in the assembly to the plugin collection
                // and merge its resources into the plugin resource dictionary.
                foreach (Type type in assembly.GetTypes())
                {
                    if (!type.IsAbstract && typeof(PluginModelBase).IsAssignableFrom(type))
                    {
                        try
                        {
                            // Create PluginModel instance.
                            PluginModelBase pluginModel = Activator.CreateInstance(type, windowViewModel) as PluginModelBase;

                            // Plugin names must be unique
                            foreach (PluginModelBase p in PluginManager.PluginModels)
                            {
                                if (p.Name == pluginModel.Name)
                                {
                                    throw new Exception(Edi.Util.Local.Strings.STR_MSG_UML_PLugin_Duplicate);
                                }
                            }

                            // Get the shared resources from the plugin.
                            ResourceDictionary sharedResources = pluginModel.Resources;

                            // If we got any resources, merge them into our plugin resource dictionary.
                            if (sharedResources != null)
                            {
                                PluginManager.PluginResources.MergedDictionaries.Add(sharedResources);
                            }

                            // Add the plugin into the collection of plugins
                            PluginManager.AddPluginModel(pluginModel);
                        }
                        catch (Exception ex)
                        {
                            msgBox.Show(ex,
                                        string.Format(Edi.Util.Local.Strings.STR_MSG_ErrorLoadingPlugin, assemblyFile),
                                        Edi.Util.Local.Strings.STR_MSG_PluginNotLoaded,
                                        MsgBoxButtons.OK, MsgBoxImage.Error);

                            ////ExceptionManager.Register(ex,
                            ////    "Plugin not loaded.",
                            ////    "An error occured while initializing a plugin found in assembly " + assemblyFile + ".");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msgBox.Show(ex,
                            string.Format(Edi.Util.Local.Strings.STR_MSG_ErrorWhileLoadingPlugin, assemblyFile),
                            Edi.Util.Local.Strings.STR_MSG_PluginNotLoaded,
                            MsgBoxButtons.OK, MsgBoxImage.Error);

                return;
            }
        }