An add-in engine.
This class allows hosting several independent add-in engines in a single application domain. In general, applications use the AddinManager class to query and manage extensions. This class is static, so the API is easily accessible. However, some kind applications may need to use several isolated add-in engines, and in this case the AddinManager class can't be used, because it is bound to a single add-in engine. Those applications can instead create several instances of the AddinEngine class. Each add-in engine can be independently initialized with different add-in registries and extension models.
Inheritance: Mono.Addins.ExtensionContext
Exemplo n.º 1
0
 internal Condition(AddinEngine addinEngine, ExtensionNodeDescription element, BaseCondition parent) : base(parent)
 {
     this.addinEngine = addinEngine;
     typeId           = element.GetAttribute("id");
     addin            = element.GetAttribute(SourceAddinAttribute);
     node             = element;
 }
Exemplo n.º 2
0
 internal void SetData(AddinEngine addinEngine, string plugid, ExtensionNodeType nodeType, ModuleDescription module)
 {
     this.addinEngine = addinEngine;
     this.addinId     = plugid;
     this.nodeType    = nodeType;
     this.module      = module;
 }
Exemplo n.º 3
0
        internal AddinRegistry(AddinEngine engine, string registryPath, string startupDirectory, string addinsDir, string databaseDir)
        {
            basePath = Path.GetFullPath(Util.NormalizePath(registryPath));

            if (addinsDir != null)
            {
                addinsDir = Util.NormalizePath(addinsDir);
                if (Path.IsPathRooted(addinsDir))
                {
                    this.addinsDir = Path.GetFullPath(addinsDir);
                }
                else
                {
                    this.addinsDir = Path.GetFullPath(Path.Combine(basePath, addinsDir));
                }
            }
            else
            {
                this.addinsDir = Path.Combine(basePath, "addins");
            }

            if (databaseDir != null)
            {
                databaseDir = Util.NormalizePath(databaseDir);
                if (Path.IsPathRooted(databaseDir))
                {
                    this.databaseDir = Path.GetFullPath(databaseDir);
                }
                else
                {
                    this.databaseDir = Path.GetFullPath(Path.Combine(basePath, databaseDir));
                }
            }
            else
            {
                this.databaseDir = Path.GetFullPath(basePath);
            }

            // Look for add-ins in the hosts directory and in the default
            // addins directory
            addinDirs = new StringCollection();
            addinDirs.Add(DefaultAddinsFolder);

            // Initialize the database after all paths have been set
            database = new AddinDatabase(engine, this);

            // Get the domain corresponding to the startup folder
            if (startupDirectory != null && startupDirectory.Length > 0)
            {
                this.startupDirectory = Util.NormalizePath(startupDirectory);
                currentDomain         = database.GetFolderDomain(null, this.startupDirectory);
            }
            else
            {
                currentDomain = AddinDatabase.GlobalDomain;
            }
        }
