//-------------------------------------------------------------------------- public void PerformQuery() { List <string> words = BuildWordsForQuery(); List <DocumentProperty> documentProperties = BuildDocumentPropertiesForQuery(); string queryMessageResult = ""; List <Document> resultDocuments = null; _currentLoadingScreen = new LoadingScreenDialog( "Running Documents Query ...", false); UpdateDocumentResultsCount(); // in order to show the loading screen as a modal dialog - we have to // run the query on a new thread Task.Run(() => { // the sleep will promise _currentLoadingScreen.ShowDialog is called // before the query result comes in, and we can then safely call // Invoke on _currentLoadingScreen System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetDocuments( words, documentProperties, (documents, status, message) => { queryMessageResult = message; resultDocuments = documents; _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetDocuments }); // this line waits until _currentLoadingScreen.CloseScreen() is called _currentLoadingScreen.ShowDialog(); // if we are here it means we got a result from the query _currentLoadingScreen = null; _parentForm.listViewDocuments.Items.Clear(); // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } foreach (Document item in resultDocuments) { ListViewItem listViewItem = new ListViewItem(); listViewItem.Text = item.GutenbergId; listViewItem.SubItems.Add(item.Author); listViewItem.SubItems.Add(item.Title); listViewItem.SubItems.Add(item.ReleaseDate.Value.ToShortDateString()); listViewItem.Tag = item; _parentForm.listViewDocuments.Items.Add(listViewItem); } UpdateDocumentResultsCount(); }
//-------------------------------------------------------------------------- public void Initialize() { if (_businessLogic != null) { return; } Configuration config = new Configuration() { #pragma warning disable CS0618 ConnectionString = ConfigurationSettings.AppSettings["connection_string"], Storage = new DirectoryInfo( ConfigurationSettings.AppSettings["storage_folder"]), ContentRetreivalResolution = InitContentRetreivalSettings(), PerformIntegrityValidations = ShouldPerformIntegirtyValidations(), Statistics = GetStatisticsConfigurations() #pragma warning restore CS0618 }; _businessLogic = new BusinessLogic(config, this); if (!_businessLogic.Initialize()) { System.Windows.Forms.MessageBox.Show( "Failed to initialize database!", "Error"); Application.Exit(); return; } _currentLoadingScreen = new LoadingScreenDialog( "Initializing Database ...", false); _currentLoadingScreen.ShowDialog(); }
//-------------------------------------------------------------------------- internal void Initialize() { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog("Retreiving Phrases ...", false); UpdatePhrasesCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Phrases.GetAll((phrases, status, message) => { queryMessageResult = message; if (status) { FillPhrasesListOnUIThread(phrases, false); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void AddGroup() { string newGroup = _parentForm.textBoxGroup.Text; if (newGroup.Length <= 0) { return; } _parentForm.textBoxGroup.Clear(); foreach (ListViewItem groupItem in _parentForm.listViewGroups.Items) { string group = groupItem.Text; if (group.ToLower().Equals(newGroup.ToLower())) { // already exists in the list groupItem.Selected = true; return; } } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Adding Group ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); // get all words _businessLogic.Groups.AddGroup(newGroup, (group, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillGroupsListOnUIThread(new List <Group>() { group }, true); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void ImportDB() { OpenFileDialog filePicker = new OpenFileDialog(); filePicker.Title = "Select xml file to import"; filePicker.Multiselect = false; filePicker.Filter = "xml files (*.xml)|*.xml"; filePicker.FilterIndex = 1; filePicker.RestoreDirectory = true; if (filePicker.ShowDialog() != DialogResult.OK) { return; } DialogResult result = System.Windows.Forms.MessageBox.Show( "Warning: in order to import this file, the entire database will be " + "erased and then the file will be imported. Any data that isn't " + "part of the import will be gone. Are you sure you want to proceed?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result != DialogResult.Yes) { return; } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Importing Database ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.ExportImport.Import( new FileInfo(filePicker.FileName), (status, message) => { queryMessageResult = message; _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void RemoveRelation(ListViewItem relationItem) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Removing Relation ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Relations.RemoveRelation( (Relation)relationItem.Tag, (status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { _parentForm.Invoke((MethodInvoker) delegate { relationItem.Remove(); UpdateRelationsCount(); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } if (_currentSelectedRelation == null) { return; } Relation removedItem = (Relation)relationItem.Tag; if (removedItem.Name.ToLower() != _currentSelectedRelation.Name.ToLower()) { return; } _currentSelectedRelation = null; _parentForm.listViewWordPairsInRelation.Items.Clear(); _parentForm.btnAddWordPair.Enabled = false; UpdateWordPairsCount(null); }
//-------------------------------------------------------------------------- public void LoadWords() { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Words ...", false); UpdateWordsInDatabaseCount(); // in order to show the loading screen as a modal dialog - we have to // run the query on a new thread Task.Run(() => { // the sleep will promise _currentLoadingScreen.ShowDialog is called // before the query result comes in, and we can then safely call // Invoke on _currentLoadingScreen System.Threading.Thread.Sleep(200); // get all words _businessLogic.Queries.GetWords(new List <Document>(), new List <WordLocationProperty>(), (words, status, message) => { queryMessageResult = message; // because we might end up adding A LOT of words to the list, we // want to keep the loading screen visible while adding the items // to the list if (String.IsNullOrEmpty(queryMessageResult)) { FillWordsListOnUIThread(words); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetDocuments }); // this line waits until _currentLoadingScreen.CloseScreen() is called _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } _parentForm.btnLoadWords.Enabled = false; }
//-------------------------------------------------------------------------- public void RemoveGroupWord() { if (_currentSelectedGroup == null) { return; } if (_parentForm.listViewWordsInGroup.SelectedItems.Count <= 0) { return; } var item = _parentForm.listViewWordsInGroup.SelectedItems[0]; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Removing Group Word ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Groups.RemoveGroupWord(_currentSelectedGroup, (Word)item.Tag, (status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { _parentForm.Invoke((MethodInvoker) delegate { item.Remove(); UpdateWordsInGroupCount(_currentSelectedGroup); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void InitializeWithDocumentsFilter() { string queryMessageResult = ""; UpdateWordsCount(); UpdateLocationsCount(); if (_wordToInspect != null) { // we are inspecting a single word FillWordsListOnUIThread(new List <Word> { _wordToInspect }); _parentForm.listViewWords.Items[0].Selected = true; WordDoubleClicked(_wordToInspect); return; } _currentLoadingScreen = new LoadingScreenDialog( "Running Words Query ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetWords(_documentsFilter, new List <WordLocationProperty>(), (words, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillWordsListOnUIThread(words); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- internal void Initialize() { _currentSelectedGroup = null; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Groups ...", false); UpdateGroupsCount(); // in order to show the loading screen as a modal dialog - we have to // run the query on a new thread Task.Run(() => { // the sleep will promise _currentLoadingScreen.ShowDialog is called // before the query result comes in, and we can then safely call // Invoke on _currentLoadingScreen System.Threading.Thread.Sleep(200); // get all words _businessLogic.Groups.GetAll((groups, status, message) => { queryMessageResult = message; // because we might end up adding A LOT of words to the list, we // want to keep the loading screen visible while adding the items // to the list if (String.IsNullOrEmpty(queryMessageResult)) { FillGroupsListOnUIThread(groups, false); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetDocuments }); // this line waits until _currentLoadingScreen.CloseScreen() is called _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void PerformQuery() { List <DocumentProperty> documentProperties = BuildDocumentPropertiesForQuery(); List <WordLocationProperty> wordLocationProperties = BuildWordLocationPropertiesForQuery(); string queryMessageResult = ""; _parentForm.richTextBoxContents.Text = ""; _currentLoadingScreen = new LoadingScreenDialog( "Running Words Query ...", false); UpdateLocationsCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetWordsLocationDetails( documentProperties, wordLocationProperties, (wordLocationsDetails, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillLocationsListOnUIThread(wordLocationsDetails); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetWordsLocationDetails }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void AddRelationWordPair(string firstWord, string secondWord) { if (_currentSelectedRelation == null) { return; } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Adding Relation Word Pair ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Relations.AddRelationWords( _currentSelectedRelation, firstWord, secondWord, (wordPair, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillRelationWordPairsListOnUIThread( _currentSelectedRelation, new List <Tuple <Word, Word> > { wordPair }, true); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void ExportDB() { SaveFileDialog saveFilePicker = new SaveFileDialog(); saveFilePicker.Title = "Select export output file"; saveFilePicker.Filter = "xml files (*.xml)|*.xml"; saveFilePicker.FilterIndex = 1; saveFilePicker.RestoreDirectory = true; if (saveFilePicker.ShowDialog() != DialogResult.OK) { return; } if (saveFilePicker.FileName.Length <= 0) { return; } //saveFilePicker.FileName; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog("Exporting ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.ExportImport.Export( new FileInfo(saveFilePicker.FileName), (status, message) => { queryMessageResult = message; _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void RemoveRelationWordPair(ListViewItem item) { if (_currentSelectedRelation == null) { return; } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Removing Relation Word Pair ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Relations.RemoveRelationWordPair( _currentSelectedRelation, (Tuple <Word, Word>)item.Tag, (status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { _parentForm.Invoke((MethodInvoker) delegate { item.Remove(); UpdateWordPairsCount(_currentSelectedRelation); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void GetLocationItemContents(ListViewItem listViewItem) { Tuple <LocationDetail, LocationDetail> phraseLocations = (Tuple <LocationDetail, LocationDetail>)listViewItem.Tag; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Contents from Document ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetContents( phraseLocations, (contents, wordOffsetBegin, wordOffsetEnd, status, message) => { queryMessageResult = message; if (status) { _parentForm.Invoke((MethodInvoker) delegate { UIUtils.SetRichTextContents(_parentForm.richTextBoxContents, contents, wordOffsetBegin, wordOffsetEnd); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void LocationDoubleClicked(LocationDetail location) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Contents from Document ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetContents( location, (contents, wordOffsetBegin, wordOffsetEnd, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { _parentForm.Invoke((MethodInvoker) delegate { UIUtils.SetRichTextContents(_parentForm.richTextBoxContents, contents, wordOffsetBegin, wordOffsetEnd); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetContents }); // this line waits until _currentLoadingScreen.CloseScreen() is called _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void WordDoubleClicked(Word word) { string queryMessageResult = ""; _parentForm.richTextBoxContents.Text = ""; _currentLoadingScreen = new LoadingScreenDialog( "Running Word in Document Query ...", false); UpdateLocationsCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetWordLocationDetails( word, _documentsFilter, (locations, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillLocationsListOnUIThread(locations, word); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); // GetDocuments }); // this line waits until _currentLoadingScreen.CloseScreen() is called _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void LoadWords() { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Words ...", false); UpdateWordsInDatabaseCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); // get all words _businessLogic.Queries.GetWords(new List <Document>(), new List <WordLocationProperty>(), (words, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillWordsListOnUIThread(words); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } _parentForm.btnLoadWords.Enabled = false; }
//-------------------------------------------------------------------------- public void GroupDoubleClicked(Group group) { string queryMessageResult = ""; _parentForm.richTextBoxContents.Text = ""; _currentLoadingScreen = new LoadingScreenDialog( "Running Groups Locations Query ...", false); UpdateLocationsCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Queries.GetWordsLocationDetails( group, (wordsLocations, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillWordsLocationsListOnUIThread(wordsLocations); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void InitializeForGroups() { _parentForm.Text = "Book Concordance - Groups Inspector"; _parentForm.listViewWords.Columns[0].Text = "Group"; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Running Groups Query ...", false); UpdateGroupsCount(); UpdateLocationsCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Groups.GetAll((groups, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillGroupsListOnUIThread(groups); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void RemovePhrase(ListViewItem phraseItem) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Removing Phrase ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Phrases.Remove((Phrase)phraseItem.Tag, (status, message) => { queryMessageResult = message; if (status) { _parentForm.Invoke((MethodInvoker) delegate { phraseItem.Remove(); UpdatePhrasesCount(); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } _parentForm.richTextBoxContents.ResetText(); }
//-------------------------------------------------------------------------- public void InsertDocuments() { OpenFileDialog documentFilesPicker = new OpenFileDialog(); documentFilesPicker.Title = "Select document files"; documentFilesPicker.Multiselect = true; documentFilesPicker.Filter = "txt files (*.txt)|*.txt"; documentFilesPicker.FilterIndex = 1; documentFilesPicker.RestoreDirectory = true; if (documentFilesPicker.ShowDialog() != DialogResult.OK) { return; } // start loading _documentsLoader = new DocumentsLoader(documentFilesPicker.FileNames, _businessLogic); if (!_documentsLoader.HasDocumentToProcess) { return; } if (!_documentsLoader.Load(_businessLogic)) { System.Windows.Forms.MessageBox.Show( "Failed loading ALL documents!", "Error"); return; } _currentLoadingScreen = new LoadingScreenDialog( "Loading documents ...", true); _currentLoadingScreen.ShowDialog(); // show report ReportDialog report = new ReportDialog(_documentsLoader.DocumentsStatus); report.ShowDialog(); }
//-------------------------------------------------------------------------- public void AddPhrase(string text) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Adding Phrase ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Phrases.Add(text, (phrase, status, message) => { queryMessageResult = message; if (status) { _parentForm.Invoke((MethodInvoker) delegate { FillPhrasesListOnUIThread(new List <Phrase>() { phrase }, true); _parentForm.richTextBoxAdd.ResetText(); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void ResetDB() { DialogResult result = System.Windows.Forms.MessageBox.Show( "Are you sure you want to proceed and lose all data?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result != DialogResult.Yes) { return; } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Reseting Database ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.ExportImport.ResetDB((status, message) => { queryMessageResult = message; _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void RelationDoubleClicked(Relation relation) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Retreiving Relation Words ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Relations.GetWordPairs( relation, (wordPairs, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillRelationWordPairsListOnUIThread(relation, wordPairs, false); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; // check results if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } _currentSelectedRelation = relation; _parentForm.btnAddWordPair.Enabled = true; }
//-------------------------------------------------------------------------- public void QueryPhrase(Phrase phrase) { string queryMessageResult = ""; _parentForm.richTextBoxContents.Text = ""; _currentLoadingScreen = new LoadingScreenDialog( "Running Phrase Query ...", false); UpdateLocationsCount(); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Phrases.Query(phrase, (phrasesLocations, status, message) => { queryMessageResult = message; if (status) { FillLocationsListOnUIThread(phrasesLocations); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void AddRelation(string newRelation) { string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Adding Relation ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Relations.AddRelation( newRelation, (relation, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillRelationsListOnUIThread(new List <Relation>() { relation }, true); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }
//-------------------------------------------------------------------------- public void RemoveGroup() { if (_parentForm.listViewGroups.SelectedItems.Count <= 0) { return; } ListViewItem item = _parentForm.listViewGroups.SelectedItems[0]; string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Removing Group ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); // get all words _businessLogic.Groups.RemoveGroup( (Group)item.Tag, (status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { _parentForm.Invoke((MethodInvoker) delegate { item.Remove(); UpdateGroupsCount(); }); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } if (_currentSelectedGroup == null) { return; } Group removedItem = (Group)item.Tag; if (removedItem.Name.ToLower() != _currentSelectedGroup.Name.ToLower()) { return; } _currentSelectedGroup = null; _parentForm.listViewWordsInGroup.Items.Clear(); _parentForm.btnAddWord.Enabled = false; UpdateWordsInGroupCount(null); }
//-------------------------------------------------------------------------- public void AddGroupWord(string newWord) { if (_currentSelectedGroup == null) { return; } if (newWord.Length <= 0) { return; } foreach (ListViewItem item in _parentForm.listViewWordsInGroup.Items) { string word = item.Text; if (word.ToLower().Equals(newWord.ToLower())) { // already exists in the list item.Selected = true; return; } } string queryMessageResult = ""; _currentLoadingScreen = new LoadingScreenDialog( "Adding Group Word ...", false); Task.Run(() => { System.Threading.Thread.Sleep(200); _businessLogic.Groups.AddGroupWord(_currentSelectedGroup, newWord, (word, status, message) => { queryMessageResult = message; if (String.IsNullOrEmpty(queryMessageResult)) { FillGroupWordsListOnUIThread(_currentSelectedGroup, new List <Word>() { word }, true); } _currentLoadingScreen.Invoke((MethodInvoker) delegate { _currentLoadingScreen.CloseScreen(); }); }); }); _currentLoadingScreen.ShowDialog(); _currentLoadingScreen = null; if (!String.IsNullOrEmpty(queryMessageResult)) { System.Windows.Forms.MessageBox.Show(queryMessageResult, "Error"); return; } }