private void ReadState() { if (File.Exists(stateFilePath)) { using (var fs = File.Open(stateFilePath, FileMode.Open, FileAccess.Read)) { using (var tr = new StreamReader(fs)) { using (var jr = new JsonTextReader(tr)) { var serializer = new JsonSerializer(); this.spec = serializer.Deserialize<Spec>(jr); } } } } else { this.spec = new Spec(); } }
public void SetState(Spec spec) { this.spec = spec; using (var fs = File.Open(stateFilePath, FileMode.OpenOrCreate, FileAccess.Write)) { using (var tw = new StreamWriter(fs)) { using (var jw = new JsonTextWriter(tw)) { jw.Indentation = 2; jw.IndentChar = ' '; jw.Formatting = Formatting.Indented; var serializer = new JsonSerializer(); serializer.Serialize(jw, this.spec); } } } }