private MetadataCache GetFreshMdc() { var mdc = MetadataCache.TestOnlyNewCache; var modelVersionPathname = Path.Combine(_workingDir, SharedConstants.ModelVersionFilename); if (!File.Exists(modelVersionPathname)) { FLExProjectSplitter.WriteVersionFile(_srcFwdataPathname); using (var fastSplitter = new FastXmlElementSplitter(_srcFwdataPathname)) { bool foundOptionalFirstElement; // NB: The main input file *does* have to deal with the optional first element. foreach (var record in fastSplitter.GetSecondLevelElementBytes(SharedConstants.AdditionalFieldsTag, SharedConstants.RtTag, out foundOptionalFirstElement)) { if (foundOptionalFirstElement) { // 2. Write custom properties file with custom properties. FileWriterService.WriteCustomPropertyFile(mdc, _workingDir, record); } else { // Write empty custom properties file. FileWriterService.WriteCustomPropertyFile(Path.Combine(_workingDir, SharedConstants.CustomPropertiesFilename), null); } break; } } } var modelData = File.ReadAllText(modelVersionPathname); mdc.UpgradeToVersion(Int32.Parse(modelData.Split(new[] { "{", ":", "}" }, StringSplitOptions.RemoveEmptyEntries)[1])); var customPropPathname = Path.Combine(_workingDir, SharedConstants.CustomPropertiesFilename); mdc.AddCustomPropInfo(new MergeOrder( customPropPathname, customPropPathname, customPropPathname, new MergeSituation(customPropPathname, "", "", "", "", MergeOrder.ConflictHandlingModeChoices.WeWin))); return(mdc); }
public void CustomFileHasKeyAttributeForEachCustomProperty() { const string originalCustomData = @"<AdditionalFields> <CustomField class='LexEntry' destclass='7' listRoot='53241fd4-72ae-4082-af55-6b659657083c' name='Tone' type='RC' /> <CustomField class='LexSense' name='Paradigm' type='String' wsSelector='-2' /> <CustomField class='WfiWordform' name='Certified' type='Boolean' /> </AdditionalFields>"; var tempPathname = Path.Combine(Path.GetTempPath(), SharedConstants.CustomPropertiesFilename); FileWriterService.WriteCustomPropertyFile(MetadataCache.TestOnlyNewCache, Path.GetTempPath(), SharedConstants.Utf8.GetBytes(originalCustomData)); using (var tempFile = TempFile.TrackExisting(tempPathname)) { var doc = XDocument.Load(tempFile.Path); Assert.IsTrue(doc.Root.Name.LocalName == "AdditionalFields"); Assert.AreEqual(3, doc.Root.Elements().Count()); foreach (var customPropertyDeclaration in doc.Root.Elements()) { Assert.IsNotNull(customPropertyDeclaration.Attribute("key")); } } }
/// <summary> /// Start doing whatever is needed for the supported type of action. /// </summary> /// <returns>'true' if the caller expects the main window to be shown, otherwise 'false'.</returns> public void StartWorking(Dictionary <string, string> commandLineArgs) { // -p <$fwroot>\foo\foo.fwdata var projectDir = Path.GetDirectoryName(commandLineArgs["-p"]); using (var chorusSystem = Utilities.InitializeChorusSystem(projectDir, commandLineArgs["-u"], FlexFolderSystem.ConfigureChorusProjectFolder)) { var newlyCreated = false; if (chorusSystem.Repository.Identifier == null) { // Write an empty custom prop file to get something in the default branch at rev 0. // The custom prop file will always exist and can be empty, so start it as empty (null). // This basic rev 0 commit will then allow for a roll back if the soon to follow main commit fails on a validation problem. FileWriterService.WriteCustomPropertyFile(Path.Combine(projectDir, SharedConstants.CustomPropertiesFilename), null); chorusSystem.Repository.AddAndCheckinFile(Path.Combine(projectDir, SharedConstants.CustomPropertiesFilename)); newlyCreated = true; } chorusSystem.EnsureAllNotesRepositoriesLoaded(); // Add the 'lock' file to keep FW apps from starting up at such an inopportune moment. var projectName = Path.GetFileNameWithoutExtension(commandLineArgs["-p"]); var lockPathname = Path.Combine(projectDir, projectName + SharedConstants.FwXmlLockExtension); try { File.WriteAllText(lockPathname, ""); var origPathname = Path.Combine(projectDir, projectName + Utilities.FwXmlExtension); // Do the Chorus business. using (var syncDlg = (SyncDialog)chorusSystem.WinForms.CreateSynchronizationDialog(SyncUIDialogBehaviors.Lazy, SyncUIFeatures.NormalRecommended | SyncUIFeatures.PlaySoundIfSuccessful)) { // The FlexBridgeSynchronizerAdjunct class (implements ISychronizerAdjunct) handles the fwdata file splitting and restoring // now. 'syncDlg' sees to it that the Synchronizer class ends up with FlexBridgeSynchronizerAdjunct, and the Synchronizer // class then calls one of the methods of the ISychronizerAdjunct interface right before the first Commit (local commit) // call. If two heads are merged, then the Synchoronizer class calls the second method of the ISychronizerAdjunct // interface, (once for each pair of merged heads) so Flex Bridge can restore the fwdata file, AND, most importantly, // produce any needed incompatible move conflict reports of the merge, which are then included in the post-merge commit. var syncAdjunt = new FlexBridgeSynchronizerAdjunct(origPathname, commandLineArgs["-f"], false); syncDlg.SetSynchronizerAdjunct(syncAdjunt); // Chorus does it in this order: // Local Commit // Pull // Merge (Only if anything came in with the pull from other sources, and commit of merged results) // Push syncDlg.SyncOptions.DoPullFromOthers = true; syncDlg.SyncOptions.DoMergeWithOthers = true; syncDlg.SyncOptions.DoSendToOthers = true; syncDlg.Text = Resources.SendReceiveView_DialogTitleFlexProject; syncDlg.StartPosition = FormStartPosition.CenterScreen; syncDlg.BringToFront(); var dlgResult = syncDlg.ShowDialog(); if (dlgResult == DialogResult.OK) { if (newlyCreated && (!syncDlg.SyncResult.Succeeded || syncDlg.SyncResult.ErrorEncountered != null)) { _gotChanges = false; // Wipe out new repo, since something bad happened in S/R, // and we don't want to leave the user in a sad state (cf. LT-14751, LT-14957). BackOutOfRepoCreation(projectDir); } else if (syncDlg.SyncResult.DidGetChangesFromOthers || syncAdjunt.WasUpdated) { _gotChanges = true; } } else { // User probably bailed out of S/R using the "X" to close the dlg. if (newlyCreated) { _gotChanges = false; // Wipe out new repo, since the user cancelled without even trying the S/R, // and we don't want to leave the user in a sad state (cf. LT-14751, LT-14957). BackOutOfRepoCreation(projectDir); } } } } finally { if (File.Exists(lockPathname)) { File.Delete(lockPathname); } } } }