public LocalFileContentProvider(IPluginContainer parent)
        {
            var settings = new Settings(Plugin.SelfPath + "/pluginfavourites.xml");

            files_path = settings.GetValue("settings", "filepath") ?? "";
            _parent    = parent;
        }
Example #2
0
        public TorrentContentProvider(IPluginContainer parent)
        {
            Parent = parent;
            var settings = new Settings(Plugin.SelfPath + "/pluginfavourites.xml");

            _path = settings.GetValue("settings", "torrentpath") ?? "";
        }
Example #3
0
        /// <summary>
        /// 从插件容器(及其子容器)中筛选指定的过滤条件的插件
        /// </summary>
        /// <param name="container">插件容器</param>
        /// <param name="filter">过滤条件委托</param>
        /// <returns></returns>
        public static IEnumerable<IPluginItem> QueryPlugins(this IPluginContainer container, Func<IPluginItem, bool> filter)
        {
            var plugins = container.Plugins.Where(filter).ToList();
            foreach (var sbuContainer in container.SubContainers)
                plugins.AddRange(QueryPlugins(sbuContainer, filter));

            return plugins;
        }
Example #4
0
 static PluginReference()
 {
     PluginReference.syncObject = new object();
     PluginReference.instances  = null;
     PluginReference.container  = null;
     PluginReference.container  = PluginFactory.Container;
     PluginReference.instances  = new Dictionary <string, IPlugin>();
 }
Example #5
0
 /// <summary>
 /// 将插件容器作为菜单,创建菜单
 /// </summary>
 /// <param name="container">插件容器</param>
 /// <returns></returns>
 private static ToolStripMenuItem CreateMenuItem(IPluginContainer container)
 {
     return(new ToolStripMenuItem
     {
         Text = container.Text,
         Name = container.Name,
         ShortcutKeys = string.IsNullOrWhiteSpace(container.ShortcutKeys) ? Keys.None : (Keys)Enum.Parse(typeof(Keys), container.ShortcutKeys)
     });
 }
 public LocalFileContentProvider(string path, IPluginContainer parent)
 {
     files_path = path;
     _parent = parent;
     var dir = new DirectoryInfo(path);
     _id = dir.Name.Replace("_", "").Replace(" ", "").ToLower();
     if (parent is LocalFileContentProvider)
         _id = parent.Id + "_" + _id;
     _title = dir.Name;
 }
Example #7
0
        private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            ThreadPool.QueueUserWorkItem(state =>
            {
                IPluginContainer root = null;

                if (e.Node.Tag.Equals("ttv"))
                {
                    treeView1.BeginInvoke(new Action(() => e.Node.Nodes.Clear()));
                    var cats = proxy.Device.ChannelsProvider.GetCategories();
                    foreach (var cat in cats)
                    {
                        treeView1.BeginInvoke(new Action(() =>
                        {
                            var node = e.Node.Nodes.Add("cat" + cat.id, cat.name);
                            node.Tag = cat;
                            foreach (var ch in cat.Channels)
                            {
                                var chnode = node.Nodes.Add("ch" + ch.id, ch.name);
                                chnode.Tag = ch;
                            }
                        }));
                    }
                }
                if (e.Node.Tag is IPluginProxy)
                {
                    root = (e.Node.Tag as IPluginProxy).GetContent(null) as IPluginContainer;
                }
                else if (e.Node.Tag is IPluginContainer)
                {
                    root = (e.Node.Tag as IPluginContainer);
                }

                if (root == null)
                {
                    return;
                }

                var contents = root.Children;
                treeView1.BeginInvoke(new Action(() => e.Node.Nodes.Clear()));
                foreach (var content in contents)
                {
                    treeView1.BeginInvoke(new Action(() =>
                    {
                        var node = e.Node.Nodes.Add(content.Id, content.Title);
                        node.Tag = content;
                        if (content is IPluginContainer)
                        {
                            node.Nodes.Add("");
                        }
                    }));
                }
            });
        }
