コード例 #1
0
ファイル: DisconfMgr.cs プロジェクト: GavinYao2018/disconfnet
        /// <summary>
        /// 远程下载
        /// </summary>
        /// <param name="clientInfo"></param>
        /// <param name="item"></param>
        /// <param name="tmpPath"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public static string DownloadData(DisconfClientInfo clientInfo, DisconfClientItem item, string tmpPath, string file)
        {
            //http://disconf.frontpay.cn/api/config/file?version=1_0_0_1&app=YaoTest&env=dev&key=FrontConfig.xml
            string    fileUrl   = $"{DisconfConfigManager.DisconfDomain}/api/config/file?version={item.Version}&app={item.AppName}&env={DisconfConfigManager.DisconfEnvironment}&key={file}";
            WebClient webClient = new WebClient();
            var       str       = webClient.DownloadString(fileUrl);

            str = str.Replace("\\ufeff", ""); //BOM格式,需要去掉头部的四个\ufeff
            str = Uncode(str);                //转换中文
            return(str);
        }
コード例 #2
0
        /// <summary>
        /// 获取客户端需要下载的配置文件
        /// </summary>
        /// <param name="clients"></param>
        /// <returns></returns>
        public static List <DisconfClientInfo> GetClientConfig(List <string> clients)
        {
            List <DisconfClientInfo> list = new List <DisconfClientInfo>();

            foreach (var client in clients)
            {
                try
                {
                    XDocument doc           = XDocument.Load(client);
                    var       configuration = doc.Elements().FirstOrDefault(s => s.Name.LocalName.EqualsIgnoreCase("configuration"));
                    var       items         = configuration.Elements().Where(s => s.Name.LocalName.EqualsIgnoreCase("Disconf"));
                    if (items.Count() == 0)
                    {
                        continue;
                    }

                    var disconf = items.First();
                    if (disconf.Attribute("FilePath") == null)
                    {
                        throw new Exception("Disconf无FilePath属性");
                    }
                    DisconfClientInfo clientInfo = new DisconfClientInfo();
                    clientInfo.FilePath = disconf.Attribute("FilePath").Value;


                    items = disconf.Elements().Where(s => s.Name.LocalName.EqualsIgnoreCase("Item"));
                    if (items.Count() == 0)
                    {
                        continue;
                    }

                    clientInfo.Items = new List <DisconfClientItem>();
                    foreach (XElement item in items)
                    {
                        DisconfClientItem clientItem = new DisconfClientItem();
                        if (item.Attribute("AppName") == null)
                        {
                            throw new Exception("某项Item无AppName属性");
                        }
                        if (item.Attribute("Version") == null)
                        {
                            throw new Exception("某项Item无Version属性");
                        }
                        if (item.Attribute("Files") == null)
                        {
                            throw new Exception("某项Item无Files属性");
                        }
                        clientItem.AppName = item.Attribute("AppName").Value;
                        clientItem.Version = item.Attribute("Version").Value;
                        clientItem.Files   = item.Attribute("Files").Value;
                        clientInfo.Items.Add(clientItem);
                    }

                    list.Add(clientInfo);
                }
                catch (Exception ex)
                {
                    Logger.Error($"读取{client}的配置错误", ex);
                }
            }

            return(list);
        }