Exemplo n.º 4
0
		public TreeNode (AddinEngine addinEngine, string id)
		{
			this.id = id;
			this.addinEngine = addinEngine;
				
			// Root node
			if (id.Length == 0)
				childrenLoaded = true;
		}
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the add-in engine.
        /// </summary>
        /// <param name='configDir'>
        /// Location of the add-in registry.
        /// </param>
        /// <param name='addinsDir'>
        /// Add-ins directory. If the path is relative, it is considered to be relative
        /// to the configDir directory.
        /// </param>
        /// <param name='databaseDir'>
        /// Location of the add-in database. If the path is relative, it is considered to be relative
        /// to the configDir directory.
        /// </param>
        /// <remarks>
        /// The add-in engine needs to be initialized before doing any add-in operation.
        /// Configuration information about the add-in registry will be stored in the
        /// provided location. The add-in engine will look for add-ins in the provided
        /// 'addinsDir' directory. Cached information about add-ins will be stored in
        /// the 'databaseDir' directory.
        ///
        /// When specifying a path, it is possible to use a special folder name as root.
        /// For example: [Personal]/.config/MyApp. In this case, [Personal] will be replaced
        /// by the location of the Environment.SpecialFolder.Personal folder. Any value
        /// of the Environment.SpecialFolder enumeration can be used (always between square
        /// brackets)
        /// </remarks>
        public static void Initialize(string configDir, string addinsDir, string databaseDir)
        {
            Assembly asm = Assembly.GetEntryAssembly();

            if (asm == null)
            {
                asm = Assembly.GetCallingAssembly();
            }
            AddinEngine.Initialize(asm, configDir, addinsDir, databaseDir);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes the add-in engine.
        /// </summary>
        /// <param name="configDir">
        /// Location of the add-in registry.
        /// </param>
        /// <remarks>
        /// The add-in engine needs to be initialized before doing any add-in operation.
        /// Configuration information about the add-in registry will be stored in the
        /// provided location. The add-in engine will look for add-ins in an 'addins'
        /// subdirectory of the provided directory.
        ///
        /// When specifying a path, it is possible to use a special folder name as root.
        /// For example: [Personal]/.config/MyApp. In this case, [Personal] will be replaced
        /// by the location of the Environment.SpecialFolder.Personal folder. Any value
        /// of the Environment.SpecialFolder enumeration can be used (always between square
        /// brackets)
        /// </remarks>
        public static void Initialize(string configDir)
        {
            Assembly asm = Assembly.GetEntryAssembly();

            if (asm == null)
            {
                asm = Assembly.GetCallingAssembly();
            }
            AddinEngine.Initialize(asm, null, configDir, null, null);
        }
Exemplo n.º 7
0
        public TreeNode(AddinEngine addinEngine, string id)
        {
            this.id          = id;
            this.addinEngine = addinEngine;

            // Root node
            if (id.Length == 0)
            {
                childrenLoaded = true;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes the add-in engine.
        /// </summary>
        /// <remarks>
        /// The add-in engine needs to be initialized before doing any add-in operation.
        /// When initialized with this method, it will look for add-ins in the global add-in registry.
        /// </remarks>
        public static void Initialize()
        {
            // Code not shared with the other Initialize since I need to get the calling assembly
            Assembly asm = Assembly.GetEntryAssembly();

            if (asm == null)
            {
                asm = Assembly.GetCallingAssembly();
            }
            AddinEngine.Initialize(asm, null, null, null, null);
        }
Exemplo n.º 9
0
 internal RuntimeAddin(AddinEngine addinEngine, RuntimeAddin parentAddin, ModuleDescription module)
 {
     this.addinEngine = addinEngine;
     this.parentAddin = parentAddin;
     this.module = module;
     id = parentAddin.id;
     baseDirectory = parentAddin.baseDirectory;
     privatePath = parentAddin.privatePath;
     ainfo = parentAddin.ainfo;
     localizer = parentAddin.localizer;
     module.RuntimeAddin = this;
 }
Exemplo n.º 10
0
 internal RuntimeAddin(AddinEngine addinEngine, RuntimeAddin parentAddin, ModuleDescription module)
 {
     this.addinEngine = addinEngine;
     this.parentAddin = parentAddin;
     this.module      = module;
     id                  = parentAddin.id;
     baseDirectory       = parentAddin.baseDirectory;
     privatePath         = parentAddin.privatePath;
     ainfo               = parentAddin.ainfo;
     localizer           = parentAddin.localizer;
     module.RuntimeAddin = this;
 }
Exemplo n.º 11
0
        internal static AddinRegistry GetGlobalRegistry(AddinEngine engine, string startupDirectory)
        {
            AddinRegistry reg = new AddinRegistry(engine, GlobalRegistryPath, startupDirectory, null, null);
            string        baseDir;

            if (Util.IsWindows)
            {
                baseDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
            }
            else
            {
                baseDir = "/etc";
            }

            reg.GlobalAddinDirectories.Add(Path.Combine(baseDir, "mono.addins"));
            return(reg);
        }
Exemplo n.º 12
0
        internal AddinRegistry(AddinEngine engine, string registryPath, string startupDirectory)
        {
            basePath = Util.GetFullPath (Util.NormalizePath (registryPath));
            database = new AddinDatabase (engine, this);

            // Look for add-ins in the hosts directory and in the default
            // addins directory
            addinDirs = new StringCollection ();
            addinDirs.Add (DefaultAddinsFolder);

            // Get the domain corresponding to the startup folder
            if (startupDirectory != null && startupDirectory.Length > 0) {
                this.startupDirectory = Util.NormalizePath (startupDirectory);
                currentDomain = database.GetFolderDomain (null, this.startupDirectory);
            } else
                currentDomain = AddinDatabase.GlobalDomain;
        }
Exemplo n.º 13
0
 /// <summary>
 /// Gets extension nodes for a type extension point
 /// </summary>
 /// <param name="instanceType">
 /// Type defining the extension point
 /// </param>
 /// <returns>
 /// A list of nodes
 /// </returns>
 /// <remarks>
 /// This method returns all nodes registered for the provided type.
 /// It will throw a InvalidOperationException if the type of one of
 /// the registered nodes is not assignable to the specified node type argument.
 /// </remarks>
 public static ExtensionNodeList <T> GetExtensionNodes <T> (Type instanceType) where T : ExtensionNode
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionNodes <T> (instanceType));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Gets extension objects registered for a type extension point.
 /// </summary>
 /// <param name="instanceType">
 /// Type defining the extension point
 /// </param>
 /// <param name="reuseCachedInstance">
 /// When set to True, it will return instances created in previous calls.
 /// </param>
 /// <returns>
 /// A list of extension objects.
 /// </returns>
 public static object[] GetExtensionObjects(Type instanceType, bool reuseCachedInstance)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionObjects(instanceType, reuseCachedInstance));
 }
