/// <summary> /// 初始化信使服务 /// </summary> /// <param name="assemblies">所有关联的程序集</param> public static void Initialize(List<Assembly> assemblies) { assemblies.ForEach(assembly => { assembly.GetTypes().Where(type => type.GetCustomAttributes().Any(attribute => attribute is RegisterToManagerServiceAttribute)) .ToList().ForEach(type => { #region 注册监听 type.GetMethods().Where(method => method.GetCustomAttributes().Any(attribute => attribute is ListenAttribute)) .ToList().ForEach(method => { method.GetCustomAttributes<ListenAttribute>().ToList() .ForEach(attribute => { MonitorInfo monitor = new MonitorInfo(attribute.ListenTo, attribute.InterestedAction, attribute.InterestedOrder , (info) => { object[] objs = new object[] { info }; method.Invoke(null, objs); }); monitors.Add(monitor); }); }); #endregion #region 注册服务 type.GetMethods().Where(method => method.GetCustomAttributes().Any(attribute => attribute is OnCallAttribute)) .ToList().ForEach(method => { OnCallAttribute attribute = method.GetCustomAttributes<OnCallAttribute>().First(); ServiceInfo service = new ServiceInfo(attribute.Supplier, attribute.ServiceName , (info) => { object[] objs = new object[] { info }; method.Invoke(null, objs); }); services.Add(service); }); #endregion }); }); }
/// <summary> /// 判断给定的服务签名是否相符 /// </summary> /// <param name="info">所要进行判断的服务信息</param> /// <returns>返回一个布尔值,表示给定的服务签名是否相符</returns> public bool Accord(ServiceInfo info) { return this.Supplier == info.Supplier && this.ServiceName.Equals(info.ServiceName); }