public override bool OpenFile(String fileName, ref FamilyTreeStoreBaseClass inFamilyTree, CompletedCallback callback) { //FamilyTreeStoreRam ramStore = (FamilyTreeStoreRam)inFamilyTree; trace.TraceInformation("XmlFileType::OpenFile( " + fileName + ") start " + DateTime.Now); FileStream fileStream = new FileStream(fileName, FileMode.Open); if (fileStream != null) { //DataContractSerializer serializer = new DataContractSerializer(typeof(FamilyTreeStoreRam)); DataContractSerializer serializer = new DataContractSerializer(inFamilyTree.GetType()); try { inFamilyTree = (FamilyTreeStoreBaseClass)serializer.ReadObject(fileStream); } catch (SerializationException e) { trace.TraceInformation("Exceptions:" + e.ToString()); inFamilyTree = null; } catch (ArgumentNullException e) { trace.TraceInformation("Exceptions:" + e.ToString()); inFamilyTree = null; } fileStream.Close(); } trace.TraceInformation("XmlFileType::OpenFile( " + fileName + ") done " + DateTime.Now); //anarkivStore.SetFile(fileName); callback(true); return(true); }
public void StoreFile(FamilyTreeStoreBaseClass familyTree, string filename, FamilyFileTypeOperation operation, int variant = 0) { trace.TraceInformation("XmlEncoder::StoreFile() start " + DateTime.Now); FileStream fileStream = new FileStream(filename, FileMode.Create); DataContractSerializer serializer = new DataContractSerializer(familyTree.GetType()); serializer.WriteObject(fileStream, familyTree); fileStream.Close(); trace.TraceInformation("XmlEncoder::StoreFile() done " + DateTime.Now); }
public override bool OpenFile(String fileName, ref FamilyTreeStoreBaseClass inFamilyTree, CompletedCallback callback) { FamilyTreeStoreAnarkiv anarkivStore; if (inFamilyTree.GetType() == typeof(FamilyTreeStoreAnarkiv)) { anarkivStore = (FamilyTreeStoreAnarkiv)inFamilyTree; } else { anarkivStore = (FamilyTreeStoreAnarkiv)CreateFamilyTreeStore(fileName, callback); ReadFile(ref inFamilyTree, anarkivStore); } trace.TraceInformation("AnarkivFileType::OpenFile( " + fileName + ")"); anarkivStore.SetFile(fileName); callback(true); return(true); }