Exemplo n.º 15
0
		internal AddinRegistry (AddinEngine engine, string registryPath, string startupDirectory, string addinsDir, string databaseDir)
		{
			basePath = Path.GetFullPath (Util.NormalizePath (registryPath));
			
			if (addinsDir != null) {
				addinsDir = Util.NormalizePath (addinsDir);
				if (Path.IsPathRooted (addinsDir))
					this.addinsDir = Path.GetFullPath (addinsDir);
				else
					this.addinsDir = Path.GetFullPath (Path.Combine (basePath, addinsDir));
			} else
				this.addinsDir = Path.Combine (basePath, "addins");
			
			if (databaseDir != null) {
				databaseDir = Util.NormalizePath (databaseDir);
				if (Path.IsPathRooted (databaseDir))
					this.databaseDir = Path.GetFullPath (databaseDir);
				else
					this.databaseDir = Path.GetFullPath (Path.Combine (basePath, databaseDir));
			}
			else
				this.databaseDir = Path.GetFullPath (basePath);

			// Look for add-ins in the hosts directory and in the default
			// addins directory
			addinDirs = new StringCollection ();
			addinDirs.Add (DefaultAddinsFolder);
			
			// Initialize the database after all paths have been set
			database = new AddinDatabase (engine, this);
			
			// Get the domain corresponding to the startup folder
			if (startupDirectory != null && startupDirectory.Length > 0) {
				this.startupDirectory = Util.NormalizePath (startupDirectory);
				currentDomain = database.GetFolderDomain (null, this.startupDirectory);
			} else
				currentDomain = AddinDatabase.GlobalDomain;
		}