Example #8
0
        public static void Start()
        {
            IPluginDomainContext pluginDomainContext = AppDomain.CurrentDomain.GetData("ModuleDomainContext") as IPluginDomainContext;
            string assemlbyLocation = AppDomain.CurrentDomain.GetData("AssemlbyLocation") as string;

            Assembly       callingAssembly = AppDomain.CurrentDomain.Load(assemlbyLocation);
            PluginAssembly pluginAssembly  = new PluginAssembly(callingAssembly);

            PluginConfiguration pluginConfiguration = new PluginConfiguration(pluginAssembly);

            pluginConfiguration.Initialize();

            AppDomain.CurrentDomain.SetData("PluginDomainName", pluginAssembly.Mainifest.Name);
            AppDomain.CurrentDomain.SetData("PluginDomainVersion", pluginAssembly.Version.ToString());

            MisfitContainerBuilder builder = new MisfitContainerBuilder();

            List <ModuleServiceType> moduleServiceTypes = pluginAssembly.ModuleServiceTypes;

            foreach (ModuleServiceType moduleServiceType in moduleServiceTypes)
            {
                if (moduleServiceType.InterfaceType == null)
                {
                    throw new InvalidDataException(string.Format("{0}没有找到对应的接口类", moduleServiceType.ImplementType.Name));
                }

                builder.Register(moduleServiceType.InterfaceType, moduleServiceType.ImplementType);
            }

            IPluginContainer misfitContainer = builder.Build();

            if (pluginAssembly.Mainifest != null)
            {
                Dictionary <string, object> pluginDomainServces = new Dictionary <string, object>();

                foreach (ServiceDescriptor beanDescriptor in pluginAssembly.Mainifest.ServiceDescriptors)
                {
                    ModuleServiceType boundaryModuleServiceType = moduleServiceTypes.FirstOrDefault(t => t.ImplementType.FullName == beanDescriptor.ClassName);
                    if (boundaryModuleServiceType == null)
                    {
                        throw new NullReferenceException("没有找配置里面对应的服务类型");
                    }

                    if (misfitContainer.HasRegistration(boundaryModuleServiceType.InterfaceType))
                    {
                        object instance = misfitContainer.Resolve(boundaryModuleServiceType.InterfaceType);

                        pluginDomainServces.Add(boundaryModuleServiceType.InterfaceType.Name, instance);
                    }
                }

                AppDomain.CurrentDomain.SetData("PluginDomainServcies", pluginDomainServces);
            }
        }
Example #9
0
 public Item(string id, string title, PluginMediaType type, IPluginContainer parent, TranslationType translation, string url)
 {
     _id = id;
     if (!string.IsNullOrEmpty(parent.Id))
         _id = parent.Id + "_" + id;
     _title = title;
     _type = type;
     _parent = parent;
     _url = url;
     Translation = translation;
 }
Example #10
0
        public static void LoadAssembly(this IPluginContainer Container, string assemblyFile)
        {
            IPluginDomainConnector pluginDomainConnector = new PluginDomainConnector();

            pluginDomainConnector.LoadAssembly(assemblyFile);
            if (pluginDomainConnector.Plugins.Count == 0)
            {
                pluginDomainConnector.Dispose();
                return;
            }
            Container.AddDomain(pluginDomainConnector.Name, pluginDomainConnector);
        }
Example #11
0
        /// <summary>
        /// 修改插件容器信息窗口
        /// </summary>
        /// <param name="pluginContainer"></param>
        public PluginContainerInfoForm(IPluginContainer pluginContainer = null)
        {
            InitializeComponent();

            this.txtCaption.Focus();
            this.cmbShortcutKeys.Items.AddRange(Enum.GetNames(typeof(Shortcut)));
            this.cmbShortcutKeys.SelectedIndex = 0;
            if (pluginContainer != null)
            {
                this.PluginContainer = pluginContainer;
            }
        }
        public LocalFileContentProvider(string path, IPluginContainer parent)
        {
            files_path = path;
            _parent    = parent;
            var dir = new DirectoryInfo(path);

            _id = dir.Name.Replace("_", "").Replace(" ", "").ToLower();
            if (parent is LocalFileContentProvider)
            {
                _id = parent.Id + "_" + _id;
            }
            _title = dir.Name;
        }
