public void FixtureSetup()
        {
            _mdc = MetadataCache.TestOnlyNewCache;
            var mergeOrder = new MergeOrder(null, null, null, new NullMergeSituation())
            {
                EventListener = new ListenerForUnitTests()
            };

            _merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, _mdc);
        }
        public override void TestSetup()
        {
            base.TestSetup();
            Mdc.UpgradeToVersion(MetadataCache.MaximumModelVersion);
            var mergeOrder = new MergeOrder(null, null, null, new NullMergeSituation())
            {
                EventListener = new ListenerForUnitTests()
            };

            _merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, Mdc);
        }
Esempio n. 3
0
        /// <summary>
        /// All callers merging FieldWorks data need to pass 'true', so the MDC will know about  any custom properties for their classes.
        ///
        /// Non-object callers (currently only the merge of the custom property definitions themselves) shoudl pass 'false'.
        /// </summary>
        internal static void Do3WayMerge(MergeOrder mergeOrder, MetadataCache mdc, bool addcustomPropertyInformation)
        {
            // Skip doing this for the Custom property definiton file, since it has no real need for the custom prop definitions,
            // which are being merged (when 'false' is provided).
            if (addcustomPropertyInformation)
            {
                mdc.AddCustomPropInfo(mergeOrder);                 // NB: Must be done before FieldWorksCommonMergeStrategy is created. since it used the MDC.
            }
            var merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, mdc);

            merger.EventListener = mergeOrder.EventListener;
            var mergeResults = merger.MergeFiles(mergeOrder.pathToOurs, mergeOrder.pathToTheirs, mergeOrder.pathToCommonAncestor);

            // Write out merged data.
            FileWriterService.WriteNestedFile(mergeOrder.pathToOurs, mergeResults.MergedNode);
        }
Esempio n. 4
0
        public void EnsureAllBinaryPropertiesAreSetUpCorrectly()
        {
            var mdc        = MetadataCache.MdCache;
            var mergeOrder = new MergeOrder(null, null, null, new NullMergeSituation())
            {
                EventListener = new ListenerForUnitTests()
            };
            var merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, mdc);

            foreach (var elementStrategy in mdc.AllConcreteClasses
                     .SelectMany(classInfo => classInfo.AllProperties, (classInfo, propertyInfo) => new { classInfo, propertyInfo })
                     .Where(@t => @t.propertyInfo.DataType == DataType.Binary)
                     .Select(@t => merger.MergeStrategies.ElementStrategies[string.Format("{0}{1}_{2}", @t.propertyInfo.IsCustomProperty ? "Custom_" : "", @t.classInfo.ClassName, @t.propertyInfo.PropertyName)]))
            {
                Assert.IsTrue(elementStrategy.IsAtomic);
                Assert.IsFalse(elementStrategy.OrderIsRelevant);
                Assert.IsFalse(elementStrategy.IsImmutable);
                Assert.AreEqual(NumberOfChildrenAllowed.ZeroOrMore, elementStrategy.NumberOfChildren);
                Assert.AreEqual(0, elementStrategy.AttributesToIgnoreForMerging.Count);
                Assert.IsInstanceOf <FindFirstElementWithSameName>(elementStrategy.MergePartnerFinder);
            }
        }
