Example #1
0
        // Summary:
        //     Load extensions which are located in the bin\extensions\ directory.
        public void loadExtensions()
        {
            var      allAssemblies  = AppDomain.CurrentDomain.GetAssemblies();
            Assembly exeAssembly    = Assembly.GetExecutingAssembly();
            string   exeLocation    = exeAssembly.Location;
            string   exePath        = Path.GetDirectoryName(exeLocation);
            string   extensionsPath = exePath + "\\extensions";

            if (!Directory.Exists(extensionsPath))
            {
                return;
            }

            // try to load *.dll in bin\extensions\
            var files = Directory.EnumerateFiles(extensionsPath, "*.dll",
                                                 SearchOption.TopDirectoryOnly);

            foreach (string file in files)
            {
                // skip the assembly that has been loaded
                string shortName = Path.GetFileName(file);
                if (allAssemblies.Any(x => x.ManifestModule.Name == shortName))
                {
                    continue;
                }

                // Assembly.LoadFile doesn't resolve dependencies,
                // so don't use Assembly.LoadFile
                Assembly assembly = Assembly.LoadFrom(file);
                if (assembly != null)
                {
                    _loadedExtensions.Add(assembly);
                }
            }

            // call init() in extensions
            foreach (Assembly assembly in _loadedExtensions)
            {
                //loadUI(assembly);
                // call init() function in the loaded assembly
                var types = from type in assembly.GetTypes()
                            where type.IsSubclassOf(typeof(IS3.Core.Extensions))
                            select type;
                foreach (var type in types)
                {
                    object obj = Activator.CreateInstance(type);
                    IS3.Core.Extensions extension = obj as IS3.Core.Extensions;
                    if (extension == null)
                    {
                        continue;
                    }
                    string msg = extension.init();
                    output(msg);
                }
            }
        }
Example #2
0
        // Summary:
        //     Load tools which are located in the bin\tools\ directory.
        public void loadToolboxes()
        {
            var      allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
            Assembly exeAssembly   = Assembly.GetExecutingAssembly();
            string   exeLocation   = exeAssembly.Location;
            string   exePath       = Path.GetDirectoryName(exeLocation);
            string   toolsPath     = exePath + "\\tools";

            if (!Directory.Exists(toolsPath))
            {
                return;
            }

            // try to load *.dll in bin\tools\
            var files = Directory.EnumerateFiles(toolsPath, "*.dll",
                                                 SearchOption.TopDirectoryOnly);

            foreach (string file in files)
            {
                string shortName = Path.GetFileName(file);
                if (allAssemblies.Any(x => x.ManifestModule.Name == shortName))
                {
                    continue;
                }

                // Assembly.LoadFile doesn't resolve dependencies,
                // so don't use Assembly.LoadFile
                Assembly assembly = Assembly.LoadFrom(file);
                if (assembly != null)
                {
                    _loadedToolboxes.Add(assembly);
                }
            }

            foreach (Assembly assembly in _loadedToolboxes)
            {
                //loadUI(assembly);
                // call init() function in the loaded assembly
                var types = from type in assembly.GetTypes()
                            where type.IsSubclassOf(typeof(IS3.Core.Extensions))
                            select type;
                foreach (var type in types)
                {
                    object obj = Activator.CreateInstance(type);
                    IS3.Core.Extensions extension = obj as IS3.Core.Extensions;
                    if (extension == null)
                    {
                        continue;
                    }
                    string msg = extension.init();
                    output(msg);
                }

                // call tools.treeItems() can add it to ToolsPanel
                types = from type in assembly.GetTypes()
                        where type.IsSubclassOf(typeof(Tools))
                        select type;
                foreach (var type in types)
                {
                    object obj   = Activator.CreateInstance(type);
                    Tools  tools = obj as Tools;
                    IEnumerable <ToolTreeItem> treeitems = tools.treeItems();
                    if (treeitems == null)
                    {
                        continue;
                    }
                    foreach (var item in treeitems)
                    {
                        ToolsPanel.toolboxesTree.add(item);
                    }
                }
            }
        }