Bladeren bron

加入Animation Desk用的event bar

kangkangtm 1 jaar geleden
bovenliggende
commit
5ad332f4f4
3 gewijzigde bestanden met toevoegingen van 122 en 0 verwijderingen
  1. 34 0
      CMSCollection/CMSCollection.cs
  2. 87 0
      CMSCollection/Data/WindowsEventbarResponse.cs
  3. 1 0
      KdanCommon.csproj

+ 34 - 0
CMSCollection/CMSCollection.cs

@@ -2,6 +2,7 @@
 using KdanCommon.Helpers;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Net.NetworkInformation;
 using System.Text;
@@ -23,6 +24,7 @@ namespace KdanCommon.CMSCollection
         private List<ISetting> _settingList = null;
         private HttpClient _httpClient = null;
         private Uri _windowsCardsUri = null;
+          private Uri _windowsEventbarUri = null;
         private Uri _pdfViewerEventBarSettingUri = null;
         private Uri _pdfOtherSettingUri = null;
         private string _appType = null;
@@ -39,6 +41,7 @@ namespace KdanCommon.CMSCollection
             _windowsCardsUri = new Uri($"{CMSDomain}/items/windows_cards");
             _pdfViewerEventBarSettingUri = new Uri($"{CMSDomain}/items/pdf_remote_config");
             _pdfOtherSettingUri = new Uri($"{CMSDomain}/items/PDF_UWP_RemoteConfig");
+            _windowsEventbarUri = new Uri($"{CMSDomain}/items/windows_eventbar");
             _appType = appType;
             _loadCardsOnly = loadCardOnly;
             _settingList = new List<ISetting>();
@@ -191,6 +194,37 @@ namespace KdanCommon.CMSCollection
             }
         }
 
+        public async Task<List<WindowsEnentbarSetting>> GetWindowsEventbarAsync()
+        {
+            var current = DateTime.UtcNow.ToString("s", CultureInfo.GetCultureInfo("en-us"));
+            string region = GetSystemRegion();
+            string lang = GetAppLanguage();
+            var querys = new List<KeyValuePair<string, string>>();
+            querys.Add(new KeyValuePair<string, string>("deep[event_information][_filter][languages_code][_eq]", lang));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][0][include_regions][_eq]", "true"));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][0][regions][_contains]", region));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][1][include_regions][_eq]", "false"));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][1][regions][_ncontains]", region));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][2][include_regions][_eq]", "false"));
+            querys.Add(new KeyValuePair<string, string>("filter[_or][2][regions][_null]", "true"));
+            querys.Add(new KeyValuePair<string, string>("filter[start][_lte]", current));
+            querys.Add(new KeyValuePair<string, string>("filter[end][_gte]", current));
+            querys.Add(new KeyValuePair<string, string>("filter[app_types][_contains]", _appType));
+            querys.Add(new KeyValuePair<string, string>("filter[status][_eq]", "published"));
+            querys.Add(new KeyValuePair<string, string>("fields", "*,event_information.*"));
+            var result = await _httpClient.GetRequest(_windowsEventbarUri, querys);
+            if (result.StatusCode == HttpStatusCode.Ok)
+            {
+                var jsonString = await result.Content.ReadAsStringAsync();
+                var response = JsonTool.DeserializeJSON<WindowsEventbarResponse>(jsonString);
+                if (response != null && response.Data != null && response.Data.Length > 0)
+                {
+                    return response.Data.ToList();
+                }
+            }
+            return null;
+        }
+
         private string GetSystemRegion()
         {
             var geographyCountryCode = new GeographicRegion().CodeTwoLetter;

+ 87 - 0
CMSCollection/Data/WindowsEventbarResponse.cs

@@ -0,0 +1,87 @@
+using KdanCommon.Helpers;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Windows.System;
+using Windows.UI;
+using Windows.UI.Xaml.Media.Animation;
+
+namespace KdanCommon.CMSCollection.Data
+{
+    public partial class WindowsEventbarResponse
+    {
+        [JsonProperty("data")]
+        public WindowsEnentbarSetting[] Data { get; set; }
+    }
+
+    public partial class WindowsEnentbarSetting : ISetting
+    {
+        [JsonConstructor]
+        private WindowsEnentbarSetting(string id, string app_type, DateTime start, DateTime end, string event_icon, string close_icon, string text_color, string background_color, EventbarInformation[] event_information)
+        {
+            if (close_icon != null)
+                CloseIcon = new Uri($"{CMSCollection.CMSDomain}/assets/{close_icon}");
+            if (event_icon != null)
+                EventIcon = new Uri($"{CMSCollection.CMSDomain}/assets/{event_icon}");
+            if (text_color != null)
+                TextColor = text_color.ToColor();
+            if (background_color != null)
+                BackgroundColor = background_color.ToColor();
+            Id = id;
+            Start = start;
+            End = end;
+            if(event_information!=null)
+            {
+                EventbarInformation = event_information.FirstOrDefault();
+            }
+        }
+        public string SettingName
+        {
+            get
+            {
+                return Id;
+            }
+        }
+
+        public string Id { get; }
+
+        public DateTime Start { get; }
+
+        public DateTime End { get; }
+
+        public Color TextColor
+        {
+            get;
+        }
+        public Color BackgroundColor
+        {
+            get;
+        }
+
+        public EventbarInformation EventbarInformation { get; }
+
+        public Uri EventIcon
+        {
+            get;
+        }
+
+        public Uri CloseIcon
+        {
+            get;
+        }
+    }
+
+    public partial class EventbarInformation
+    {
+
+        [JsonProperty("event_title")]
+        public string EventTitle { get; set; }
+
+        [JsonProperty("event_link")]
+        public string EventLink { get; set; }
+    }
+
+}

+ 1 - 0
KdanCommon.csproj

@@ -125,6 +125,7 @@
     <Compile Include="CMSCollection\Data\JsonSetting.cs" />
     <Compile Include="CMSCollection\Data\ViewerEventBarSettingResponse.cs" />
     <Compile Include="CMSCollection\Data\WindowsCardsResponse.cs" />
+    <Compile Include="CMSCollection\Data\WindowsEventbarResponse.cs" />
     <Compile Include="GoogleCloud\Data\Lang.cs" />
     <Compile Include="GoogleCloud\Data\Vision\ImgesRequest.cs" />
     <Compile Include="GoogleCloud\Data\Vision\ImgesResponse.cs" />