public void DeleteCheckpoint() { using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); // Add a checkpoint with some files File.WriteAllText("Dummy.txt", "abcde"); storage.AddCheckpoint("checkpoint1", new string[] { "Dummy.txt" }); // Delete a checkpoint storage.DeleteCheckpoint("checkpoint1"); } Assert.AreEqual(Utilities.TableToString(fileName, "Report1"), "CheckpointID,SimulationID, Col1, Col2\r\n" + " 1, 1,2017-01-01, 1.000\r\n" + " 1, 1,2017-01-02, 2.000\r\n" + " 1, 2,2017-01-01,11.000\r\n" + " 1, 2,2017-01-02,12.000\r\n"); Assert.AreEqual(Utilities.TableToString(fileName, "_Checkpoints"), "ID, Name,Version,Date\r\n" + " 1,Current, , \r\n"); Assert.AreEqual(Utilities.TableToString(fileName, "_CheckpointFiles"), "\r\n"); }
public void AddCheckpoint() { using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); // Add a checkpoint storage.AddCheckpoint("checkpoint1"); } Assert.AreEqual(Utilities.TableToString(fileName, "Report1"), "CheckpointID,SimulationID, Col1, Col2\r\n" + " 1, 1,2017-01-01, 1.000\r\n" + " 1, 1,2017-01-02, 2.000\r\n" + " 1, 2,2017-01-01,11.000\r\n" + " 1, 2,2017-01-02,12.000\r\n" + " 2, 1,2017-01-01, 1.000\r\n" + " 2, 1,2017-01-02, 2.000\r\n" + " 2, 2,2017-01-01,11.000\r\n" + " 2, 2,2017-01-02,12.000\r\n"); Assert.AreEqual(Utilities.TableToString(fileName, "_Checkpoints", new string[] { "ID", "Name" }), "ID, Name\r\n" + " 1, Current\r\n" + " 2,checkpoint1\r\n"); File.Delete("Temp.apsimx"); }
public void AddCheckpointThenWriteNewRows() { DataTable data = null; using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); data = storage.RunQuery("SELECT Col1 FROM Report1"); // Add a checkpoint storage.AddCheckpoint("checkpoint1"); // Write new rows for sim2. Should get rid of old sim2 data and replace // with these 2 new rows. string[] simulationNames = new string[] { "Sim1", "Sim2" }; string[] simulationNamesBeingRun = new string[] { "Sim2" }; Utilities.CallEvent(storage, "RunCommencing", new object[] { simulationNames, simulationNamesBeingRun }); string[] columnNames1 = new string[] { "Col1", "Col2" }; storage.WriteRow("Sim2", "Report1", columnNames1, new string[] { null, "g" }, new object[] { new DateTime(2017, 1, 1), 3.0 }); storage.WriteRow("Sim2", "Report1", columnNames1, new string[] { null, "g" }, new object[] { new DateTime(2017, 1, 2), 4.0 }); Utilities.CallEvent(storage, "EndRun"); } Assert.AreEqual(Utilities.TableToString(fileName, "Report1"), "CheckpointID,SimulationID, Col1, Col2\r\n" + " 1, 1,2017-01-01, 1.000\r\n" + " 1, 1,2017-01-02, 2.000\r\n" + " 1, 2,2017-01-01, 3.000\r\n" + " 1, 2,2017-01-02, 4.000\r\n" + " 2, 1,2017-01-01, 1.000\r\n" + " 2, 1,2017-01-02, 2.000\r\n" + " 2, 2,2017-01-01,11.000\r\n" + " 2, 2,2017-01-02,12.000\r\n"); }
public void ListCheckpoints() { DataTable data = null; using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); data = storage.RunQuery("SELECT Col1 FROM Report1"); // Add a checkpoint storage.AddCheckpoint("checkpoint1"); // Add a checkpoint storage.AddCheckpoint("checkpoint2"); Assert.AreEqual(storage.Checkpoints(), new string[] { "Current", "checkpoint1", "checkpoint2" }); } }
/// <summary> /// Checkpoint the simulation. /// </summary> /// <param name="checkpointName">Name of checkpoint</param> public void AddCheckpoint(string checkpointName) { List <string> filesReferenced = new List <string>(); filesReferenced.Add(FileName); filesReferenced.AddRange(FindAllReferencedFiles()); DataStore storage = Apsim.Find(this, typeof(DataStore)) as DataStore; if (storage != null) { storage.AddCheckpoint(checkpointName, filesReferenced); } }
public void RevertCheckpoint() { using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); // Add a checkpoint with some files File.WriteAllText("Dummy.txt", "abcde"); storage.AddCheckpoint("checkpoint1", new string[] { "Dummy.txt" }); // Change contents of our file. File.WriteAllText("Dummy.txt", "qwerty"); // Write some new current data. // Create a database with 3 sims. string[] simulationNamesBeingRun = new string[] { "Sim1" }; Dictionary <string, string> simsAndFolders = new Dictionary <string, string>(); simsAndFolders.Add("Sim1", "Folder"); simsAndFolders.Add("Sim2", "Folder"); object[] arguments = new object[] { simsAndFolders, simulationNamesBeingRun }; Utilities.CallEvent(storage, "RunCommencing", arguments); string[] columnNames1 = new string[] { "Col1", "Col2" }; storage.WriteRow("Sim1", "Report1", columnNames1, new string[] { null, "g" }, new object[] { new DateTime(2017, 1, 3), 100.0 }); storage.WriteRow("Sim1", "Report1", columnNames1, new string[] { null, "g" }, new object[] { new DateTime(2017, 1, 4), 200.0 }); Utilities.CallEvent(storage, "EndRun"); // Now revert back to checkpoint1 storage.RevertCheckpoint("checkpoint1"); } Assert.AreEqual(Utilities.TableToString(fileName, "Report1"), "CheckpointID,SimulationID, Col1, Col2\r\n" + " 1, 1,2017-01-01, 1.000\r\n" + " 1, 1,2017-01-02, 2.000\r\n" + " 1, 2,2017-01-01,11.000\r\n" + " 1, 2,2017-01-02,12.000\r\n" + " 2, 1,2017-01-01, 1.000\r\n" + " 2, 1,2017-01-02, 2.000\r\n" + " 2, 2,2017-01-01,11.000\r\n" + " 2, 2,2017-01-02,12.000\r\n"); Assert.AreEqual(Utilities.TableToString(fileName, "_Checkpoints", new string[] { "ID", "Name" }), "ID, Name\r\n" + " 1, Current\r\n" + " 2,checkpoint1\r\n"); }
public void GetCheckpointFiles() { using (DataStore storage = new DataStore(fileName)) { CreateTable(storage); // Add a checkpoint File.WriteAllText("Dummy.txt", "abcde"); storage.AddCheckpoint("checkpoint1", new string[] { "Dummy.txt" }); var files = storage.GetCheckpointFiles("checkpoint1"); Assert.AreEqual(files.Count(), 1); Assert.AreEqual(files.ElementAt(0).fileName, "Dummy.txt"); Assert.AreEqual(System.Text.Encoding.UTF8.GetString(files.ElementAt(0).contents), "abcde"); } File.Delete("Dummy.txt"); }