コード例 #1
0
        public static void Load()
        {
            lock (Plugin.LoadedPlugins.Plugins)
            {
                if (Plugin.LoadedPlugins.Plugins.Count > 0)
                {
                    return;
                }

                var file = new FileInfo(Application.ExecutablePath);

                FileInfo[] plugins =
                    Directory.Exists(Path.Combine(file.Directory.FullName, "Plugins"))
                                   ? new DirectoryInfo(Path.Combine(file.Directory.FullName, "Plugins")).GetFiles("*.dll")
                                   : new FileInfo[] { };

                var pluginFiles = plugins.Where(pluginFile =>
                                                !pluginFile.Name.StartsWith("System.") &&
                                                !pluginFile.Name.StartsWith("ICSharpCode.") &&
                                                !pluginFile.Name.StartsWith("Microsoft."));

                foreach (var pluginFile in pluginFiles)
                {
                    try
                    {
                        Debug.WriteLine("Loading plugin...", pluginFile.Name);
                        var types = Assembly.LoadFile(pluginFile.FullName).GetTypes();
                        PluginExtraction.ExtractPluginTypes(types);
                    }
                    catch (SystemException ex)
                    {
                        string exInfo = "Exception info:\r\n";

                        var rtle = ex as ReflectionTypeLoadException;
                        if (rtle != null)
                        {
                            foreach (var el in rtle.LoaderExceptions)
                            {
                                exInfo += el.Message + "\r\n";
                            }
                        }
                        else
                        {
                            Action <Exception> getEx = null;
                            getEx = arg =>
                            {
                                exInfo += arg.Message + "\r\n"; if (arg.InnerException != null)
                                {
                                    getEx(arg.InnerException);
                                }
                            };
                            getEx(ex);
                        }

                        MessageBox.Show(string.Format("Failed to load plugin {0} : \r\n{1}", pluginFile, exInfo));
                        Trace.WriteLine(ex.Message);
                    }
                }
            }
        }
コード例 #2
0
        public static void Load()
        {
            lock (GitUI.Plugin.LoadedPlugins.Plugins)
            {
                if (GitUI.Plugin.LoadedPlugins.Plugins.Count > 0)
                {
                    return;
                }

                var file = new FileInfo(Application.ExecutablePath);

                // Only search for plugins in the plugins folder. This increases performance a little bit.
                // In DEBUG search for plugins in the root folder to make debugging plugins easier.
#if DEBUG
                var plugins = file.Directory.GetFiles("*.dll", SearchOption.AllDirectories);
#else
                FileInfo[] plugins =
                    Directory.Exists(Path.Combine(file.Directory.FullName, "Plugins"))
                                   ? new DirectoryInfo(Path.Combine(file.Directory.FullName, "Plugins")).GetFiles("*.dll")
                                   : new FileInfo[] { };
#endif

                foreach (var pluginFile in plugins)
                {
                    if (pluginFile.Name.StartsWith("Microsoft."))
                    {
                        continue;
                    }

                    try
                    {
                        var types = Assembly.LoadFile(pluginFile.FullName).GetTypes();
                        Debug.WriteLine("Loading plugin...", pluginFile.Name);
                        PluginExtraction.ExtractPluginTypes(types);
                    }
                    catch (Exception ex)
                    {
                        string exInfo = "Exception info:\r\n";

                        var rtle = ex as ReflectionTypeLoadException;
                        if (rtle != null)
                        {
                            foreach (var el in rtle.LoaderExceptions)
                            {
                                exInfo += el.Message + "\r\n";
                            }
                        }
                        else
                        {
                            Action <Exception> getEx = null;
                            getEx = arg => { exInfo += arg.Message + "\r\n"; if (arg.InnerException != null)
                                             {
                                                 getEx(arg.InnerException);
                                             }
                            };
                            getEx(ex);
                        }

                        MessageBox.Show(string.Format("Failed to load plugin {0} : \r\n{1}", pluginFile, exInfo));
                        Trace.WriteLine(ex.Message);
                    }
                }
            }
        }