/// <summary> /// Loads, saves and checks if it's equal /// </summary> /// <param name="stateName">State name</param> public static void LoadSaveAndAssert(string stateName) { MemoryStream streamExpected = new MemoryStream(); MemoryStream streamCurrent = new MemoryStream(); using (Stream streamTemp = OpenStateFromResources(stateName)) { streamTemp.CopyTo(streamExpected); } streamExpected.Position = 0; streamCurrent.Position = 0; SimulationBase sim = SimulationBase.LoadFromStream(streamExpected); SimulationBase.SaveToStream(streamCurrent, sim); streamExpected.Position = 0; streamCurrent.Position = 0; SHA1Managed hash = new SHA1Managed(); byte[] hashExpected = hash.ComputeHash(streamExpected); byte[] hashCurrent = hash.ComputeHash(streamCurrent); AssertArraysEqual(hashExpected, hashCurrent); }
private void OnSaveButtonClick(object sender, EventArgs e) { if (simulation == null) { return; } using (SaveFileDialog dialog = new SaveFileDialog()) { const string ext = ".trs"; dialog.Filter = "Simulation State File (*" + ext + ")|*" + ext; dialog.FilterIndex = 0; dialog.RestoreDirectory = true; dialog.Title = "Save state as…"; dialog.FileName = "Untitled" + ext; if (dialog.ShowDialog(this) != DialogResult.OK) { return; } string filename = dialog.FileName; using (FileStream s = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.None)) { SimulationBase.SaveToStream(s, simulation); } } }