static void Main(string[] args) { if (args.Length != 1) { return; } try { string connectionString = args[0]; using (IrbisConnection connection = new IrbisConnection(connectionString)) { ConnectedClient provider = new ConnectedClient(connection); CatalogState first; if (File.Exists("first.state")) { first = SerializationUtility .RestoreObjectFromFile <CatalogState> ( "first.state" ); Console.WriteLine("Previous state restored from first.state"); } else { first = provider.GetCatalogState("ISTU"); first.SaveToFile("first.state"); Console.WriteLine("Initial state saved to first.state"); return; } CatalogState second = provider.GetCatalogState("ISTU"); second.SaveToFile("second.state"); Console.WriteLine("New state saved to second.state"); CatalogDelta delta = CatalogDelta.Create ( first, second ); delta.SaveToFile("state.delta"); Console.WriteLine("Difference saved to state.delta"); Console.WriteLine(delta); } } catch (Exception e) { Console.WriteLine(e); } }
public void CatalogDelta_Create_1() { CatalogState firstState = new CatalogState { Id = 1, Date = new DateTime(2017, 12, 8, 22, 42, 0), Database = "IBIS", MaxMfn = 4, LogicallyDeleted = new[] { 1, 2 }, Records = new[] { new RecordState { Id = 2, Mfn = 1, Status = RecordStatus.LogicallyDeleted, Version = 3 }, new RecordState { Id = 3, Mfn = 2, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 4, Mfn = 3, Status = RecordStatus.Last, Version = 1 }, new RecordState { Id = 5, Mfn = 4, Status = RecordStatus.Last, Version = 2 } } }; CatalogState secondState = new CatalogState { Id = 2, Date = new DateTime(2017, 12, 9, 22, 42, 0), Database = "IBIS", MaxMfn = 6, LogicallyDeleted = new[] { 1, 2, 3 }, Records = new[] { new RecordState { Id = 2, Mfn = 1, Status = RecordStatus.LogicallyDeleted, Version = 3 }, new RecordState { Id = 3, Mfn = 2, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 4, Mfn = 3, Status = RecordStatus.LogicallyDeleted, Version = 2 }, new RecordState { Id = 5, Mfn = 4, Status = RecordStatus.Last, Version = 4 }, new RecordState { Id = 6, Mfn = 5, Status = RecordStatus.Last, Version = 1 }, new RecordState { Id = 7, Mfn = 6, Status = RecordStatus.Last, Version = 1 } } }; CatalogDelta delta = CatalogDelta.Create ( firstState, secondState ); Assert.AreEqual(0, delta.Id); Assert.AreEqual(new DateTime(2017, 12, 8, 22, 42, 0, 0), delta.FirstDate); Assert.AreEqual(new DateTime(2017, 12, 9, 22, 42, 0, 0), delta.SecondDate); Assert.AreEqual("IBIS", delta.Database); Assert.IsNotNull(delta.NewRecords); Assert.AreEqual(2, delta.NewRecords.Length); Assert.AreEqual(5, delta.NewRecords[0]); Assert.AreEqual(6, delta.NewRecords[1]); Assert.IsNotNull(delta.DeletedRecords); Assert.AreEqual(1, delta.DeletedRecords.Length); Assert.AreEqual(3, delta.DeletedRecords[0]); Assert.IsNotNull(delta.AlteredRecords); Assert.AreEqual(1, delta.AlteredRecords.Length); Assert.AreEqual(4, delta.AlteredRecords[0]); }