Exemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlScrNote"/> class based on
        /// the given Scripture note.
        /// </summary>
        /// <param name="ann">The Scripture annotation.</param>
        /// <param name="wsDefault">The default (analysis) writing system.</param>
        /// <param name="lgwsf">The writing system factory.</param>
        /// ------------------------------------------------------------------------------------
        public XmlScrNote(IScrScriptureNote ann, int wsDefault, ILgWritingSystemFactory lgwsf)
            : this()
        {
            m_wsDefault      = wsDefault;
            m_lgwsf          = lgwsf;
            ResolutionStatus = ann.ResolutionStatus;
            m_typeName       = ann.AnnotationTypeRA.Name.get_String(WritingSystemServices.FallbackUserWs(ann.Cache)).Text;
            m_guidType       = ann.AnnotationTypeRA.Guid;
            SetNoteType(ann);

            m_startRef = ann.BeginRef;
            if (ann.BeginRef != ann.EndRef)
            {
                m_endRef = ann.EndRef;
            }

            if (ann.BeginObjectRA != null)
            {
                m_guidBegObj = ann.BeginObjectRA.Guid;
            }

            if (ann.BeginObjectRA != ann.EndObjectRA && ann.EndObjectRA != null)
            {
                m_guidEndObj = ann.EndObjectRA.Guid;
            }

            BeginOffset = ann.BeginOffset;
            EndOffset   = ann.EndOffset;

            m_createdDate  = ann.DateCreated;
            m_modifiedDate = ann.DateModified;
            m_resolvedDate = ann.DateResolved;

            Quote      = XmlNotePara.GetParagraphList(ann.QuoteOA, m_wsDefault, m_lgwsf);
            Discussion = XmlNotePara.GetParagraphList(ann.DiscussionOA, m_wsDefault, m_lgwsf);
            Suggestion = XmlNotePara.GetParagraphList(ann.RecommendationOA, m_wsDefault, m_lgwsf);
            Resolution = XmlNotePara.GetParagraphList(ann.ResolutionOA, m_wsDefault, m_lgwsf);
            Categories = XmlNoteCategory.GetCategoryList(ann, m_lgwsf);
            Responses  = XmlNoteResponse.GetResponsesList(ann, m_wsDefault, m_lgwsf);
        }
		public void ExistingAnnotation_WithNewResponse()
		{
			IScrScriptureNote existingAnn =
				m_scrInMemoryCache.AddAnnotation(null, 02002008, NoteType.Translator, "This is my discussion");
			existingAnn.ResolutionStatus = NoteStatus.Open;

			IStJournalText exisingResponse1 = existingAnn.ResponsesOS.Append(new StJournalText());
			AddParasTo(exisingResponse1, "This is my first response");

			IStJournalText exisingResponse2 = existingAnn.ResponsesOS.Append(new StJournalText());
			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 = LangProject.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 a new response");
			ann.Responses.Add(secondResponse);
			XmlNoteResponse thirdResponse = new XmlNoteResponse();
			AddParasTo(thirdResponse.Paragraphs, "This is my second response");
			ann.Responses.Add(thirdResponse);

			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);

			FdoOwningSequence<IStJournalText> responses = note.ResponsesOS;
			Assert.AreEqual(3, responses.Count);
			TestAnnotationField(responses[0], "This is my first response");
			TestAnnotationField(responses[1], "This is my second response");
			TestAnnotationField(responses[2], "This is a new response");
		}
		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");
		}