예제 #1
0
        public HttpResponseMessage GetSegClassList(dynamic obj)
        {
            List <SegClassInfo> segClassInfos = new List <SegClassInfo>();

            try
            {
                var type = typeof(ICodeSeg);
                var otherPlatformType = typeof(IOtherFlatformSeg);
                var test  = Assembly.GetExecutingAssembly().GetTypes().Where(item => item.GetInterfaces().Contains(typeof(ICodeSeg))).ToList();
                var types = Assembly.Load(new AssemblyName("Acctrue.CMC.CodeBuild")).GetTypes().ToArray();
                //var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(s => s.GetTypes()).Where<Type>(p => type.IsAssignableFrom(p.GetGenericTypeDefinition()));
                //AppDomain.CurrentDomain.AssemblyLoad().SelectMany(s => s.GetTypes())
                //.Where(p => type.IsAssignableFrom(p.GetGenericTypeDefinition()));

                foreach (var v in types)
                {
                    if (v.IsClass && !v.IsAbstract && type.IsAssignableFrom(v))
                    {
                        if ((obj.codeRuleType == 2 && otherPlatformType.IsAssignableFrom(v)) || (obj.codeRuleType == 1 && !otherPlatformType.IsAssignableFrom(v)))
                        {
                            ICodeSeg     seg     = (Activator.CreateInstance(v) as ICodeSeg);
                            SegClassInfo segInfo = new SegClassInfo();
                            segInfo.ClassName     = v.FullName;
                            segInfo.Description   = seg.Description;
                            segInfo.CodeRuleType  = (CodeRuleType)Convert.ToInt32(obj.codeRuleType);
                            segInfo.SegParameters = seg.GetArgsFormat();
                            segClassInfos.Add(segInfo);
                        }
                    }
                }
            }
            catch
            {
                throw new Exception("反射码段信息失败,请重试或重启IIS服务器!");
            }
            string respon = "{ \"code\":0,\"msg\":1,\"count\":" + segClassInfos.Count + ",\"data\":" + JsonConvert.SerializeObject(segClassInfos).ToString() + "}";
            HttpResponseMessage result = new HttpResponseMessage {
                Content = new StringContent(respon, Encoding.GetEncoding("UTF-8"), "application/json")
            };

            return(result);
        }
예제 #2
0
        public string GetSegClassConfig(dynamic obj)
        {
            int    stateCode = 0;
            string msg       = string.Empty;
            List <Model.Code.ParameterInfo> argsInfo = new List <Model.Code.ParameterInfo>();

            try
            {
                //(Activator.CreateInstance(v) as ICodeSeg);
                Type type = Assembly.Load(new AssemblyName("Acctrue.CMC.CodeBuild")).GetType((string)obj.ClassName);

                ICodeSeg seg = (Activator.CreateInstance(type) as ICodeSeg);
                argsInfo = seg.GetArgsFormat();
            }
            catch
            {
            }
            //argsInfo.Clear();
            //argsInfo.Add(new Model.CodeRules.ParameterInfo() { CheckFormat="aaaa", Description="aaa", ParamenterKey="aaa", ParamenterValues="aaa"});
            string respon = "{ \"code\":" + stateCode + ",\"msg\":\"" + msg + "\",\"data\":" + JsonConvert.SerializeObject(argsInfo).ToString() + "}";

            return(respon);
        }