Esempio n. 1
0
        private PluginManager()
        {
            Assemblies = new List<PluginAssemblyInfo>();
            Plugins = new Dictionary<Type, List<PluginInfo>>();
            Selected = new Dictionary<Type, PluginInfo>();

            // Build lists
            Plugins[typeof(MoCapPluginLib.IAnimationExporter)] = new List<PluginInfo>();
            Plugins[typeof(MoCapPluginLib.ISkeletonImporter)] = new List<PluginInfo>();

            string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");
            if (!System.IO.Directory.Exists(path))
                return;

            foreach (string file in System.IO.Directory.GetFiles(path))
            {
                if (System.IO.Path.GetExtension(file).Equals(".dll") && System.IO.File.Exists(file))
                {
                    try
                    {
                        Assembly asm = Assembly.LoadFile(file);
                        Type[] types = asm.GetExportedTypes();
                        FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location);
                        PluginAssemblyInfo plugin = new PluginAssemblyInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.Comments });
                        Assemblies.Add(plugin);

                        foreach (Type t in types)
                        {
                            foreach (Type keyType in Plugins.Keys)
                            {
                                if (t.GetInterfaces().Contains(keyType))
                                {
                                    object plugObject = Activator.CreateInstance(t);
                                    if (plugObject != null)
                                    {
                                        string plugName = t.Name;
                                        MoCapPluginLib.AdvertiseSettings settingsRoot = t.GetCustomAttribute<MoCapPluginLib.AdvertiseSettings>();
                                        if (settingsRoot != null)
                                            plugName = settingsRoot.Name;
                                        PluginInfo plugInfo = new PluginInfo(plugObject, plugName);
                                        Plugins[keyType].Add(plugInfo);
                                    }
                                }
                            }
                        }

                        if (plugin.Components.Count > 0)
                            Assemblies.Add(plugin);
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.GetInst().PushError(ex);
                    }
                }
            }
        }
Esempio n. 2
0
        private PluginManager()
        {
            Assemblies = new List <PluginAssemblyInfo>();
            Plugins    = new Dictionary <Type, List <PluginInfo> >();
            Selected   = new Dictionary <Type, PluginInfo>();

            // Build lists
            Plugins[typeof(MoCapPluginLib.IAnimationExporter)] = new List <PluginInfo>();
            Plugins[typeof(MoCapPluginLib.ISkeletonImporter)]  = new List <PluginInfo>();

            string path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "plugins");

            if (!System.IO.Directory.Exists(path))
            {
                return;
            }

            foreach (string file in System.IO.Directory.GetFiles(path))
            {
                if (System.IO.Path.GetExtension(file).Equals(".dll") && System.IO.File.Exists(file))
                {
                    try
                    {
                        Assembly           asm               = Assembly.LoadFile(file);
                        Type[]             types             = asm.GetExportedTypes();
                        FileVersionInfo    myFileVersionInfo = FileVersionInfo.GetVersionInfo(asm.Location);
                        PluginAssemblyInfo plugin            = new PluginAssemblyInfo(asm.ManifestModule.Name, new string[] { myFileVersionInfo.ProductName, myFileVersionInfo.ProductVersion, myFileVersionInfo.CompanyName, myFileVersionInfo.Comments });
                        Assemblies.Add(plugin);

                        foreach (Type t in types)
                        {
                            foreach (Type keyType in Plugins.Keys)
                            {
                                if (t.GetInterfaces().Contains(keyType))
                                {
                                    object plugObject = Activator.CreateInstance(t);
                                    if (plugObject != null)
                                    {
                                        string plugName = t.Name;
                                        MoCapPluginLib.AdvertiseSettings settingsRoot = t.GetCustomAttribute <MoCapPluginLib.AdvertiseSettings>();
                                        if (settingsRoot != null)
                                        {
                                            plugName = settingsRoot.Name;
                                        }
                                        PluginInfo plugInfo = new PluginInfo(plugObject, plugName);
                                        Plugins[keyType].Add(plugInfo);
                                    }
                                }
                            }
                        }

                        if (plugin.Components.Count > 0)
                        {
                            Assemblies.Add(plugin);
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler.GetInst().PushError(ex);
                    }
                }
            }
        }