private void SaveConfiguration(string profile, TeamNotifierModel model, ObservableCollectionEx <CommandViewModel> commands) { lock (m_ConfigurationLock) { var sb = new StringBuilder(); string modeldata = TeamNotifierLogic.Serialize(model); sb.Append(modeldata); foreach (var cmd in commands) { sb.Append("~~~"); sb.Append(TeamNotifierLogic.Serialize(cmd.Model)); } TeamNotifierLogic.AddOrUpdateAppSettings(profile, sb.ToString()); var sb2 = new StringBuilder(); foreach (var prof in Profiles) { sb2.Append(TeamNotifierLogic.Serialize(prof)); sb2.Append("~~~"); } if (sb2.ToString(sb2.Length - 3, 3) == "~~~") { sb2.Remove(sb2.Length - 3, 3); } TeamNotifierLogic.AddOrUpdateAppSettings("Profiles", sb2.ToString()); var selectedprofile = TeamNotifierLogic.Serialize(SelectedProfile); TeamNotifierLogic.AddOrUpdateAppSettings("SelectedProfile", selectedprofile); } }
void MainWindow_Closed(object sender, EventArgs e) { try { TeamNotifierLogic.ClearOSD(); m_Client.Disconnect(); } catch (Exception ex) { Log.Message(ex.ToString()); } }
public void DeleteProfileHandler() { MessageBoxResult messageBoxResult = MessageBox.Show(string.Format("Are you sure you want to delete '{0}' profile?", SelectedProfile.Name), "Delete Profile", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.No) { return; } var profiletodelete = SelectedProfile; SelectedProfile = Profiles.First(x => x.Name != SelectedProfile.Name); Profiles.Remove(profiletodelete); lock (m_ConfigurationLock) TeamNotifierLogic.DeleteAppSetting(profiletodelete.Name); }
private void RefreshOSD() { StringBuilder sb = new StringBuilder("<C0=FFA0A0><C1=9FDA40><C2=5CB3FF><C3=FFFF32><C4=F2F2F2>" + "<C5=FFD27F><C6=C44FFF><C7=FFC0CB><C8=4FFFFF><C30=FFFFFF><C31=FFC04C>"); foreach (var msg in m_OSDMessages) { sb.AppendLine(); sb.Append(msg); } try { TeamNotifierLogic.SaveOSD(sb.ToString()); } catch (Exception ex) { Log.Message(ex.ToString()); } }
private void SetProfile(bool startup = false) { if (!startup) { PropertyChanged -= ViewModelChanged; Model.PropertyChanged -= ModelChanged; ((INotifyPropertyChanged)Commands).PropertyChanged -= CommandModelChanged; Commands.MemberPropertyChanged -= CommandModelChanged; } var settings = ConfigurationManager.AppSettings[SelectedProfile.Name]; var settingsArray = settings.Split(new string[] { "~~~" }, StringSplitOptions.None); Model = TeamNotifierLogic.Deserialize <TeamNotifierModel>(settingsArray[0]); Commands = new ObservableCollectionEx <CommandViewModel>(); for (var i = 1; i < settingsArray.Length; i++) { var cmd = TeamNotifierLogic.Deserialize <CommandModel>(settingsArray[i]); var cmdvm = new CommandViewModel(cmd); cmdvm.DeleteCommand = new DelegateCommand(DeleteCommandHandler); Commands.Add(cmdvm); } if (string.IsNullOrEmpty(Model.User)) { Model.User = Environment.UserName; } ((INotifyPropertyChanged)Commands).PropertyChanged += CommandModelChanged; Commands.MemberPropertyChanged += CommandModelChanged; PropertyChanged += ViewModelChanged; Model.PropertyChanged += ModelChanged; if (!startup) { RaisePropertyChanged("Commands"); Model.RaisePropertyChanged("Model"); } }
private void LoadConfiguration() { lock (m_ConfigurationLock) { var profiles = ConfigurationManager.AppSettings["Profiles"]; var profilesArray = profiles.Split(new string[] { "~~~" }, StringSplitOptions.None); Profiles = new ObservableCollectionEx <Profile>(); for (var i = 0; i < profilesArray.Length; i++) { if (!string.IsNullOrEmpty(profilesArray[i])) { var profile = TeamNotifierLogic.Deserialize <Profile>(profilesArray[i]); Profiles.Add(profile); } } ((INotifyPropertyChanged)Profiles).PropertyChanged += ViewModelChanged; var selectedprofile = ConfigurationManager.AppSettings["SelectedProfile"]; SelectedProfile = TeamNotifierLogic.Deserialize <Profile>(selectedprofile); SetProfile(true); } }