using BO.Utils; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WeightClient { public class AppContext { private static string loginConfigPath = Application.StartupPath + "\\Config.xml"; public ServerUrlConfig UrlConfig { get; set; } public LoginUserInfo UserConfig { get; set; } private AppContext() { UrlConfig = new ServerUrlConfig(); UserConfig = new LoginUserInfo(); } public static AppContext Context { get { if (_appContext == null) _appContext = CreateAppContext(); return _appContext; } } private static AppContext _appContext; static AppContext CreateAppContext() { var config = new AppContext(); if (!File.Exists(loginConfigPath)) { XmlUtil.SerializerObjToFile(config, loginConfigPath); } else config = XmlUtil.DeserializeFromFile(loginConfigPath); return config; } public void Save() { XmlUtil.SerializerObjToFile(_appContext, loginConfigPath); } } }