当前位置: 首页>>代码示例>>C#>>正文


C# Plugin.Load方法代码示例

本文整理汇总了C#中Plugin.Load方法的典型用法代码示例。如果您正苦于以下问题:C# Plugin.Load方法的具体用法?C# Plugin.Load怎么用?C# Plugin.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Plugin的用法示例。


在下文中一共展示了Plugin.Load方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadPlugins

 // --- functions ---
 /// <summary>Loads all non-runtime plugins.</summary>
 internal static void LoadPlugins()
 {
     UnloadPlugins();
     string folder = Program.FileSystem.GetDataFolder("Plugins");
     string[] files = Directory.GetFiles(folder);
     List<Plugin> list = new List<Plugin>();
     foreach (string file in files) {
         if (file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) {
             try {
                 Plugin plugin = new Plugin(file);
                 Assembly assembly = Assembly.LoadFile(file);
                 Type[] types = assembly.GetTypes();
                 foreach (Type type in types) {
                     if (type.IsSubclassOf(typeof(OpenBveApi.Textures.TextureInterface))) {
                         plugin.Texture = (OpenBveApi.Textures.TextureInterface)assembly.CreateInstance(type.FullName);
                     }
                     if (type.IsSubclassOf(typeof(OpenBveApi.Sounds.SoundInterface))) {
                         plugin.Sound = (OpenBveApi.Sounds.SoundInterface)assembly.CreateInstance(type.FullName);
                     }
                     if (type.IsSubclassOf(typeof(OpenBveApi.Objects.ObjectInterface))) {
                         plugin.Object = (OpenBveApi.Objects.ObjectInterface)assembly.CreateInstance(type.FullName);
                     }
                 }
                 if (plugin.Texture != null | plugin.Sound != null | plugin.Object != null) {
                     plugin.Load();
                     list.Add(plugin);
                 }
             } catch {
                 // TODO //
             }
         }
     }
     LoadedPlugins = list.ToArray();
 }
开发者ID:sladen,项目名称:openbve,代码行数:36,代码来源:Plugins.cs

示例2: LoadPlugins

 // --- functions ---
 /// <summary>Loads all non-runtime plugins.</summary>
 /// <returns>Whether loading all plugins was successful.</returns>
 internal static bool LoadPlugins()
 {
     UnloadPlugins();
     string folder = Program.FileSystem.GetDataFolder("Plugins");
     string[] files = Directory.GetFiles(folder);
     List<Plugin> list = new List<Plugin>();
     StringBuilder builder = new StringBuilder();
     foreach (string file in files) {
         if (file.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) {
             #if !DEBUG
             try {
                 #endif
                 Plugin plugin = new Plugin(file);
                 Assembly assembly = Assembly.LoadFile(file);
                 Type[] types = assembly.GetTypes();
                 bool iruntime = false;
                 foreach (Type type in types) {
                     if (type.IsSubclassOf(typeof(OpenBveApi.Textures.TextureInterface))) {
                         plugin.Texture = (OpenBveApi.Textures.TextureInterface)assembly.CreateInstance(type.FullName);
                     }
                     if (type.IsSubclassOf(typeof(OpenBveApi.Sounds.SoundInterface))) {
                         plugin.Sound = (OpenBveApi.Sounds.SoundInterface)assembly.CreateInstance(type.FullName);
                     }
                     if (type.IsSubclassOf(typeof(OpenBveApi.Objects.ObjectInterface))) {
                         plugin.Object = (OpenBveApi.Objects.ObjectInterface)assembly.CreateInstance(type.FullName);
                     }
                     if (typeof(OpenBveApi.Runtime.IRuntime).IsAssignableFrom(type)) {
                         iruntime = true;
                     }
                 }
                 if (plugin.Texture != null | plugin.Sound != null | plugin.Object != null) {
                     plugin.Load();
                     list.Add(plugin);
                 } else if (!iruntime) {
                     builder.Append("Plugin ").Append(Path.GetFileName(file)).AppendLine(" does not implement compatible interfaces.");
                     builder.AppendLine();
                 }
                 #if !DEBUG
             } catch (Exception ex) {
                 builder.Append("Could not load plugin ").Append(Path.GetFileName(file)).AppendLine(":").AppendLine(ex.Message);
                 builder.AppendLine();
             }
             #endif
         }
     }
     LoadedPlugins = list.ToArray();
     string message = builder.ToString().Trim();
     if (message.Length != 0) {
         return MessageBox.Show(message, Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button2) == DialogResult.OK;
     } else {
         return true;
     }
 }
开发者ID:kev5873,项目名称:openbvemultiplayer,代码行数:56,代码来源:Plugins.cs

示例3: LoadPlugin

        /// <summary>
        /// Loads a given plugin
        /// </summary>
        /// <param name="plugin"></param>
        /// <param name="waitingForAccess"></param>
        protected void LoadPlugin(Plugin plugin, bool waitingForAccess = false)
        {
            if (!File.Exists(plugin.Filename))
            {
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.LogWarning("Script no longer exists: {0}", plugin.Name);
                return;
            }

            try
            {
                plugin.Load();
                Interface.Oxide.UnloadPlugin(plugin.Name);
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.PluginLoaded(plugin);
            }
            catch (IOException)
            {
                if (!waitingForAccess) Interface.Oxide.LogWarning("Waiting for another application to stop using script: {0}", plugin.Name);
                Interface.Oxide.GetLibrary<Timer>().Once(.5f, () => LoadPlugin(plugin, true));
            }
            catch (Exception ex)
            {
                LoadingPlugins.Remove(plugin.Name);
                Interface.Oxide.LogException($"Failed to load plugin {plugin.Name}", ex);
            }
        }
开发者ID:906507516,项目名称:Oxide,代码行数:32,代码来源:PluginLoader.cs

示例4: loadPluginList

        // loads all the available plugins into the treeview
        void loadPluginList()
        {
            string dir = AppDomain.CurrentDomain.BaseDirectory;
            if (dir.Length == 0) return;

            dir = System.IO.Path.Combine (dir, "plugins");
            if (!System.IO.Directory.Exists (dir)) return;

            foreach (string file in System.IO.Directory.GetFiles (dir, "*.dll"))
            {
                bool exists = false;
                foreach (Plugin plugin in plugin_list)
                {
                    if (plugin.Path == file)
                    {
                        exists = true;
                        store.AppendValues (plugin);
                    }
                }

                if (!exists)
                {
                    Plugin plugin = new Plugin (file);
                    if (plugin.Load ())
                    {
                        store.AppendValues (plugin);
                        plugin_list.Add (plugin);
                    }
                }
            }
        }
开发者ID:gsterjov,项目名称:fusemc,代码行数:32,代码来源:PluginsWindow.cs


注:本文中的Plugin.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。