예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates the scripture checks and updates the annotation definitions by checking
        /// that for each check we have a corresponding annotation definition in the database.
        /// </summary>
        /// <param name="dataSource">The data source.</param>
        /// ------------------------------------------------------------------------------------
        private static SortedList <ScrCheckKey, IScriptureCheck> InstantiateChecks(
            ScrChecksDataSource dataSource)
        {
            FdoCache cache = dataSource.Cache;

            SortedList <ScrCheckKey, IScriptureCheck> scriptureChecks =
                new SortedList <ScrCheckKey, IScriptureCheck>();

            using (new SuppressSubTasks(cache))
            {
                Dictionary <Guid, ICmAnnotationDefn> errorTypes =
                    new Dictionary <Guid, ICmAnnotationDefn>();

                ICmAnnotationDefn annDefnChkError = new CmAnnotationDefn(cache,
                                                                         LangProject.kguidAnnCheckingError);

                foreach (ICmAnnotationDefn errorType in annDefnChkError.SubPossibilitiesOS)
                {
                    errorTypes[errorType.Guid] = errorType;
                }

                foreach (Type type in s_scrCheckList)
                {
                    IScriptureCheck scrCheck =
                        (IScriptureCheck)Activator.CreateInstance(type, dataSource);

                    if (scrCheck == null)
                    {
                        continue;
                    }

                    // Get the localized version of the check name
                    string scrCheckName = GetCheckProperty(ScrFdoResources.ResourceManager,
                                                           scrCheck.CheckId, "Name", scrCheck.CheckName);
                    scriptureChecks.Add(new ScrCheckKey(scrCheck.RelativeOrder, scrCheckName), scrCheck);

                    ICmAnnotationDefn chkType;
                    if (!errorTypes.TryGetValue(scrCheck.CheckId, out chkType))
                    {
                        chkType = new CmAnnotationDefn();
                        annDefnChkError.SubPossibilitiesOS.Append(chkType);
                        chkType.Guid        = scrCheck.CheckId;
                        chkType.IsProtected = true;
                        chkType.Name.UserDefaultWritingSystem = scrCheckName;
                        chkType.Description.UserDefaultWritingSystem.UnderlyingTsString =
                            StringUtils.MakeTss(scrCheck.Description, cache.DefaultUserWs);
                        chkType.HelpId = scrCheck.CheckName.Replace(' ', '_');
                        InheritAttributes(annDefnChkError, chkType);
                    }
                    else if (chkType.Name.UserDefaultWritingSystem != scrCheckName)
                    {
                        // Store the localized version of the check name as the current UI name.
                        chkType.Name.UserDefaultWritingSystem = scrCheckName;
                    }
                }
            }
            return(scriptureChecks);
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Runs the check.
        /// </summary>
        /// <param name="check">The check.</param>
        /// ------------------------------------------------------------------------------------
        public void RunCheck(IScriptureCheck check)
        {
            if (m_bookChecksFailed == null)
            {
                m_bookChecksFailed = new Dictionary <int, Dictionary <Guid, ScrCheckRunResult> >();
            }

            if (m_pendingCheckErrors == null)
            {
                m_pendingCheckErrors = new Dictionary <int, Dictionary <Guid, Dictionary <string, List <IScrScriptureNote> > > >();
            }

            Dictionary <Guid, Dictionary <string, List <IScrScriptureNote> > > pendingErrorsForBook;
            int bookNum = m_bookBeingChecked.CanonicalNum;

            if (!m_pendingCheckErrors.TryGetValue(bookNum, out pendingErrorsForBook))
            {
                pendingErrorsForBook          = new Dictionary <Guid, Dictionary <string, List <IScrScriptureNote> > >();
                m_pendingCheckErrors[bookNum] = pendingErrorsForBook;
            }
            Dictionary <string, List <IScrScriptureNote> > pendingErrorsForCheck =
                new Dictionary <string, List <IScrScriptureNote> >();

            pendingErrorsForBook[check.CheckId] = pendingErrorsForCheck;

            IScrBookAnnotations annotations =
                (IScrBookAnnotations)m_scr.BookAnnotationsOS[bookNum - 1];

            // Find previously created error annotions for the current book and check.
            foreach (IScrScriptureNote ann in annotations.NotesOS)
            {
                BCVRef beginRef = new BCVRef(ann.BeginRef);
                // ENHANCE, use a smarter algorithm to search for the start of the annotations for this book
                if (beginRef.Book == bookNum && ann.AnnotationTypeRA.Guid == check.CheckId)
                {
                    BCVRef     endRef         = new BCVRef(ann.EndRef);
                    IStTxtPara quotePara      = (IStTxtPara)ann.QuoteOA.ParagraphsOS[0];
                    IStTxtPara discussionPara = (IStTxtPara)ann.DiscussionOA.ParagraphsOS[0];
                    string     key            = beginRef.AsString + endRef.AsString + quotePara.Contents.Text +
                                                discussionPara.Contents.Text;

                    List <IScrScriptureNote> errors;
                    if (!pendingErrorsForCheck.TryGetValue(key, out errors))
                    {
                        errors = new List <IScrScriptureNote>();
                        pendingErrorsForCheck[key] = errors;
                    }
                    errors.Add(ann);
                }
            }

            if (!m_bookChecksFailed.ContainsKey(bookNum))
            {
                m_bookChecksFailed[bookNum] = new Dictionary <Guid, ScrCheckRunResult>();
            }

            // Before running the check, reset the check result for this book and check.
            // This is like initializing our check result to green bar in an NUnit test.
            // As the check is running, that status may get changed to "Inconsistencies"
            // (red bar) or "IgnoredInconsistencies" (yellow bar).
            m_bookChecksFailed[bookNum][check.CheckId] = ScrCheckRunResult.NoInconsistencies;

            // Create a hash table for this check to tally how many times each unique error is generated.
            if (m_errorCounts != null)
            {
                m_errorCounts.Clear();
                m_errorCounts = null;
            }
            m_errorCounts = new ErrorInventory();

            // Run the Scripture check.
            check.Check(TextTokens(), RecordError);

            // Find a check history record for the check just run.
            // If one cannot be found, then create a new one.
            IScrCheckRun checkRun = null;

            foreach (IScrCheckRun scrChkRun in annotations.ChkHistRecsOC)
            {
                if (scrChkRun.CheckId == check.CheckId)
                {
                    checkRun = scrChkRun;
                    break;
                }
            }

            if (checkRun == null)
            {
                checkRun = Cache.ServiceLocator.GetInstance <IScrCheckRunFactory>().Create();
                annotations.ChkHistRecsOC.Add(checkRun);
                checkRun.CheckId = check.CheckId;
            }

            checkRun.RunDate = DateTime.Now;
            checkRun.Result  = m_bookChecksFailed[bookNum][check.CheckId];

            foreach (List <IScrScriptureNote> obsoleteErrors in pendingErrorsForCheck.Values)
            {
                foreach (IScrScriptureNote obsoleteError in obsoleteErrors)
                {
                    annotations.NotesOS.Remove(obsoleteError);
                }
            }
        }
예제 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:ScrChkTreeNode"/> class.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		internal ScrChkTreeNode(string checkName, DateTime lastRun, string[] tipBookList,
			IScriptureCheck scrCheck)
		{
			Name = checkName;
			m_lastRun = lastRun;
			m_scrCheck = scrCheck;
			m_tipBookList = tipBookList;
			Text = ToString();
		}