コード例 #1
0
        private void AddNewCaller(Type serviceType, HttpApiMethod httpApi)
        {
            //将方法添加到字典
            var callerInfo = new HttpCallerInfo
            {
                CacheTime     = httpApi.CacheTime,
                Service       = serviceType,
                Method        = httpApi.Method,
                TypeString    = httpApi.Method.ReturnType == typeof(string),
                Description   = httpApi.Description,
                Authorized    = httpApi.Authorized,
                AuthParameter = httpApi.AuthParameter,
                HttpMethod    = httpApi.HttpMethod
            };

            string fullName = httpApi.Name;

            if (callers.ContainsKey(fullName))
            {
                //处理重复的方法
                for (int i = 0; i < 10000; i++)
                {
                    var name = fullName + (i + 1);
                    if (!callers.ContainsKey(name))
                    {
                        fullName = name;
                        break;
                    }
                }
            }

            callerInfo.CallerName = fullName;
            callers[fullName]     = callerInfo;
        }
コード例 #2
0
        /// <summary>
        /// 获取Item文档
        /// </summary>
        /// <param name="caller"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private string GetItemDocument(HttpCallerInfo caller, string name)
        {
            var template = itemTemplate;
            var plist    = new List <string>();

            foreach (var p in caller.Method.GetParameters())
            {
                if (caller.Authorized && string.Compare(p.Name, caller.AuthParameter, true) == 0)
                {
                    continue;
                }

                plist.Add(string.Format("{0}=[{0}]", p.Name).Replace('[', '{').Replace(']', '}'));
            }

            string uri = string.Empty;

            if (caller.HttpMethod == HttpMethod.GET && plist.Count > 0)
            {
                uri = string.Format("/{0}?{1}", caller.CallerName, string.Join("&", plist.ToArray()));
            }
            else
            {
                uri = string.Format("/{0}", caller.CallerName);
            }

            var url = string.Format("<a rel=\"operation\" target=\"_blank\" title=\"{0}\" href=\"{0}\">{0}</a> 处的服务", uri.ToLower());

            var description = caller.Description == null ? null : caller.Description.Replace("\r\n", "<br/>");
            var serviceInfo = string.Format("【{0}】\r\n【{1}】", caller.Service.FullName, caller.Method.ToString());

            template = template.Replace("${method}", string.Format("<p title=\"分布式服务接口:\r\n{2}\"><b><a href='/help/{0}'>{0}</a></b><br/>{1}</p>",
                                                                   caller.CallerName, description, serviceInfo));

            var strParameter = GetMethodParameter(caller.Method, caller.Authorized, caller.AuthParameter, name);

            if (string.IsNullOrEmpty(strParameter))
            {
                template = template.Replace("${parameter}", "&nbsp;");
            }
            else
            {
                template = template.Replace("${parameter}", strParameter);
            }

            template = template.Replace("${type}", caller.HttpMethod == HttpMethod.GET ? "GET<br/>POST" : "<font color='red'>POST</font>");
            template = template.Replace("${auth}", caller.Authorized ? "<font color='red'>是</font>" : "&nbsp;");
            if (caller.Authorized)
            {
                template = template.Replace("${authparameter}", caller.AuthParameter);
            }
            else
            {
                template = template.Replace("${authparameter}", "&nbsp;");
            }
            template = template.Replace("${uri}", url.ToString());

            return(template);
        }
コード例 #3
0
        /// <summary>
        /// 获取Item文档
        /// </summary>
        /// <param name="caller"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private string GetItemDocument(HttpCallerInfo caller, string name)
        {
            var template = itemTemplate;
            var plist = new List<string>();
            foreach (var p in caller.Method.GetParameters())
            {
                if (caller.Authorized && string.Compare(p.Name, caller.AuthParameter, true) == 0)
                    continue;

                plist.Add(string.Format("{0}=[{0}]", p.Name).Replace('[', '{').Replace(']', '}'));
            }

            string uri = string.Empty;
            if (caller.HttpMethod == HttpMethod.GET && plist.Count > 0)
                uri = string.Format("/{0}?{1}", caller.CallerName, string.Join("&", plist.ToArray()));
            else
                uri = string.Format("/{0}", caller.CallerName);

            var url = string.Format("<a rel=\"operation\" target=\"_blank\" title=\"{0}\" href=\"{0}\">{0}</a> 处的服务", uri.ToLower());

            var description = caller.Description == null ? null : caller.Description.Replace("\r\n", "<br/>");
            var serviceInfo = string.Format("【{0}】\r\n【{1}】", caller.Service.FullName, caller.Method.ToString());
            template = template.Replace("${method}", string.Format("<p title=\"分布式服务接口:\r\n{2}\"><b><a href='/help/{0}'>{0}</a></b><br/>{1}</p>",
                caller.CallerName, description, serviceInfo));

            var strParameter = GetMethodParameter(caller.Method, caller.Authorized, caller.AuthParameter, name);
            if (string.IsNullOrEmpty(strParameter))
                template = template.Replace("${parameter}", "&nbsp;");
            else
                template = template.Replace("${parameter}", strParameter);

            template = template.Replace("${type}", caller.HttpMethod == HttpMethod.GET ? "GET<br/>POST" : "<font color='red'>POST</font>");
            template = template.Replace("${auth}", caller.Authorized ? "<font color='red'>是</font>" : "&nbsp;");
            if (caller.Authorized)
                template = template.Replace("${authparameter}", caller.AuthParameter);
            else
                template = template.Replace("${authparameter}", "&nbsp;");
            template = template.Replace("${uri}", url.ToString());

            return template;
        }
コード例 #4
0
        private void AddNewCaller(Type serviceType, HttpApiMethod httpApi)
        {
            //将方法添加到字典
            var callerInfo = new HttpCallerInfo
            {
                CacheTime = httpApi.CacheTime,
                Service = serviceType,
                Method = httpApi.Method,
                TypeString = httpApi.Method.ReturnType == typeof(string),
                Description = httpApi.Description,
                Authorized = httpApi.Authorized,
                AuthParameter = httpApi.AuthParameter,
                HttpMethod = httpApi.HttpMethod
            };

            string fullName = httpApi.Name;
            if (callers.ContainsKey(fullName))
            {
                //处理重复的方法
                for (int i = 0; i < 10000; i++)
                {
                    var name = fullName + (i + 1);
                    if (!callers.ContainsKey(name))
                    {
                        fullName = name;
                        break;
                    }
                }
            }

            callerInfo.CallerName = fullName;
            callers[fullName] = callerInfo;
        }