/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines whether the specified resource is out-of-date (or not created).
        /// </summary>
        /// <param name="resourceName">Name of the resource.</param>
        /// <param name="newVersion">The latest version (i.e., the version from the resource
        /// file).</param>
        /// ------------------------------------------------------------------------------------
        protected bool IsResourceOutdated(string resourceName, Guid newVersion)
        {
            // Get the current version of the settings used in this project.
            ICmResource resource = GetResource(resourceName);

            return(resource == null || newVersion != resource.Version);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the current version of the key terms list used in this project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private Guid GetLangProjKtListVersion(ILangProject lp)
        {
            ICmResource resource = (from res in lp.TranslatedScriptureOA.ResourcesOC.ToArray()
                                    where res.Name.Equals(TeResourceHelper.BiblicalTermsResourceName)
                                    select res).FirstOrDefault();

            return((resource != null) ? resource.Version : Guid.Empty);
        }
        public void SetAndAccessDummyList()
        {
            ILexDb      lexDb  = Cache.LangProject.LexDbOA;
            ILexEntry   entry1 = null;
            ICmResource res1   = null;

            NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
            {
                var leFactory    = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
                entry1           = leFactory.Create();
                ILexEntry entry2 = leFactory.Create();
                res1             = Cache.ServiceLocator.GetInstance <ICmResourceFactory>().Create();
                lexDb.ResourcesOC.Add(res1);
            });

            int hvoRoot = 10578;
            ObjectListPublisher publisher = new ObjectListPublisher(Cache.MainCacheAccessor as ISilDataAccessManaged, ObjectListFlid);
            var      values   = new int[] { 23, 56, 2048 };
            Notifiee recorder = new Notifiee();

            publisher.AddNotification(recorder);
            publisher.CacheVecProp(hvoRoot, values);
            Assert.AreEqual(values.Length, publisher.get_VecSize(hvoRoot, ObjectListFlid), "override of vec size");
            //Assert.AreEqual(Cache.LangProject.Texts.Count, publisher.get_VecSize(Cache.LangProject.Hvo, LangProjectTags.kflidTexts), "base vec size");

            Assert.AreEqual(23, publisher.get_VecItem(hvoRoot, ObjectListFlid, 0), "override of vec item");
            Assert.AreEqual(res1.Hvo, publisher.get_VecItem(lexDb.Hvo, LexDbTags.kflidResources, 0), "base vec item");
            Assert.AreEqual(56, publisher.get_VecItem(hvoRoot, ObjectListFlid, 1), "override of vec item, non-zero index");

            VerifyCurrentValue(hvoRoot, publisher, values, "original value");
            Assert.AreEqual(lexDb.ResourcesOC.Count(), publisher.VecProp(lexDb.Hvo, LexDbTags.kflidResources).Length, "base VecProp");

            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 0, values.Length, 0) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);

            recorder = new Notifiee();
            publisher.AddNotification(recorder);
            publisher.Replace(hvoRoot, 1, new int[] { 97, 98 }, 0);
            VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 97, 98, 56, 2048 }, "after inserting 97, 98");
            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 2, 0) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);

            recorder = new Notifiee();
            publisher.AddNotification(recorder);
            publisher.Replace(hvoRoot, 1, new int[0], 2);
            VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 56, 2048 }, "after deleting 97, 98");
            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 0, 2) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets the new version in the DB for the named resource.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void SetNewResourceVersion(string name, Guid newVersion)
        {
            ICmResource resource = GetResource(name);

            if (resource == null)
            {
                // Resource does not exist yet. Add it to the collection.
                ICmResource newResource = Cache.ServiceLocator.GetInstance <ICmResourceFactory>().Create();
                ResourceList.Add(newResource);
                newResource.Name    = name;
                newResource.Version = newVersion;
#if DEBUG
                m_fVersionUpdated = true;
#endif
                return;
            }

            resource.Version = newVersion;
#if DEBUG
            m_fVersionUpdated = true;
#endif
        }
Beispiel #5
0
        public void TestOwningFlid()
        {
            Assert.AreEqual(0, Cache.LangProject.OwningFlid);             // no owner
            Assert.AreEqual(LangProjectTags.kflidLexDb, Cache.LangProject.LexDbOA.OwningFlid);
            // atomic, on an owner with many
            var         servLoc  = Cache.ServiceLocator;
            ILexEntry   entry    = null;
            ICmResource resource = null;
            ILexSense   sense1   = null;
            ILexSense   sense2   = null;
            ILexSense   sense3   = null;
            IMoForm     form1    = null;
            IMoForm     form2    = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                resource = servLoc.GetInstance <ICmResourceFactory>().Create();
                Cache.LangProject.LexDbOA.ResourcesOC.Add(resource);
                entry  = servLoc.GetInstance <ILexEntryFactory>().Create();
                sense1 = servLoc.GetInstance <ILexSenseFactory>().Create();
                entry.SensesOS.Add(sense1);
                sense2 = servLoc.GetInstance <ILexSenseFactory>().Create();
                entry.SensesOS.Add(sense2);
                sense3 = servLoc.GetInstance <ILexSenseFactory>().Create();
                entry.SensesOS.Add(sense3);
                form1 = servLoc.GetInstance <IMoStemAllomorphFactory>().Create();
                entry.AlternateFormsOS.Add(form1);
                form2 = servLoc.GetInstance <IMoStemAllomorphFactory>().Create();
                entry.AlternateFormsOS.Add(form2);
            }
                                        );
            Assert.AreEqual(LexDbTags.kflidResources, resource.OwningFlid);           // owning collection
            Assert.AreEqual(LexEntryTags.kflidSenses, sense1.OwningFlid);             // owning sequence
            Assert.AreEqual(LexEntryTags.kflidSenses, sense2.OwningFlid);             // owning sequence, middle
            Assert.AreEqual(LexEntryTags.kflidSenses, sense3.OwningFlid);             // owning sequence, last
            Assert.AreEqual(LexEntryTags.kflidAlternateForms, form1.OwningFlid);      // owning sequence, not longest
            Assert.AreEqual(LexEntryTags.kflidAlternateForms, form2.OwningFlid);      // owning sequence, not longest or first
        }