Example #13
0
 /// <summary>
 /// 通过反射创建插件容器中的插件的命令(ICommand),设置命令的传入参数
 /// </summary>
 /// <param name="container"></param>
 /// <param name="cmdData"></param>
 public static void LoadPluginCommands <TCmdData>(this IPluginContainer container, TCmdData cmdData)
 {
     foreach (var pageContainer in container.SubContainers)
     {
         foreach (var groupContainer in pageContainer.SubContainers)
         {
             foreach (var plugin in groupContainer.Plugins)
             {
                 plugin.CreateCommand <TCmdData>(cmdData);
             }
         }
     }
 }
Example #14
0
 public Item(string id, string title, PluginMediaType type, IPluginContainer parent, TranslationType translation, string url)
 {
     _id = id;
     if (!string.IsNullOrEmpty(parent.Id))
     {
         _id = parent.Id + "_" + id;
     }
     _title      = title;
     _type       = type;
     _parent     = parent;
     _url        = url;
     Translation = translation;
 }
Example #15
0
 /// <summary>
 /// 通过反射创建插件容器中的插件的命令(ICommand),设置命令的传入参数
 /// </summary>
 /// <param name="container">插件容器</param>
 /// <param name="cmdData">插件命令的传入参数</param>
 public static void LoadPluginCommands<TCmdData>(this IPluginContainer container, TCmdData cmdData)
 {
     var sbErrorCmds = new StringBuilder();
     foreach (var plugin in container.QueryPlugins())
     {
         try
         {
             plugin.CreateCommand<TCmdData>(cmdData);
         }
         catch { sbErrorCmds.AppendLine($"程序集:{ plugin.AssemblyPath}\r\n命令:{plugin.TypeName}"); }
     }
     if (sbErrorCmds.Length > 0)
     {
         sbErrorCmds.Insert(0, "以下插件命令创建失败(找不到程序集或命令,请注意程序集路径、名称、后缀(dll、exe)、类名是否正确):");
         throw new Exception(sbErrorCmds.ToString());
     }
 }
Example #16
0
        /// <summary>
        /// 向菜单项加载子菜单项(插件)
        /// </summary>
        /// <param name="container"></param>
        /// <param name="menuItem"></param>
        /// <param name="form"></param>
        private static void LoadPluginContainer(IPluginContainer container, ToolStripMenuItem menuItem, Form form)
        {
            foreach (var subContainer in container.SubContainers)
            {
                var subMenuItem = CreateMenuItem(container);
                menuItem.DropDownItems.Add(subMenuItem);

                foreach (var container1 in subContainer.SubContainers)
                {
                    LoadPluginContainer(container1, subMenuItem, form);
                }
            }

            foreach (var plugin in container.Plugins)
            {
                menuItem.DropDownItems.Add(CreateMenuItem(plugin, form));
            }
        }
Example #17
0
        public override void BrowseDirectChildren(XmlWriter writer, string idParams, uint startingIndex, uint requestedCount,
                                                  string sortCriteria, out string numberReturned, out string totalMatches, string host, HashSet <string> filterSet)
        {
            _childItems.Clear();
            IPluginContainer container = null;

            try
            {
                if (string.IsNullOrEmpty(idParams))
                {
                    container = _plugin.GetContent(null) as IPluginContainer;
                }
                else
                {
                    idParams  = idParams.Replace(ParentId + "_", "");
                    container =
                        _plugin.GetContent(new Dictionary <string, string> {
                        { "id", idParams }
                    }) as IPluginContainer;
                }
            }
            catch (Exception)
            {
            }

            if (container != null)
            {
                _childItems.Clear();
                CanSorted = container.CanSorted;
                foreach (var item in container.Children)
                {
                    _childItems.Add(GetItem(item, host));
                }

                base.BrowseDirectChildren(writer, idParams, startingIndex, requestedCount, sortCriteria,
                                          out numberReturned, out totalMatches, host, filterSet);
            }
            else
            {
                numberReturned = "0";
                totalMatches   = "0";
            }
        }
