Example #1
0
        private async void Parse()
        {
            if (parserController.options.TextToParsePath != null && parserController.options.Language != null)
            {
                bool correctParserConfirmed = parserController.ConfirmParserCompatibility(textSample, textPreview);

                try {
                    if (correctParserConfirmed == false)
                    {
                        MessageBoxResult parsingProblemMessageBox = MessageBox.Show("Potential language incompatibilities detected. Are you sure you want to continue? \r\n \r\n Click 'Cancel' to go back and select the correct language (RECOMMENDED) or 'OK' to continue (WARNING: program might became inestable or crash.)",
                                                                                    "Parsing problem?", System.Windows.MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.Cancel);
                        if (parsingProblemMessageBox == MessageBoxResult.OK)
                        {
                            correctParserConfirmed = true;
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message, "Parsing problem");
                }

                if (correctParserConfirmed)
                {
                    //Async parsing
                    LW = new LoadingWindow();
                    await Task.Run(() => parserController.RunParser(parserController.options.TextToParsePath));

                    LW.CloseLoadingWindow();

                    //Result generation
                    dynamic result = parserController.ReportParsingResult(false);

                    if (result != null)
                    {
                        MessageBox.Show(result.clippingCount + " clippings parsed.", "Parsing successful.");
                        MessageBox.Show(result.databaseEntries.ToString() + " clippings added to database. " +
                                        result.removedClippings.ToString() + " empty or null clippings removed.", "Database created.");
                        if (result.databaseEntries <= 0)
                        {
                            MessageBox.Show("No clippings added to database, please try again with a different file.");
                        }
                        else
                        {
                            //If you want to update UI from this task a dispatcher has to be used, since it has to be in the UI thread.
                            Dispatcher.Invoke((Action) delegate() {
                                LaunchDatabaseWindow();
                            });
                        }
                    }
                    else
                    {
                        MessageBox.Show("Parsing failed");
                    }
                }
            }

            if (parserController.options.TextToParsePath == null)
            {
                MessageBox.Show("No path to .txt found, please select your Kindle clipping file and try again.");
            }

            if (parserController.options.Language == null)
            {
                MessageBox.Show("Problems detecting language, please select your language and try again.");
            }
        }