Parcourir la source

sepereat basic setting and front page setting

Robert il y a 3 ans
Parent
commit
5a773dad71
2 fichiers modifiés avec 41 ajouts et 1 suppressions
  1. 37 1
      Bellwether/Utility/Setting.cs
  2. 4 0
      BellwetherBackend/Utility/Setting.cs

+ 37 - 1
Bellwether/Utility/Setting.cs

@@ -13,10 +13,11 @@ namespace Bellwether.Utility
         public static readonly List<string> PageNameList = new List<string>() { "大事記", "產品展示", "社會責任" };
 
         public static int BackHomeSec { get => settingJsonFile.BackHomeSec; }
-        public static string SolarEnergyUrl { get => settingJsonFile.SolarEnergyUrl; }
+        public static string SolarEnergyUrl { get => frontpageJsonFile.SolarEnergyUrl; }
 
         private static string dataDirectory = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Data");
         private static string settingJsonDataPath = System.IO.Path.Combine(dataDirectory, "setting.ini");
+        private static string frontpageJsonDataPath = System.IO.Path.Combine(dataDirectory,"FrontPage", "frontpage.ini");
 
         private static SettingJson _settingJsonFile;
         private static SettingJson settingJsonFile
@@ -33,6 +34,21 @@ namespace Bellwether.Utility
             }
         }
 
+        private static FrontPageJson _frontpageJsonFile;
+        private static FrontPageJson frontpageJsonFile
+        {
+            get
+            {
+                if (_frontpageJsonFile != null)
+                    return _frontpageJsonFile;
+                else
+                {
+                    AnalyzJsonFile();
+                    return _frontpageJsonFile;
+                }
+            }
+        }
+
         public static void Reload()
         {
             AnalyzJsonFile();
@@ -64,6 +80,22 @@ namespace Bellwether.Utility
                 }
                 _settingJsonFile = DeserializeFromJson<SettingJson>(jsonResult);
             }
+
+            if (!File.Exists(frontpageJsonDataPath))
+            {
+                _frontpageJsonFile = new FrontPageJson()
+                {
+                    SolarEnergyUrl = "https://dsegomspoctestenv.azurewebsites.net/api/siteoverview?act=9237&token=BWsolarenergy"
+                };
+            }
+            else
+            {
+                using (StreamReader sr = new StreamReader(frontpageJsonDataPath))
+                {
+                    jsonResult = sr.ReadToEnd();
+                }
+                _frontpageJsonFile = DeserializeFromJson<FrontPageJson>(jsonResult);
+            }
         }
         #endregion
 
@@ -72,6 +104,10 @@ namespace Bellwether.Utility
     public class SettingJson
     {
         public int BackHomeSec { get; set; }
+    }
+
+    public class FrontPageJson
+    {
         public string SolarEnergyUrl { get; set; }
     }
 }

+ 4 - 0
BellwetherBackend/Utility/Setting.cs

@@ -90,6 +90,10 @@ namespace BellwetherBackend.Utility
     public class SettingJson
     {
         public int BackHomeSec { get; set; }
+    }
+
+    public class FrontPageJson
+    {
         public string SolarEnergyUrl { get; set; }
     }
 }