コード例 #1
0
		private void LoadPluginItem(ServiceInfo item)
		{
			ListViewItem lvt = new ListViewItem(item.ServiceDescription == null ? item.TypeName : item.ServiceDescription.Name);
			lvt.SubItems.Add(GetStateDescription(item.State));

			if (item.ServiceProvider == null)
			{
				lvt.SubItems.Add("");
			}
			else
			{
				lvt.SubItems.Add(item.ServiceProvider.Version);
			}

			lvt.SubItems.Add(item.ServiceDescription.Author);
			lvt.SubItems.Add(item.Assembly);
			lvt.SubItems.Add(item.TypeName);

			if (item.ServiceProvider != null && item.ServiceProvider.PluginIcon != null)
			{
				imgList.Images.Add(item.TypeName, item.ServiceProvider.PluginIcon);
				lvt.ImageKey = item.TypeName;
			}
			lvt.Checked = item.Enabled;

			pluginsList.Items.Add(lvt);
			lvt.Tag = item;
		}
コード例 #2
0
ファイル: ServiceManager.cs プロジェクト: iraychen/IpMsg.Net
		/// <summary>
		/// 查找指定程序集中所有的服务类
		/// </summary>
		/// <param name="assembly"></param>
		/// <returns></returns>
		public static ServiceInfo[] GetServicesInAssembly(Assembly assembly)
		{
			System.Type[] types = assembly.GetTypes();

			List<ServiceInfo> typeList = new List<ServiceInfo>();
			Array.ForEach(types, s =>
			{
				if (!s.IsPublic || s.IsAbstract) return;
				Type t = s.GetInterface(typeof(IServiceProvider).FullName);
				if (t == null) return;

				object[] infos = s.GetCustomAttributes(typeof(ServiceAttribute), true);

				ServiceInfo info = new ServiceInfo();
				info.Assembly = System.IO.Path.GetFileName(assembly.Location);
				info.TypeName = s.FullName;

				if (infos == null || infos.Length == 0)
				{
					info.Enabled = true;
				}
				else
				{
					info.Enabled = (infos[0] as ServiceAttribute).Description.DefaultEnabled;
				}
				typeList.Add(info);
			});

			return typeList.ToArray();
		}
コード例 #3
0
		/// <summary>
		/// 查找黑名单插件
		/// </summary>
		/// <returns></returns>
		bool SearchBlankListPlugins()
		{
			if (_blanklistPlugins != null) return _blanklistPlugins.ServiceProvider != null;
			else
			{
				_blanklistPlugins = Env.IPMClient.ServiceList.SingleOrDefault(s => s.TypeName == FSLib.IPMessager.Services.ServiceManager.InnerServiceTypeList[FSLib.IPMessager.Services.InnerService.BlackListBlocker]);
				return _blanklistPlugins != null && _blanklistPlugins.ServiceProvider != null;
			}
		}
コード例 #4
0
ファイル: Env.cs プロジェクト: iraychen/IpMsg.Net
		/// <summary>
		/// 卸载指定插件
		/// </summary>
		/// <param name="si"></param>
		/// <returns></returns>
		public static bool ShutdownServiceProvider(ServiceInfo si)
		{
			return si.State == ServiceState.Unload || si.ShutDown();
		}
コード例 #5
0
ファイル: Env.cs プロジェクト: iraychen/IpMsg.Net
		/// <summary>
		/// 尝试启动指定插件
		/// </summary>
		/// <param name="si"></param>
		/// <returns></returns>
		public static bool StartupServiceProvider(ServiceInfo si)
		{
			if (si.EnsureLoadAssembly() && si.CreateProviderInstance() && si.InitialzingServiceProvider(Env.IPMClient))
			{
				if (!si.LoadService()) return false;
				else { Env.HandleServiceConfigLoad(si.ServiceProvider); return true; }
			}
			return si.State != ServiceState.Running;
		}