Example #18
0
        /// <summary>
        /// 向插件窗口的RibbonControl控件加载插件
        /// </summary>
        /// <param name="container"></param>
        /// <param name="ribbonCtrl"></param>
        private static void LoadPluginContainer(this IPluginContainer container, RibbonControl ribbonCtrl)
        {
            var form            = ribbonCtrl.FindForm();
            var imageCollection = ribbonCtrl.Images == null ? new ImageCollection() : (ImageCollection)ribbonCtrl.LargeImages;

            ribbonCtrl.LargeImages = imageCollection;
            foreach (var pageContainer in container.SubContainers)
            {
                var page = new RibbonPage {
                    Text = pageContainer.Text, Name = pageContainer.Name
                };
                ribbonCtrl.DefaultPageCategory.Pages.Add(page);
                foreach (var groupContainer in pageContainer.SubContainers)
                {
                    var group = new RibbonPageGroup {
                        Text = groupContainer.Text, Name = groupContainer.Name
                    };
                    page.Groups.Add(group);
                    var plugins = groupContainer.Plugins.OrderBy(v => v.Index);
                    foreach (var plugin in plugins)
                    {
                        var image      = plugin.GetImage();
                        int imageIndex = image == null ? -1 : imageCollection.Images.Add(image);
                        var item       = new BarButtonItem
                        {
                            Caption         = plugin.Text,
                            SuperTip        = SuperTipsEx.CreateSuperTips(plugin.Tips, plugin.Text),
                            RibbonStyle     = RibbonItemStyles.All,
                            LargeImageIndex = imageIndex,
                            Tag             = plugin
                        };
                        if (!string.IsNullOrWhiteSpace(plugin.ShortcutKeys))
                        {
                            item.ItemShortcut = new BarShortcut((Keys)Enum.Parse(typeof(Keys), plugin.ShortcutKeys));
                        }

                        item.ItemClick += (sender, e) => plugin.Command.Invoke(form);
                        group.ItemLinks.Add(item);
                    }
                }
            }
        }
Example #19
0
        /// <summary>
        /// 向插件窗口的<see cref="MenuStrip"/>加载插件
        /// </summary>
        /// <param name="container"></param>
        /// <param name="menuStrip"></param>
        public static void LoadPluginContainer(this MenuStrip menuStrip, IPluginContainer container)
        {
            var form = menuStrip.FindForm();

            foreach (var subContainer in container.SubContainers)
            {
                var menuItem = CreateMenuItem(container);
                menuStrip.Items.Add(menuItem);

                foreach (var container1 in subContainer.SubContainers)
                {
                    LoadPluginContainer(subContainer, menuItem, form);
                }
            }

            foreach (var plugin in container.Plugins)
            {
                menuStrip.Items.Add(CreateMenuItem(plugin, form));
            }
        }
Example #20
0
        public object ActivateInstance(ResolutionContext resolutionContext)
        {
            if (this._container == null)
            {
                this._container = resolutionContext.Container;
            }

            var constructors     = this._implementationType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
            var finalConstructor = this._constructorSelector.SelectConstructor(constructors, resolutionContext);

            object[] finalArguments = this._argumentCollector.CollectArguments(
                this._container.Resolve,
                finalConstructor.GetParameters(),
                resolutionContext);

            if (finalArguments != null && finalArguments.Length != finalConstructor.GetParameters().Length)
            {
                throw new InvalidOperationException(string.Format("没有找到{0}对应结构函数", this._implementationType.Name));
            }

            return(finalConstructor.Invoke(finalArguments));
        }
Example #21
0
 /// <summary>
 /// 从插件容器(及其子容器)中筛选指定的调用类型的插件
 /// </summary>
 /// <param name="container">插件容器</param>
 /// <param name="invokeType">插件调用类型</param>
 /// <returns></returns>
 public static IEnumerable<IPluginItem> QueryPlugins(this IPluginContainer container, EPluginInvokeType invokeType)
 {
     return QueryPlugins(container, plugin => plugin.InvokType == invokeType);
 }
 public YoutubeItem(string id, string title, PluginMediaType type, IPluginContainer parent, TranslationType translation, string url) : base(id, title, type, parent, translation, "")
 {
     ItemUrl = url;
 }
