private void XMLSaveLoad() { //XML serialization---------------------------------------------------------------------------- //By far the simplest and easiest method. But is it really the most feasible?? //string xmlPath = "C:\\Users\\rforzisi\\Documents\\Test Projects\\StorageTesting\\XmlStorage.ICPWorksheet"; string rootProgramDirectory = AppDomain.CurrentDomain.BaseDirectory; string allExercisesXmlFilename = "XMLStorage.ICPWorksheet"; string xmlPath = rootProgramDirectory + allExercisesXmlFilename; watch.Start(); XmlHelper.ToXmlFile(worksheetIn, xmlPath); worksheetOut = XmlHelper.FromXmlFile <ExampleWorksheet2>(xmlPath); ListViewItems.Add("XML Create/load time = " + watch.Elapsed); watch.Restart(); //for (int i = 0; i < worksheetIn.Solutions.Count; i++) //{ // //worksheetIn.Solutions.ElementAtOrDefault(i).SolutionName = "We are all the same"; // XmlHelper.ToXmlFile(worksheetIn, xmlPath); // worksheetOut = XmlHelper.FromXmlFile<ExampleWorksheet2>(xmlPath); //i know this is only going to keep the last one but mehhh //} ListViewItems.Add("XML update time = " + watch.Elapsed); string written = XmlHelper.ToXml(worksheetIn); //ListViewItems.Add("Total Chars written: " + written.Length); int lineCount = written.Length - written.Replace("\r\n", "").Length; //ListViewItems.Add("Total Lines written: " + lineCount); watch.Reset(); }
private void XMLSaveLoadEncrypt() { //XML serialization with Encryption ---------------------------------------------------------------------------- //Still pretty simple and easy. plus adds a detail of encryption so you cant sneakily change results string xmlPath = "C:\\Users\\rforzisi\\Documents\\Test Projects\\StorageTesting\\XmlStorageEncrypted.ICPWorksheet"; watch.Start(); string toEncrypt = XmlHelper.ToXml(worksheetIn); //string toEncrypt = "Test"; string Testout = ""; string toWrite = EncryptionHelper.EncryptString(toEncrypt, "Password"); File.WriteAllText(xmlPath, toWrite); string read = File.ReadAllText(xmlPath); string decrypted = EncryptionHelper.DecryptString(read, "Password"); worksheetOut = XmlHelper.FromXml <ExampleWorksheet2>(decrypted); watch.Stop(); ListViewItems.Add("Write/Read time:" + watch.Elapsed); ListViewItems.Add("Total Chars written: " + toEncrypt.Length); int lineCount = toEncrypt.Length - toEncrypt.Replace("\r\n", "").Length; ListViewItems.Add("Total Lines written: " + lineCount); watch.Reset(); }