Explorar el Código

远程广告接口左下角广告控制

lvle hace 1 año
padre
commit
ceb9fa6bc9

+ 59 - 10
PDF Office/Helper/ADServiceHelper.cs

@@ -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();
+
+
+        }
 
 
 

+ 17 - 0
PDF Office/Helper/CacheFilePath.cs

@@ -34,6 +34,11 @@ namespace PDF_Master.Helper
 
         private List<string> CreatedFile = new List<string>() { "CreatedFile"};
 
+        /// <summary>
+        /// 扫描仪缓存文件夹路径
+        /// </summary>
+        List<string> ADFile = new List<string> { "ADTemp" };
+
 
         private CPDFDocument copyDoc;
         /// <summary>
@@ -121,6 +126,18 @@ namespace PDF_Master.Helper
         }
 
 
+        /// <summary>
+        /// AD文件的缓存文件夹
+        /// </summary>
+        public string ADFilePath
+        {
+            get
+            {
+                return CreateCacheDirectory(ADFile);
+            }
+        }
+
+
         /// <summary>
         /// 用于保存新建的临时文档
         /// </summary>

+ 1 - 7
PDF Office/ViewModels/Dialog/ServiceDialog/RegisterDialogViewModel.cs

@@ -23,13 +23,7 @@ namespace PDF_Master.ViewModels.Dialog.ServiceDialog
 
         public event Action<IDialogResult> RequestClose;
 
-        private string _ADtest=Settings.Default.ADDate.Pngtest;
-        
-        public string ADtest
-        {
-            get { return _ADtest; }
-            set { _ADtest = value; }
-        }
+      
 
         private string _RegisterRegionName;
         public string RegisterRegionName

+ 2 - 2
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -334,8 +334,8 @@ namespace PDF_Master.ViewModels
                 ));
 
                 App.IsFirstOpen = false;
-                //ADServiceHelper.GetAD("PDFMasterWindows");
-                
+                ADServiceHelper.GetAD("PDFMasterWindows");
+
 
             }
             //判断本地有没有token,没有显示登录,有再判断登录状态

+ 2 - 4
PDF Office/Views/Dialog/ServiceDialog/RegisterDialog.xaml

@@ -17,10 +17,8 @@
             <ColumnDefinition/>
         </Grid.ColumnDefinitions>
         <Grid >
-            <!--<Image Source="pack://application:,,,/Resources/Service/Login.png" />-->
-            <Image Source="{Binding ADtest}" MouseLeftButtonDown="Image_MouseLeftButtonDown" >
-                
-            </Image>
+            <Image Source="pack://application:,,,/Resources/Service/Login.png" />
+         
         </Grid>
         <Grid Grid.Column="1" >
             <ContentControl prism:RegionManager.RegionName="{Binding RegisterRegionName}" Visibility="Visible"/>

+ 1 - 4
PDF Office/Views/Dialog/ServiceDialog/RegisterDialog.xaml.cs

@@ -34,9 +34,6 @@ namespace PDF_Master.Views.Dialog.ServiceDialog
             RegionManager.UpdateRegions();
         }
 
-        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
-        {
-            Process.Start(new ProcessStartInfo(Settings.Default.ADDate.Pnglinktest)); 
-        }
+      
     }
 }

+ 2 - 2
PDF Office/Views/HomeContent.xaml

@@ -188,9 +188,9 @@
             Grid.RowSpan="2"
             Grid.Column="1"
             prism:RegionManager.RegionName="{Binding ToolRegionName}" />
-        <cus:LoadingControl
+        <!--<cus:LoadingControl
             Grid.RowSpan="2"
             Grid.ColumnSpan="2"
-            Visibility="{Binding IsLoading}" />
+            Visibility="{Binding IsLoading}" />-->
     </Grid>
 </UserControl>

+ 1 - 0
PDF Office/Views/HomePanel/PromotionContent.xaml

@@ -135,6 +135,7 @@
                 Grid.Row="1"
                 Width="184"
                 Height="243"
+                Source="C:\\Users\\kdan\\Documents\\PDF Master\\ADTemp\\1.png"
                 Margin="0,24"
                 VerticalAlignment="Bottom"
                 PreviewMouseLeftButtonDown="ImgeActivity_PreviewMouseLeftButtonDown" />

+ 23 - 4
PDF Office/Views/HomePanel/PromotionContent.xaml.cs

@@ -1,4 +1,5 @@
-using System;
+using PDF_Master.Properties;
+using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Linq;
@@ -53,9 +54,10 @@ namespace PDF_Master.Views.HomePanel
         {
             InitializeComponent();
             InitPromotionBanner();
-            LoadPromotionContents();
+            //LoadPromotionContents();
+            ADDispaly();
 
-            ImgeActivity.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/PromotionIcon/black_pdfreaderpro_home_en.png"));
+         
         }
 
         private void InitPromotionBanner()
@@ -74,6 +76,23 @@ namespace PDF_Master.Views.HomePanel
             OthersListview.ItemsSource = OthersPromotion;
         }
 
+
+        private void ADDispaly()
+        {
+            DateTime targetstartTime = DateTimeOffset.FromUnixTimeMilliseconds(Settings.Default.ADDate.ADStartTime).DateTime; 
+            DateTime targetendTime = DateTimeOffset.FromUnixTimeMilliseconds(Settings.Default.ADDate.ADEndTime).DateTime; 
+            DateTime localTime = DateTime.Now; 
+            
+            if (Settings.Default.ADDate.ADhiddenSidebar.ToLower()=="false"&& localTime<targetendTime&&localTime>targetstartTime)
+            {
+                ImgeActivity.Visibility = Visibility.Visible;
+            }
+            else 
+            {
+                ImgeActivity.Visibility = Visibility.Collapsed;
+            }
+        }
+
         private void LoadPromotionContents()                                          
         {
             if(ImgeActivity.Visibility == Visibility.Visible)
@@ -107,7 +126,7 @@ namespace PDF_Master.Views.HomePanel
 
         private void ImgeActivity_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
-            GotoURI(ActiveUri);
+            GotoURI(Settings.Default.ADDate.ADLinkSidebar);
         }
 
         /// <summary>

+ 9 - 3
PDFSettings/ADDate.cs

@@ -8,9 +8,15 @@ namespace PDFSettings
 {
    public class ADDate
     {
-       
-            public string Pngtest { get; set; }
-        public string Pnglinktest { get; set; }
+         public string ADVersion { get; set; }
+        public long ADStartTime { get; set; }
+        public long ADEndTime { get; set; }
+        
+
+
+        public string ADSidebar { get; set; }
+        public string ADLinkSidebar { get; set; }
+        public string ADhiddenSidebar{ get; set; }
 
     }