/// <summary> /// Saves the commands to a .xml file which is loaded automatically when the /// application next starts. /// </summary> private void SaveCommands() { ConfigObject obj = config.LoadConfig(); List <Command> commands = new List <Command>(); foreach (KeyValuePair <string, Command> i in connection.commandsList) { commands.Add(i.Value); } config.SaveConfig(commands, obj.username, obj.oauth, obj.channel); }
public Login() { InitializeComponent(); tokenTextBox.PasswordChar = '*'; if (File.Exists("Config.xml")) { Cache = smg.LoadConfig(); UsernameTextBox.Text = Cache.username; tokenTextBox.Password = Cache.oauth; ChannelTextBox.Text = Cache.channel; } }
public void SaveConfig(List <Command> commandList, string username, string oauth, string channel) { using (FileStream fs = new FileStream("Config.xml", FileMode.Create, FileAccess.Write)) { XmlSerializer xs = new XmlSerializer(typeof(ConfigObject)); ConfigObject obj = new ConfigObject(); obj.oauth = oauth; obj.username = username; obj.channel = channel; obj.commandList = commandList; xs.Serialize(fs, obj); } }
/// <summary> /// Loads the commands and timers onto the proper CommandGrid. /// </summary> private void LoadCommands() { ConfigObject obj = config.LoadConfig(); DateTime date = new DateTime(1979, 07, 28, 22, 35, 5); // the default date foreach (Command cmd in obj.commandList) { if (cmd.timerlength != TimeSpan.Zero || !cmd.timerstart.Equals(date)) { // this is a timer command timers.AddCommand(cmd); } else { // this is a command command commands.AddCommand(cmd); } } config.SaveConfig(obj.commandList, obj.username, obj.oauth, obj.channel); }
public ConfigObject LoadConfig() { ConfigObject obj = new ConfigObject(); try { using (FileStream fs = new FileStream("Config.xml", FileMode.Open, FileAccess.Read)) { XmlSerializer xs = new XmlSerializer(typeof(ConfigObject)); obj = (ConfigObject)xs.Deserialize(fs); foreach (Command cmd in obj.commandList) { cmd.cooldown = new TimeSpan(cmd.ticks); } } } catch (FileNotFoundException e) { } return(obj); }