public void ExistingAnnotation_WithResponses()
        {
            IScrScriptureNote existingAnn =
                AddAnnotation(null, 02002008, NoteType.Translator, "This is my discussion");

            existingAnn.ResolutionStatus = NoteStatus.Open;

            IStJournalText exisingResponse1 = Cache.ServiceLocator.GetInstance <IStJournalTextFactory>().Create();

            existingAnn.ResponsesOS.Add(exisingResponse1);
            AddParasTo(exisingResponse1, "This is my first response");

            IStJournalText exisingResponse2 = Cache.ServiceLocator.GetInstance <IStJournalTextFactory>().Create();

            existingAnn.ResponsesOS.Add(exisingResponse2);
            AddParasTo(exisingResponse2, "This is my second response");

            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "EXO 2:8";
            ann.ResolutionStatus   = NoteStatus.Open;
            ann.AnnotationTypeGuid = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString();
            ann.DateTimeModified   = utcNow.AddDays(1).ToString();
            AddParasTo(ann.Discussion, "This is my discussion");
            XmlNoteResponse firstResponse = new XmlNoteResponse();

            AddParasTo(firstResponse.Paragraphs, "This is my first response");
            ann.Responses.Add(firstResponse);
            XmlNoteResponse secondResponse = new XmlNoteResponse();

            AddParasTo(secondResponse.Paragraphs, "This is my second response");
            ann.Responses.Add(secondResponse);

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[1];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.AreEqual(DateTime.MinValue, note.DateResolved);

            IFdoOwningSequence <IStJournalText> responses = note.ResponsesOS;

            Assert.AreEqual(2, responses.Count);
            TestAnnotationField(responses[0], "This is my first response");
            TestAnnotationField(responses[1], "This is my second response");
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a collection of annotations for Genesis (in a real DB, this would be done for
        /// all 66 books in TeScrInitializer).
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            IScrBookAnnotations notes = Cache.ServiceLocator.GetInstance <IScrBookAnnotationsFactory>().Create();

            m_scr.BookAnnotationsOS.Add(notes);
            m_notesEditingHelper = new DummyNotesEditingHelper(Cache, null);
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create an annotation in response to an error returned by a check.
        /// The check calls this delegate whenever an error is found.
        /// </summary>
        /// <param name="args">Information about the potential inconsistency being reported</param>
        /// ------------------------------------------------------------------------------------
        public void RecordError(RecordErrorEventArgs args)
        {
            ScrCheckingToken firstToken = args.Tts.FirstToken as ScrCheckingToken;
            ScrCheckingToken lastToken  = args.Tts.LastToken as ScrCheckingToken;

            Debug.Assert(firstToken != null);
            Debug.Assert(lastToken != null);
            Debug.Assert(firstToken.Object == lastToken.Object);
            int    offset       = args.Tts.Offset;
            int    length       = args.Tts.Length;
            Guid   checkId      = args.CheckId;
            string formattedMsg = args.Tts.Message;

            // If the token is for a missing reference, then replace the token's
            // reference range with the missing reference range.
            if (args.Tts.MissingStartRef != null && !args.Tts.MissingStartRef.IsEmpty)
            {
                firstToken.m_startRef = new BCVRef(firstToken.MissingStartRef);
                firstToken.m_endRef   = new BCVRef(firstToken.MissingEndRef != null ?
                                                   firstToken.m_missingEndRef : firstToken.m_startRef);
            }

            int    bookNum   = firstToken.StartRef.Book;
            string citedText = args.Tts.Text;

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

            // key for the error with the same cited text and message at a particular reference.
            string errorLocKey = firstToken.StartRef.AsString + lastToken.EndRef.AsString +
                                 citedText + formattedMsg;
            // key for an error with the same cited text and message.
            string errorKey = checkId.ToString() + citedText + formattedMsg;

            if (CheckForPreviousInconsistency(firstToken, lastToken, citedText, offset, length, checkId, errorLocKey, errorKey))
            {
                return;
            }

            // NOTE: A maxIdenticalErrors value of -1 indicates that there is no maximum set.
            int maxIdenticalErrors = GetMaxIdenticalErrors(checkId);
            int errorCount         = m_errorCounts.GetValue(errorKey);

            // Check the number of times this same error has already been reported.
            // If the maximum allowed number of identical errors already has been reached then
            // we don't want to report the error as usual.
            if (errorCount == maxIdenticalErrors)
            {
                formattedMsg = GetExceededErrorMsg(checkId);
            }
            else if (errorCount > maxIdenticalErrors && maxIdenticalErrors > -1)
            {
                // We have exceeded the maximum allowed for this error, so don't write out an annotation.
                return;
            }

            m_errorCounts.IncrementError(errorKey);
            AddErrorAnnotation(citedText, offset, length, checkId, firstToken, lastToken, formattedMsg);
            m_bookChecksFailed[bookNum][checkId] = ScrCheckRunResult.Inconsistencies;
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Cleanups the scripture note import manager.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static void Cleanup()
 {
     s_existingAnnotations = null;
     s_checkNamesToGuids   = null;
     s_annotationList      = null;
     s_prevBookNum         = 0;
     s_scr = null;
 }
Esempio n. 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Cleanups the scripture note import manager.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void Cleanup()
		{
			s_existingAnnotations = null;
			s_checkNamesToGuids = null;
			s_annotationList = null;
			s_prevBookNum = 0;
			s_scr = null;
		}
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Writes this annotation to the specified cache.
        /// </summary>
        /// <param name="scr">The scripture.</param>
        /// <param name="styleSheet">The style sheet.</param>
        /// <returns>The created annotation</returns>
        /// ------------------------------------------------------------------------------------
        internal IScrScriptureNote WriteToCache(IScripture scr, FwStyleSheet styleSheet)
        {
            if (AnnotationTypeGuid == Guid.Empty.ToString())
            {
                return(null);
            }

            Debug.Assert(scr.Cache == styleSheet.Cache, "This can't end well");
            int bookNum             = BeginScrBCVRef.Book;
            IScrBookAnnotations sba = scr.BookAnnotationsOS[bookNum - 1];

            if (sba == null)
            {
                sba = scr.Cache.ServiceLocator.GetInstance <IScrBookAnnotationsFactory>().Create();
                scr.BookAnnotationsOS.Insert(bookNum - 1, sba);
            }

            IScrScriptureNote scrNote = FindOrCreateAnnotation(styleSheet);

            scrNote.BeginOffset      = BeginOffset;
            scrNote.EndOffset        = EndOffset;
            scrNote.ResolutionStatus = ResolutionStatus;

            if (m_createdDate > DateTime.MinValue)
            {
                scrNote.DateCreated = m_createdDate;
            }

            if (m_modifiedDate > DateTime.MinValue)
            {
                scrNote.DateModified = m_modifiedDate;
            }

            if (m_resolvedDate > DateTime.MinValue)
            {
                scrNote.DateResolved = m_resolvedDate;
            }

            foreach (XmlNoteCategory category in Categories)
            {
                category.WriteToCache(scrNote);
            }

            foreach (XmlNoteResponse response in Responses)
            {
                response.WriteToCache(scrNote, styleSheet);
            }

            //((Scripture)scr).AttachAnnotatedObjects(bookNum, scrNote);
            if (scrNote.BeginObjectRA == null && scrNote.CitedTextTss != null)
            {
                AttachAnnotatedObjects(scr, bookNum, scrNote);
            }

            return(scrNote);
        }
        public void SavingDeserializedAnnotationsToCache_WithResponses()
        {
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "EXO 2:8";
            ann.ResolutionStatus   = NoteStatus.Open;
            ann.AnnotationTypeGuid = LangProject.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString();
            ann.DateTimeModified   = utcNow.AddDays(1).ToString();
            AddParasTo(ann.Discussion, "This is my discussion");
            AddParasTo(ann.Resolution, "This is my resolution for the note");
            AddParasTo(ann.Quote, "This is the quoted text");
            AddParasTo(ann.Suggestion, "This is my suggestion");
            XmlNoteResponse firstResponse = new XmlNoteResponse();

            AddParasTo(firstResponse.Paragraphs, "This is", "my", "first", "response");
            ann.Responses.Add(firstResponse);
            XmlNoteResponse secondResponse = new XmlNoteResponse();

            AddParasTo(secondResponse.Paragraphs, "This is", "my second response");
            ann.Responses.Add(secondResponse);

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[1];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDateTimesClose(now.AddDays(1), note.DateModified));
            Assert.AreEqual(DateTime.MinValue, note.DateResolved);

            TestAnnotationField(note.QuoteOA, "This is the quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my discussion");
            TestAnnotationField(note.ResolutionOA, "This is my resolution for the note");
            TestAnnotationField(note.RecommendationOA, "This is my suggestion");

            FdoOwningSequence <IStJournalText> responses = note.ResponsesOS;

            Assert.AreEqual(2, responses.Count);
            TestAnnotationField(responses[0], "This is", "my", "first", "response");
            TestAnnotationField(responses[1], "This is", "my second response");
        }
Esempio n. 8
0
        public void SavingDeserializedAnnotationsToCache_WithHyperlink()
        {
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "GEN 2:8";
            ann.ResolutionStatus   = NoteStatus.Closed;
            ann.AnnotationTypeGuid = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString(CultureInfo.InvariantCulture);
            ann.DateTimeModified   = utcNow.AddDays(1).ToString(CultureInfo.InvariantCulture);
            ann.DateTimeResolved   = utcNow.AddDays(2).ToString(CultureInfo.InvariantCulture);
            AddParasTo(ann.Discussion, "This is my", "discussion");
            AddParasTo(ann.Resolution, "This is my", "resolution for", "the note");
            AddParasTo(ann.Quote, "This is the", "quoted text");
            AddParasTo(ann.Suggestion, "This is", "my", "suggestion");
            AddHyperTo(ann.Suggestion[1], "http://www.tim.david.com/cooldudes.html");

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[0];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.IsTrue(AreDatesClose(now.AddDays(2), note.DateResolved));

            TestAnnotationField(note.QuoteOA, "This is the", "quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my", "discussion");
            TestAnnotationField(note.ResolutionOA, "This is my", "resolution for", "the note");
            TestAnnotationField(note.RecommendationOA, "This is", "mymy link", "suggestion");

            // Check the hyperlink location
            ITsTextProps props = ((IStTxtPara)note.RecommendationOA.ParagraphsOS[1]).Contents.get_Properties(1);
            string       href  = TsStringUtils.GetURL(props.GetStrPropValue((int)FwTextPropType.ktptObjData));

            Assert.AreEqual("http://www.tim.david.com/cooldudes.html", href);

            Assert.AreEqual(0, note.ResponsesOS.Count);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Scroll new note into view.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="fromUndoRedo">True if the event was fired from an undo (or rollback) or
        /// redo, false otherwise.</param>
        /// ------------------------------------------------------------------------------------
        private void ScrollAfterPropChangedCompleted(object sender, bool fromUndoRedo)
        {
            // In test teardown, cache may already have been cleared
            if (Cache == null)
            {
                return;
            }
            ((IActionHandlerExtensions)Cache.ActionHandlerAccessor).PropChangedCompleted -= ScrollAfterPropChangedCompleted;
            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[m_bookNewNote - 1];
            IScrScriptureNote   annotation  = annotations.NotesOS[m_indexNewNote];
            TeNotesVc           notesVc     = CurrentNotesVc;

            if (notesVc != null)
            {
                // tell the VC that the newly inserted item should be expanded. That will cause
                // the view to be updated to show the new note.
                notesVc.ExpandItem(annotation.Hvo, EditedRootBox);
                notesVc.ExpandItem(annotation.DiscussionOA.Hvo, EditedRootBox);
            }

            if (Control != null)
            {
                Control.Focus();
            }

            // Make a selection in the discussion so the user can start to type
            int iPos = m_indexNewNote;

            if (notesVc != null)
            {
                // Get the corresponding index in the virtual property.
                iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess).
                       GetFilteredIndexOfItem(annotations.Hvo, iPos);
                // New note doesn't match current filter - need to turn it off
                if (iPos < 0)
                {
                    // Turn off the filter so the new note will show
                    ((NotesDataEntryView)Control).OnChangeFilter(null);
                    iPos = ((FilteredDomainDataByFlidDecorator)EditedRootBox.DataAccess).
                           GetFilteredIndexOfItem(annotations.Hvo, m_indexNewNote);
                    Debug.Assert(iPos >= 0);
                }
            }

            IVwRootSite rootSite = Control as IVwRootSite;

            MakeSelectionInNote(notesVc, m_bookNewNote - 1, iPos, rootSite, true);
        }
Esempio n. 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add an annotation to a language project.
        /// </summary>
        /// <param name="testBase">in-memory cache to use for testing</param>
        /// <param name="noteText">text to include in discussion</param>
        /// <param name="startRef"></param>
        /// <param name="endRef"></param>
        /// <param name="topPara">Begin IStTxtPara to annotate</param>
        /// <param name="bottomPara">End IStTxtPara to annotate</param>
        /// <returns>a new annotation</returns>
        /// ------------------------------------------------------------------------------------
        internal static IScrScriptureNote AddAnnotation(ScrInMemoryFdoTestBase testBase, string noteText,
                                                        ScrReference startRef, ScrReference endRef, ICmObject topPara, ICmObject bottomPara)
        {
            ILangProject        lp          = testBase.Cache.LangProject;
            IScrBookAnnotations annotations = lp.TranslatedScriptureOA.BookAnnotationsOS[startRef.Book - 1];
            IScrScriptureNote   note        = annotations.InsertNote(startRef, endRef, topPara, bottomPara,
                                                                     StandardNoteType(testBase.Cache).Guid);

            IStTxtPara discussionPara = (IStTxtPara)note.DiscussionOA.ParagraphsOS[0];

            testBase.AddRunToMockedPara(discussionPara, noteText, testBase.Cache.DefaultAnalWs);

            note.DateCreated = new DateTime(s_Ticks++);

            return(note);
        }
Esempio n. 11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the error annotation to the database.
        /// </summary>
        /// <param name="citedText">The cited text.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="checkId">The Scripture error checking id.</param>
        /// <param name="firstToken">The first token.</param>
        /// <param name="lastToken">The last token.</param>
        /// <param name="formattedMsg">The formatted error message.</param>
        /// ------------------------------------------------------------------------------------
        private void AddErrorAnnotation(string citedText, int offset, int length, Guid checkId,
                                        ScrCheckingToken firstToken, ScrCheckingToken lastToken, string formattedMsg)
        {
            IScrBookAnnotations annotations =
                (IScrBookAnnotations)m_scr.BookAnnotationsOS[firstToken.StartRef.Book - 1];

            StTxtParaBldr     quote      = SetCitedText(citedText, firstToken.Ws);
            StTxtParaBldr     discussion = SetErrorMessage(formattedMsg);
            IScrScriptureNote note       = annotations.InsertErrorAnnotation(firstToken.StartRef,
                                                                             lastToken.EndRef, firstToken.Object, lastToken.Object, checkId, quote,
                                                                             discussion);

            note.BeginOffset = firstToken.ParaOffset + offset;
            note.EndOffset   = note.BeginOffset + length;
            note.Flid        = firstToken.Flid;
        }
Esempio n. 12
0
        public void SavingDeserializedAnnotationsToCache()
        {
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "GEN 2:8";
            ann.ResolutionStatus   = NoteStatus.Closed;
            ann.AnnotationTypeGuid = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString(CultureInfo.InvariantCulture);
            ann.DateTimeModified   = utcNow.AddDays(1).ToString(CultureInfo.InvariantCulture);
            ann.DateTimeResolved   = utcNow.AddDays(2).ToString(CultureInfo.InvariantCulture);
            ann.BeginObjGuid       = m_paraObj.Guid;
            ann.EndObjGuid         = m_paraObj.Guid;
            AddParasTo(ann.Discussion, "This is my", "discussion");
            AddParasTo(ann.Resolution, "This is my", "resolution for", "the note");
            AddParasTo(ann.Quote, "This is the", "quoted text");
            AddParasTo(ann.Suggestion, "This is", "my", "suggestion");

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[0];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.IsTrue(AreDatesClose(now.AddDays(2), note.DateResolved));

            TestAnnotationField(note.QuoteOA, "This is the", "quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my", "discussion");
            TestAnnotationField(note.ResolutionOA, "This is my", "resolution for", "the note");
            TestAnnotationField(note.RecommendationOA, "This is", "my", "suggestion");

            Assert.AreEqual(0, note.ResponsesOS.Count);
        }
Esempio n. 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the scripture note import manager.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void Initialize(IScripture scr, int bookNum, string alternateRfcWsDir)
		{
			s_scr = scr;

			if (!string.IsNullOrEmpty(alternateRfcWsDir))
				s_alternateRfcWsDir = alternateRfcWsDir;

			CacheCheckIds();

			if (bookNum != s_prevBookNum)
			{
				s_prevBookNum = bookNum;
				s_annotationList = scr.BookAnnotationsOS[bookNum - 1];
				s_existingAnnotations = new Dictionary<ScrNoteKey, IScrScriptureNote>();

				foreach (IScrScriptureNote ann in s_annotationList.NotesOS)
					s_existingAnnotations[ann.Key] = ann;
			}
		}
        public void SavingDeserializedAnnotationsToCache_InvalidResolvedAndModifiedDate()
        {
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "GEN 2:8";
            ann.ResolutionStatus   = NoteStatus.Closed;
            ann.AnnotationTypeGuid = LangProject.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString();
            ann.DateTimeModified   = "0009-05-02 20:00:00.00";
            ann.DateTimeResolved   = "0003-01-01 20:00:00.00";
            AddParasTo(ann.Discussion, "This is my discussion");
            AddParasTo(ann.Resolution, "This is my resolution for the note");
            AddParasTo(ann.Quote, "This is the quoted text");
            AddParasTo(ann.Suggestion, "This is my suggestion");

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[0];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDateTimesClose(DateTime.FromFileTime(0), note.DateModified));
            Assert.IsTrue(AreDateTimesClose(DateTime.FromFileTime(0), note.DateModified));

            TestAnnotationField(note.QuoteOA, "This is the quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my discussion");
            TestAnnotationField(note.ResolutionOA, "This is my resolution for the note");
            TestAnnotationField(note.RecommendationOA, "This is my suggestion");

            Assert.AreEqual(0, note.ResponsesOS.Count);
        }
        public void SavingDeserializedAnnotationsToCache_InvalidResolvedDate()
        {
#if __MonoCS__ // TODO-Linux: work around [SetCulture("en-US")] being ignored on mono
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
#endif
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();
            ann.BeginScrRef        = "GEN 2:8";
            ann.ResolutionStatus   = NoteStatus.Closed;
            ann.AnnotationTypeGuid = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString();
            ann.DateTimeModified   = utcNow.AddDays(1).ToString();
            ann.DateTimeResolved   = "0003-01-01 20:00:00.00";
            AddParasTo(ann.Discussion, "This is my discussion");
            AddParasTo(ann.Resolution, "This is my resolution for the note");
            AddParasTo(ann.Quote, "This is the quoted text");
            AddParasTo(ann.Suggestion, "This is my suggestion");

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();
            list.Annotations.Add(ann);

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[0];
            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];
            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.IsTrue(AreDateTimesClose(note.DateModified, note.DateResolved));

            TestAnnotationField(note.QuoteOA, "This is the quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my discussion");
            TestAnnotationField(note.ResolutionOA, "This is my resolution for the note");
            TestAnnotationField(note.RecommendationOA, "This is my suggestion");

            Assert.AreEqual(0, note.ResponsesOS.Count);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inserts a note referencing the currently selected paragraph.
        /// </summary>
        /// <param name="noteType">Type of note</param>
        /// <param name="startRef">reference at beginning of selection</param>
        /// <param name="endRef">reference at end of selection</param>
        /// <param name="topObj">The object where quoted text begins.</param>
        /// <param name="bottomObj">The object where quoted text ends.</param>
        /// <param name="startOffset">The starting character offset.</param>
        /// <param name="endOffset">The ending character offset.</param>
        /// <param name="tssQuote">The text of the quote.</param>
        /// <returns>The inserted note</returns>
        /// ------------------------------------------------------------------------------------
        public virtual IScrScriptureNote InsertNote(ICmAnnotationDefn noteType, BCVRef startRef,
                                                    BCVRef endRef, ICmObject topObj, ICmObject bottomObj,
                                                    int startOffset, int endOffset, ITsString tssQuote)
        {
            CheckDisposed();

            int iPos;

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[startRef.Book - 1];

            StTxtParaBldr quoteParaBldr = new StTxtParaBldr(m_cache);

            quoteParaBldr.ParaStyleName = ScrStyleNames.Remark;
            quoteParaBldr.StringBuilder.ReplaceTsString(0, 0, tssQuote);
            IScrScriptureNote annotation = annotations.InsertNote(startRef, endRef, topObj, bottomObj,
                                                                  noteType.Guid, startOffset, endOffset, quoteParaBldr, null, null, null,
                                                                  out iPos);

            RegisterScrollCallBack(startRef.Book, iPos);

            // REVIEW: Do we need to create a synch record?
            return(annotation);
        }
Esempio n. 17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes the scripture note import manager.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public static void Initialize(IScripture scr, int bookNum, string alternateRfcWsDir)
        {
            s_scr = scr;

            if (!string.IsNullOrEmpty(alternateRfcWsDir))
            {
                s_alternateRfcWsDir = alternateRfcWsDir;
            }

            CacheCheckIds();

            if (bookNum != s_prevBookNum)
            {
                s_prevBookNum         = bookNum;
                s_annotationList      = scr.BookAnnotationsOS[bookNum - 1];
                s_existingAnnotations = new Dictionary <ScrNoteKey, IScrScriptureNote>();

                foreach (IScrScriptureNote ann in s_annotationList.NotesOS)
                {
                    s_existingAnnotations[ann.Key] = ann;
                }
            }
        }
Esempio n. 18
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the current book, particularly picking the right set of annotations
        /// to add new ones to. Also (and more conspicuously) ends the current Undo task
        /// and makes a new one for importing the new book. Should therefore be called
        /// BEFORE setting up the Undo action for the creation of the book.
        /// </summary>
        /// <param name="nCanonicalBookNumber">The canonical book number.</param>
        /// <param name="fVernacular">if set to <c>true</c> currently importing the vernacular.
        /// </param>
        /// <returns>The existing book in the current imported version, if any; otherwise
        /// <c>null</c></returns>
        /// <remarks>If importing annotations and/or BTs without importing the vernacular, the
        /// importer is responsible for calling this directly.</remarks>
        /// ------------------------------------------------------------------------------------
        private IScrBook SetCurrentBook(int nCanonicalBookNumber, bool fVernacular)
        {
            if (nCanonicalBookNumber <= 0 || nCanonicalBookNumber > BCVRef.LastBook)
            {
                throw new ArgumentOutOfRangeException("nCanonicalBookNumber", nCanonicalBookNumber, "Expected a canonical book number.");
            }

            IActionHandler actionHandler = m_cache.DomainDataByFlid.GetActionHandler();

            // We want a new undo task for each new book, except the first one
            if (m_importedBooks.Count > 0)
            {
                actionHandler.EndUndoTask();
            }

            if (actionHandler.CurrentDepth == 0)
            {
                // No need to use localizable string from resources because the user will never
                // see these labels because we collapse to a single undo task when the import
                // completes.
                actionHandler.BeginUndoTask("Undo Import Book " + nCanonicalBookNumber,
                                            "Redo Import Book " + nCanonicalBookNumber);
            }
            if (m_importedBooks.ContainsKey(nCanonicalBookNumber))
            {
                m_lastBookAddedToImportedBooks = 0;
            }
            else
            {
                m_lastBookAddedToImportedBooks        = nCanonicalBookNumber;
                m_importedBooks[nCanonicalBookNumber] = fVernacular;
            }

            m_annotations = m_scr.BookAnnotationsOS[nCanonicalBookNumber - 1];

            return((m_importedVersion == null) ? null : m_importedVersion.FindBook(nCanonicalBookNumber));
        }
Esempio n. 19
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);
                }
            }
        }
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Call MouseUp on the rootbox
        /// </summary>
        /// -----------------------------------------------------------------------------------
        protected override void CallMouseUp(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            IVwSelection      sel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            IScrScriptureNote ann = CurrentAnnotation;

            int  noteTagToSelect         = ScrScriptureNoteTags.kflidDiscussion;
            bool fMakeSelInFirstResponse = false;

            if (sel != null && sel.SelType == VwSelType.kstPicture)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo[]    info      = selHelper.LevelInfo;

                if (info.Length >= 1 &&
                    info[0].tag == ScrScriptureNoteTags.kflidDiscussion ||
                    info[0].tag == ScrScriptureNoteTags.kflidRecommendation ||
                    m_fdoCache.ServiceLocator.ObjectRepository.GetClsid(info[0].hvo) == StJournalTextTags.kClassId)
                {
                    if (m_vc.ToggleItemExpansion(info[0].hvo, m_rootb))
                    {
                        // If the tag is not a valid tag, the assumption
                        // is we're expanding the responses.
                        fMakeSelInFirstResponse = (info[0].tag < 0);
                        noteTagToSelect         = info[0].tag;
                    }
                }
                else if (selHelper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) ==
                         -(int)NotesFrags.kfrConnotCategory)                // This is not a real flid, just a unique number to match on.
                {
                    SetAnnotationCategory(ann);
                }
                else if (info.Length >= 2 && info[1].tag == kCurrentNotesTag)
                {
                    m_vc.ToggleItemExpansion(info[1].hvo, m_rootb);
                    m_ignoreSelChanged = true;
                }
            }

            m_suspendHighlightChange = true;
            try
            {
                base.CallMouseUp(pt, rcSrcRoot, rcDstRoot);
            }
            finally
            {
                m_ignoreSelChanged       = false;
                m_suspendHighlightChange = false;
            }

            UpdateNoteHighlight(ann);

            if (!m_pictureSelected)
            {
                return;
            }

            m_pictureSelected = false;

            if (ann == null)
            {
                return;
            }

            // Make a selection in the proper place in the annotation.
            int book = BCVRef.GetBookFromBcv(ann.BeginRef) - 1;
            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[book];
            int index = m_rootb.DataAccess.GetObjIndex(annotations.Hvo, ScrBookAnnotationsTags.kflidNotes, ann.Hvo);

            if (fMakeSelInFirstResponse)
            {
                NotesEditingHelper.MakeSelectionInNote(book, index, 0, ScrScriptureNoteTags.kflidResponses);
            }
            else if (m_vc.IsExpanded(ann.Hvo) &&
                     m_vc.IsExpanded(m_rootb.DataAccess.get_ObjectProp(ann.Hvo, noteTagToSelect)))
            {
                NotesEditingHelper.MakeSelectionInNote(m_vc, false, book,
                                                       index, 0, noteTagToSelect, this, true);
            }
            else
            {
                NotesEditingHelper.MakeSelectionInNoteRef(m_vc, book, index, this);
            }
        }
