public void CreateEmptyFile(string FileName) { List<Message> m = new List<Message>(); List<Prescription> p = new List<Prescription>(); DocumentSerializable d = new DocumentSerializable(m, p); string path = GetPathFile(FileName); SerializeListDoc(d, path); }
public Data getUser(string pseudo, string password) { int id = _db.SelectRequest.SelectUser(pseudo, password).UserId; DocumentManager _doc = new DocumentManager(_db); DocumentSerializable doc; Dictionary<Patient, Professional[]> follower = _db.SelectRequest.SelectAllFollow(id); User user = _db.SelectRequest.SelectUser(id); Professional test = _db.SelectRequest.SelectProfessional(id); if (test == null) { doc = _doc.SeeDocument(id); } else { doc = new DocumentSerializable(new List<Message>(), new List<Prescription>()); //follower.Select(p => follower.Keys). foreach (var patient in follower) { foreach (var message in _doc.SeeDocument(id, patient.Key.PatientId).Messages) { doc.Messages.Add(message); } foreach (var prescription in _doc.SeeDocument(id, patient.Key.PatientId).Prescriptions) { doc.Prescriptions.Add(prescription); } } } Data swag = new Data(doc, follower, user); return swag; }
public DocumentSerializableXML CreateDocuments(DocumentSerializable documents) { DocumentSerializableXML d = new DocumentSerializableXML(); d.Message = CreateMessagesList(documents.Messages); d.Prescription = CreatePrescriptionList(documents.Prescriptions); return d; }
private DocumentSerializable DeserializeListDoc(string FilePath) { List<Message> m = new List<Message>(); List<Prescription> p = new List<Prescription>(); DocumentSerializable d = new DocumentSerializable(m, p); Stream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); try { BinaryFormatter formatter = new BinaryFormatter(); DocumentSerializable newdoc = (DocumentSerializable)formatter.Deserialize(fileStream); foreach(var message in newdoc.Messages) { d.Messages.Add(message); } foreach (var prescription in newdoc.Prescriptions) { d.Prescriptions.Add(prescription); } } catch (SerializationException e) { Console.WriteLine("Failed to deserialize. Reason: " + e.Message); throw; } finally { fileStream.Close(); } return d; }
private void SerializeListDoc(DocumentSerializable Documents, string FilePath) { Stream fileStream = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None); BinaryFormatter formatter = new BinaryFormatter(); try { formatter.Serialize(fileStream, Documents); } catch (SerializationException e) { Console.WriteLine("Failed to serialize. Reason: " + e.Message); throw; } finally { fileStream.Close(); } }