private void SaveTag() { try { if (SelectedCategory == null) { return; } if (SelectedTag == null) { StateManager.Instance.DataStore.AddTag(SelectedCategory.ID, TagName); TagName = null; } else { SelectedTag.Name = TagName; StateManager.Instance.DataStore.UpdateTag(SelectedTag); } LoadWindow(SelectedCategory.ID); Changed = true; } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void LoadDatabase() { try { if (string.IsNullOrEmpty(DatabasePath)) { throw new Exception("Path cannot be empty."); } var exists = File.Exists(databasePath); dataStore = new DataStore(databasePath, !exists); QuoteService.Instance.SetDataStore(dataStore); //Store Properties.Settings.Default.LastPath = databasePath; Properties.Settings.Default.Save(); RaisePropertyChanged("Loaded"); RaisePropertyChanged("NotLoaded"); RefreshQuote(); QuoteService.Instance.StartTimer(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private async void ViewSpecificProfile() { try { var dlg = new IDInputWindow(IDInputWindowViewModel.Type.Profile); dlg.Owner = window; dlg.ShowDialog(); string username = dlg.InputValue; if (!string.IsNullOrEmpty(username)) { bool valid = await api.IsValidUser(username); if (valid) { ViewProfile(username); } else { throw new Exception(username + " does not exist."); } } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(Username) || string.IsNullOrEmpty(Name)) { throw new Exception("All fields are required."); } PasswordItem pwd = new PasswordItem(); pwd.Username = Username; pwd.Password = Password; pwd.Name = Name; if (isEdit) { pwd.ID = existing.ID; ds.UpdatePassword(pwd); } else { ds.AddPassword(pwd); } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void DeleteItem() { try { if (SelectedTask == null) { return; } else if (!MessageBoxFactory.ShowConfirmAsBool("Are you sure you want to delete this Task and ALL it's SubTasks?", "Confirm Delete", System.Windows.MessageBoxImage.Exclamation)) { return; } var parent = SelectedTask.Parent; int?pid = parent == null ? null : (int?)parent.TaskItemID; Workspace.API.DeleteTask(SelectedTask); TasksChanged(); if (pid != null) { ExpandAndSelect(tasks, pid.Value); } //Need to update list as well //TODO Duplicate: RefreshListsView(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SaveSettings() { try { if (string.IsNullOrEmpty(DbPath) || !Path.IsPathRooted(DbPath)) { throw new Exception("DB Path is empty or not valid."); } settings.DbPath = DbPath; settings.Username = Username; settings.Password = settingsWindow.PasswordBox.Password; settings.HideChrome = HideBrowser; settings.Save(); Changed = true; settingsWindow.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (string.IsNullOrEmpty(Comment)) { throw new Exception("The comment cannot be empty."); } Data = new Core.Comment() { Text = Comment, }; //Returns a List and then API checks if it has ID, if yes update, else add if (IsEdit) { Data.CommentID = existing.CommentID; } else { Data.Created = DateTime.Now; } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void EditLogin() { try { if (SelectedLogin == null) { return; } try { var dlg = new EditLoginWindow(ds, passwordsMap, SelectedLogin); dlg.Owner = mainWindow; dlg.ShowDialog(); if (!dlg.Cancelled) { LoadLists(); } } catch (Exception e) { MessageBoxFactory.ShowError(e); } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
//TODO: Clean, figure out whether should do in GameBoard or here private void OnClick(int r, int c) { if (board.IsMine(r, c)) { MessageBoxFactory.ShowError("Lose", "You Lose"); InGame = false; } else { CellsLeft--; var button = buttonGrid[r, c]; if (button.IsEmpty) { for (int row = r - 1; row <= r + 1; row++) { for (int col = c - 1; col <= c + 1; col++) { GridButton gb = GetButton(row, col); if (gb != null && gb != button && !gb.Clicked && !gb.IsMine) { gb.Click(); //This is recursive } } } } CheckWin(); } }
private void DoSearch() { try { if (IsSearching) { ClearSearch(); } else { if (SearchFilter == null || string.IsNullOrEmpty(SearchFilter.Trim())) { throw new Exception("No search string entered"); } items.Clear(); List <IDataItem> results = DataManager.Instance().DataStore.Search(SearchFilter); foreach (var i in results) { Items.Add(new ItemViewModel(i, SVMLookup[i.GetSource()])); } } SortedView.Refresh(); IsSearching = !IsSearching; RefreshViewModel(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (String.IsNullOrEmpty(Name)) { throw new Exception("Name is empty"); } if (IsEdit) { existing.Name = Name; } else { Topic t = new Topic() { Name = Name }; Util.DB.Topics.Add(t); } Util.DB.SaveChanges(); window.Close(); } catch (Exception e) { Util.DB.RejectChanges(); MessageBoxFactory.ShowError(e); } }
private void AddNewToCurrent() { try { if (string.IsNullOrEmpty(NewTagName)) { return; } var exists = ds.GetTags(NewTagName); if (exists.Count > 0) { throw new Exception("The tag already exists."); } else { CurrentList.Add(new Tag() { TagName = NewTagName }); NewTagName = ""; } } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Export() { try { if (string.IsNullOrEmpty(SavePath)) { throw new Exception("Save path not defined."); } else if (string.IsNullOrEmpty(SelectedExporter)) { throw new Exception("No exporter selected."); } else if (SelectedBook == null) { throw new Exception("No book selected."); } if (File.Exists(SavePath) && !MessageBoxFactory.ShowConfirmAsBool("Overwrite existing file?", "File Exists")) { return; } BaseExporter exporter = GetExporter(); exporter.Export(SelectedBook, SavePath); MessageBoxFactory.ShowInfo("Book has been exported to: " + SavePath, "Book Exported"); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { TaskList newList = new TaskList(Name, Description, ConvertType(SelectedListType)); var type = ConvertType(SelectedListType); if (existing != null) { Workspace.API.UpdateList(existing, Name, Description, type); } else { Workspace.API.InsertList(Name, Description, type); } Cancelled = false; window.Close(); } catch (Exception e) { Workspace.Instance.RejectChanges(); MessageBoxFactory.ShowError(e); } }
public void Load() { try { if (string.IsNullOrEmpty(WorkspacePath)) { throw new Exception("The path cannot be empty."); } string dbFile = GetDbFilePath(WorkspacePath); if (!Directory.Exists(WorkspacePath)) { Directory.CreateDirectory(WorkspacePath); } else { ValidateWorkspace(workspacePath); } LoadWorkspaceAsync(dbFile); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (!Enabled) { Hotkey.ClearHotkey(); } else { ModifierKeys mod = ToModifier(SelectedModifier); Key key = ToKey(Character); Hotkey hk = new Hotkey(mod, key); Hotkey.RegisterHotkey(hk, showDashboardCb); } Changed = true; closeWindowCb.Invoke(); } catch (Exception e) { MessageBoxFactory.ShowError(e); Changed = false; } }
/// <summary> /// Comment on a specific rant using the RantSelector /// </summary> private async void ViewSpecificRant() { var rantSelector = new IDInputWindow(IDInputWindowViewModel.Type.Rant); rantSelector.Owner = window; rantSelector.ShowDialog(); if (!string.IsNullOrEmpty(rantSelector.InputValue)) { try { Dtos.Rant rant = await api.GetRant(Convert.ToInt64(rantSelector.InputValue)); var dlg = new RantViewerWindow(new ViewModels.Rant(rant), api); dlg.Owner = window; dlg.ShowDialog(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } } }
private void OpenDataStore() { try { if (string.IsNullOrEmpty(Path) || string.IsNullOrEmpty(pwdBox.Password)) { throw new Exception("A path and password are required."); } else if (!Path.EndsWith(Extension)) { Path += Extension; } IDataStore ds = new SQLiteDataStore(Path, pwdBox.Password); ds.Open(); DataStore = ds; pathHistory.AddItem(Path); settings.History = pathHistory.SerializeToString(); settings.Save(); Cancelled = false; openDatabaseWindow.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private async void RefreshWatchlistItemsAsync() { IsRefreshing = false; await Task.Run(() => { try { //TODO: Disable Button RefreshWatchlistItems(false); App.Current.Dispatcher.Invoke(() => { LoadFromContext(); IsRefreshing = true; }); } catch (Exception e) { App.Current.Dispatcher.Invoke(() => { MessageBoxFactory.ShowError(e); IsRefreshing = true; }); } }); }
private async void RefreshRecentMoviesAsync() { IsRefreshing = false; await Task.Run(() => { try { var result = RefreshRecentlyAdded(); App.Current.Dispatcher.Invoke(() => { ShowRefreshStatus(result); LoadFromContext(); IsRefreshing = true; }); } catch (Exception e) { App.Current.Dispatcher.Invoke(() => { MessageBoxFactory.ShowError(e); IsRefreshing = true; }); } }); }
private void SaveChange() { try { if (string.IsNullOrEmpty(Location)) { throw new RequiredFieldException("Location"); } else if (string.IsNullOrEmpty(OriginalText)) { throw new RequiredFieldException("OriginalText"); } else if (SelectedTopic == null) { throw new RequiredFieldException("Topic"); } if (IsEdit) { note.Location = Location; note.OriginalText = OriginalText; note.Published = IsPublished; //note.SubTopic = SelectedSubTopic; note.Topic = SelectedTopic; note.Updated = DateTime.Now; note.WriteUp = WriteUp; note.Notes = Notes; } else { Note note = new Note() { Book = book, Topic = SelectedTopic, Location = Location, OriginalText = OriginalText, //SubTopic = SelectedSubTopic, Created = DateTime.Now, Updated = DateTime.Now, WriteUp = WriteUp, Notes = Notes }; Workspace.Current.DB.Notes.Add(note); } Workspace.Current.DB.SaveChanges(); cancelled = false; window.Close(); } catch (Exception e) { Workspace.Current.DB.RejectChanges(); MessageBoxFactory.ShowError(e); } }
private void Save() { try { ds.SetDefaultRange(DefaultStoryRange); ds.SetDefaultFeed(DefaultFeed); AddedUsers = ds.SetFollowing(users); ds.SetUpdatesInterval(UpdateCheckInterval); if (!string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { api.User.Login(Username, Password); } ds.SetHideUsername(!ShowUsername); ds.SetShowCreateTime(ShowCreateTime); ds.SetFilterOutRead(FilterOutRead); ds.SetLimits(ResultsLimit, MinScore, MaxPages); //Check DBPath if (ds.DBFolder != DBFolder) { ds.SetDBFolder(DBFolder); DatabaseChanged = true; } //Check/Save Login if (Username != null && Password != null) { var info = ds.GetLoginInfo(); if (info != null) { if (Username != info.Username || Password != info.Password) { ds.SetLogin(new LoginInfo(Username, Password)); LoginChanged = true; } } else { ds.SetLogin(new LoginInfo(Username, Password)); LoginChanged = true; } } Cancelled = false; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void TryLoad() { try { AppStateManager.Initialize(mainWindow); } catch (Exception e) { MessageBoxFactory.ShowError(e, "Loading Error"); } }
private void FeedListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { vm.OpenPost(); } catch (Exception ex) { MessageBoxFactory.ShowError(ex, owner: this); } }
public void Save() { try { if (String.IsNullOrEmpty(Name)) { throw new Exception("Name is empty."); } if (existing != null) { rule = existing.Original; if (AppState.Instance.FindExisting(rule.ID, Name) != null) { throw new Exception("Name already exists."); } rule.Name = Name; AppState.Instance.UpdateRule(rule); } else { if (AppState.Instance.FindExisting(Name) != null) { throw new Exception("Name already exists."); } else if (SelectedChecker == null) { throw new Exception("No Checker selected."); } else if (SelectedChecker.HasExtensions && string.IsNullOrEmpty(SelectedExt)) { throw new Exception("No Extension selected."); } else if (SelectedChecker.HasPath && !RegistryUtil.IsValid(Path)) { throw new Exception("Path is invalid."); } rule = SelectedChecker.GetValues(Path, SelectedExt); rule.Name = Name; AppState.Instance.AddNewRule(rule); } Result = WindowResult.Saved; window.Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SendRandomMessage() { try { waClient.SendRandomMessage(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void SendSong() { try { waClient.SendMessage(azClient.GetRandom()); } catch (Exception e) { MessageBoxFactory.ShowError(e, owner: window); } }
private void CheckChanges() { try { ChangeChecker.CheckForChanges(false); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Save() { try { if (string.IsNullOrEmpty(Name)) { throw new Exception("Name is empty"); } switch (type) { case ItemType.Author: Author author = item as Author; if (author.Name == Name) { Close(); return; } if (ds.GetAuthors().Where(x => x.Name == Name).FirstOrDefault() != null) { throw new Exception(Name + " already exists"); } author.Name = Name; ds.UpdateAuthor(author); break; case ItemType.Tag: Tag tag = item as Tag; if (tag.TagName == Name) { Close(); return; } if (ds.GetTags().Where(x => x.TagName == Name).FirstOrDefault() != null) { throw new Exception(Name + " already exists"); } tag.TagName = Name; ds.UpdateTag(tag); break; } Close(); } catch (Exception e) { MessageBoxFactory.ShowError(e); } }
private void Select() { if (Reason == null) { MessageBoxFactory.ShowError("A reason must be selected."); } else { downvoteReasonWindow.Close(); } }