예제 #1
0
        public void LoadPlugins(Workspace workspace)
        {
            ResourceViewProviders.Clear();

            var pluginLoadFailures = new List <String>();

            var pluginsFolder = Path.Combine(workspace.ProjectFolder, "SXEPlugins");

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

            AddFolderToAssemblyResolve(pluginsFolder);

            foreach (var pluginDll in Directory.EnumerateFiles(pluginsFolder, "*Plugin.dll", SearchOption.AllDirectories))
            {
                try
                {
                    var assembly = Assembly.LoadFile(pluginDll);

                    LoadViewProviders(workspace, assembly, pluginLoadFailures);
                    LoadMenuItemProviders(workspace, assembly, pluginLoadFailures);
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    pluginLoadFailures.Add(Path.GetFileNameWithoutExtension(pluginDll) + " Failed to load: " + ex.ToString());
                }
            }

            if (pluginLoadFailures.Count > 0)
            {
                var message = String.Join("\n", pluginLoadFailures);
                Message.Show(message, "Failed to load plugins");
            }
        }
예제 #2
0
        private void LoadViewProviders(Workspace workspace, Assembly assembly, List <String> pluginLoadFailures)
        {
            foreach (var providerType in assembly.GetTypes().Where(e => e.GetInterface(typeof(IResourceViewProvider).Name) != null))
            {
                try
                {
                    var constructor = providerType.GetConstructor(new Type[] { typeof(object) });
                    var provider    = constructor.Invoke(new object[] { workspace });

                    ResourceViewProviders.Add(provider);
                }
                catch (Exception ex)
                {
                    if (ex is TargetInvocationException)
                    {
                        ex = ex.InnerException;
                    }

                    pluginLoadFailures.Add(providerType.Name + " Failed to load: " + ex.ToString());
                }
            }
        }