public void Save() { Console.WriteLine($"Saving originator state in memento. Name: {Originator.StateName}"); SnapShotModels.Add(Originator.Save()); //maybe bad format //using (FileStream fs = new FileStream($@"E:\studying\education\6сем\трпз\lab1\files\lab1\lab3_States\CareTaker.json", FileMode.OpenOrCreate)) //{ // await JsonSerializer.SerializeAsync<CareTaker>(fs, this); // Console.WriteLine("CareTaker has been saved to json file"); //} //JsonSerializer serializer = new JsonSerializer(); //serializer.NullValueHandling = NullValueHandling.Ignore; //using (StreamWriter sw = new StreamWriter(@"E:\studying\education\6сем\трпз\lab1\files\lab1\lab3_States\CareTakerNetSoft.json")) //using (JsonWriter writer = new JsonTextWriter(sw)) //{ // serializer.Serialize(writer, this); //} //datacontractJsonSerialization DataContractSerialization(FileMode.OpenOrCreate); }
public void Compare(string name) { var model = SnapShotModels.Find(o => o.StateName == name); if (model.MyHtmlModel.HTML == Originator.MyHtmlModel.HTML) { Console.WriteLine($"SnapShot with state name{Originator.StateName} is the same as SnapShot with state name {name}"); } else { Console.WriteLine($"SnapShot with state name{Originator.StateName} is not the same as SnapShot with state name {name}"); } }
public void Restore(string stateName) { if (SnapShotModels.Count > 0) { var model = SnapShotModels.Find(o => o.StateName == stateName); Console.WriteLine($"Restoring to state {model.StateName}"); try { Originator.Restore(model); DataContractSerialization(FileMode.Create); } catch (Exception e) { Console.WriteLine(e); } } else { return; } }