|
@@ -3,6 +3,8 @@ using Newtonsoft.Json.Linq;
|
|
|
using PDF_Master.Properties;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Drawing;
|
|
|
+using System.Drawing.Imaging;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Management;
|
|
@@ -14,9 +16,10 @@ using System.Threading.Tasks;
|
|
|
|
|
|
namespace PDF_Master.Helper
|
|
|
{
|
|
|
+ //本辅助类不使用viewmodel,因为同时在PDFreaderPro上使用
|
|
|
public static class ADServiceHelper
|
|
|
{
|
|
|
-
|
|
|
+ public static bool IsUpdate=false;
|
|
|
public static string RequestHost = "http://test-store.kdan.cn:3019";
|
|
|
public static string AdUrl = "/api/advertise-new";
|
|
|
public static string ImageUrl;
|
|
@@ -60,31 +63,77 @@ namespace PDF_Master.Helper
|
|
|
foreach (var j in jarr)
|
|
|
{
|
|
|
|
|
|
- Console.WriteLine(j[2].ToString());
|
|
|
+ Console.WriteLine(j["detail"].ToString());
|
|
|
JObject jobject2 = (JObject)JsonConvert.DeserializeObject(j["detail"].ToString());
|
|
|
- Settings.Default.ADDate.Pngtest= (jobject2["productsidebar"]["imageURL"]["en"].ToObject<string>());
|
|
|
- Settings.Default.ADDate.Pnglinktest = (jobject2["linkURL"]["en"].ToObject<string>());
|
|
|
-
|
|
|
+ Settings.Default.ADDate.ADhiddenSidebar = jobject2["productsidebar"]["hidden"].ToObject<string>();
|
|
|
+ Settings.Default.ADDate.ADStartTime = jobject2["startTime"].ToObject<long>();
|
|
|
+ Settings.Default.ADDate.ADEndTime = jobject2["endTime"].ToObject<long>();
|
|
|
+ if (Settings.Default.ADDate.ADVersion != jobject2["version"].ToObject<string>())
|
|
|
+ {
|
|
|
+ //清除ADTemp文件夹及该目录中的所有子内容
|
|
|
+ string ADPath = Path.Combine(App.CurrentPath, "ADTemp");
|
|
|
+ DirectoryInfo Scantempfolder = new DirectoryInfo(ADPath);
|
|
|
+ if (Scantempfolder.Exists)
|
|
|
+ {
|
|
|
+ Directory.Delete(ADPath, true);
|
|
|
+ }
|
|
|
+ IsUpdate = true;
|
|
|
+
|
|
|
+ Settings.Default.ADDate.ADSidebar = jobject2["productsidebar"]["imageURL"]["en"].ToObject<string>();
|
|
|
+ Settings.Default.ADDate.ADLinkSidebar = jobject2["productsidebar"]["linkURL"]["en"].ToObject<string>();
|
|
|
+
|
|
|
+
|
|
|
+ Settings.Default.ADDate.ADVersion = jobject2["version"].ToObject<string>();
|
|
|
+ Settings.Default.Save();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+ if(IsUpdate==true)
|
|
|
+ {
|
|
|
+ string path = App.CachePath.ADFilePath;
|
|
|
+ string FileName = path + "\\" + 1 + ".png";
|
|
|
+
|
|
|
+ WebClient client = new WebClient();
|
|
|
+ client.DownloadFile(Settings.Default.ADDate.ADSidebar, FileName);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+ string str1 = System.Environment.CurrentDirectory;
|
|
|
return jobject["code"].ToObject<string>().ToLower();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
catch (System.Net.WebException e)
|
|
|
{
|
|
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
- if (Settings.Default.AppProperties.LoginToken == "")
|
|
|
- return "No Token";
|
|
|
- else if (e.Message == "远程服务器返回错误: (401) 未经授权。")
|
|
|
+
|
|
|
+ if (e.Message == "未能解析此远程名称: 'test-store.kdan.cn'")
|
|
|
{
|
|
|
- return "401";
|
|
|
+ return "404";
|
|
|
}
|
|
|
- else return "300";
|
|
|
+ else return "0000";
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static void Down(string url, string dtnow)
|
|
|
+ {
|
|
|
+ WebRequest wreq = WebRequest.Create(url);
|
|
|
+
|
|
|
+ HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
|
|
|
+ Stream s = wresp.GetResponseStream();
|
|
|
+ System.Drawing.Image img;
|
|
|
+ img = System.Drawing.Image.FromStream(s);
|
|
|
+ img.Save("E:\\" + dtnow, ImageFormat.Jpeg);
|
|
|
+ MemoryStream ms = new MemoryStream();
|
|
|
+ img.Save(ms, ImageFormat.Jpeg);
|
|
|
+ img.Dispose();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|