コード例 #1
0
        public void kcptBinaryTests()
        {
            IUserConfigAcct acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctFactory>().Create();

            Cache.LanguageProject.UserAccountsOC.Add(acct);
            acct.Sid = new byte[] { 4, 5 };
            var startingValue = acct.Sid;
            var newValue      = new byte[] { 1, 2, 3 };

            acct.Sid = newValue;
            Assert.AreEqual(newValue, acct.Sid);
            // Reset it to original value.
            acct.Sid = startingValue;
            Assert.AreEqual(startingValue, acct.Sid);
        }
コード例 #2
0
        public void BasicDataTypes()
        {
            Cache.DomainDataByFlid.BeginNonUndoableTask();

            var lp = Cache.LanguageProject;

            // 'Remember' some guids.
            // Atomic property.
            var lpGuid = lp.Guid;
            // Owning collection property.
            var aaGuids = new HashSet <Guid>();

            foreach (var aa in lp.AnalyzingAgentsOC)
            {
                aaGuids.Add(aa.Guid);
            }
            // Owning sequence property.
            var pssGuid = lp.TranslationTagsOA.PossibilitiesOS[0].Guid;

            // CellarPropertyType.Boolean:
            lp.TranslationTagsOA.IsClosed = true;
            var isClosed = lp.TranslationTagsOA.IsClosed;
            var isSorted = lp.TranslationTagsOA.IsSorted;

            // CellarPropertyType.Integer:
            lp.TranslationTagsOA.Depth = 5;
            var depth = lp.TranslationTagsOA.Depth;
            // CellarPropertyType.Time
            var dateCreated = lp.DateCreated;
            // CellarPropertyType.Guid
            ICmPossibilityList possList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();

            Cache.LanguageProject.TimeOfDayOA = possList;
            possList.ListVersion = Guid.NewGuid();
            var versionGuid = possList.ListVersion;
            var possGuid    = possList.Guid;

            // CellarPropertyType.GenDate
            lp.PeopleOA = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
            var eve = Cache.ServiceLocator.GetInstance <ICmPersonFactory>().Create();

            lp.PeopleOA.PossibilitiesOS.Add(eve);
            eve.DateOfBirth = new GenDate(GenDate.PrecisionType.Before, 1, 1, 3000, true);
            var eveDOB = eve.DateOfBirth;
            // CellarPropertyType.Binary:
            IUserConfigAcct acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctFactory>().Create();

            Cache.LanguageProject.UserAccountsOC.Add(acct);
            var acctGuid       = acct.Guid;
            var byteArrayValue = new byte[] { 1, 2, 3 };

            acct.Sid = byteArrayValue;
            // CellarPropertyType.Unicode:
            const string newEthCode = "ZPI";

            lp.EthnologueCode = newEthCode;
            // CellarPropertyType.String:
            var le = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var irOriginalValue = Cache.TsStrFactory.MakeString("<import & residue>",
                                                                Cache.WritingSystemFactory.UserWs);

            le.ImportResidue = irOriginalValue;
            var xmlOriginalValue     = TsStringUtils.GetXmlRep(irOriginalValue, Cache.WritingSystemFactory, Cache.WritingSystemFactory.UserWs, true);
            var irOriginalBlankValue = Cache.TsStrFactory.MakeString("    ",
                                                                     Cache.WritingSystemFactory.UserWs);

            le.Comment.set_String(Cache.WritingSystemFactory.UserWs, irOriginalBlankValue);
            var xmlOriginalBlankValue = TsStringUtils.GetXmlRep(irOriginalBlankValue, Cache.WritingSystemFactory, Cache.WritingSystemFactory.UserWs, true);
            // ITsTextProps
            var userWs = Cache.WritingSystemFactory.UserWs;
            var bldr   = TsPropsBldrClass.Create();

            bldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Arial");
            bldr.SetIntPropValues((int)FwTextPropType.ktptWs, 0, userWs);
            var style = Cache.ServiceLocator.GetInstance <IStStyleFactory>().Create();

            lp.StylesOC.Add(style);
            const string styleName = "Name With <this> & <that>";

            style.Name  = styleName;
            style.Rules = bldr.GetTextProps();
            var    rOriginalvalue        = style.Rules;
            string xmlOriginalValueRules = TsStringUtils.GetXmlRep(rOriginalvalue, Cache.WritingSystemFactory);

            // Use same test, since the multiString and MultiUnicode props
            // all use the same mechanism (on MultiAccessor) to read/write
            // the data.
            // CellarPropertyType.MultiString:
            // CellarPropertyType.MultiUnicode:
            var tsf          = Cache.TsStrFactory;
            var englishWsHvo = Cache.WritingSystemFactory.GetWsFromStr("en");
            var nameEnValue  = tsf.MakeString("Stateful FDO Test Project", englishWsHvo);

            TsStringUtils.GetXmlRep(nameEnValue, Cache.WritingSystemFactory, 0, true);
            // Set LP's Name.
            //lp.Name.set_String(
            //    englishWsHvo,
            //    nameEnValue);
            //var nameEsValue = tsf.MakeString("Proyecto de prueba: FDO", spanishWsHvo);
            //streamWrapper = TsStreamWrapperClass.Create();
            //streamWrapper.WriteTssAsXml(nameEsValue,
            //     Cache.WritingSystemFactory,
            //     0,
            //     spanishWsHvo, true);
            //var esXML = streamWrapper.Contents;
            //lp.Name.set_String(
            //    spanishWsHvo,
            //    nameEsValue);

            // Check that ScriptureReferenceSystem is persisted & reloaded.
            var srs = Cache.ServiceLocator.GetInstance <IScrRefSystemFactory>().Create();

            // Restart BEP.
            RestartCache(true);
            lp = Cache.LanguageProject;

            // Atomic property.
            var lpGuidRestored = lp.Guid;

            Assert.IsTrue(lpGuid == lpGuidRestored, "Object Guid not saved/restored properly.");

            // Owning collection property.
            Assert.AreEqual(aaGuids.Count, lp.AnalyzingAgentsOC.Count, "Wrong number of analyzing agents.");
            foreach (var aa in lp.AnalyzingAgentsOC)
            {
                Assert.IsTrue(aaGuids.Contains(aa.Guid), "Analyzing Agent not found.");
            }

            // Owning sequence property.
            Assert.IsTrue(lp.TranslationTagsOA.PossibilitiesOS[0].Guid == pssGuid, "Translation type Guid not the same.");

            // Check bool.
            Assert.IsTrue(lp.TranslationTagsOA.IsClosed, "Wrong boolean value restored (for true).");
            Assert.AreEqual(isSorted, lp.TranslationTagsOA.IsSorted, "Wrong boolean value restored (for false).");
            // Check int.
            Assert.AreEqual(depth, lp.TranslationTagsOA.Depth, "Wrong integer value restored.");
            // Check time.
            Assert.AreEqual(dateCreated.Year, lp.DateCreated.Year, "Wrong year part of time value restored.");
            Assert.AreEqual(dateCreated.Month, lp.DateCreated.Month, "Wrong month part of time value restored.");
            Assert.AreEqual(dateCreated.Day, lp.DateCreated.Day, "Wrong day part of time value restored.");
            Assert.AreEqual(dateCreated.Hour, lp.DateCreated.Hour, "Wrong hour part of time value restored.");
            Assert.AreEqual(dateCreated.Minute, lp.DateCreated.Minute, "Wrong minute part of time value restored.");
            Assert.AreEqual(dateCreated.Second, lp.DateCreated.Second, "Wrong second part of time value restored.");
            Assert.AreEqual(dateCreated.Millisecond, lp.DateCreated.Millisecond, "Wrong millisecond time value restored.");
            // Check Guid.
            possList = Cache.ServiceLocator.GetInstance <ICmPossibilityListRepository>().GetObject(possGuid);
            Assert.AreEqual(versionGuid, possList.ListVersion, "Wrong Guid value restored.");
            // Check GenDate
            eve = (ICmPerson)lp.PeopleOA.PossibilitiesOS[0];
            Assert.AreEqual(eveDOB, eve.DateOfBirth, "Wrong DOB value restored.");
            // Check Binary.
            acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctRepository>().GetObject(acctGuid);
            Assert.AreEqual(byteArrayValue, acct.Sid, "Wrong Binary value restored.");
            // Check Unicode
            Assert.AreEqual(newEthCode, lp.EthnologueCode, "Wrong Unicode value restored.");
            // Check string (ITsString)
            var irRestoredValue  = lp.LexDbOA.Entries.ToArray()[0].ImportResidue;
            var xmlRestoredValue = TsStringUtils.GetXmlRep(irRestoredValue, Cache.WritingSystemFactory, Cache.WritingSystemFactory.UserWs, true);

            Assert.AreEqual(xmlOriginalValue, xmlRestoredValue, "Wrong ITsString value restored.");
            var irRestoredBlankValue  = lp.LexDbOA.Entries.ToArray()[0].Comment.get_String(Cache.WritingSystemFactory.UserWs);
            var xmlRestoredBlankValue = TsStringUtils.GetXmlRep(irRestoredBlankValue, Cache.WritingSystemFactory, Cache.WritingSystemFactory.UserWs, true);

            Assert.AreEqual(xmlOriginalBlankValue, xmlRestoredBlankValue, "Wrong ITsString value restored for blank string.");
            // ITsTextProps
            var rRestoredValue        = lp.StylesOC.ToArray()[0].Rules;
            var xmlRestoredValueRules = TsStringUtils.GetXmlRep(rRestoredValue, Cache.WritingSystemFactory);

            Assert.AreEqual(xmlOriginalValueRules, xmlRestoredValueRules, "Wrong ITsTextProps value restored.");

            var styleRestoredName = lp.StylesOC.ToArray()[0].Name;

            Assert.AreEqual(styleName, styleRestoredName, "Wrong style name restored.");

            //englishWsHvo = Cache.WritingSystemFactory.GetWsFromStr("en");
            //irRestoredValue = lp.Name.get_String(englishWsHvo);
            //streamWrapper = TsStreamWrapperClass.Create();
            //streamWrapper.WriteTssAsXml(irRestoredValue,
            //     Cache.WritingSystemFactory,
            //     0,
            //     englishWsHvo, true);
            //Assert.AreEqual(enXML, streamWrapper.Contents,
            //    "Wrong ITsString value (Name) restored.");
            //spanishWsHvo = Cache.WritingSystemFactory.GetWsFromStr("es");
            //irRestoredValue = lp.Name.get_String(spanishWsHvo);
            //streamWrapper = TsStreamWrapperClass.Create();
            //streamWrapper.WriteTssAsXml(irRestoredValue,
            //     Cache.WritingSystemFactory,
            //     0,
            //     spanishWsHvo, true);
            //Assert.AreEqual(esXML, streamWrapper.Contents,
            //    "Wrong ITsString value (Name) restored.");

            Assert.AreEqual(srs.Guid, Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.Guid, "Wrong ScrRefSystem Guid.");
        }
