예제 #1
0
        public void LoadPlugin(PluginInfo pluginInfo, Control pluginToLoad)
        {
            if (!TabPages.ContainsKey(pluginInfo.Name))
            {
                if (SelectedIndex >= 0)
                    TabPages.Insert(SelectedIndex + 1, new PluginTabPage(pluginInfo, pluginToLoad));
                else
                    TabPages.Add(new PluginTabPage(pluginInfo, pluginToLoad));
            }

            SelectTab(pluginInfo.Name);
        }
예제 #2
0
        public PluginTabPage(PluginInfo pluginInfo, Control plugin, PluginTabPage parentTab)
            : base(pluginInfo.Name)
        {
            plugin.SuspendLayout();
            plugin.Dock = DockStyle.Fill;

            Info = pluginInfo;
            Plugin = plugin;
            FromTab = parentTab;

            Controls.Add(plugin);
            Name = pluginInfo.Name;
            plugin.ResumeLayout();
        }
예제 #3
0
 public PluginTabPage(PluginInfo pluginInfo, Control plugin)
     : this(pluginInfo, plugin, null)
 {
 }
예제 #4
0
 public void Add(PluginInfo pluginInfo)
 {
     Items.Add(pluginInfo);
 }
예제 #5
0
 /// <summary>
 /// Creates a new  instance of <see cref="PluginStoreRefreshProgressEventArgs"/>
 /// </summary>
 /// <param name="currentPlugin"></param>
 /// <param name="total"></param>
 /// <param name="current"></param>
 public PluginStoreRefreshProgressEventArgs(PluginInfo currentPlugin, int total, int current)
 {
     Total = total;
     Current = current;
     CurrentPlugin = currentPlugin;
 }
예제 #6
0
        /// <summary>
        /// Inspects assemblies and executables in the specified directory using
        /// reflection and searches for controls with the PluginAttribute marked
        /// against its type. Updates the plugin store with discovered plugins.
        /// </summary>
        /// <param name="pluginStore"></param>
        /// <param name="directory"></param>
        /// <param name="files"></param>
        /// <param name="totalFiles"> </param>
        /// <param name="currentCumulate"> </param>
        private static void LoadPluginsInDirectory(ref PluginStore pluginStore, string directory,
            IList<string> files, int totalFiles, int currentCumulate)
        {
            for (var i = 0; i < files.Count; i++)
            {
                var file = files[i];

                // Process only dll and exe files
                if (!file.EndsWith(".dll") && !file.EndsWith(".exe")) continue;

                try
                {
                    var asm = Assembly.LoadFile(file);
                    var types = asm.GetTypes();

                    foreach (var t in types)
                    {
                        if (!t.IsSubclassOf(typeof(Control))) continue;

                        var pluginAttributes = t.GetCustomAttributes(typeof(PluginAttribute), false);

                        if (pluginAttributes.Length <= 0) continue;

                        var pluginAttribute = (PluginAttribute)pluginAttributes[0];

                        // Check if an icon file is present
                        var iconFile = Path.Combine(directory, t.Name + ".ico");

                        if (!File.Exists(iconFile))
                            iconFile = @"\Resources\Icons\YinYang.ico";

                        var currentPlugin = new PluginInfo
                        {
                            Name = pluginAttribute.Name,
                            Description = pluginAttribute.Description,
                            Type = t.FullName,
                            AssemblyFile = file.Replace(AppDomain.CurrentDomain.BaseDirectory, ""),
                            InstallPath = directory.Replace(AppDomain.CurrentDomain.BaseDirectory, ""),
                            Icon = iconFile.Replace(AppDomain.CurrentDomain.BaseDirectory, "")
                        };

                        pluginStore.Plugins.Add(currentPlugin);

                        NotifyOnPluginStoreRefreshProgress(
                            new PluginStoreRefreshProgressEventArgs(currentPlugin, totalFiles, currentCumulate + i + 1));
                    }
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                { }
            }
        }
예제 #7
0
        private void DisplayPluginLoadError(PluginInfo p, Exception e)
        {
            var message = null != e.InnerException
                ? e.InnerException.Message
                : e.Message;

            MessageBox.Show(this, message, Resources.ErrLoadPlug, MessageBoxButtons.OK);
            SetStatusText(p.Name + " could not be loaded.", StatusMessageType.Error);
        }
예제 #8
0
 private void UpdateCurrentPluginInUse(PluginInfo pluginInfo)
 {
     Text = pluginInfo.Name + Resources.dXToolsManager;
     SetStatusText(pluginInfo.Description, StatusMessageType.Info);
     Icon = IconSet.GetIcon(pluginInfo.Icon);
 }