// =====================================================
        // Things needed by the task itself...

        private void Main(ICmObject target)
        {
            var f = new RestructureDialectsDialog();

            f.ShowDialog();
            if (f.DialogResult == DialogResult.Cancel)
            {
                return;
            }

            var esb = new StringBuilder();

            esb.AppendLine("Original pairs prior to swapping: ");

            //var sda = target.Cache.DomainDataByFlid;

            //TODO: figure out how to not need target

            ILexEntryRepository repo = target.Cache.ServiceLocator.GetInstance <ILexEntryRepository>();
            var wsRepo = target.Cache.ServiceLocator.GetInstance <IWritingSystemContainer>();

            _vern = wsRepo.DefaultVernacularWritingSystem.Handle;
            _ana  = wsRepo.DefaultAnalysisWritingSystem.Handle;

            int i   = 0;
            int max = f.GetMaxToProcess();

            foreach (ILexEntry entry in repo.AllInstances())
            {
                if (i >= max)
                {
                    break;
                }

                ILexEntry vWinner = GetWinningVariant(entry, f.GetPeckingOrder());

                if (vWinner != null)
                {
                    // There is a dialectal variant we need to swap with
                    string s = Swap(entry, vWinner);
                    i++;
                    if (i < 15)
                    {
                        esb.AppendLine(s);
                    }
                    else if (i == 15)
                    {
                        esb.AppendLine("...");
                    }
                }
            }

            MessageBox.Show(esb.ToString(), f.GetPeckingOrder() + ": Made " + i + " swaps. Done restructuring.");
        }
Пример #2
0
        public void RunConversion()
        {
            Logger.Notice("FdoToMongo: Converting lexicon for project {0}", LfProject.ProjectCode);
            ILexEntryRepository repo = GetInstance <ILexEntryRepository>();

            if (repo == null)
            {
                Logger.Error("Can't find LexEntry repository for FieldWorks project {0}", LfProject.ProjectCode);
                return;
            }

            // Custom field configuration AND view configuration should all be set at once
            Dictionary <string, LfConfigFieldBase> lfCustomFieldList  = new Dictionary <string, LfConfigFieldBase>();
            Dictionary <string, string>            lfCustomFieldTypes = new Dictionary <string, string>();

            _convertCustomField.WriteCustomFieldConfig(lfCustomFieldList, lfCustomFieldTypes);
            Connection.SetCustomFieldConfig(LfProject, lfCustomFieldList);
            _convertCustomField.CreateCustomFieldsConfigViews(LfProject, lfCustomFieldList, lfCustomFieldTypes);

            Dictionary <Guid, DateTime> previousModificationDates = Connection.GetAllModifiedDatesForEntries(LfProject);

            int i = 1;

            foreach (ILexEntry fdoEntry in repo.AllInstances())
            {
                bool     createdEntry = false;
                DateTime previousDateModified;
                if (!previousModificationDates.TryGetValue(fdoEntry.Guid, out previousDateModified))
                {
                    // Looks like this entry is new in FDO
                    createdEntry         = true;
                    previousDateModified = DateTime.MinValue;                     // Ensure it will seem modified when comparing it later
                }
                // Remember that FDO's DateModified is stored in local time for some incomprehensible reason...
                if (!createdEntry && previousDateModified.ToLocalTime() == fdoEntry.DateModified)
                {
                    // Hasn't been modified since last time: just skip this record entirely
                    continue;
                }
                LfLexEntry lfEntry = FdoLexEntryToLfLexEntry(fdoEntry);
                lfEntry.IsDeleted = false;
                Logger.Info("{3} - FdoToMongo: {0} LfEntry {1} ({2})", createdEntry ? "Created" : "Modified", lfEntry.Guid, ConvertUtilities.EntryNameForDebugging(lfEntry), i++);
                Connection.UpdateRecord(LfProject, lfEntry);
            }
            LfProject.IsInitialClone = false;

            RemoveMongoEntriesDeletedInFdo();
            // Logger.Debug("Running FtMComments, should see comments show up below:");
            var commCvtr = new ConvertFdoToMongoComments(Connection, LfProject, Logger, Progress, ProjectRecordFactory);

            commCvtr.RunConversion();
        }