Esempio n. 21
0
        public void SavingDeserializedAnnotationsToCache_WithCategories()
        {
            DateTime now    = DateTime.Now;
            DateTime utcNow = now.ToUniversalTime();

            XmlScrNote ann = CreateNote();

            ann.BeginScrRef        = "LEV 2:8";
            ann.ResolutionStatus   = NoteStatus.Open;
            ann.AnnotationTypeGuid = CmAnnotationDefnTags.kguidAnnTranslatorNote.ToString();
            ann.DateTimeCreated    = utcNow.ToString(CultureInfo.InvariantCulture);
            ann.DateTimeModified   = utcNow.AddDays(1).ToString(CultureInfo.InvariantCulture);
            AddParasTo(ann.Discussion, "This is my discussion");
            AddParasTo(ann.Resolution, "This is my resolution for the note");
            AddParasTo(ann.Quote, "This is the quoted text");
            AddParasTo(ann.Suggestion, "This is my suggestion");
            XmlNoteCategory category1 = new XmlNoteCategory();

            category1.CategoryName = "Monkey";
            category1.IcuLocale    = "en";
            ann.Categories.Add(category1);
            XmlNoteCategory category2 = new XmlNoteCategory();

            category2.CategoryName = "Discourse";
            category2.IcuLocale    = "en";
            ann.Categories.Add(category2);

            DummyXmlScrAnnotationsList list = new DummyXmlScrAnnotationsList();

            list.Annotations.Add(ann);

            // Make sure 'Monkey' is not in the DB yet
            int wsEn = Cache.ServiceLocator.WritingSystemManager.GetWsFromStr("en");

            foreach (ICmPossibility poss in m_scr.NoteCategoriesOA.PossibilitiesOS)
            {
                Assert.AreNotEqual("Monkey", poss.Name.get_String(wsEn));
            }

            list.CallWriteToCache(Cache, m_stylesheet);

            IScrBookAnnotations annotations = m_scr.BookAnnotationsOS[2];

            Assert.AreEqual(1, annotations.NotesOS.Count);

            IScrScriptureNote note = annotations.NotesOS[0];

            Assert.AreEqual(NoteType.Translator, note.AnnotationType);
            Assert.IsTrue(AreDateTimesClose(now, note.DateCreated));
            Assert.IsTrue(AreDatesClose(now.AddDays(1), note.DateModified));
            Assert.AreEqual(DateTime.MinValue, note.DateResolved);

            TestAnnotationField(note.QuoteOA, "This is the quoted text");
            TestAnnotationField(note.DiscussionOA, "This is my discussion");
            TestAnnotationField(note.ResolutionOA, "This is my resolution for the note");
            TestAnnotationField(note.RecommendationOA, "This is my suggestion");

            Assert.AreEqual(0, note.ResponsesOS.Count);

            bool foundMonkey = false;

            foreach (ICmPossibility poss in m_scr.NoteCategoriesOA.PossibilitiesOS)
            {
                foundMonkey |= (poss.Name.get_String(wsEn).Text == "Monkey");
            }
            Assert.IsTrue(foundMonkey, "Monkey should have been added to the DB");

            Assert.AreEqual(2, note.CategoriesRS.Count);
            Assert.AreEqual("Monkey", note.CategoriesRS[0].Name.get_String(wsEn).Text);
            Assert.AreEqual("Discourse", note.CategoriesRS[1].Name.get_String(wsEn).Text);
        }
