Example #1
0
        protected override PluginInfoList OnProbe(string pluginFolderPath, SearchOption scanDeapth)
        {
            PluginInfoList list = new PluginInfoList();

            string[] exes = Directory.GetFiles(pluginFolderPath, "*.exe", scanDeapth);
            string[] dlls = Directory.GetFiles(pluginFolderPath, "*.dll", scanDeapth);
            string[] pys  = Directory.GetFiles(pluginFolderPath, "*.py", scanDeapth);

            List <string> files = new List <string>();

            files.AddRange(exes);
            files.AddRange(dlls);
            files.AddRange(pys);

            foreach (string file in files)
            {
                try
                {
                    PluginInfo info = this.OnGetInfo(file);

                    if (info != null)
                    {
                        list.Add(info);
                    }
                }
                catch (Exception) { }
            }

            return(list);
        }
Example #2
0
        /// <summary>
        /// Add singleton of "instanceType" into info array for "pluginType"
        /// </summary>
        /// <param name="instanceType"></param>
        /// <param name="pluginType"></param>
        private void AddPluginImplementation(Type instanceType, Type pluginType)
        {
            object         singleton      = GetSingleton(instanceType);
            PluginInfoList pluginInfoList = this.GetPluginInfoList(pluginType, true);

            pluginInfoList.AddImplementation(instanceType, singleton);
        }
        protected PluginLoaderBase()
        {
            this.IsPluginLoaded = false;
            this.EventsEnabled = true;

            _currentInfoList = new PluginInfoList();
            this.AssemblyResolutionPaths = new List<string>();

            this.ShadowCopyEnabled = false;
            this.UseDefaultExecutionValidation = true;
        }
        protected PluginLoaderBase()
        {
            this.IsPluginLoaded = false;
            this.EventsEnabled  = true;

            _currentInfoList             = new PluginInfoList();
            this.AssemblyResolutionPaths = new List <string>();

            this.ShadowCopyEnabled             = false;
            this.UseDefaultExecutionValidation = true;
        }
Example #5
0
        /// <summary>
        /// Get or Create new info list for "pluginType".
        /// One pluginType has one PluginInfoList, in one PluginInfoList is contained List of instances (type, instance, activity).
        /// If one instance implements more than one plugin, then this same instance (=singleton) is referenced from more PluginInfoList (each one for each pluginType).
        /// </summary>
        /// <param name="pluginType"></param>
        /// <param name="canCreateNewInfo">true = can create new info, when does not exists / false ´when does not exists, return null</param>
        /// <returns></returns>
        private PluginInfoList GetPluginInfoList(Type pluginType, bool canCreateNewInfo)
        {
            PluginInfoList pluginInfoList;

            if (!this._PluginsDict.TryGetValue(pluginType, out pluginInfoList))
            {
                pluginInfoList = new PluginInfoList(pluginType);
                this._PluginsDict.Add(pluginType, pluginInfoList);
            }
            return(pluginInfoList);
        }
Example #6
0
        private void MainView_Load(object sender, EventArgs e)
        {
            Console.WriteInfo("Probing for plugins in plugins folder '" + this.PluginFolder + "'...");

            //Probe for plugins in the plugins folder and add them to the ListBox to be displayed.
            //PluginLoaderBase.Probe will return a list of PluginInfo objects which contain information about each available plugin
            PluginInfoList pluginInfoList = this.PluginLoader.Probe(this.PluginFolder, SearchOption.AllDirectories);

            for (int i = 0; i < pluginInfoList.Count; i++)
            {
                lbPlugins.Items.Add(pluginInfoList[i]);
            }
        }
        public virtual PluginInfoList GetLoadedInstances(string pluginFileName)
        {
            PluginInfoList list = new PluginInfoList();

            for (int i = 0; i < this._currentInfoList.Count; i++)
            {
                if (pluginFileName.Equals(this._currentInfoList[i].PluginFileName))
                {
                    list.Add(this._currentInfoList[i]);
                }
            }

            return(list);
        }
Example #8
0
        /// <summary>
        /// Returns all objects, which implements specified interface.
        /// When type is null or is not interface, return empty array.
        /// When type is interface, which is not descendant of IPlugin, return also empty array.
        /// When return non-empty array, then none of items is null.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="isDebugMode"></param>
        /// <returns></returns>
        public IEnumerable <object> GetPlugins(Type type, bool isDebugMode)
        {
            List <object> result = new List <object>();

            if (type != null && type.IsInterface)
            {
                PluginInfoList infoList = this.GetPluginInfoList(type, false);
                if (infoList != null)
                {
                    result.AddRange(infoList.PluginList
                                    .Where(i => i.IsActiveInMode(isDebugMode))
                                    .Select(i => i.Instance));
                }
            }
            return(result);
        }
        public virtual PluginInfoList Probe(string pluginFolderPath, SearchOption scanDeapth)
        {
            AppDomain      domain   = null;
            PluginInfoList infoList = new PluginInfoList();

            domain = AppDomain.CreateDomain("PluginLoaderBase.Probe");
            Type             t      = this.GetType();
            PluginLoaderBase loader = (PluginLoaderBase)domain.CreateInstanceFromAndUnwrap(t.Assembly.Location, t.FullName);

            infoList = loader.OnProbeWrapper(pluginFolderPath, scanDeapth);

            AppDomain.Unload(domain);

            ProbeCompleteEventArgs probeCompleteArgs = new ProbeCompleteEventArgs(infoList);

            this.OnProbeComplete(probeCompleteArgs);

            return(infoList);
        }
 public ProbeCompleteEventArgs(PluginInfoList infoList)
     : base()
 {
     this.InfoList = infoList;
 }
        public virtual PluginInfoList Probe(string pluginFolderPath, SearchOption scanDeapth)
        {
            AppDomain domain = null;
            PluginInfoList infoList = new PluginInfoList();

            domain = AppDomain.CreateDomain("PluginLoaderBase.Probe");
            Type t = this.GetType();
            PluginLoaderBase loader = (PluginLoaderBase)domain.CreateInstanceFromAndUnwrap(t.Assembly.Location, t.FullName);
            infoList = loader.OnProbeWrapper(pluginFolderPath, scanDeapth);

            AppDomain.Unload(domain);

            ProbeCompleteEventArgs probeCompleteArgs = new ProbeCompleteEventArgs(infoList);
            this.OnProbeComplete(probeCompleteArgs);

            return infoList;
        }
        public virtual PluginInfoList GetLoadedInstances(string pluginFileName)
        {
            PluginInfoList list = new PluginInfoList();

            for (int i = 0; i < this._currentInfoList.Count; i++)
            {
                if (pluginFileName.Equals(this._currentInfoList[i].PluginFileName))
                    list.Add(this._currentInfoList[i]);
            }

            return list;
        }
 public ProbeCompleteEventArgs(PluginInfoList infoList)
     : base()
 {
     this.InfoList = infoList;
 }