Exemplo n.º 16
0
 /// <summary>
 /// Initializes the add-in engine.
 /// </summary>
 /// <param name="startupAsm">The startup assembly</param>
 /// <param name="configDir">
 /// Location of the add-in registry.
 /// </param>
 /// <remarks>
 /// The add-in engine needs to be initialized before doing any add-in operation.
 /// Configuration information about the add-in registry will be stored in the
 /// provided location. The add-in engine will look for add-ins in an 'addins'
 /// subdirectory of the provided directory.
 ///
 /// When specifying a path, it is possible to use a special folder name as root.
 /// For example: [Personal]/.config/MyApp. In this case, [Personal] will be replaced
 /// by the location of the Environment.SpecialFolder.Personal folder. Any value
 /// of the Environment.SpecialFolder enumeration can be used (always between square
 /// brackets)
 /// </remarks>
 public static void Initialize(Assembly startupAsm, string configDir)
 {
     AddinEngine.Initialize(startupAsm, configDir, null, null);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Unregister a listener of extension node changes.
 /// </summary>
 /// <param name="path">
 /// Path of the node.
 /// </param>
 /// <param name="handler">
 /// A handler method.
 /// </param>
 /// <remarks>
 /// This method unregisters a delegate from the node change event of a path.
 /// </remarks>
 public static void RemoveExtensionNodeHandler(string path, ExtensionNodeEventHandler handler)
 {
     AddinEngine.CheckInitialized();
     AddinEngine.RemoveExtensionNodeHandler(path, handler);
 }
Exemplo n.º 18
0
		internal Condition (AddinEngine addinEngine, ExtensionNodeDescription element, BaseCondition parent): base (parent)
		{
			this.addinEngine = addinEngine;
			typeId = element.GetAttribute ("id");
			addin = element.GetAttribute (SourceAddinAttribute);
			node = element;
		}
Exemplo n.º 19
0
 /// <summary>
 /// Forces the loading of an add-in.
 /// </summary>
 /// <param name="statusMonitor">
 /// Status monitor to keep track of the loading process.
 /// </param>
 /// <param name="id">
 /// Full identifier of the add-in to load.
 /// </param>
 /// <remarks>
 /// This method loads all assemblies that belong to an add-in in memory.
 /// All add-ins on which the specified add-in depends will also be loaded.
 /// Notice that in general add-ins don't need to be explicitly loaded using
 /// this method, since the add-in engine will load them on demand.
 /// </remarks>
 public static void LoadAddin(IProgressStatus statusMonitor, string id)
 {
     AddinEngine.LoadAddin(statusMonitor, id);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Gets extension objects registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.
 /// </param>
 /// <param name="arrayElementType">
 /// Type of the return array elements.
 /// </param>
 /// <param name="reuseCachedInstance">
 /// When set to True, it will return instances created in previous calls.
 /// </param>
 /// <returns>
 /// An array of objects registered in the path.
 /// </returns>
 /// <remarks>
 /// This method can only be used if all nodes in the provided extension path
 /// are of type Mono.Addins.TypeExtensionNode. The returned array is composed
 /// by all objects created by calling the TypeExtensionNode.CreateInstance()
 /// method for each node (or TypeExtensionNode.GetInstance() if
 /// reuseCachedInstance is set to true).
 ///
 /// An InvalidOperationException exception is thrown if one of the found
 /// objects is not a subclass of the provided type.
 /// </remarks>
 public static object[] GetExtensionObjects(string path, Type arrayElementType, bool reuseCachedInstance)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionObjects(path, arrayElementType, reuseCachedInstance));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Checks if the provided add-ins are installed, and requests the installation of those
 /// which aren't.
 /// </summary>
 /// <param name="message">
 /// Message to show to the user when new add-ins have to be installed.
 /// </param>
 /// <param name="addinIds">
 /// List of IDs of the add-ins to be checked.
 /// </param>
 /// <remarks>
 /// This method checks if the specified add-ins are installed.
 /// If some of the add-ins are not installed, it will use
 /// the installer assigned to the DefaultAddinInstaller property
 /// to install them. If the installation fails, or if DefaultAddinInstaller
 /// is not set, an exception will be thrown.
 /// </remarks>
 public static void CheckInstalled(string message, params string[] addinIds)
 {
     AddinEngine.CheckInstalled(message, addinIds);
 }
Exemplo n.º 22
0
 internal RuntimeAddin(AddinEngine addinEngine)
 {
     this.addinEngine = addinEngine;
 }
Exemplo n.º 23
0
 /// <summary>
 /// Sets the default localizer to be used for this add-in engine
 /// </summary>
 /// <param name="localizer">
 /// The add-in localizer
 /// </param>
 public static void InitializeDefaultLocalizer(IAddinLocalizer localizer)
 {
     AddinEngine.InitializeDefaultLocalizer(localizer);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Finalizes an add-in engine.
 /// </summary>
 public static void Shutdown()
 {
     AddinEngine.Shutdown();
 }
Exemplo n.º 25
0
 public ExtensionTree(AddinEngine addinEngine, ExtensionContext context)
     : base(addinEngine, "")
 {
     this.context = context;
 }
Exemplo n.º 26
0
 public ExtensionTree(AddinEngine addinEngine, ExtensionContext context) : base(addinEngine, "")
 {
     this.context = context;
 }
Exemplo n.º 27
0
 /// <summary>
 /// Creates a new extension context.
 /// </summary>
 /// <returns>
 /// The new extension context.
 /// </returns>
 /// <remarks>
 /// Extension contexts can be used to query the extension model using particular condition values.
 /// </remarks>
 public static ExtensionContext CreateExtensionContext()
 {
     return(AddinEngine.CreateExtensionContext());
 }
Exemplo n.º 28
0
 /// <summary>
 /// Gets extension objects registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.
 /// </param>
 /// <returns>
 /// An array of objects registered in the path.
 /// </returns>
 /// <remarks>
 /// This method can only be used if all nodes in the provided extension path
 /// are of type Mono.Addins.TypeExtensionNode. The returned array is composed
 /// by all objects created by calling the TypeExtensionNode.CreateInstance()
 /// method for each node.
 ///
 /// An InvalidOperationException exception is thrown if one of the found
 /// objects is not a subclass of the provided type.
 /// </remarks>
 public static T[] GetExtensionObjects <T> (string path)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionObjects <T> (path));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Gets extension nodes registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.>
 /// </param>
 /// <returns>
 /// All nodes registered in the provided path.
 /// </returns>
 public static ExtensionNodeList GetExtensionNodes(string path)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionNodes(path));
 }
