Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="assemblyinfo"></param>
        /// <param name="errinfo"></param>
        /// <returns></returns>
        public bool ValidatePackage(ServicePackageInfo assemblyinfo, out ErrPackageInfo errinfo)
        {
            errinfo = new ErrPackageInfo();
            string infpath   = assemblyinfo.InfAssemblyName;
            string implepath = assemblyinfo.ImpleAssemblyName;

            Assembly infAssembly   = GetAssembly(ConfigUtil.GetBizPluginFullPath(infpath));
            Assembly impleAssembly = GetAssembly(ConfigUtil.GetBizPluginFullPath(implepath));

            if (!ValidateAssembly(errinfo, infAssembly, impleAssembly))
            {
                return(false);
            }

            List <ServiceInfo> errservices = CheckServices(infAssembly, impleAssembly, assemblyinfo);

            foreach (ServiceInfo info in errservices)
            {
                ErrServiceInfo errserviceinfo = new ErrServiceInfo();
                errserviceinfo.ServiceKey = info.Key;
                errinfo.ErrServiceInfoList.Add(errserviceinfo);
            }

            //if (errservices.Count != 0)
            //{
            //Console.WriteLine(errservices.Count);
            //for (int i = 0; i < errservices.Count; i++)
            //{
            //   Console.WriteLine("service: " + errservices[i].ServiceTypeName + " imple:" + errservices[i].ImpleTypeName);
            //}
            //throw new ConfigException("配置文件服务和对应Assembly内服务不符");
            //}
            return(true);
        }
Example #2
0
 /// <summary>
 /// 从配置文件装载插件信息
 /// </summary>
 /// <param name="info">服务包裹信息</param>
 /// <param name="elem">装载的插件元素</param>
 /// <returns></returns>
 public static void SavePackageInfo(ServicePackageInfo info, XmlElement elem)
 {
     elem.RemoveAll();
     elem.SetAttribute("Name", info.Name);
     elem.SetAttribute("ImpleAssembly", info.ImpleAssemblyName);
     elem.SetAttribute("InfAssembly", info.InfAssemblyName);
     foreach (ServiceInfo s in info.Services)
     {
         XmlElement childelem = elem.OwnerDocument.CreateElement("service");
         SaveServiceInfo(s, childelem);
         elem.AppendChild(childelem);
     }
 }
Example #3
0
        /// <summary>
        /// 从配置文件装载插件信息
        /// </summary>
        /// <param name="elem">装载的插件元素</param>
        /// <returns></returns>
        public static ServicePackageInfo GetPackageInfo(XmlElement elem)
        {
            ServicePackageInfo ba = new ServicePackageInfo();

            ba.Name = XmlUtil.GetAttributeValue(elem, "Name");
            ba.ImpleAssemblyName = XmlUtil.GetAttributeValue(elem, "ImpleAssembly");
            ba.InfAssemblyName   = XmlUtil.GetAttributeValue(elem, "InfAssembly");
            foreach (XmlNode node in elem.ChildNodes)
            {
                if (!(node is XmlElement))
                {
                    continue;
                }

                XmlElement  serviceelem = node as XmlElement;
                ServiceInfo srvinfo     = ParseServiceInfo(serviceelem);
                ba.Services.Add(srvinfo);
            }
            return(ba);
        }
Example #4
0
        /// <summary>
        /// 从配置文件装载服务包信息,并通过Assembly验证
        /// </summary>
        /// <param name="elem"></param>
        /// <returns></returns>
        public ServicePackageInfo GetPackageInfoAssemblyValidate(XmlElement elem)
        {
            ServicePackageInfo bizinfo           = PackageInfoLoader.GetPackageInfo(elem);
            ParseAssembly      pa                = new ParseAssembly();
            string             infAssemblyPath   = Global.defaultBizFolder + bizinfo.InfAssemblyName;
            string             impleAssemblyPath = Global.defaultBizFolder + bizinfo.ImpleAssemblyName;
            ServicePackageInfo assemblyinfo      = pa.GetAssemblyInfo(infAssemblyPath, impleAssemblyPath);

            ServicePackageInfo result = new ServicePackageInfo();

            result.ImpleAssemblyName = bizinfo.ImpleAssemblyName;
            result.InfAssemblyName   = bizinfo.InfAssemblyName;
            foreach (ServiceInfo service in bizinfo.Services)
            {
                if (FindService(assemblyinfo.Services, service) != null)
                {
                    result.Services.Add(service);
                }
            }
            return(result);
        }
Example #5
0
        /// <summary>
        /// 获取业务插件的服务信息
        /// </summary>
        /// <param name="infpath"></param>
        /// <param name="implepath"></param>
        /// <returns></returns>
        public ServicePackageInfo GetAssemblyInfo(string infpath, string implepath)
        {
            ServicePackageInfo info = new ServicePackageInfo();

            info.InfAssemblyName   = ConfigUtil.GetBizPluginAssemblyName(infpath);
            info.ImpleAssemblyName = ConfigUtil.GetBizPluginAssemblyName(implepath);
            Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();

            Assembly infassembly   = AssemblyHelper.LoadAssembly(infpath);
            Assembly impleassembly = AssemblyHelper.LoadAssembly(implepath);

            Type[] inftypes   = infassembly.GetTypes();
            Type[] impletypes = impleassembly.GetTypes();

            foreach (Type t in impletypes)
            {
                if (t.GetInterface("DrectSoft.FrameWork.BizBus.Service.IService") != null)
                {
                    Type[] ts = t.GetInterfaces();
                    foreach (Type parenttype in ts)
                    {
                        if (!parenttype.Equals(typeof(IService)))
                        {
                            Type servicetype = FindTypes(inftypes, parenttype);
                            if (servicetype != null)
                            {
                                ServiceInfo si = new ServiceInfo();
                                si.Key             = servicetype.FullName;
                                si.ServiceTypeName = servicetype.FullName;
                                si.ImpleTypeName   = t.FullName;
                                info.Services.Add(si);
                            }
                        }
                    }
                }
            }
            return(info);
        }
Example #6
0
        private List <ServiceInfo> CheckServices(Assembly infassembly, Assembly impleassembly, ServicePackageInfo assemblyinfo)
        {
            List <ServiceInfo> errservice = new List <ServiceInfo>();

            for (int i = 0; i < assemblyinfo.Services.Count; i++)
            {
                ServiceInfo info    = assemblyinfo.Services[i];
                Type        inftype = infassembly.GetType(info.ServiceTypeName, false);
                if (inftype == null)
                {
                    errservice.Add(info);
                    continue;
                }
                Type impletype = impleassembly.GetType(info.ImpleTypeName, false);
                if (impletype == null)
                {
                    errservice.Add(info);
                    continue;
                }
            }
            return(errservice);
        }
Example #7
0
 /// <summary>
 /// 获取服务URI地址
 /// </summary>
 /// <param name="baseuripath"></param>
 /// <param name="packageinfo"></param>
 /// <param name="desc"></param>
 /// <returns></returns>
 public static string GetServiceUri(string baseuripath, ServicePackageInfo packageinfo, ServiceDesc desc)
 {
     //服务的URI地址=基础URI路径+服务包名称+服务关键字
     return(baseuripath + packageinfo.Name + "/" + desc.Key);
 }