public void NewEntriesAdded_MultipleFilesSucessiveChanges() { //This test demonstrates that LiftUpdate files are applied in the order they are created when time stamps are used to order the names up the LIFTUpdate files. //Notice that the files names of the LIFT update files are purposely created so that the alphabetical ordering does not match the time stamp ordering. //Create a LIFT file with 3 entries which will have updates applied to it. WriteFile(_baseLiftFileName, s_LiftData1, _directory); //Create a .lift.update file with three entries. One to replace the second entry in the original LIFT file. //The other two are new and should be appended to the original LIFT file. WriteFile("LiftChangeFileB" + SynchronicMerger.ExtensionOfIncrementalFiles, s_LiftUpdate1, _directory); if (!Platform.IsWindows) { Thread.Sleep(1000); // Wait long enough to ensure different timestamps. This is a problem for Linux/Mono. } //Create a .lift.update file with two entries. One to replace one of the changes from the first LiftUpdate file and one new entry. WriteFile("LiftChangeFileA" + SynchronicMerger.ExtensionOfIncrementalFiles, s_LiftUpdate2, _directory); FileInfo[] files = SynchronicMerger.GetPendingUpdateFiles(Path.Combine(_directory, _baseLiftFileName)); XmlDocument doc = MergeAndGetResult(true, _directory, files); Console.WriteLine("------------------------BEGIN DEBUG----------------------"); Console.WriteLine(doc.OuterXml); Console.WriteLine("------------------------END DEBUG----------------------"); Assert.AreEqual(6, doc.SelectNodes("//entry").Count, "Should have been 6 entries"); Assert.AreEqual(1, doc.SelectNodes("//entry[@id='one']").Count, "should have been one entry with id of one"); Assert.AreEqual(0, doc.SelectNodes("//entry[@id='two']").Count, "should not have been any entries with id of two"); Assert.AreEqual(1, doc.SelectNodes("//entry[@id='twoblatblat']").Count, "should have had one entry with id twoblatblat"); Assert.AreEqual(0, doc.SelectNodes("//entry[@id='four']").Count, "should have been no entries with id four"); Assert.AreEqual(1, doc.SelectNodes("//entry[@id='fourChangedFirstAddition']").Count, "should have been one entry with id 'forchangedfirstaddition'"); Assert.AreEqual(1, doc.SelectNodes("//entry[@id='six']").Count, "should have been one entry with id of 6"); }
/// <summary> /// /// </summary> /// <returns>false if it failed (and it would have already reported the error)</returns> private void MergeIncrementFiles() { //merge the increment files if (SynchronicMerger.GetPendingUpdateFiles(_liftFilePath).Length > 0) { #if DEBUG Logger.WriteMinorEvent("++before pending updates: {0}", SynchronicMerger.GetPendingUpdateFiles(_liftFilePath).Length); #endif Logger.WriteEvent("Running Synchronic Merger"); try { var merger = new SynchronicMerger(); merger.MergeUpdatesIntoFile(_liftFilePath); } catch (BadUpdateFileException error) { string contents = File.ReadAllText(error.PathToNewFile); if (contents.Trim().Length == 0) { ErrorReport.NotifyUserOfProblem( "It looks as though WeSay recently crashed while attempting to save. It will try again to preserve your work, but you will want to check to make sure nothing was lost."); File.Delete(error.PathToNewFile); } else { File.Move(error.PathToNewFile, error.PathToNewFile + ".bad"); ErrorReport.NotifyUserOfProblem( "WeSay was unable to save some work you did in the previous session. The work might be recoverable from the file {0}. The next screen will allow you to send a report of this to the developers.", error.PathToNewFile + ".bad"); ErrorReport.ReportNonFatalException(error); } //return false; //!!! remove CJP } catch (Exception e) { ErrorReport.NotifyUserOfProblem(e, "Could not finish updating LIFT dictionary file. Will try again later." + Environment.NewLine + " (" + e.Message + ")"); } #if DEBUG Logger.WriteMinorEvent("--after pending updates: {0}", SynchronicMerger.GetPendingUpdateFiles(_liftFilePath).Length); #endif } }
public void EntryDeleted_DeletionDateAdded() { //This test demonstrates that a deletion of an entry is applied to a LIFT file. //Now 'tomb stoning' is done. The entry is not actually deleted, but a dateDeleted attribute is added //Create a LIFT file with 3 entries which will have updates applied to it. WriteFile(_baseLiftFileName, s_LiftData1, _directory); //Create a .lift.update file with and entry which is indicating that an entry was deleted (tombstone). WriteFile("LiftChangeFile" + SynchronicMerger.ExtensionOfIncrementalFiles, s_LiftUpdateDeleteEntry, _directory); FileInfo[] files = SynchronicMerger.GetPendingUpdateFiles(Path.Combine(_directory, _baseLiftFileName)); XmlDocument doc = MergeAndGetResult(true, _directory, files); Assert.AreEqual(4, doc.SelectNodes("//entry").Count); Assert.AreEqual(1, doc.SelectNodes("//entry[@id='one']").Count); XmlNodeList nodesDeleted = doc.SelectNodes("//entry[@id='two' and @guid='0ae89610-fc01-4bfd-a0d6-1125b7281d22']"); Assert.AreEqual(1, nodesDeleted.Count); //ensure there is only one entry with this guid XmlNode nodeDeleted = nodesDeleted[0]; //Make sure the contents of the node was changed to match the deleted entry from the .lift.update file Assert.AreEqual("2012-05-08T06:40:44Z", nodeDeleted.Attributes["dateDeleted"].Value); Assert.IsNullOrEmpty(nodeDeleted.InnerXml); }
public void GetPendingUpdateFiles_SimpleFileNameInsteadOfPath_Throws() { WriteFile(_baseLiftFileName, "", _directory); SynchronicMerger.GetPendingUpdateFiles(_baseLiftFileName); }
public void Setup() { _merger = new SynchronicMerger(); _directory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Directory.CreateDirectory(_directory); }