//--------------------------------------------------------------------------
        public bool Initialize()
        {
            if (!_workerThread.Start())
            {
                return(false);
            }

            return(_workerThread.PostTask(_ => {
                try {
                    DatabaseConnectionService.Instance.Initialize();
                    try {
                        WordsService.Instance.Initialize();
                        CollectStats();
                    } catch (Exception) {
                        // ignore it because we might have an empty DB
                    }

                    GlobalParamatersService.Delegate.OnInitializationComplete(
                        true, null);
                } catch (Exception e) {
                    GlobalParamatersService.Delegate.OnInitializationComplete(
                        false, e.Message);
                }
            }));
        }
        //--------------------------------------------------------------------------
        public bool GetAll(GetPhrasesCallback callback)
        {
            if (callback == null)
            {
                return(false);
            }

            return(_workerThread.PostTask(_ => {
                try {
                    List <Phrase> result = PhrasesService.Instance.GetAll();
                    callback(result, true, null);
                } catch (Exception e) {
                    callback(null, false, e.Message);
                }
            }));
        }
Ejemplo n.º 3
0
        //--------------------------------------------------------------------------
        public bool Export(FileInfo filename, ExportImportCallback callback)
        {
            if (callback == null)
            {
                return(false);
            }

            return(_workerThread.PostTask(_ => {
                try {
                    DatabaseConnectionService.Instance.ExportDatabase(filename);

                    callback(true, null);
                } catch (Exception e) {
                    callback(false, e.Message);
                }
            }));
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------------------
        public bool GetDocuments(
            List <string> words, GetDocumentsCallback callback)
        {
            if (callback == null)
            {
                return(false);
            }

            return(_workerThread.PostTask(_ => {
                try {
                    List <Document> result =
                        DocumentsService.Instance.QueryByWords(words);
                    callback(result, true, null);
                } catch (Exception e) {
                    callback(null, false, e.Message);
                }
            }));
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------------------
        public bool GetAll(StatisticsDelegate statsDelegate,
                           GetStatisticsCallback callback)
        {
            return(_workerThread.PostTask(_ => {
                try {
                    // word frequencies - start with this so that the user can
                    // play with the frequencies while we get other stats
                    List <Tuple <Word, uint> > frequencies =
                        StatisticsService.Instance.GetWordFrequencies();
                    statsDelegate.OnWordFrequenciesReady(frequencies);

                    // average words
                    statsDelegate.OnAvgWordsPerLine(
                        StatisticsService.Instance.AvgWordsPerLine());
                    statsDelegate.OnAvgWordsPerSentence(
                        StatisticsService.Instance.AvgWordsPerSentence());
                    statsDelegate.OnAvgWordsPerParagraph(
                        StatisticsService.Instance.AvgWordsPerParagraph());
                    statsDelegate.OnAvgWordsPerPage(
                        StatisticsService.Instance.AvgWordsPerPage());
                    statsDelegate.OnAvgWordsPerDocument(
                        StatisticsService.Instance.AvgWordsPerDocument());

                    // average chars
                    statsDelegate.OnAvgCharsPerLine(
                        StatisticsService.Instance.AvgCharsPerLine());
                    statsDelegate.OnAvgCharsPerSentence(
                        StatisticsService.Instance.AvgCharsPerSentence());
                    statsDelegate.OnAvgCharsPerParagraph(
                        StatisticsService.Instance.AvgCharsPerParagraph());
                    statsDelegate.OnAvgCharsPerPage(
                        StatisticsService.Instance.AvgCharsPerPage());
                    statsDelegate.OnAvgCharsPerDocument(
                        StatisticsService.Instance.AvgCharsPerDocument());

                    callback(true, null);
                } catch (Exception e) {
                    callback(false, e.Message);
                }
            }));
        }