Пример #3
0
        public void Action_RunTwice_ShouldNotDuplicatePictures()
        {
            // Setup initial Mongo project has 1 picture and 2 captions
            var lfProj = _lfProj;
            var data   = new SampleData();
            int newMongoPictureCount = data.bsonTestData["senses"][0]["pictures"].AsBsonArray.Count;
            int newMongoCaptionCount = data.bsonTestData["senses"][0]["pictures"][0]["caption"].AsBsonDocument.Count();

            Assert.That(newMongoPictureCount, Is.EqualTo(2));
            Assert.That(newMongoCaptionCount, Is.EqualTo(2));

            // Initial FDO project has 63 entries, 3 internal pictures, and 1 externally linked picture
            FdoCache            cache     = _cache;
            ILexEntryRepository entryRepo = _servLoc.GetInstance <ILexEntryRepository>();
            int originalNumOfFdoPictures  = entryRepo.AllInstances().Count(
                e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));

            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(originalNumOfFdoPictures, Is.EqualTo(3 + 1));
            string expectedGuidStrBefore = data.bsonTestData["guid"].AsString;
            Guid   expectedGuidBefore    = Guid.Parse(expectedGuidStrBefore);
            var    entryBefore           = entryRepo.GetObject(expectedGuidBefore);

            Assert.That(entryBefore.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entryBefore.SensesOS.First().PicturesOS.Count, Is.EqualTo(1));

            // Exercise running Action twice
            data.bsonTestData["authorInfo"]["modifiedDate"] = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            sutMongoToFdo.Run(lfProj);
            data.bsonTestData["authorInfo"]["modifiedDate"] = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            sutMongoToFdo.Run(lfProj);

            string expectedGuidStr = data.bsonTestData["guid"].AsString;
            Guid   expectedGuid    = Guid.Parse(expectedGuidStr);
            var    entry           = entryRepo.GetObject(expectedGuid);

            Assert.IsNotNull(entry);
            Assert.That(entry.Guid, Is.EqualTo(expectedGuid));

            Assert.That(entry.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entry.SensesOS.First().PicturesOS.Count, Is.EqualTo(2));
        }
Пример #4
0
 /// <summary>
 /// Create one. The SDA passed MAY be the DomainDataByFlid of the cache, but it is usually another
 /// decorator.
 /// </summary>
 public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid, ICmPossibility publication)
     : base(domainDataByFlid)
 {
     Cache                     = cache;
     m_entryRepo               = Cache.ServiceLocator.GetInstance <ILexEntryRepository>();
     m_lexRefRepo              = Cache.ServiceLocator.GetInstance <ILexReferenceRepository>();
     m_senseRepo               = Cache.ServiceLocator.GetInstance <ILexSenseRepository>();
     m_lerRepo                 = Cache.ServiceLocator.GetInstance <ILexEntryRefRepository>();
     m_LexDbEntriesFlid        = mainFlid;
     m_headwordFlid            = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWord", false);
     m_mlHeadwordFlid          = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "MLHeadWord", false);
     m_picsOfSensesFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PicturesOfSenses", false);
     m_senseOutlineFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "LexSenseOutline", false);
     m_mlOwnerOutlineFlid      = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "MLOwnerOutlineName", false);
     m_publishAsMinorEntryFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishAsMinorEntry", false);
     m_headwordRefFlid         = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordRef", false);
     m_headwordReversalFlid    = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "ReversalName", false);
     m_reversalNameFlid        = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "ReversalName", false);
     Publication               = publication;
     BuildExcludedObjects();
     BuildFieldsToFilter();
     BuildHomographInfo();
 }
 /// <summary>
 /// Create one. The SDA passed MAY be the DomainDataByFlid of the cache, but it is usually another
 /// decorator.
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="domainDataByFlid"></param>
 public DictionaryPublicationDecorator(FdoCache cache, ISilDataAccessManaged domainDataByFlid, int mainFlid, ICmPossibility publication)
     : base(domainDataByFlid)
 {
     Cache = cache;
     m_entryRepo = Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
     m_lexRefRepo = Cache.ServiceLocator.GetInstance<ILexReferenceRepository>();
     m_senseRepo = Cache.ServiceLocator.GetInstance<ILexSenseRepository>();
     m_lerRepo = Cache.ServiceLocator.GetInstance<ILexEntryRefRepository>();
     m_LexDbEntriesFlid = mainFlid;
     m_headwordFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWord", false);
     m_mlHeadwordFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "MLHeadWord", false);
     m_picsOfSensesFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PicturesOfSenses", false);
     m_senseOutlineFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "LexSenseOutline", false);
     m_mlOwnerOutlineFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "MLOwnerOutlineName", false);
     m_publishAsMinorEntryFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "PublishAsMinorEntry", false);
     m_doNotShowMainEntryInFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "DoNotShowMainEntryIn", false);
     m_headwordRefFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordRef", false);
     m_headwordReversalFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexEntryTags.kClassId, "HeadWordReversal", false);
     m_reversalNameFlid = Cache.MetaDataCacheAccessor.GetFieldId2(LexSenseTags.kClassId, "ReversalName", false);
     Publication = publication;
     BuildExcludedObjects();
     BuildFieldsToFilter();
     BuildHomographInfo();
 }
