Ejemplo n.º 1
0
 public void NotFwDataFileForBreakupShouldThrow()
 {
     using (var tempFile = new TempFile(""))
     {
         var pathname = tempFile.Path;
         Assert.Throws <ApplicationException>(() => FLExProjectSplitter.PushHumptyOffTheWall(new NullProgress(), pathname));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Allow the client to do something right after a merge, but before the merge is committed.
 /// </summary>
 /// <remarks>This method is not be called at all, if there was no merging.</remarks>
 public void PrepareForPostMergeCommit(IProgress progress)
 {
     RestoreProjectFile(progress);
     progress.WriteMessage("Checking project for merge problems");
     if (RunFixFwData(progress))
     {
         progress.WriteMessage("Ran fix-up utility after merge.");
         FLExProjectSplitter.PushHumptyOffTheWall(progress, _writeVerbose, _fwdataPathname);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Allow the client to do something right before the initial local commit.
 /// </summary>
 public void PrepareForInitialCommit(IProgress progress)
 {
     if (!_needToNestMainFile)
     {
         return;                 // Only nest it one time.
     }
     progress.WriteMessage("Split up project file: {0}", ProjectFilename);
     FLExProjectSplitter.PushHumptyOffTheWall(progress, _writeVerbose, _fwdataPathname);
     progress.WriteMessage("Finished splitting up project file: {0}", ProjectFilename);
     _needToNestMainFile = false;
 }
Ejemplo n.º 4
0
 public void UserCancelledBreakupShouldThrow()
 {
     using (var tempFile = TempFile.WithFilename("foo" + Utilities.FwXmlExtension))
     {
         var progress = new NullProgress
         {
             CancelRequested = true
         };
         var pathname = tempFile.Path;
         Assert.Throws <UserCancelledException>(() => FLExProjectSplitter.PushHumptyOffTheWall(progress, pathname));
     }
 }
Ejemplo 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);
        }
Ejemplo n.º 6
0
 public void NonExistingFileForBreakupShouldThrow()
 {
     Assert.Throws <ApplicationException>(() => FLExProjectSplitter.PushHumptyOffTheWall(new NullProgress(), "Bogus" + Utilities.FwXmlExtension));
 }
Ejemplo n.º 7
0
 public void EmptyPathnameForBreakupShouldThrow()
 {
     Assert.Throws <ApplicationException>(() => FLExProjectSplitter.PushHumptyOffTheWall(new NullProgress(), ""));
 }