Esempio n. 22
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the current book, particularly picking the right set of annotations
		/// to add new ones to. Also (and more conspicuously) ends the current Undo task
		/// and makes a new one for importing the new book. Should therefore be called
		/// BEFORE setting up the Undo action for the creation of the book.
		/// </summary>
		/// <param name="nCanonicalBookNumber">The canonical book number.</param>
		/// <param name="fVernacular">if set to <c>true</c> currently importing the vernacular.
		/// </param>
		/// <returns>The existing book in the current imported version, if any; otherwise
		/// <c>null</c></returns>
		/// <remarks>If importing annotations and/or BTs without importing the vernacular, the
		/// importer is responsible for calling this directly.</remarks>
		/// ------------------------------------------------------------------------------------
		private IScrBook SetCurrentBook(int nCanonicalBookNumber, bool fVernacular)
		{
			if (nCanonicalBookNumber <= 0 || nCanonicalBookNumber > BCVRef.LastBook)
				throw new ArgumentOutOfRangeException("nCanonicalBookNumber", nCanonicalBookNumber, "Expected a canonical book number.");

			IActionHandler actionHandler = m_cache.DomainDataByFlid.GetActionHandler();

			// We want a new undo task for each new book, except the first one
			if (m_importedBooks.Count > 0)
				actionHandler.EndUndoTask();

			if (actionHandler.CurrentDepth == 0)
			{
				// No need to use localizable string from resources because the user will never
				// see these labels because we collapse to a single undo task when the import
				// completes.
				actionHandler.BeginUndoTask("Undo Import Book " + nCanonicalBookNumber,
					"Redo Import Book " + nCanonicalBookNumber);
			}
			if (m_importedBooks.ContainsKey(nCanonicalBookNumber))
				m_lastBookAddedToImportedBooks = 0;
			else
			{
				m_lastBookAddedToImportedBooks = nCanonicalBookNumber;
				m_importedBooks[nCanonicalBookNumber] = fVernacular;
			}

			m_annotations = m_scr.BookAnnotationsOS[nCanonicalBookNumber - 1];

			return (m_importedVersion == null) ? null : m_importedVersion.FindBook(nCanonicalBookNumber);
		}