Exemplo n.º 1
0
        /// <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);
            }
        }  
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
        public static void SaveDomDocument(DomNode node, Uri uri, ISchemaLoader schemaLoader)
        {
            string filePath = uri.LocalPath;

            Directory.CreateDirectory(new FileInfo(filePath).Directory.FullName);       // (make sure the directory exists)
            FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate;

            using (FileStream stream = new FileStream(filePath, fileMode))
            {
                // note --  "LevelEditor" project has a ComstDomXmlWriter object that contains some
                //          special case code for certain node types. We're just using the default
                //          DomXmlWriter, so we won't benefit from that special behaviour.
                var writer = new Sce.Atf.Dom.DomXmlWriter(schemaLoader.TypeCollection);
                writer.Write(node, stream, uri);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 /// <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);
         Document fsmDocument = (Document)document;
         writer.Write(fsmDocument.DomNode, stream, uri);
     }
 }
Exemplo n.º 6
0
 public void Write(Stream stream)
 {
     var writer = new DomXmlWriter(s_schemaLoader.TypeCollection);
     writer.Write(DomNode, stream, Uri);
 }
Exemplo n.º 7
0
 public static void SaveDomDocument(DomNode node, Uri uri, ISchemaLoader schemaLoader)
 {
     string filePath = uri.LocalPath;
     Directory.CreateDirectory(new FileInfo(filePath).Directory.FullName);       // (make sure the directory exists)
     FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.OpenOrCreate;
     using (FileStream stream = new FileStream(filePath, fileMode))
     {
         // note --  "LevelEditor" project has a ComstDomXmlWriter object that contains some
         //          special case code for certain node types. We're just using the default
         //          DomXmlWriter, so we won't benefit from that special behaviour.
         var writer = new Sce.Atf.Dom.DomXmlWriter(schemaLoader.TypeCollection);
         writer.Write(node, stream, uri);
     }
 }