コード例 #3
0
        public void ReconcileModifyingProperties()
        {
            var entry1 = MakeEntry("kick", "strike with foot");
            var sense1 = entry1.SensesOS[0];

            VerifyReconcilingAChange(
                () =>
            {
                SetString(sense1.Definition, Cache.DefaultAnalWs, "swing foot and make sharp contact with object");
                SetString(sense1.Definition, Cache.DefaultVernWs, "slam with nether appendage");
                SetString(sense1.Gloss, Cache.DefaultVernWs, "hit with foot");
            },
                "set multistring properties");
            VerifyReconcilingAChange(
                () => AddSense(entry1, "strike with boot"),
                "edit owing sequence");
            IText text = null;

            UndoableUnitOfWorkHelper.Do("undo make text", "redo make text", m_actionHandler,
                                        () =>
            {
                text = Cache.ServiceLocator.GetInstance <ITextFactory>().Create();
                //Cache.LangProject.TextsOC.Add(text);
            });
            IStText     stText = null;
            ICmObjectId id1    = null;

            VerifyReconcilingAChange(
                () =>
            {
                stText          = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();
                text.ContentsOA = stText;
                id1             = stText.Id;
            },
                "set owning atomic");
            stText = (IStText)Cache.ServiceLocator.GetObject(id1);
            ICmPossibility senseType = null;

            UndoableUnitOfWorkHelper.Do("undo make sense type", "redo make sense type", m_actionHandler,
                                        () =>
            {
                var senseTypesList = Cache.LangProject.LexDbOA.SenseTypesOA;
                if (senseTypesList == null)
                {
                    senseTypesList = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                    Cache.LangProject.LexDbOA.SenseTypesOA = senseTypesList;
                }
                senseType = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                senseTypesList.PossibilitiesOS.Add(senseType);
            });
            VerifyReconcilingAChange(
                () => sense1.SenseTypeRA = senseType,
                "set ref atomic");
            ICmPossibilityList thesaurusItemsList = null;

            UndoableUnitOfWorkHelper.Do("undo make thes list", "redo make thes list", m_actionHandler,
                                        () =>
            {
                thesaurusItemsList = Cache.LangProject.ThesaurusRA;
                if (thesaurusItemsList == null)
                {
                    thesaurusItemsList            = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create();
                    Cache.LangProject.ThesaurusRA = thesaurusItemsList;
                }
            });
            ICmPossibility thesaurusItem1 = null;
            ICmPossibility thesaurusItem2 = null;
            ICmObjectId    id2            = null;

            VerifyReconcilingAChange(
                () =>
            {
                thesaurusItem1 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem1);
                id1            = thesaurusItem1.Id;
                thesaurusItem2 = Cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();
                thesaurusItemsList.PossibilitiesOS.Add(thesaurusItem2);
                id2 = thesaurusItem2.Id;
            },
                "adding two items to an owning collection");
            // Verify undoes creating them, then creates new ones with the same IDs. We need the new valid objects.
            thesaurusItem1 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1);
            thesaurusItem2 = (ICmPossibility)Cache.ServiceLocator.GetObject(id1);
            VerifyReconcilingAChange(
                () =>
            {
                sense1.ThesaurusItemsRC.Add(thesaurusItem1);
                sense1.ThesaurusItemsRC.Add(thesaurusItem2);
            },
                "adding two items to a reference collection");
            VerifyReconcilingAChange(
                () =>
            {
                entry1.MainEntriesOrSensesRS.Add(sense1);
            },
                "adding an item to a reference sequence");
            IStTxtPara para = null;

            UndoableUnitOfWorkHelper.Do("undo make para", "redo make para", m_actionHandler,
                                        () =>
            {
                para = Cache.ServiceLocator.GetInstance <IStTxtParaFactory>().Create();
                stText.ParagraphsOS.Add(para);
            });
            VerifyReconcilingAChange(
                () =>
            {
                SetParaContents(para, "Hello world");                                     // big string
                para.Label = Cache.TsStrFactory.MakeString("label", Cache.DefaultVernWs); // non-big string, just to be sure
            },
                "setting a simple string, previously empty");
            VerifyReconcilingAChange(
                () => SetParaContents(para, "Goodbye, world"),
                "setting a simple string, previously non-empty");
            VerifyReconcilingAChange(
                () => para.ParseIsCurrent = true,
                "setting a boolean");
            VerifyReconcilingAChange(
                () => thesaurusItem2.HelpId = "look for help here!",
                "setting a plain unicode string");
            VerifyReconcilingAChange(
                () => thesaurusItemsList.Depth = 17,
                "setting an integer");
            VerifyReconcilingAChange(
                () => thesaurusItemsList.ListVersion = Guid.NewGuid(),
                "setting a guid property");
            var propsBldr = TsPropsBldrClass.Create();

            propsBldr.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "red hot");
            var props = propsBldr.GetTextProps();

            VerifyReconcilingAChange(
                () => para.StyleRules = props,
                "setting a text props");
            IRnGenericRec genericRec = null;

            UndoableUnitOfWorkHelper.Do("undo make notebook record", "redo make notebook record", m_actionHandler,
                                        () =>
            {
                genericRec = Cache.ServiceLocator.GetInstance <IRnGenericRecFactory>().Create();
                Cache.LangProject.ResearchNotebookOA.RecordsOC.Add(genericRec);
            });
            VerifyReconcilingAChange(
                () => genericRec.DateOfEvent = new GenDate(GenDate.PrecisionType.Exact, 7, 23, 1908, true),
                "setting a generic date");
            IUserConfigAcct acct = null;

            UndoableUnitOfWorkHelper.Do("undo make user view", "redo", m_actionHandler,
                                        () =>
            {
                acct = Cache.ServiceLocator.GetInstance <IUserConfigAcctFactory>().Create();
                Cache.LanguageProject.UserAccountsOC.Add(acct);
            });
            VerifyReconcilingAChange(() => acct.Sid = new byte[] { 1, 2, 3 }, "setting a binary property");
        }