Пример #1
0
        private void RemoveMongoEntriesDeletedInFdo()
        {
            IEnumerable <LfLexEntry> lfEntries = Connection.GetRecords <LfLexEntry>(LfProject, MagicStrings.LfCollectionNameForLexicon);

            foreach (LfLexEntry lfEntry in lfEntries)
            {
                if (lfEntry.Guid == null)
                {
                    continue;
                }
                if (!ServiceLocator.ObjectRepository.IsValidObjectId(lfEntry.Guid.Value) ||
                    !ServiceLocator.ObjectRepository.GetObject(lfEntry.Guid.Value).IsValidObject)
                {
                    if (lfEntry.IsDeleted)
                    {
                        // Don't need to delete this record twice
                        continue;
                    }

                    lfEntry.IsDeleted    = true;
                    lfEntry.DateModified = DateTime.UtcNow;
                    Logger.Info("FdoToMongo: Deleted LfEntry {0} ({1})", lfEntry.Guid, ConvertUtilities.EntryNameForDebugging(lfEntry));
                    Connection.UpdateRecord(LfProject, lfEntry);
                }
            }
        }
Пример #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();
        }