public void LoadOPC() { // Loading, clear existing nodes this.UMLCollection.Clear(); try { // Use the default path and filename if none were provided if (string.IsNullOrEmpty(this.FullyQualifiedFilename)) { this.FullyQualifiedFilename = UML.DefaultFullyQualifiedFilename; } string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), GlobalData.ApplicationFolderName); tempFolder = Path.Combine(tempFolder, GlobalData.AppDataFolderName + @"\"); OPCUtility.ExtractPackage(FullyQualifiedFilename, tempFolder); XmlSerializer xml = new XmlSerializer(typeof(UML)); using (Stream stream = new FileStream(tempFolder + OPCContentFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { UML pc = (UML)xml.Deserialize(stream); stream.Close(); foreach (Shape shape in pc.UMLCollection) { this.UMLCollection.Add(shape); } // To avoid circular references when serializing family data to xml, only the person Id // is seralized to express relationships. When family data is loaded, the correct // person object is found using the person Id and assigned to the appropriate relationship. foreach (Shape p in this.UMLCollection) { foreach (Relationship r in p.Relationships) { r.RelationTo = this.UMLCollection.Find(r.ShapeId); } } // Set the current person in the list this.CurrentShapeId = pc.CurrentShapeId; this.CurrentShapeName = pc.CurrentShapeName; this.UMLCollection.Current = this.UMLCollection.Find(this.CurrentShapeId); } this.UMLCollection.IsDirty = false; return; } catch { // Could not load the file. Handle all exceptions // the same, ignore and continue. this.fullyQualifiedFilename = string.Empty; } }
public void LoadVersion2() { // Loading, clear existing nodes this.UMLCollection.Clear(); try { // Use the default path and filename if none were provided if (string.IsNullOrEmpty(this.FullyQualifiedFilename)) { this.FullyQualifiedFilename = UML.DefaultFullyQualifiedFilename; } XmlSerializer xml = new XmlSerializer(typeof(UML)); using (Stream stream = new FileStream(this.FullyQualifiedFilename, FileMode.Open, FileAccess.Read, FileShare.Read)) { UML pc = (UML)xml.Deserialize(stream); stream.Close(); foreach (Shape shape in pc.UMLCollection) { this.UMLCollection.Add(shape); } // Setup temp folders for this family to be packaged into OPC later string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), GlobalData.ApplicationFolderName); tempFolder = Path.Combine(tempFolder, GlobalData.AppDataFolderName); RecreateDirectory(tempFolder); string photoFolder = Path.Combine(tempFolder, Photo.Const.PhotosFolderName); RecreateDirectory(photoFolder); string storyFolder = Path.Combine(tempFolder, GlobalData.CommentsFolderName); RecreateDirectory(storyFolder); foreach (Shape p in this.UMLCollection) { // To avoid circular references when serializing family data to xml, only the person Id // is seralized to express relationships. When family data is loaded, the correct // person object is found using the person Id and assigned to the appropriate relationship. foreach (Relationship r in p.Relationships) { r.RelationTo = this.UMLCollection.Find(r.ShapeId); } // store the stories into temp directory to be packaged into OPC later foreach (Photo photo in p.Photos) { string photoOldPath = Path.Combine(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), GlobalData.ApplicationFolderName), photo.RelativePath); if (File.Exists(photoOldPath)) { string photoFile = Path.Combine(photoFolder, Path.GetFileName(photo.FullyQualifiedPath)); // Remove spaces since they'll be packaged as %20, breaking relative paths that expect spaces photoFile = photoFile.Replace(" ", ""); photo.RelativePath = photo.RelativePath.Replace(" ", ""); File.Copy(photoOldPath, photoFile, true); } } if (p.Comments != null) { string storyOldPath = Path.Combine(Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), GlobalData.ApplicationFolderName), p.Comments.RelativePath); if (File.Exists(storyOldPath)) { string storyFile = Path.Combine(storyFolder, Path.GetFileName(p.Comments.AbsolutePath)); // Remove spaces since they'll be packaged as %20, breaking relative paths that expect spaces storyFile = ReplaceEncodedCharacters(storyFile); p.Comments.RelativePath = ReplaceEncodedCharacters(p.Comments.RelativePath); File.Copy(storyOldPath, storyFile, true); } } } // Set the current person in the list this.CurrentShapeId = pc.CurrentShapeId; this.CurrentShapeName = pc.currentShapeName; this.UMLCollection.Current = this.UMLCollection.Find(this.CurrentShapeId); } this.UMLCollection.IsDirty = false; return; } catch (Exception) { // Could not load the file. Handle all exceptions // the same, ignore and continue. this.fullyQualifiedFilename = string.Empty; } }