Example #23
0
 /// <summary>
 /// 判断容器是否为指定类型之一
 /// </summary>
 /// <param name="eTypes"></param>
 /// <returns></returns>
 public static bool IsTypeOf(this IPluginContainer container, params EPluginContainerType[] eTypes)
 {
     return eTypes.Any(t => t == container.Type);
 }
Example #24
0
 /// <summary>
 /// 是否为顶层插件容器
 /// <para>包括菜单栏、工具栏、快捷菜单、Ribbon风格的菜单栏</para>
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 public static bool IsTopContainer(this IPluginContainer container)
 {
     return IsTypeOf(container, EPluginContainerType.ContextMenu, EPluginContainerType.MenuStrip, EPluginContainerType.ToolBar, EPluginContainerType.RibbonMenu);
 }
Example #25
0
 public PluginLogicService(IPluginContainer container)
 {
     this.Container = container;
 }
Example #26
0
 public PluginEventArgs(IPluginContainer container)
 {
     Container = container;
 }
Example #27
0
		private void UnsubscribeToPluginContainer(IPluginContainer pluginContainer)
		{
			List<IPlugin> plugins;
			
			lock (pluginContainer)
			{
				pluginContainer.PluginAdded -= PluginContainer_PluginAdded;
				pluginContainer.PluginRemoved -= PluginContainer_PluginRemoved;

				plugins = pluginContainer.GetAllPlugins().ToList();
			}

			foreach (var plugin in plugins)
				PluginRemoved(this, new ObjectEventArgs<IPlugin>(plugin));
		}
 public TorrentContentProvider(IPluginContainer parent)
 {
     Parent = parent;
     var settings = new Settings(Plugin.SelfPath + "/pluginfavourites.xml");
     _path = settings.GetValue("settings", "torrentpath") ?? "";
 }
 public TorrentItem(string id, string title, PluginMediaType type, IPluginContainer parent, TranslationType translation, string url) : base(id, title, type, parent, translation, "")
 {
     _itemurl = url;
     Translation = TranslationType.VoD;
 }
Example #30
0
 public PluginContainer(string id, IPluginContainer parent)
 {
     this.id = id;
     this.Parent = parent;
 }
 public YoutubeItem(string id, string title, PluginMediaType type, IPluginContainer parent, TranslationType translation, string url) : base(id, title, type, parent, translation, "")
 {
     ItemUrl = url;
 }
Example #32
0
 public QwPluginService(IPluginContainer container)
 {
     _container = container;
     _services  = new QwDictionary <Type, object>(MissingValueProvider);
 }
Example #33
0
 public MisfitContainerBuilder()
 {
     this._registrationContainer  = new RegistrationContainer();
     this._registrationCallbacks  = new List <Action>();
     this._bootStrappingContainer = this.Build();
 }
Example #34
0
 public PluginContainer(string id, IPluginContainer parent)
 {
     this.id     = id;
     this.Parent = parent;
 }
Example #35
0
 private TMod GetModule <TMod>(IPluginContainer pc, String name) where TMod : class
 {
     return(pc.GetInstance <TMod>(name));
 }
Example #36
0
 /// <summary>
 /// 是否为插件项的直接容器
 /// <para>包括工具栏、快捷菜单、子菜单、Ribbon风格的菜单组</para>
 /// </summary>
 /// <param name="container"></param>
 /// <returns></returns>
 public static bool IsItemContainer(this IPluginContainer container)
 {
     return IsTypeOf(container, EPluginContainerType.ContextMenu, EPluginContainerType.ToolBar, EPluginContainerType.SubMenu, EPluginContainerType.RibbonGroup);
 }
Example #37
0
 internal async void OnPluginUnloaded(IPluginContainer container)
 {
     await _taskFactory.StartNew(() => PluginUnloaded?.Invoke(this, new PluginEventArgs(container))).ConfigureAwait(false);
 }
 public LocalFileContentProvider(IPluginContainer parent)
 {
     var settings = new Settings(Plugin.SelfPath + "/pluginfavourites.xml");
     files_path = settings.GetValue("settings", "filepath") ?? "";
     _parent = parent;
 }