/// <summary> /// Чтение данных /// </summary> public void LoadData() { try { //Отчего-то фишка как с сериализацией не прокатила(хотя в потоке все нормально) //так что костыли - наше все XmlSerializer formatter = new XmlSerializer(typeof(ClassData)); GoogleDriveClass driveClass = new GoogleDriveClass(); driveClass.Authorize(); MemoryStream stream = driveClass.FileRead(driveClass.GetFileId("Data.txt")); FileStream file = new FileStream("TempData.xml", FileMode.OpenOrCreate); stream.Seek(0, SeekOrigin.Begin); stream.CopyTo(file); file.Close(); using (FileStream fs = new FileStream("TempData.xml", FileMode.OpenOrCreate)) //using (XmlWriter xmlWriter = new XmlTextWriter(fs, Encoding.UTF8)) { ClassData classData = (ClassData)formatter.Deserialize(fs); this.calendar = classData.calendar; this.diary = classData.diary; this.finansialAssistant = classData.finansialAssistant; this.information = classData.information; this.notes = classData.notes; this.photo = classData.photo; this.plants = classData.plants; this.routineDay = classData.routineDay; this.test = classData.test; } File.Delete("TempData.xml"); } catch { } }
/// <summary> /// Сохранение данных /// </summary> public void SaveData() { XmlSerializer formatter = new XmlSerializer(typeof(ClassData)); MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, this); GoogleDriveClass driveClass = new GoogleDriveClass(); driveClass.Authorize(); driveClass.FileUpdate("Data.txt", stream); //using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate)) //using (XmlWriter xmlWriter = new XmlTextWriter(fs, Encoding.UTF8)) //{ // formatter.Serialize(fs, this); //} }