Пример #6
0
        public void Action_ChangedWithSampleData_ShouldUpdatePictures()
        {
            // Setup initial Mongo project has 1 picture and 2 captions
            var lfProj = _lfProj;
            var data   = new SampleData();

            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            string expectedInternalFileName = Path.Combine("Pictures", data.bsonTestData["senses"][0]["pictures"][0]["fileName"].ToString());
            string expectedExternalFileName = data.bsonTestData["senses"][0]["pictures"][1]["fileName"].ToString();
            int    newMongoPictureCount     = data.bsonTestData["senses"][0]["pictures"].AsBsonArray.Count;
            int    newMongoCaptionCount     = data.bsonTestData["senses"][0]["pictures"][0]["caption"].AsBsonDocument.Count();

            Assert.That(newMongoPictureCount, Is.EqualTo(2));
            Assert.That(newMongoCaptionCount, Is.EqualTo(2));

            // Initial FDO project has 63 entries, 3 internal pictures, and 1 externally linked picture
            FdoCache            cache     = _cache;
            ILexEntryRepository entryRepo = _servLoc.GetInstance <ILexEntryRepository>();
            int originalNumOfFdoPictures  = entryRepo.AllInstances().
                                            Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));

            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(originalNumOfFdoPictures, Is.EqualTo(3 + 1));
            string expectedGuidStr = data.bsonTestData["guid"].AsString;
            Guid   expectedGuid    = Guid.Parse(expectedGuidStr);
            var    entryBefore     = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;

            Assert.That(entryBefore.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entryBefore.SensesOS.First().PicturesOS.Count, Is.EqualTo(1));

            // Exercise adding 1 picture with 2 captions. Note that the picture that was previously attached
            // to this FDO entry will end up being deleted, because it does not have a corresponding picture in LF.
            data.bsonTestData["authorInfo"]["modifiedDate"] = DateTime.UtcNow;
            _conn.UpdateMockLfLexEntry(data.bsonTestData);
            sutMongoToFdo.Run(lfProj);

            // Verify "Added" picture is now the only picture on the sense (because the "old" picture was deleted),
            // and that it has 2 captions with the expected values.
            entryRepo = _servLoc.GetInstance <ILexEntryRepository>();
            int numOfFdoPictures = entryRepo.AllInstances().
                                   Count(e => (e.SensesOS.Count > 0) && (e.SensesOS[0].PicturesOS.Count > 0));

            Assert.That(entryRepo.Count, Is.EqualTo(OriginalNumOfFdoEntries));
            Assert.That(numOfFdoPictures, Is.EqualTo(originalNumOfFdoPictures));

            var entry = cache.ServiceLocator.GetObject(expectedGuid) as ILexEntry;

            Assert.IsNotNull(entry);
            Assert.That(entry.Guid, Is.EqualTo(expectedGuid));
            Assert.That(entry.SensesOS.Count, Is.GreaterThan(0));
            Assert.That(entry.SensesOS.First().PicturesOS.Count, Is.EqualTo(2));
            Assert.That(entry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                        Is.EqualTo(expectedInternalFileName));
            Assert.That(entry.SensesOS[0].PicturesOS[1].PictureFileRA.InternalPath.ToString(),
                        Is.EqualTo(expectedExternalFileName));

            LfMultiText expectedNewCaption = ConvertFdoToMongoLexicon.
                                             ToMultiText(entry.SensesOS[0].PicturesOS[0].Caption, cache.ServiceLocator.WritingSystemManager);
            int expectedNumOfNewCaptions = expectedNewCaption.Count();

            Assert.That(expectedNumOfNewCaptions, Is.EqualTo(2));
            string expectedNewVernacularCaption = expectedNewCaption["qaa-x-kal"].Value;
            string expectedNewAnalysisCaption   = expectedNewCaption["en"].Value;

            Assert.That(expectedNewVernacularCaption.Equals("First Vernacular caption"));
            Assert.That(expectedNewAnalysisCaption.Equals("Internal path reference"));

            var testSubEntry = cache.ServiceLocator.GetObject(Guid.Parse(TestSubEntryGuidStr)) as ILexEntry;

            Assert.That(testSubEntry, Is.Not.Null);
            Assert.That(testSubEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                        Is.EqualTo("Pictures\\TestImage.tif"));
            var kenEntry = cache.ServiceLocator.GetObject(Guid.Parse(KenEntryGuidStr)) as ILexEntry;

            Assert.That(kenEntry, Is.Not.Null);
            Assert.That(kenEntry.SensesOS[0].PicturesOS[0].PictureFileRA.InternalPath.ToString(),
                        Is.EqualTo("F:\\src\\xForge\\web-languageforge\\test\\php\\common\\TestImage.jpg"));
        }
