Beispiel #1
0
        /// <summary>
        /// Updates the wordform. This will be run in the UI thread when the application is idle. If it can't be done right now,
        /// it returns false, and the caller should try again later.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        /// <returns></returns>
        private bool UpdateWordforms(object parameter)
        {
            if (IsDisposed)
            {
                return(true);
            }
            // If a UOW is in progress, the application isn't really idle, so try again later. One case where this used
            // to be true was the dialog in IText for choosing the writing system of a new text, which was run while
            // the UOW was active.
            if (!((IActionHandlerExtensions)m_cache.ActionHandlerAccessor).CanStartUow)
            {
                return(false);
            }

            // update all of the wordforms in a batch, this might slow down the UI thread a little, if it causes too much unresponsiveness
            // we can bail out early if there is a message in the Win32 message queue
            IEnumerable <ParseResult> results;

            lock (m_syncRoot)
            {
                results = m_resultQueue.ToArray();
                m_resultQueue.Clear();
            }

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                foreach (ParseResult result in results)
                {
                    if (!result.IsValid)
                    {
                        // the wordform or the candidate analyses are no longer valid, so just skip this parse
                        FireWordformUpdated(result.Wordform, result.Priority);
                        continue;
                    }
                    var startTime = DateTime.Now;
                    string form   = result.Wordform.Form.BestVernacularAlternative.Text;
                    using (new TaskReport(String.Format(ParserCoreStrings.ksUpdateX, form), m_taskUpdateHandler))
                    {
                        // delete old problem annotations
                        var problemAnnotations = from ann in m_baseAnnotationRepository.AllInstances()
                                                 where
                                                 ann.BeginObjectRA == result.Wordform &&
                                                 ann.SourceRA == m_parserAgent
                                                 select ann;
                        foreach (var problem in problemAnnotations)
                        {
                            m_cache.DomainDataByFlid.DeleteObj(problem.Hvo);
                        }

                        if (result.ErrorMessage != null)
                        {
                            // there was an error, so create a problem annotation
                            var problemReport = m_baseAnnotationFactory.Create();
                            m_cache.LangProject.AnnotationsOC.Add(problemReport);
                            problemReport.CompDetails      = result.ErrorMessage;
                            problemReport.SourceRA         = m_parserAgent;
                            problemReport.AnnotationTypeRA = null;
                            problemReport.BeginObjectRA    = result.Wordform;
                            FinishWordForm(result.Wordform);
                        }
                        else
                        {
                            // update the wordform
                            foreach (var analysis in result.Analyses)
                            {
                                ProcessAnalysis(result.Wordform, analysis);
                            }
                            FinishWordForm(result.Wordform);
                            MarkAnalysisParseFailures(result.Wordform);
                        }
                        result.Wordform.Checksum = (int)result.Crc;
                    }
                    // notify all listeners that the wordform has been updated
                    FireWordformUpdated(result.Wordform, result.Priority);
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    m_ticksFiler += ttlTicks;
                    m_numberOfWordForms++;
                    Trace.WriteLineIf(m_tracingSwitch.TraceInfo, "parser filer(" + form + ") took : " + TimeSpan.FromTicks(ttlTicks).TotalMilliseconds);
                }
            });
            return(true);
        }