Beispiel #1
0
 public void RegisterMenu()
 {
     if (string.IsNullOrEmpty(MicroServiceConfig.ImsHost))
     {
         logger.LogError(new Exception("向IMS注册功能菜单异常,IMS服务地址未配置"), "请到IMS->参数配置->微服务配置中进行“IMS服务地址”的配置");
     }
     else
     {
         string          url     = $"http://{MicroServiceConfig.ImsHost}/api/Common/MicroService/RegisterFunction";
         tsdnHttpRequest request = new tsdnHttpRequest();
         request.AddressUrl = url;
         request.Method     = HttpMethod.Post;
         var pData = new
         {
             App   = SysConfig.MicroServiceOption.Application,
             Menus = SysConfig.MicroServiceOption.ImsMenu
         };
         request.Body = pData;
         var result = request.SendAsync <ApiResult <bool> >().Result;
         if (result.Code.IsSuccessCode())
         {
             logger.LogInformation($"向{url}成功注册了功能菜单{JsonConvert.SerializeObject(pData)}");
         }
         else
         {
             logger.LogError(result.Exception, $"向{url}注册功能菜单出现异常,{result.Message}");
         }
     }
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        public void Configure()
        {
            MicroRegisterInfo info = new MicroRegisterInfo();

            info.app   = GetAppInfo();
            info.hosts = GetHostInfo();
            info.paths = GetApiInfo();

            string          url     = SysConfig.MicroServiceOption.Cloud.RegistCenterUri + "/micro/UDDI/Register";
            tsdnHttpRequest request = new tsdnHttpRequest();

            request.AddressUrl = url;
            request.Method     = HttpMethod.Post;
            request.Body       = info;
            bool result = request.SendAsync <bool>().Result;

            if (result)
            {
                logger.LogInformation($"向注册中心({SysConfig.MicroServiceOption.Cloud.RegistCenterUri})注册节点成功");
                if (SysConfig.MicroServiceOption.Type == RegisterType.IMS)
                {
                    var menuRegister = iocManager.Resolve <IMenuRegister>(RegisterType.IMS.ToString());
                    menuRegister.RegisterMenu();
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// 从WebAPI中获取列表数据
 /// </summary>
 /// <param name="info">EXECL相关信息</param>
 /// <param name="token">用户认证令牌</param>
 /// <returns></returns>
 private static DataTable GetGirdData(ExcelInfo info, string token)
 {
     if (info.IsExportSelectData)
     {
         if (info.Data == null)
         {
             info.Data = new DataTable();
         }
         return(info.Data);
     }
     try
     {
         HttpMethod method = HttpMethod.Get;
         if (info.Type.Equals(HttpMethod.Post.ToString(), StringComparison.OrdinalIgnoreCase))
         {
             method = HttpMethod.Post;
         }
         tsdnHttpRequest request = new tsdnHttpRequest
         {
             Method     = method,
             Token      = token,
             AddressUrl = info.Api,
             Body       = info.Condition
         };
         var responseJson = request.SendAsync <ExcelApiResult>().Result;
         if (!responseJson.HasError && responseJson.Message != "logout")
         {
             return(info.ConvertDataEx2Data(responseJson.Result));
         }
         else
         {
             DataTable dt = new DataTable();
             dt.Columns.Add(info.ColumnInfoList[0].Field);
             DataRow dr = dt.NewRow();
             //接口报错
             if (responseJson.HasError)
             {
                 dr[0] = responseJson.Message;
             }
             if (responseJson.Message == "logout")
             {
                 dr[0] = "登录超时,请刷新页面重试";
             }
             dt.Rows.Add(dr);
             return(dt);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #4
0
        public void Configure()
        {
            IIocManager      iocManager = IocManager.Instance;
            IAppInfoProvider appInfo    = iocManager.Resolve <IAppInfoProvider>();
            ILogger          logger     = iocManager.Resolve <ILogger <AfterRunConfigureModule> >();
            IEnumerable <IAfterRunConfigure> configures = iocManager.Resolve <IEnumerable <IAfterRunConfigure> >();

            Task.Factory.StartNew(() =>
            {
                tsdnHttpRequest request = new tsdnHttpRequest();
                string name             = SysConfig.MicroServiceOption.Application.Name;
                request.AddressUrl      = $"http://{appInfo.IpAddress}:{appInfo.Ports[0]}/api/{name}/Health/ApiServer";
                int i = 0;
                while (true)
                {
                    try
                    {
                        var responeMessage = request.SendAsync().Result;
                        if (responeMessage.StatusCode == HttpStatusCode.OK)
                        {
                            if (configures != null && configures.Count() > 0)
                            {
                                foreach (var item in configures.OrderBy(e => e.Order))
                                {
                                    try
                                    {
                                        item.Configure();
                                    }
                                    catch (Exception e)
                                    {
                                        logger.LogError(e.InnerException != null ? e.InnerException : e, $"调用类型{item.GetType().ToString()}的Configure方法异常");
                                    }
                                }
                            }
                            break;
                        }
                    }
                    catch { }
                    if (i > 30)
                    {
                        logger.LogError("程序启动异常,30s内http服务还未启动成功");
                        break;
                    }
                    i++;
                    Task.Delay(100).Wait();
                }
            });
        }
Beispiel #5
0
        /// <summary>
        /// 获取系统api接口信息
        /// </summary>
        /// <returns></returns>
        private List <MicroApiInfo> GetApiInfo()
        {
            tsdnHttpRequest request = new tsdnHttpRequest();

            request.AddressUrl = $"http://{appInfo.IpAddress}:{appInfo.Ports[0]}/swagger/v1/swagger.json";
            var             jobject = request.SendAsync <JObject>().Result;
            var             Paths   = jobject["paths"].ToObject <IDictionary <string, PathDetail> >();
            var             list    = new List <MicroApiInfo>();
            OperationDetail detail  = null;
            string          method  = string.Empty;

            foreach (string path in Paths.Keys)
            {
                var item = Paths[path];
                detail = GetOperationDetail(item, out method);
                if (detail == null)
                {
                    continue;
                }
                list.Add(new MicroApiInfo
                {
                    scheme  = "http",
                    path    = path,
                    method  = method,
                    tags    = detail.Tags != null ? string.Join(",", detail.Tags) : "",
                    summary = detail.Summary
                });
            }
            if (SysConfig.MicroServiceOption.ImsMenu != null)
            {
                foreach (var item in SysConfig.MicroServiceOption.ImsMenu)
                {
                    if (string.IsNullOrEmpty(item.ParentCode) || string.IsNullOrEmpty(item.FunctionUrl))
                    {
                        continue;
                    }
                    list.Add(new MicroApiInfo
                    {
                        scheme  = "menu",
                        path    = "/" + SysConfig.MicroServiceOption.Application.Name + item.FunctionUrl,
                        feature = item.FunctionUrl,
                        tags    = "",
                        summary = item.FunctionName
                    });
                }
            }
            return(list);
        }