Пример #7
0
		private void VerifyFirstEntryStTextDataImportExact(ILexEntryRepository repoEntry, int cpara, int flidCustom)
		{
			ILexEntry entry1;
			Assert.IsTrue(repoEntry.TryGetObject(new Guid("494616cc-2f23-4877-a109-1a6c1db0887e"), out entry1));
			Assert.AreEqual(1, entry1.SensesOS.Count);
			var sense1 = entry1.SensesOS[0];
			Assert.AreEqual(sense1.Guid, new Guid("3e0ae703-db7f-4687-9cf5-481524095905"));

			var hvo = Cache.DomainDataByFlid.get_ObjectProp(entry1.Hvo, flidCustom);
			Assert.AreNotEqual(0, hvo, "The first entry has a value in the \"Long Text\" custom field.");
			var text = Cache.ServiceLocator.ObjectRepository.GetObject(hvo) as IStText;
			Assert.IsNotNull(text);
			Assert.AreEqual(cpara, text.ParagraphsOS.Count,
				String.Format("The first Long Text field should have {0} paragraphs.", cpara));
			Assert.AreEqual("Bulleted List", text.ParagraphsOS[0].StyleName);
			ITsIncStrBldr tisb = TsIncStrBldrClass.Create();
			var wsEn = Cache.WritingSystemFactory.GetWsFromStr("en");
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsEn);
			tisb.Append("This is a test of sorts.  This field can contain ");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasized Text");
			tisb.Append("multiple");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
			tisb.Append(" paragraphs.");
			var tss = tisb.GetString();
			tisb.Clear();
			tisb.ClearProps();
			var para = text.ParagraphsOS[0] as IStTxtPara;
			Assert.IsNotNull(para);
			Assert.AreEqual(tss.Text, para.Contents.Text);
			Assert.IsTrue(tss.Equals(para.Contents), "The first paragraph contents should have all its formatting.");

			Assert.AreEqual("Bulleted List", text.ParagraphsOS[1].StyleName);
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsEn);
			tisb.Append("For example, this is the second paragraph already.");
			tss = tisb.GetString();
			tisb.Clear();
			tisb.ClearProps();
			para = text.ParagraphsOS[1] as IStTxtPara;
			Assert.IsNotNull(para);
			Assert.AreEqual(tss.Text, para.Contents.Text);
			Assert.IsTrue(tss.Equals(para.Contents), "The second paragraph contents should have all its formatting.");

			Assert.AreEqual("Normal", text.ParagraphsOS[2].StyleName);
			tisb.SetIntPropValues((int)FwTextPropType.ktptWs, 0, wsEn);
			tisb.Append("This third paragraph is back in the normal (default) paragraph style, and some character ");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Emphasized Text");
			tisb.Append("formatting");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
			tisb.Append(" to produce ");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, "Strong");
			tisb.Append("multiple");
			tisb.SetStrPropValue((int)FwTextPropType.ktptNamedStyle, null);
			tisb.Append(" spans within the paragraph.");
			tss = tisb.GetString();
			tisb.Clear();
			tisb.ClearProps();
			para = text.ParagraphsOS[2] as IStTxtPara;
			Assert.IsNotNull(para);
			Assert.AreEqual(tss.Text, para.Contents.Text);
			Assert.IsTrue(tss.Equals(para.Contents), "The third paragraph contents should have all its formatting.");
		}