public static void LoadSettings() { if (!GlobalVariablesManager.Exists(key)) { return; } string str = (string)GlobalVariablesManager.GetValue(key); byte[] buffer = System.Text.Encoding.Default.GetBytes(str); TradeTweetSettings ts = null; using (Stream stream = new MemoryStream()) { stream.Write(buffer, 0, buffer.Length); stream.Position = 0; DataContractSerializer deserializer = new DataContractSerializer(typeof(TradeTweetSettings)); ts = deserializer.ReadObject(stream) as TradeTweetSettings; } if (ts != null) { ast = ts.ast; atn = ts.atn; autoTweet = ts.autoTweet; Set = ts.Set; key = ts.key; } }
public static void SaveSettings() { TradeTweetSettings tts = new TradeTweetSettings() { ast = ast, atn = atn, autoTweet = autoTweet, Set = Set, key = key }; var str = string.Empty; using (MemoryStream memoryStream = new MemoryStream()) using (StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(typeof(TradeTweetSettings)); serializer.WriteObject(memoryStream, tts); memoryStream.Position = 0; string res = reader.ReadToEnd(); GlobalVariablesManager.SetValue(key, res, VariableLifetime.SaveFile); GlobalVariablesManager.Flush(); } }