public SettingContainer GetSettings() { if (currentSettings == null) { try { XmlSerializer serializer = new XmlSerializer(typeof(SettingContainer)); FileStream stream = new FileStream(Path.Combine(Application.dataPath, saveFile), FileMode.Open); SettingContainer container = serializer.Deserialize(stream) as SettingContainer; stream.Close(); currentSettings = container; if (!currentSettings.Verify(GetComponent <SetupScript>())) { Debug.Log("Settings incompatible, generating new Settings"); currentSettings = new SettingContainer(GetComponent <SetupScript>()); } } catch (System.Exception) { currentSettings = new SettingContainer(GetComponent <SetupScript>()); } } currentSettings.FileLocation = saveFile; return(currentSettings); }
public IGame Show() { var settingContainer = new SettingContainer(); int selectedSetting = 0; ConsoleKeyInfo lastKey = new ConsoleKeyInfo('\0', ConsoleKey.NoName, false, false, false); while (true) { const int startX = 2; int settingIndex = 0; foreach (var setting in settingContainer) { (Console.CursorLeft, Console.CursorTop) = (startX, UserInterface.TopPanelHeight + settingIndex + 1); bool isSelected = selectedSetting == settingIndex; if (isSelected) { setting.OnInput(lastKey); } setting.Draw(isSelected); settingIndex++; } lastKey = Console.ReadKey(intercept: true); switch (lastKey.Key) { case ConsoleKey.W: case ConsoleKey.UpArrow: selectedSetting--; if (selectedSetting < 0) { selectedSetting = 0; } break; case ConsoleKey.S: case ConsoleKey.DownArrow: selectedSetting++; if (selectedSetting >= settingContainer.Length) { selectedSetting = settingContainer.Length - 1; } break; case ConsoleKey.Enter: IGame game = (IGame)Activator.CreateInstance(settingContainer.GameDisplayer.GameSelected); foreach (var setting in settingContainer.GameSettings) { setting.Property.SetValue(game, setting.Value); } return(game); } } }
public IOProxy(SettingContainer settingContainer) { _SettingContainer = settingContainer; _Running = true; _BackgroundTask = Task.Factory.StartNew(() => { DoWork(); }, TaskCreationOptions.LongRunning); }
public static void MarkContainer <T>(SettingContainer container, string containerValue, T value) { #if !NETFX_CORE var json = Newtonsoft.Json.JsonConvert.SerializeObject(value); LocalSettings.Values[containerValue] = json; #else _ = LocalSettings.CreateContainer(container.ToString(), ApplicationDataCreateDisposition.Always); LocalSettings.Containers[container.ToString()].Values[containerValue] = value != null?JsonConvert.SerializeObject(value) : null; #endif }
public static T GetContainerValue <T>(SettingContainer container, string containerValue) { #if !NETFX_CORE var json = (string)ApplicationData.Current.LocalSettings.Values[containerValue]; return(Newtonsoft.Json.JsonConvert.DeserializeObject <T>(json)); #else _ = LocalSettings.CreateContainer(container.ToString(), ApplicationDataCreateDisposition.Always); if (!(LocalSettings.Containers[container.ToString()].Values[containerValue] is string currentValue)) { return(default);
// load ANPRCam, Setting obj private void loadGlobalSetting() { if (!File.Exists("setting_global.dat")) { return; } byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(ConfigurationManager.ConnectionStrings["aesPassword"].ConnectionString); RijndaelManaged AES = new RijndaelManaged(); AES.KeySize = 256; AES.BlockSize = 128; var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000); AES.Key = key.GetBytes(AES.KeySize / 8); AES.IV = key.GetBytes(AES.BlockSize / 8); AES.Padding = PaddingMode.PKCS7; AES.Mode = CipherMode.CBC; var settingContainer = new SettingContainer(); try { BinaryFormatter binFmt = new BinaryFormatter(); using (FileStream rdr = new FileStream("setting_global.dat", FileMode.Open)) { using (CryptoStream cs = new CryptoStream(rdr, AES.CreateDecryptor(), CryptoStreamMode.Read)) { settingContainer = (SettingContainer)binFmt.Deserialize(cs); setting = settingContainer.globalSetting; _anprCamList = settingContainer.camList; cs.Close(); } rdr.Close(); } } catch (Exception e) { MessageBox.Show("Setting file open error : " + e.Message); } foreach (ANPRCam cam in _anprCamList) { treeView1.Nodes.Add(cam.node); gMapControl1.Overlays.Add(cam.markersOverlay); } }
// save ANPRCam, Setting obj private void saveGlobalSetting() { byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }; byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(ConfigurationManager.ConnectionStrings["aesPassword"].ConnectionString); RijndaelManaged AES = new RijndaelManaged(); AES.KeySize = 256; AES.BlockSize = 128; var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000); AES.Key = key.GetBytes(AES.KeySize / 8); AES.IV = key.GetBytes(AES.BlockSize / 8); AES.Padding = PaddingMode.PKCS7; AES.Mode = CipherMode.CBC; var settingContainer = new SettingContainer(); settingContainer.globalSetting = setting; settingContainer.camList = _anprCamList; try { BinaryFormatter binFmt = new BinaryFormatter(); using (FileStream fs = new FileStream("setting_global.dat", FileMode.Create)) { using (CryptoStream cs = new CryptoStream(fs, AES.CreateEncryptor(), CryptoStreamMode.Write)) { binFmt.Serialize(cs, settingContainer); cs.Close(); } fs.Close(); } } catch (Exception e) { MessageBox.Show("setting save error : " + e.Message); } }
/// <summary> /// The constructor used to instaintiate user specific configuration /// </summary> /// <param name="userId">The database id of the user</param> /// <param name="userSettings">The settings contanier holding the user specific settings</param> public ConfigurationUser(long userId, SettingContainer userSettings) { UserId = userId; UserSettings = userSettings; }
/// <summary> /// The constructor used to instaintiate application specific configuration /// </summary> /// <param name="applicationSettings">The settings contanier holding application specific settings</param> public ConfigurationApplication(SettingContainer applicationSettings) { ApplicationSettings = applicationSettings; }