123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BellwetherBackend.Utility
- {
- public static class Setting
- {
- private static readonly string dataDirectory = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Data");
- public static readonly string settingJsonDataPath = System.IO.Path.Combine(dataDirectory, "setting.ini");
- public static readonly List<string> PageNameList = new List<string>() { "大事記", "產品展示", "社會責任" };
- public enum PageType : int
- {
- FrontPage,
- History,
- Product,
- CSR,
- }
- public static readonly Dictionary<PageType, string> PageFolderName
- = new Dictionary<PageType, string>() {
- { PageType.History, "History" },
- { PageType.Product, "Product" },
- { PageType.CSR, "CSR" },
- };
- private static SettingJson _settingJsonFile;
- public static SettingJson settingJsonFile
- {
- get
- {
- if (_settingJsonFile != null)
- return _settingJsonFile;
- else
- {
- AnalyzJsonFile();
- return _settingJsonFile;
- }
- }
- set
- {
- _settingJsonFile = value;
- //save Json
- SaveJson();
- }
- }
- private static void AnalyzJsonFile()
- {
- string jsonResult;
- if (!File.Exists(settingJsonDataPath))
- {
- _settingJsonFile = new SettingJson()
- {
- BackHomeSec = 60,
- };
- return;
- }
- else
- {
- using (StreamReader sr = new StreamReader(settingJsonDataPath))
- {
- jsonResult = sr.ReadToEnd();
- }
- _settingJsonFile = JsonConvert.DeserializeObject<SettingJson>(jsonResult);
- }
- }
- private static void SaveJson()
- {
- string jsonString;// = JsonConvert.SerializeObject(_settingJsonFile, Newtonsoft.Json.Formatting.Indented);
- jsonString = JsonConvert.SerializeObject(_settingJsonFile, Newtonsoft.Json.Formatting.Indented);
- using (StreamWriter sw = new StreamWriter(settingJsonDataPath, false, Encoding.Unicode))
- {
- sw.Write(jsonString);
- sw.Close();
- }
- }
- }
- public class SettingJson
- {
- public int BackHomeSec { get; set; }
- }
- public class FrontPageJson
- {
- public string SolarEnergyUrl { get; set; }
- }
- }
|