public FrameDLRObject GetRouteDesc(string version)
 {
     return(RouteDesc.GetValue(version) == null ? null : (FrameDLRObject)RouteDesc.GetValue(version));
 }
Beispiel #2
0
        /// <summary>
        /// 创建Rest入口节点上下文
        /// </summary>
        /// <param name="assemblyName">logic所在的Assembly名称</param>
        /// <param name="mainversion">主版本号</param>
        /// <returns></returns>
        public override void Load(string assemblyName, string mainversion, Type logicBaseType)
        {
            MainVersion = mainversion;
            Assembly asm = Assembly.Load(new AssemblyName(assemblyName));

            Type[] ts   = asm.GetTypes();
            var    reg  = new Regex(@"(?<=.)V\d+._\d+", RegexOptions.IgnoreCase);
            var    list = ts.Where(p => p.GetTypeInfo().IsSubclassOf(logicBaseType)).ToList();

            foreach (var t in list.Where(p => p.GetTypeInfo().BaseType == logicBaseType))
            {
                var ple = EntryPointEntity.CreateFrom(t, list, logicBaseType);
                //如果为null,则不处理
                if (ple == null)
                {
                    continue;
                }
                //在版本号下构建多入口节点
                if (!_d_entry_.ContainsKey(ple.APIVersion))
                {
                    var entrylist = new List <EntryPointEntity>();
                    entrylist.Add(ple);
                    _d_entry_.Add(ple.APIVersion, entrylist);
                }
                else
                {
                    _d_entry_[ple.APIVersion].Add(ple);
                }
            }
            RouteDesc     = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            MainRouteDesc = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase);
            foreach (var litem in _d_entry_)
            {
                foreach (var item in litem.Value)
                {
                    if (!RouteDesc.Keys.Contains(item.APIVersion))
                    {
                        RouteDesc.SetValue(item.APIVersion, item.RouteDesc);
                    }
                    else
                    {
                        var rd    = (FrameDLRObject)RouteDesc.GetValue(item.APIVersion);
                        var index = rd.Keys.Count;
                        foreach (var v in item.RouteDesc.Items)
                        {
                            rd.SetValue($"NO.{index+1}", v.Value);
                            index++;
                        }
                    }
                }
            }
            if (MainVersion == "")
            {
                var ver = "v0.0";
                foreach (KeyValuePair <string, object> item in RouteDesc.Items)
                {
                    var v = double.Parse(item.Key.Replace("v", ""));
                    if (v > double.Parse(ver.Replace("v", "")))
                    {
                        ver = item.Key;
                    }
                }
                MainVersion = ver;
            }
            if (RouteDesc.GetValue(MainVersion) != null)
            {
                MainRouteDesc = (FrameDLRObject)RouteDesc.GetValue(MainVersion);
            }
            else
            {
                MainRouteDesc.SetValue("warning", "无可调用API");
            }
        }