Exemplo n.º 1
0
 /// <summary>
 /// Removes the first occurrence of a specified <see cref="AvailablePlugin"/>
 /// from the collection.
 /// </summary>
 /// <param name="plugin">
 /// The <see cref="AvailablePlugin"/> to remove from the collection.
 /// </param>
 public void Remove(AvailablePlugin plugin)
 {
     if (base.List.Contains(plugin))
     {
         base.List.Remove(plugin);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the plugin's configuration dialog.
 /// </summary>
 /// <param name="plugin">
 /// The plugin to get the configuration from.
 /// </param>
 /// <returns>
 /// A dialog form containing the settings read from the specified
 /// plugin's configuration.
 /// </returns>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="plugin"/> cannot be null.
 /// </exception>
 public FormSettingsDialog GetConfigurationDialog(AvailablePlugin plugin)
 {
     if (plugin == null)
     {
         throw new ArgumentNullException("plugin");
     }
     return(new FormSettingsDialog(plugin));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Inserts a <see cref="AvailablePlugin"/> into the collection at the
 /// specified index.
 /// </summary>
 /// <param name="index">
 /// The zero-based index at which the <see cref="AvailablePlugin"/>
 /// should be inserted.
 /// </param>
 /// <param name="plugin">
 /// The <see cref="AvailablePlugin"/> to insert into the collection.
 /// </param>
 /// <exception cref="DuplicatePluginInstanceException">
 /// An instance of the specified plugin already exists in the collection.
 /// </exception>
 public void Insert(Int32 index, AvailablePlugin plugin)
 {
     if (base.List.Contains(plugin))
     {
         throw new DuplicatePluginInstanceException(plugin.Instance);
     }
     base.List.Insert(index, plugin);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Adds the specified <see cref="AvailablePlugin"/> to the collection
 /// if it is not already in the collection.
 /// </summary>
 /// <param name="plugin">
 /// The plugin to add to the collection.
 /// </param>
 /// <returns>
 /// If successful, the zero-based index position into which the plugin
 /// was added; Otherwise, -1.
 /// </returns>
 public Int32 Add(AvailablePlugin plugin)
 {
     if (!base.List.Contains(plugin))
     {
         return(base.List.Add(plugin));
     }
     return(-1);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <b>CyrusBuilt.CyNetTools.Plugins.FormSettingsDialog</b>
 /// class with the plugin to load the configuration from.
 /// </summary>
 /// <param name="plugin">
 /// The plugin to load the configuration from.
 /// </param>
 public FormSettingsDialog(AvailablePlugin plugin)
 {
     this.InitializeComponent();
     if (plugin != null)
     {
         this._name   = plugin.Instance.Name;
         this._config = plugin.Instance.GetConfiguration();
         Assembly asm = Assembly.ReflectionOnlyLoadFrom(plugin.AssemblyPath);
         this._asmName = asm.GetName().Name;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Finds a plugin in the available Plugins.
        /// </summary>
        /// <param name="nameOrPath">
        /// The name or File path of the plugin to find.
        /// </param>
        /// <returns>
        /// Available Plugin, or null if the plugin is not found.
        /// </returns>
        public AvailablePlugin Find(String nameOrPath)
        {
            AvailablePlugin found = null;

            foreach (AvailablePlugin ap in this)
            {
                if ((ap.Instance.Name.Equals(nameOrPath)) || (ap.AssemblyPath.Equals(nameOrPath)))
                {
                    found = ap;
                    break;
                }
            }
            return(found);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Compares this instance to the specified plugin to see if they are
        /// equal.
        /// </summary>
        /// <param name="plugin">
        /// The plugin to compare to.
        /// </param>
        /// <returns>
        /// true if the two are equal; Otherwise, false.
        /// </returns>
        public Boolean Equals(AvailablePlugin plugin)
        {
            if (plugin == null)
            {
                return(false);
            }

            if ((Object)plugin == null)
            {
                return(false);
            }

            return((this._assemblyPath == plugin.AssemblyPath) &&
                   (this._pluginInstance == plugin.Instance));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Loads the specified plugin and adds it to the managed plugin
        /// collection.
        /// </summary>
        /// <param name="file">
        /// The assembly (*.dll file) that is the plugin.
        /// </param>
        /// <exception cref="ObjectDisposedException">
        /// This instance has been disposed.
        /// </exception>
        private void AddPlugin(FileInfo file)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException("PluginManager");
            }

            if ((file == null) || (!file.Exists))
            {
                return;
            }

            Type            typeInterface  = null;
            IPlugin         instance       = null;
            AvailablePlugin newPlugin      = null;
            var             pluginAssembly = Assembly.LoadFrom(file.FullName);

            foreach (var pluginType in pluginAssembly.GetTypes())
            {
                if ((pluginType.IsPublic) && (!pluginType.IsAbstract))
                {
                    typeInterface = pluginType.GetInterface("CyrusBuilt.CyNetTools.Plugins.IPlugin", true);
                    if (typeInterface != null)
                    {
                        // Load the assembly instance if it is a valid plugin.
                        this.OnPluginFound(new FoundPluginEventArgs(file.FullName));
                        instance = (IPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));

                        // Initialize the plugin and add it to the managed collection.
                        newPlugin = new AvailablePlugin(instance, file.FullName);
                        newPlugin.Instance.Host = this;
                        newPlugin.Instance.Initialize();
                        this._plugins.Add(newPlugin);
                        this.OnPluginLoaded(new PluginLoadedEventArgs(instance.Name, instance.Version));
                    }
                }
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Determines the index of a specific <see cref="AvailablePlugin"/> in
 /// the collection.
 /// </summary>
 /// <param name="plugin">
 /// The <see cref="AvailablePlugin"/> to locate in the collection.
 /// </param>
 /// <returns>
 /// The index of the <see cref="AvailablePlugin"/> if found in the
 /// collection; Otherwise, -1.
 /// </returns>
 public Int32 IndexOf(AvailablePlugin plugin)
 {
     return(base.List.IndexOf(plugin));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Determines whether or not the collection contains a specific
 /// <see cref="AvailablePlugin"/>.
 /// </summary>
 /// <param name="plugin">
 /// The <see cref="AvailablePlugin"/> to locate in the collection.
 /// </param>
 /// <returns>
 /// true if the <see cref="AvailablePlugin"/> is found in the collection;
 /// Otherwise, false.
 /// </returns>
 public Boolean Contains(AvailablePlugin plugin)
 {
     return(base.List.Contains(plugin));
 }