Beispiel #6
0
        public void VectorPropertyTests()
        {
            var       servLoc         = Cache.ServiceLocator;
            var       entryFactory    = servLoc.GetInstance <ILexEntryFactory>();
            var       resourceFactory = servLoc.GetInstance <ICmResourceFactory>();
            var       lexDb           = Cache.LanguageProject.LexDbOA;
            ILexEntry le2             = null;

            // The following tests assume one resource originally exists. We also need le2, to be the owner
            // of the senses.
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler,
                                        () =>
            {
                lexDb.ResourcesOC.Add(resourceFactory.Create());
                le2 = entryFactory.Create();
            });
            // 1
            ClearChanges();
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lexDb.ResourcesOC.Clear());
            // Check the Resources vector prop.
            CheckChanges(1, -1, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, -1, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, 0);
            m_actionHandler.Redo();
            ClearChanges();

            // 2
            // Test a collection property.
            ICmResource res1 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add one item.
                res1 = resourceFactory.Create();
                lexDb.ResourcesOC.Add(res1);
            });
            // Check the Entries vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, 1);
            m_actionHandler.Redo();
            ClearChanges();

            // 3
            ICmResource res2 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add another item.
                res2 = resourceFactory.Create();
                lexDb.ResourcesOC.Add(res2);
            });
            // Check the Resources vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 0, 1);
            m_actionHandler.Redo();
            SetLexeme(le2, "second");
            ClearChanges();

            // 4
            ICmResource res3 = null;
            ICmResource res4 = null;

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add two new items.
                res3 = resourceFactory.Create();
                lexDb.ResourcesOC.Add(res3);
                res4 = resourceFactory.Create();
                lexDb.ResourcesOC.Add(res4);
            });
            // Check the Entries vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 2, 2, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 2, 0, 2);
            m_actionHandler.Redo();
            ClearChanges();

            // 5
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Remove a couple of non-contiguous items.
                res1.Delete();
                res3.Delete();
            });
            // Check the Entries vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 1, 3);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 3, 1);
            m_actionHandler.Redo();
            ClearChanges();

            // 6
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => res4.Delete());
            // Check the Entries vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 0, 1);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 1, 1, 0);
            m_actionHandler.Redo();
            ClearChanges();

            // 7
            // Test a sequence property.
            // By this point only le2 is still there,
            // which is fine, since we are moving to test senses,
            // and they can all go into le2.
            var senseFactory = servLoc.GetInstance <ILexSenseFactory>();

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add one item.
                var se1 = senseFactory.Create();
                le2.SensesOS.Add(se1);
            });
            // Check the Senses vector prop.
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 0, 1);
            m_actionHandler.Redo();
            ClearChanges();

            // 8
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add another item, but before the other sense.
                var se2 = senseFactory.Create();
                le2.SensesOS.Insert(0, se2);
            });
            // Check the Senses vector prop.
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 0, 0, 1);
            m_actionHandler.Redo();
            ClearChanges();

            // 9
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add another item, but between the other two senses.
                var se3 = senseFactory.Create();
                le2.SensesOS.Insert(1, se3);
            });
            // Check the Senses vector prop.
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 1, 1, 0);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 1, 0, 1);
            m_actionHandler.Redo();
            ClearChanges();

            // 10
            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () =>
            {
                // Add another item, but between two senses.
                var se4 = senseFactory.Create();
                le2.SensesOS.Insert(2, se4);
                // Add yet another one at the end.
                var se5 = senseFactory.Create();
                le2.SensesOS.Add(se5);
            });
            // Check the Senses vector prop.
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 2, 3, 1);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(le2.Hvo, LexEntryTags.kflidSenses, 2, 1, 3);
            m_actionHandler.Redo();
            ClearChanges();

            // 11
            // Clear Entries prop
            var resourcesCount = lexDb.ResourcesOC.Count();

            UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => lexDb.ResourcesOC.Clear());
            // Check the Entries vector prop.
            CheckChanges(1, 0, lexDb.Hvo, LexDbTags.kflidResources, 0, 0, resourcesCount);
            ClearChanges();
            m_actionHandler.Undo();
            CheckChanges(lexDb.Hvo, LexDbTags.kflidResources, 0, resourcesCount, 0);
            m_actionHandler.Redo();
            ClearChanges();
        }