/// <summary> /// The main entry point for the application</summary> private static void Main(string[] args) { string ExecutablePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var gameSchemaLoader = new GameSchemaLoader(); DomNode game = null; // create game either using DomNode or DomNodeAdapter. game = CreateGameUsingDomNode(); //game = CreateGameUsingDomNodeAdapter(); Print(game); // create directory for data files Directory.CreateDirectory(Path.Combine(ExecutablePath, @"data")); string filePath = Path.Combine(ExecutablePath, "data\\game.xml"); var gameUri = new Uri(filePath); // save game. FileMode fileMode = FileMode.Create; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(gameSchemaLoader.TypeCollection); writer.Write(game, stream, gameUri); } }
private void WriteToDisk() { if (!m_bDirty) { return; } try { if (m_collection == null) { return; } if (m_collection.ProfileInfo.Count <= 0) { return; } var schemaLoader = SledServiceInstance.Get <SledSharedSchemaLoader>(); if (schemaLoader == null) { return; } var projDir = m_projectService.Get.ProjectDirectory; var filePath = Path.Combine( projDir + Path.DirectorySeparatorChar, m_collection.Name + ".xml"); var uri = new Uri(filePath); using (var stream = new FileStream(uri.LocalPath, FileMode.Create, FileAccess.Write)) { var writer = new DomXmlWriter(schemaLoader.TypeCollection); writer.Write(m_collection.DomNode, stream, uri); } } catch (Exception ex) { SledOutDevice.OutLine( SledMessageType.Error, "[SledLuaProfilerService] Failure to " + "save profiler data to disk: {0}", ex.Message); } finally { m_bDirty = false; } }
/// <summary> /// Saves the document at the given URI</summary> /// <param name="document">Document to save</param> /// <param name="uri">New document URI</param> public void Save(IDocument document, Uri uri) { Document doc = document as Document; string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(m_schemaLoader.TypeCollection); writer.Write(doc.DomNode, stream, uri); } }
/// <summary> /// Saves the document at the given URI</summary> /// <param name="document">Document to save</param> /// <param name="uri">New document URI</param> public void Save(IDocument document, Uri uri) { string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(m_schemaLoader.TypeCollection); WinGuiCommonDataDocument eventSequenceDocument = (WinGuiCommonDataDocument)document; writer.Write(eventSequenceDocument.DomNode, stream, uri); } }
private void DomNode_AttributeChanged(object sender, AttributeEventArgs e) { SchemaLoader schemaTypeLoader = Globals.MEFContainer.GetExportedValue <SchemaLoader>(); string filePath = Uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { var writer = new DomXmlWriter(schemaTypeLoader.TypeCollection); writer.Write(DomNode, stream, Uri); } }
/// <summary> /// Saves the document at the given URI</summary> /// <param name="document">Document to save</param> /// <param name="uri">New document URI</param> public void Save(IDocument document, Uri uri) { string filePath = uri.LocalPath; FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate; using (FileStream stream = new FileStream(filePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(m_schemaLoader.TypeCollection); StoryDocument storyDocument = (StoryDocument)document; if (storyDocument != null) { storyDocument.Write(); writer.Write(storyDocument.DomNode, stream, uri); } } }
private void SaveActiveDocument() { if (m_activeDocument == null || m_activeDocument.Uri == null) { return; } FileMode fileMode = FileMode.Create; using (FileStream stream = new FileStream(m_activeDocument.Uri.AbsolutePath, fileMode)) { DomXmlWriter writer = new DomXmlWriter(s_schemaLoader.TypeCollection); writer.Write(m_activeDocument.DomNode, stream, m_activeDocument.Uri); } m_activeDocument.Dirty = false; }
public void TestDomXmlWriterPicksCorrectSubstitutions() { var loader = GetSchemaLoader(); DomNode node; string output; const string testDoc = @"<?xml version=""1.0"" encoding=""utf-8""?> <root xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns=""test""> <basic name=""something"" /> <middle name=""some-other-thing"" special=""true"" /> <descendant name=""leaf-thing"" special=""true"" extra=""important"" /> <container name=""some-container""> <middle name=""some-nested-thing"" /> <middle name=""some-other-nested-thing"" special=""true"" /> </container> </root>"; using (Stream s = CreateStreamFromString(testDoc)) { DomXmlReader reader = new DomXmlReader(loader); node = reader.Read(s, null); } Assert.AreEqual(4, node.Children.Count()); var children = node.Children.ToList(); Assert.AreEqual("test:basicType", children[0].Type.Name); Assert.AreEqual("test:middleType", children[1].Type.Name); Assert.AreEqual("test:descendantType", children[2].Type.Name); Assert.AreEqual("test:containerType", children[3].Type.Name); using (MemoryStream s = new MemoryStream()) { DomXmlWriter writer = new DomXmlWriter(loader.GetTypeCollection("test")); writer.Write(node, s, null); output = Encoding.UTF8.GetString(s.ToArray()); } Assert.AreEqual(testDoc, output); }
public void Write(Stream stream) { var writer = new DomXmlWriter(s_schemaLoader.TypeCollection); writer.Write(DomNode, stream, Uri); }