Esempio n. 5
0
        private void RoundTripData(Stopwatch breakupTimer, Stopwatch restoreTimer, Stopwatch ambiguousTimer, StringBuilder sbValidation)
        {
            File.Copy(_srcFwdataPathname, _srcFwdataPathname + ".orig", true); // Keep it safe.
            GetFreshMdc();                                                     // Want it fresh.
            breakupTimer.Start();
            FLExProjectSplitter.PushHumptyOffTheWall(new NullProgress(), _srcFwdataPathname);
            breakupTimer.Stop();
            GC.Collect(2, GCCollectionMode.Forced);

            if (_cbCheckAmbiguousElements.Checked)
            {
                var allDataFiles = new HashSet <string>();
                var currentDir   = Path.Combine(_workingDir, "Linguistics");
                if (Directory.Exists(currentDir))
                {
                    allDataFiles.UnionWith(from pathname in Directory.GetFiles(currentDir, "*.*", SearchOption.AllDirectories)
                                           where !pathname.ToLowerInvariant().EndsWith("chorusnotes")
                                           select pathname);
                }
                currentDir = Path.Combine(_workingDir, "Anthropology");
                if (Directory.Exists(currentDir))
                {
                    allDataFiles.UnionWith(from pathname in Directory.GetFiles(currentDir, "*.*", SearchOption.AllDirectories)
                                           where !pathname.ToLowerInvariant().EndsWith("chorusnotes")
                                           select pathname);
                }
                currentDir = Path.Combine(_workingDir, "Other");
                if (Directory.Exists(currentDir))
                {
                    allDataFiles.UnionWith(
                        from pathname in Directory.GetFiles(currentDir, "*.*", SearchOption.AllDirectories)
                        where !pathname.ToLowerInvariant().EndsWith("chorusnotes")
                        select pathname);
                }
                currentDir = Path.Combine(_workingDir, "General");
                if (Directory.Exists(currentDir))
                {
                    allDataFiles.UnionWith(from pathname in Directory.GetFiles(currentDir, "*.*", SearchOption.AllDirectories)
                                           where !pathname.ToLowerInvariant().EndsWith("chorusnotes")
                                           select pathname);
                }
                var mergeOrder = new MergeOrder(null, null, null, new NullMergeSituation())
                {
                    EventListener = new ChangeAndConflictAccumulator()
                };
                var merger = FieldWorksMergeServices.CreateXmlMergerForFieldWorksData(mergeOrder, MetadataCache.MdCache);
                ambiguousTimer.Start();
                foreach (var dataFile in allDataFiles)
                {
                    var    extension           = Path.GetExtension(dataFile).Substring(1);
                    string optionalElementName = null;
                    string mainRecordName      = null;
                    switch (extension)
                    {
                    case SharedConstants.Style:
                        mainRecordName = SharedConstants.StStyle;
                        break;

                    case SharedConstants.List:
                        mainRecordName = SharedConstants.CmPossibilityList;
                        break;

                    case SharedConstants.langproj:
                        mainRecordName = SharedConstants.LangProject;
                        break;

                    case SharedConstants.Annotation:
                        mainRecordName = SharedConstants.CmAnnotation;
                        break;

                    case SharedConstants.Filter:
                        mainRecordName = SharedConstants.CmFilter;
                        break;

                    case SharedConstants.orderings:
                        mainRecordName = SharedConstants.VirtualOrdering;
                        break;

                    case SharedConstants.pictures:
                        mainRecordName = SharedConstants.CmPicture;
                        break;

                    case SharedConstants.ArchivedDraft:
                        mainRecordName = SharedConstants.ScrDraft;
                        break;

                    case SharedConstants.ImportSetting:
                        mainRecordName = SharedConstants.ScrImportSet;
                        break;

                    case SharedConstants.Srs:
                        mainRecordName = SharedConstants.ScrRefSystem;
                        break;

                    case SharedConstants.Trans:
                        mainRecordName = SharedConstants.Scripture;
                        break;

                    case SharedConstants.bookannotations:
                        mainRecordName = SharedConstants.ScrBookAnnotations;
                        break;

                    case SharedConstants.book:
                        mainRecordName = SharedConstants.ScrBook;
                        break;

                    case SharedConstants.Ntbk:
                        optionalElementName = SharedConstants.Header;
                        mainRecordName      = SharedConstants.RnGenericRec;
                        break;

                    case SharedConstants.Reversal:
                        optionalElementName = SharedConstants.Header;
                        mainRecordName      = SharedConstants.ReversalIndexEntry;
                        break;

                    case SharedConstants.Lexdb:
                        optionalElementName = SharedConstants.Header;
                        mainRecordName      = SharedConstants.LexEntry;
                        break;

                    case SharedConstants.TextInCorpus:
                        mainRecordName = SharedConstants.Text;
                        break;

                    case SharedConstants.Inventory:
                        optionalElementName = SharedConstants.Header;
                        mainRecordName      = SharedConstants.WfiWordform;
                        break;

                    case SharedConstants.DiscourseExt:
                        optionalElementName = SharedConstants.Header;
                        mainRecordName      = SharedConstants.DsChart;
                        break;

                    case SharedConstants.Featsys:
                        mainRecordName = SharedConstants.FsFeatureSystem;
                        break;

                    case SharedConstants.Phondata:
                        mainRecordName = SharedConstants.PhPhonData;
                        break;

                    case SharedConstants.Morphdata:
                        mainRecordName = SharedConstants.MoMorphData;
                        break;

                    case SharedConstants.Agents:
                        mainRecordName = SharedConstants.CmAgent;
                        break;
                    }
                    using (var fastSplitter = new FastXmlElementSplitter(dataFile))
                    {
                        bool foundOptionalFirstElement;
                        foreach (var record in fastSplitter.GetSecondLevelElementBytes(optionalElementName, mainRecordName, out foundOptionalFirstElement))
                        {
                            XmlMergeService.RemoveAmbiguousChildren(merger.EventListener, merger.MergeStrategies, CreateXmlNodeFromBytes(record));
                        }
                    }
                }
                ambiguousTimer.Stop();
                foreach (var warning in ((ChangeAndConflictAccumulator)merger.EventListener).Warnings)
                {
                    sbValidation.AppendLine(warning.Description);
                    sbValidation.AppendLine();
                    sbValidation.AppendLine(warning.HtmlDetails);
                    sbValidation.AppendLine();
                }
                GC.Collect(2, GCCollectionMode.Forced);
            }
            restoreTimer.Start();
            FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), _srcFwdataPathname);
            restoreTimer.Stop();
            GC.Collect(2, GCCollectionMode.Forced);
        }