Exemplo n.º 1
0
 private void RestoreProjectFile(IProgress progress)
 {
     WasUpdated = true;
     progress.WriteMessage("Rebuild project file '{0}'", ProjectFilename);
     FLExProjectUnifier.PutHumptyTogetherAgain(progress, _writeVerbose, _fwdataPathname);
     progress.WriteMessage("Finished rebuilding project file '{0}'", ProjectFilename);
 }
Exemplo n.º 2
0
 private void RestoreMainFileFromPieces(Stopwatch restoreTimer)
 {
     GetFreshMdc();             // Want it fresh.
     restoreTimer.Start();
     FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), _srcFwdataPathname);
     restoreTimer.Stop();
 }
Exemplo n.º 3
0
 public void NonExistantPathForRestoreShouldThrow()
 {
     using (var tempFile = new TempFile())
     {
         var pathname = tempFile.Path;
         Assert.Throws <ApplicationException>(() => FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), Path.Combine(pathname, "Itaintthere")));
     }
 }
        private void RebuildFlexFileIfRelevant()
        {
            if (GetRepoType() != RepoType.FLEx)
            {
                return;
            }

            var fwdataPathname = Path.Combine(_repoFolder, Path.GetFileName(_repoFolder) + Utilities.FwXmlExtension);

            if (!File.Exists(fwdataPathname))
            {
                File.WriteAllText(fwdataPathname, @"");
            }
            FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), fwdataPathname);
        }
        public void FinishCloning(Dictionary <string, string> commandLineArgs, string cloneLocation, string expectedPathToClonedRepository)
        {
            var actualCloneResult = new ActualCloneResult
            {
                // Be a bit pessimistic at first.
                CloneResult       = null,
                ActualCloneFolder = null,
                FinalCloneResult  = FinalCloneResult.ExistingCloneTargetFolder
            };

            _newProjectFilename   = Path.GetFileName(cloneLocation) + Utilities.FwXmlExtension;
            _newFwProjectPathname = Path.Combine(cloneLocation, _newProjectFilename);

            // Check the actual FW model number in the '-fwmodel' of 'commandLineArgs' parm.
            // Update to the head of the desired branch, if possible.
            UpdateToTheCorrectBranchHeadIfPossible(commandLineArgs, actualCloneResult, cloneLocation);

            _gotClone = false;
            switch (actualCloneResult.FinalCloneResult)
            {
            case FinalCloneResult.ExistingCloneTargetFolder:
                MessageBox.Show(CommonResources.kFlexProjectExists, CommonResources.kObtainProject, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Directory.Delete(cloneLocation, true);
                _newFwProjectPathname = null;
                return;

            case FinalCloneResult.FlexVersionIsTooOld:
                MessageBox.Show(actualCloneResult.Message, CommonResources.kObtainProject, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Directory.Delete(cloneLocation, true);
                _newFwProjectPathname = null;
                return;

            case FinalCloneResult.Cloned:
                _gotClone = true;
                break;
            }

            FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), false, _newFwProjectPathname);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
 public void NonExistingFileForRestoreShouldThrow()
 {
     Assert.Throws <ApplicationException>(() => FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), "Bogus" + Utilities.FwXmlExtension));
 }
Exemplo n.º 8
0
 public void EmptyPathnameForRestoreShouldThrow()
 {
     Assert.Throws <ApplicationException>(() => FLExProjectUnifier.PutHumptyTogetherAgain(new NullProgress(), ""));
 }
        private static void UpdateToTheCorrectBranchHeadIfPossible(Dictionary <string, string> commandLineArgs,
                                                                   ActualCloneResult cloneResult,
                                                                   string cloneLocation)
        {
            var repo = new HgRepository(cloneLocation, new NullProgress());
            Dictionary <string, Revision> allHeads = Utilities.CollectAllBranchHeads(cloneLocation);
            var      desiredBranchName             = commandLineArgs["-fwmodel"];
            var      desiredModelVersion           = uint.Parse(desiredBranchName);
            Revision desiredRevision;

            if (!allHeads.TryGetValue(desiredBranchName, out desiredRevision))
            {
                // Remove any that are too high.
                var gonerKeys = new HashSet <string>();
                foreach (var headKvp in allHeads)
                {
                    uint currentVersion;
                    if (headKvp.Key == Default)
                    {
                        repo.Update(headKvp.Value.Number.LocalRevisionNumber);
                        var modelVersion = FLExProjectUnifier.GetModelVersion(cloneLocation);
                        currentVersion = (modelVersion == null)
                                                                                         ? uint.MaxValue // Get rid of the initial default commit by making it max for uint. It had no model version file.
                                                                                         : uint.Parse(modelVersion);
                    }
                    else
                    {
                        currentVersion = uint.Parse(headKvp.Value.Branch);
                    }
                    if (currentVersion > desiredModelVersion)
                    {
                        gonerKeys.Add((headKvp.Key == Default) ? Default : headKvp.Key);
                    }
                }
                foreach (var goner in gonerKeys)
                {
                    allHeads.Remove(goner);
                }

                // Replace 'default' with its real model number.
                if (allHeads.ContainsKey(Default))
                {
                    repo.Update(allHeads[Default].Number.LocalRevisionNumber);
                    var modelVersion = FLExProjectUnifier.GetModelVersion(cloneLocation);
                    if (modelVersion != null)
                    {
                        if (allHeads.ContainsKey(modelVersion))
                        {
                            // Pick the highest revision of the two.
                            var defaultHead           = allHeads[Default];
                            var otherHead             = allHeads[modelVersion];
                            var defaultRevisionNumber = int.Parse(defaultHead.Number.LocalRevisionNumber);
                            var otherRevisionNumber   = int.Parse(otherHead.Number.LocalRevisionNumber);
                            allHeads[modelVersion] = defaultRevisionNumber > otherRevisionNumber ? defaultHead : otherHead;
                        }
                        else
                        {
                            allHeads.Add(modelVersion, allHeads[Default]);
                        }
                    }
                    allHeads.Remove(Default);
                }

                // 'default' is no longer present in 'allHeads'.
                // If all of them are higher, then it is a no go.
                if (allHeads.Count == 0)
                {
                    // No useable model version, so bailout with a message to the user telling them they are 'toast'.
                    cloneResult.FinalCloneResult = FinalCloneResult.FlexVersionIsTooOld;
                    cloneResult.Message          = CommonResources.kFlexUpdateRequired;
                    Directory.Delete(cloneLocation, true);
                    return;
                }

                // Now. get to the real work.
                var sortedRevisions = new SortedList <uint, Revision>();
                foreach (var kvp in allHeads)
                {
                    sortedRevisions.Add(uint.Parse(kvp.Key), kvp.Value);
                }
                desiredRevision = sortedRevisions.Values[sortedRevisions.Count - 1];
            }
            repo.Update(desiredRevision.Number.LocalRevisionNumber);
            cloneResult.ActualCloneFolder = cloneLocation;
            cloneResult.FinalCloneResult  = FinalCloneResult.Cloned;
        }