123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Xml;
- using System.Text;
- using CB.Common;
- namespace CB.Config
- {
- public class ColumnConfigs
- {
- private static string configPath = AppDomain.CurrentDomain.BaseDirectory + "Config\\ColumnConfigs.config";
- private static long version = 0;
- private static ColumnConfigInfo config = null;
- private static object lockObject = new object();
- static ColumnConfigs()
- { LoadConfig(); }
- private ColumnConfigs() { }
- private static void LoadConfig()
- {
- var _config = new ColumnConfigInfo();
- if (File.Exists(configPath))
- {
- XmlDocument doc = new XmlDocument();
- doc.Load(configPath);
- var root = doc.SelectSingleNode("Config");
- if (null != root)
- {
- var node = root.SelectSingleNode("TukuFileUrl");
- if (null != node)
- _config.TukuFileUrl = node.InnerText.Trim();
- node = root.SelectSingleNode("TukuWebServiceUrl");
- if (null != node)
- _config.TukuWebServiceUrl = node.InnerText.Trim();
- node = root.SelectSingleNode("TukuDomain");
- if (null != node)
- _config.TukuDomain = node.InnerText.Trim();
- }
- version = File.GetLastWriteTime(configPath).Ticks;
- }
- config = _config;
- }
- public static ColumnConfigInfo GetConfig()
- {
- if (null == config)
- { LoadConfig(); }
- if (version != File.GetLastWriteTime(configPath).Ticks)
- { LoadConfig(); }
- return config;
- }
- /// <summary>
- /// 保存配置文件
- /// </summary>
- /// <param name="config"></param>
- /// <returns></returns>
- public static bool SaveConfig(ColumnConfigInfo config)
- {
- var sp = new StringBuilder(2000);
- sp.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n");
- sp.Append("<Config>\r\n");
- sp.Append(" <TukuFileUrl>" + config.TukuFileUrl + "</TukuFileUrl>\r\n");
- sp.Append(" <TukuWebServiceUrl>" + config.TukuWebServiceUrl + "</TukuWebServiceUrl>\r\n");
- sp.Append(" <TukuDomain>" + config.TukuDomain + "</TukuDomain>\r\n");
- sp.Append("</Config>");
- using (StreamWriter writer = new StreamWriter(configPath, false, System.Text.Encoding.UTF8, sp.Length))
- {
- writer.Write(sp.ToString());
- }
- return true;
- }
- /// <summary>
- /// 获取图库最新已上传文件列表
- /// </summary>
- /// <returns></returns>
- public static List<GalleryEntity> GetTukuFileList(int cid)
- {
- try
- {
- //TuKuWebService.tuku tk = new TuKuWebService.tuku();
- //tk.Url = config.TukuWebServiceUrl;
- //tk.Timeout = 5000;
- //return tk.GetFileList();
- WebServiceTuku.WebServiceTuku tuku = new WebServiceTuku.WebServiceTuku();
- string res = tuku.GetNewGallery(cid);
- if (!string.IsNullOrEmpty(res))
- {
- List<GalleryEntity> list = JSONUtil.ParseFormByJson<List<GalleryEntity>>(res);
- return list;
- //"galleryName": "3D联盟好彩乐第二版",
- //"galleryNumberNew": "29",
- //"galleryID": 263,
- //"UrlParms": "2017264_A",
- //"CreateTime": "2017-09-20T15:25:18.41",
- //"PerNumber": "257"
- }
- return null;
- }
- catch(Exception e)
- {
- Console.WriteLine(e.Message);
- return null;
- }
- }
- /// <summary>
- /// 获取图库最新期数
- /// </summary>
- /// <returns></returns>
- public static int GetTukuLatestQi()
- {
- try
- {
- //TuKuWebService.tuku tk = new TuKuWebService.tuku();
- //tk.Url = config.TukuWebServiceUrl;
- //tk.Timeout = 5000;
- //return tk.GetMaxQi();http://tk.55128.cn/WebServiceTuku.asmx
- WebServiceTuku.WebServiceTuku tuku = new WebServiceTuku.WebServiceTuku();
- int res = tuku.GetNewPeriodsNumber();
- return res;
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- return 0;
- }
- }
- }
- }
|