Esempio n. 1
0
        /// <summary>
        /// 从缓存中获取接口定义
        /// </summary>
        /// <param name="strApiName">接口名称</param>
        /// <returns></returns>
        public APIItem GetApiFromCache(string strApiName)
        {
            APIItem        item  = null;
            Cache          cache = HttpRuntime.Cache;
            List <APIItem> items = (List <APIItem>)cache.Get("apilist");

            if (items == null)
            {
                APIManage manager = APIManage.GetInstance();
                items = manager.GetApiList();
            }
            item = GetApiByName(items, strApiName);

            return(item);
        }
Esempio n. 2
0
 /// <summary>
 /// 获取ApiManager的单例形式
 /// </summary>
 /// <returns></returns>
 public static APIManage GetInstance()
 {
     if (_Instance != null)
     {
         return(_Instance);
     }
     lock (_Lock)
     {
         if (_Instance == null)
         {
             _Instance = new APIManage();
         }
     }
     return(_Instance);
 }
Esempio n. 3
0
        /// <summary>
        /// 执行API方法并把执行结果返回
        /// </summary>
        /// <param name="APIName"></param>
        /// <param name="APIData"></param>
        /// <returns></returns>
        public static bool ExecAPI(string APIName, string APIData, out string ExecResult, ref string apiChinaName)
        {
            bool isSuccess = false;
            //实例化API管理对象
            APIManage manager = APIManage.GetInstance();
            //获取指定API名称的详细信息
            APIItem item = manager.GetApiFromCache(APIName);
            //API执行结果描述
            APIResult apiResult = new APIResult();

            try
            {
                if (item == null)
                {
                    throw new Exception("接口不存在,找不到此接口:" + APIName);
                }
                //获取命名空间
                string strNameSpace = manager.GetNameSpace();
                //程序集名称
                string strAssemblyName = item.AssemblyName;
                //类型全名称
                string strTypeFullName = strNameSpace + "." + item.TypeName;
                //方法名
                string strMethodName = item.MethodName;

                apiChinaName = item.APIBrief;
                ///接口不存在

                object obj = Reflect.ExecAPI(strAssemblyName, strTypeFullName, strMethodName, APIData, item.ObjectMode);
                if (item.ObjectMode)
                {
                    apiResult.result    = 0;
                    apiResult.resultStr = "执行成功";
                    apiResult.data      = obj;
                    ExecResult          = ReturnStrJson(apiResult);
                }
                else
                {
                    ExecResult = ReturnStrJson(obj);
                }

                isSuccess = true;
            }
            catch (Exception e)
            {
                apiResult.result = 1;
                if (e.InnerException != null)
                {
                    apiResult.resultStr = e.InnerException.Message.Replace("\r\n", "");
                }
                else
                {
                    apiResult.resultStr = e.Message.Replace("\r\n", "");
                }

                ExecResult = ReturnStrJson(apiResult);
            }
            //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式

            return(isSuccess);
        }