public static Bookmark LoadBookmark(Uri uri) { using (var stream = File.OpenRead(uri.LocalPath)) { var schemaLoader = Globals.MEFContainer.GetExport <ISchemaLoader>().Value; var reader = new CustomDomXmlReader(uri, schemaLoader as XmlSchemaTypeLoader); var opaqueNode = reader.Read(stream, uri); return(opaqueNode.As <Bookmark>()); } }
public static XLEPlacementDocument OpenOrCreate(Uri uri, ISchemaLoader schemaLoader) { if (!uri.IsAbsoluteUri) { return(null); } var docRegistry = GetDocRegistry(); if (docRegistry != null) { var existing = docRegistry.FindDocument(uri); if (existing != null) { return(null); // prevent a second reference here } } string filePath = uri.LocalPath; bool createdNewFile = false; DomNode rootNode = null; if (File.Exists(filePath)) { // read existing document using custom dom XML reader using (FileStream stream = File.OpenRead(filePath)) { var reader = new CustomDomXmlReader(uri, schemaLoader as XmlSchemaTypeLoader); rootNode = reader.Read(stream, uri); } } else { // create new document by creating a Dom node of the root type defined by the schema rootNode = new DomNode(Schema.placementsDocumentType.Type, Schema.placementsDocumentRootElement); createdNewFile = true; } var doc = rootNode.As <XLEPlacementDocument>(); doc.Uri = uri; // Initialize Dom extensions now that the data is complete rootNode.InitializeExtensions(); // sync all the prefab instances { UniqueNamer uniqueNamer = new UniqueNamer('_'); foreach (var prefab in doc.As <DomNode>().Subtree.AsIEnumerable <IPrefabInstance>()) { prefab.Resolve(uniqueNamer); } } if (docRegistry != null) { docRegistry.Add(doc); } doc.Dirty = createdNewFile; return(doc); }