Exemplo n.º 30
0
 /// <summary>
 /// Gets extension objects registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.
 /// </param>
 /// <param name="reuseCachedInstance">
 /// When set to True, it will return instances created in previous calls.
 /// </param>
 /// <returns>
 /// An array of objects registered in the path.
 /// </returns>
 /// <remarks>
 /// This method can only be used if all nodes in the provided extension path
 /// are of type Mono.Addins.TypeExtensionNode. The returned array is composed
 /// by all objects created by calling the TypeExtensionNode.CreateInstance()
 /// method for each node (or TypeExtensionNode.GetInstance() if
 /// reuseCachedInstance is set to true).
 ///
 /// An InvalidOperationException exception is thrown if one of the found
 /// objects is not a subclass of the provided type.
 /// </remarks>
 public static T[] GetExtensionObjects <T> (string path, bool reuseCachedInstance)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionObjects <T> (path, reuseCachedInstance));
 }
Exemplo n.º 31
0
 /// <summary>
 /// Gets extension nodes registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.
 /// </param>
 /// <param name="expectedNodeType">
 /// Expected node type.
 /// </param>
 /// <returns>
 /// A list of nodes
 /// </returns>
 /// <remarks>
 /// This method returns all nodes registered under the provided path.
 /// It will throw a InvalidOperationException if the type of one of
 /// the registered nodes is not assignable to the provided type.
 /// </remarks>
 public static ExtensionNodeList GetExtensionNodes(string path, Type expectedNodeType)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionNodes(path, expectedNodeType));
 }
Exemplo n.º 32
0
 /// <summary>
 /// Unregister a listener of extension node changes.
 /// </summary>
 /// <param name="instanceType">
 /// Type defining the extension point
 /// </param>
 /// <param name="handler">
 /// A handler method.
 /// </param>
 public static void RemoveExtensionNodeHandler(Type instanceType, ExtensionNodeEventHandler handler)
 {
     AddinEngine.CheckInitialized();
     AddinEngine.RemoveExtensionNodeHandler(instanceType, handler);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Gets extension nodes registered in a path.
 /// </summary>
 /// <param name="path">
 /// An extension path.
 /// </param>
 /// <returns>
 /// A list of nodes
 /// </returns>
 /// <remarks>
 /// This method returns all nodes registered under the provided path.
 /// It will throw a InvalidOperationException if the type of one of
 /// the registered nodes is not assignable to the provided type.
 /// </remarks>
 public static ExtensionNodeList <T> GetExtensionNodes <T> (string path) where T : ExtensionNode
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionNodes <T> (path));
 }
Exemplo n.º 34
0
 internal RuntimeAddin(AddinEngine addinEngine)
 {
     this.addinEngine = addinEngine;
 }
Exemplo n.º 35
0
 /// <summary>
 /// Gets extension nodes for a type extension point
 /// </summary>
 /// <param name="instanceType">
 /// Type defining the extension point
 /// </param>
 /// <param name="expectedNodeType">
 /// Expected extension node type
 /// </param>
 /// <returns>
 /// A list of nodes
 /// </returns>
 /// <remarks>
 /// This method returns all nodes registered for the provided type.
 /// It will throw a InvalidOperationException if the type of one of
 /// the registered nodes is not assignable to the provided node type.
 /// </remarks>
 public static ExtensionNodeList GetExtensionNodes(Type instanceType, Type expectedNodeType)
 {
     AddinEngine.CheckInitialized();
     return(AddinEngine.GetExtensionNodes(instanceType, expectedNodeType));
 }
Exemplo n.º 36
0
 /// <summary>
 /// Checks if an add-in has been loaded.
 /// </summary>
 /// <param name="id">
 /// Full identifier of the add-in.
 /// </param>
 /// <returns>
 /// True if the add-in is loaded.
 /// </returns>
 public static bool IsAddinLoaded(string id)
 {
     return(AddinEngine.IsAddinLoaded(id));
 }
Exemplo n.º 37
0
        internal static AddinRegistry GetGlobalRegistry(AddinEngine engine, string startupDirectory)
        {
            AddinRegistry reg = new AddinRegistry (engine, GlobalRegistryPath, startupDirectory);
            string baseDir;
            if (Util.IsWindows)
                baseDir = Environment.GetFolderPath (Environment.SpecialFolder.CommonProgramFiles);
            else
                baseDir = "/etc";

            reg.GlobalAddinDirectories.Add (Path.Combine (baseDir, "mono.addins"));
            return reg;
        }