private void exportMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var exportDict = new Dictionary <string, Sprite>();

            foreach (Sprite sprite in sprites)
            {
                if (exportDict.ContainsKey(sprite.Name))
                {
                    string            errorMessage = "Duplicate names found! Please ensure all sprites have unique names.";
                    string            caption      = "Save Aborted";
                    MessageBoxButtons saveError    = MessageBoxButtons.OK;

                    MessageBox.Show(errorMessage, caption, saveError);
                    return;
                }
                exportDict.Add(sprite.Name, sprite);
            }

            if (saveMapDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CurrentSpriteMapFileLocation = saveMapDialog.FileName;

                using (XmlWriter writer = XmlWriter.Create(CurrentSpriteMapFileLocation))
                {
                    IntermediateSerializer.Serialize(writer, exportDict, null);
                }
            }
        }
Ejemplo n.º 2
0
        public static T Serialize <T>(T data)
        {
            var stringBuilder = new StringBuilder();

            XmlWriterSettings settings = new XmlWriterSettings {
                Indent = true
            };

            using (XmlWriter writer = XmlWriter.Create(stringBuilder, settings))
            {
                IntermediateSerializer.Serialize(writer, data, null);
            }

            var xml = stringBuilder.ToString();

            Trace.WriteLine("-----------------------------");
            Trace.WriteLine(xml);
            Trace.WriteLine("-----------------------------");


            using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
            {
                return(IntermediateSerializer.Deserialize <T>(reader, null));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Serializes the specified ParticleEffect instance.
        /// </summary>
        /// <param name="effect">The ParticleEffect to be serialized.</param>
        /// <param name="filename">The desired output file name,</param>
        public void Serialize(ParticleEffect effect, string filename)
        {
            // Create a new xml document...
            XDocument xmlDocument = new XDocument();

            // Use the XNA serializer to populate the xml document...
            using (XmlWriter writer = xmlDocument.CreateWriter())
            {
                IntermediateSerializer.Serialize <ParticleEffect>(writer, effect, ".\\");
            }

            //// hack: Workaround for intermediate serializer not putting nodes in the right order...
            //foreach (XElement emitterElement in xmlDocument.Descendants("Asset").Elements("Item"))
            //{
            //    XElement releaseQuantityElement = emitterElement.Element("ReleaseQuantity");

            //    if ((releaseQuantityElement.PreviousNode as XElement).Name == "Name")
            //    {
            //        XElement termElement = emitterElement.Element("Term");

            //        termElement.AddAfterSelf(releaseQuantityElement);

            //        releaseQuantityElement.Remove();
            //    }
            //}

            // Save the xml document...
            xmlDocument.Save(filename);
        }
Ejemplo n.º 4
0
        private void saveAnimationSetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var animSet = new AnimationSet();

            foreach (Animation anim in animations)
            {
                if (animSet.Anims.ContainsKey(anim.Name))
                {
                    string            errorMessage = "Duplicate names found! Please ensure all animations have unique names.";
                    string            caption      = "Save Aborted";
                    MessageBoxButtons saveError    = MessageBoxButtons.OK;

                    MessageBox.Show(errorMessage, caption, saveError);
                    return;
                }
                else
                {
                    animSet.Add(anim);
                }
            }

            if (saveAnimationSetDialog.ShowDialog() == DialogResult.OK)
            {
                using (XmlWriter writer = XmlWriter.Create(saveAnimationSetDialog.FileName))
                {
                    IntermediateSerializer.Serialize(writer, animSet, null);
                }
            }
        }
Ejemplo n.º 5
0
 private static void SerializeCollection <T>(string filename, SpaceCollection <T> collection, XmlWriterSettings settings)
 {
     using (XmlWriter writter = XmlWriter.Create(String.Format("{0}.xml", filename), settings))
     {
         IntermediateSerializer.Serialize(writter, collection, null);
     }
 }
Ejemplo n.º 6
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            Stream         myStream       = null;
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = "c:\\";
            saveFileDialog.Filter           = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 2;
            saveFileDialog.RestoreDirectory = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = saveFileDialog.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            XmlWriterSettings s = new XmlWriterSettings();
                            s.Indent = true;
                            XmlWriter writer = XmlWriter.Create(myStream, s);
                            IntermediateSerializer.Serialize <Formation>(writer, mFormation, null);
                            writer.Close();
                            myStream.Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            Data d = new Data();

            d.Land = new List <LandData>();
            d.Land.Add(new LandData());

            LandData ld = new LandData();

            ld.DestRect = new Rectangle(1, 2, 3, 4);
            ld.Shape    = Shape.Sq;
            d.Land.Add(ld);

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create("Item.xml", settings))
                IntermediateSerializer.Serialize(writer, d, "Item.xml");

            Storage.SaveXml <Data>("Item2.xml", d);
        }
Ejemplo n.º 8
0
        public void Action(string[] args)
        {
            var dllPath   = args[1];
            var className = args[2];

            var asm = Assembly.LoadFile(dllPath);

            var inputType = asm.GetType(className);

            if (inputType == null)
            {
                Console.Error.WriteLine($"Can not found type {className} in assembly.");
                return;
            }

            var obj = Activator.CreateInstance(inputType);

            var xmlSettings = new XmlWriterSettings {
                Indent = true
            };
            var outputString = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(outputString, xmlSettings))
            {
                IntermediateSerializer.Serialize(xmlWriter, obj, null);
            }

            Console.WriteLine(outputString.ToString());
        }
Ejemplo n.º 9
0
        public int Execute()
        {
            var asm = Assembly.LoadFile(DllPath);

            var inputType = asm.GetType(ClassName);

            if (inputType == null)
            {
                Output.WriteError($"Can not found type {ClassName} in assembly.");
                return(ReturnCode.Failure);
            }

            var obj = Activator.CreateInstance(inputType);

            var xmlSettings = new XmlWriterSettings {
                Indent = true
            };
            var outputString = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(outputString, xmlSettings))
            {
                IntermediateSerializer.Serialize(xmlWriter, obj, null);
            }

            Output.WriteSuccess(outputString.ToString());
            return(ReturnCode.Success);
        }
Ejemplo n.º 10
0
        private void SerializeLevel()
        {
            string levelPath = "Textures/";

            Level level = new Level(int.Parse(datas["id"]));

            int[,] tiles = ParseLevel(datas["niveau"]);

            level.SetTiles2D(tiles);
            level.Width         = tiles.GetLength(0);
            level.Depth         = tiles.GetLength(1);
            level.WallTexture   = levelPath + datas["textureMur"];
            level.GroundTexture = levelPath + datas["textureSol"];
            level.TopTexture    = levelPath + datas["texturePlafond"];
            level.FinishTexture = levelPath + datas["textureArrivee"];
            level.SkyboxType    = (SkyboxType)skyboxType.SelectedIndex;
            level.BlockSizes    = new Size3(int.Parse(datas["tileWidth"]), int.Parse(datas["tileHeight"]), int.Parse(datas["tileDepth"]));
            tempLevel           = level;
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };

            using (XmlWriter writer = XmlWriter.Create(String.Format("level_{0}.xml", level.Id), settings))
            {
                IntermediateSerializer.Serialize <Level>(writer, level, null);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Writes the Object to the specified file in XNA format.
        /// Note that it only writes public data members unless with [ContentSerializer] tag.
        /// Editor Note: Remember the Microsoft.Xna.Framework.Content.Pipeline Reference.
        /// </summary>
        /// <param name="xObject">The object to be written.</param>
        /// <param name="FilePath">Location of file to be written.</param>
        public void WriteToXml(Object xObject, string FilePath)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(FilePath, settings))
            { IntermediateSerializer.Serialize(writer, xObject, null); }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Save this curve to given filename.
 /// </summary>
 /// <param name="filename"></param>
 public void Save(string filename)
 {
     using (XmlWriter xw = XmlWriter.Create(filename))
     {
         IntermediateSerializer.Serialize(xw, originalCurve,
                                          Path.GetDirectoryName(filename));
         dirty = false;
     }
 }
Ejemplo n.º 13
0
 private void saveAnimationToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (saveAnimationDialog.ShowDialog() == DialogResult.OK)
     {
         using (XmlWriter writer = XmlWriter.Create(saveAnimationDialog.FileName))
         {
             IntermediateSerializer.Serialize(writer, currentAnimation, null);
         }
     }
 }
Ejemplo n.º 14
0
        public static void Serialize <T>(string filename, T data)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(filename, settings))
            {
                IntermediateSerializer.Serialize <T>(writer, data, null);
            }
        }
Ejemplo n.º 15
0
        public static void Save <T>(string path, T obj)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            using (XmlWriter writer = XmlWriter.Create(path, settings))
            {
                IntermediateSerializer.Serialize <T>(writer, obj, null);
            }
        }
Ejemplo n.º 16
0
        public static void Serialize <T>(string filename, T objectToSerialize)
        {
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Indent = true;

            using (XmlWriter xmlWriter = XmlWriter.Create(filename, xmlSettings))
            {
                IntermediateSerializer.Serialize(xmlWriter, objectToSerialize, null);
            }
        }
Ejemplo n.º 17
0
        public void SaveToXML(object obj, string FileName)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(FileName + ".xml", settings))
            {
                IntermediateSerializer.Serialize(writer, obj, null);
            }
        }
Ejemplo n.º 18
0
        public static void MadeNewXml <T>(string name, T type)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(name + ".xml", settings))
            {
                IntermediateSerializer.Serialize(writer, type, null);
            }
        }
Ejemplo n.º 19
0
        public void Save(int levelNb)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create($"level{levelNb}.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, this, null);
            }
        }
Ejemplo n.º 20
0
        public static void WriteToFile(string filepath, object data)
        {
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(filepath, settings))
            {
                IntermediateSerializer.Serialize(writer, data, null);
            }
        }
Ejemplo n.º 21
0
        protected string BuildObject(object input, string processor, IDictionary <string, object> processorParameters)
        {
            var filename = Guid.NewGuid().ToString("B");

            using (var writer = XmlWriter.Create(filename + ".xml"))
            {
                IntermediateSerializer.Serialize(writer, input, null);
            }
            ContentBuilder.Add(filename + ".xml", null, null, processor, processorParameters);
            return(filename);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Serializes the specified particle effect to the specified file path.
        /// </summary>
        /// <param name="particleEffect">The particle effect to be serialized.</param>
        /// <param name="filePath">The path to the desired output file.</param>
        public void Serialize(ParticleEffect particleEffect, string filePath)
        {
            XDocument xmlDocument = new XDocument();

            using (XmlWriter writer = xmlDocument.CreateWriter())
            {
                IntermediateSerializer.Serialize <ParticleEffect>(writer, particleEffect, ".\\");
            }

            xmlDocument.Save(filePath);
        }
        private void SaveProject()
        {
            if (CurrentProjectFileLocation != null)
            {
                SpriteMapProject project = new SpriteMapProject(CurrentSpriteSheetFileLocation, sprites.ToList());

                using (XmlWriter writer = XmlWriter.Create(CurrentProjectFileLocation))
                {
                    IntermediateSerializer.Serialize(writer, project, null);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Saves all known factories back to file.
        /// </summary>
        public static void Save()
        {
            // In case we need to create new files.
            string baseFolder;

            // Ask for destination folder if we didn't load before.
            if (AttributePools.Count > 0 && AttributePoolFilenames.Count == 0)
            {
                // TODO
                //return;
                baseFolder = SavePath;
            }
            else
            {
                baseFolder = AttributePoolFilenames.Values.First().Replace('\\', '/');
                baseFolder = baseFolder.Substring(0, baseFolder.LastIndexOf('/') + 1);
            }

            object output;

            foreach (var attributePool in AttributePools.Values)
            {
                if (!AttributePoolFilenames.ContainsKey(attributePool))
                {
                    // No such factories yet, create new file.
                    var fileName = baseFolder + attributePool.GetType().Name + ".xml";
                    AttributePoolFilenames.Add(attributePool, fileName);
                }
            }
            // Yes. Create specific array.
            var array = Array.CreateInstance(AttributePools.Values.ElementAt(0).GetType(), AttributePools.Count);

            for (var i = 0; i < AttributePools.Values.Count; i++)
            {
                array.SetValue(AttributePools.Values.ElementAt(i), i);
            }
            output = array;
            using (var writer = new XmlTextWriter(AttributePoolFilenames[AttributePools.Values.ElementAt(0)], Encoding.UTF8))
            {
                writer.Formatting = Formatting.Indented;
                writer.WriteStartDocument();
                try
                {
                    IntermediateSerializer.Serialize(writer, output, null);
                }
                catch (InvalidContentException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
Ejemplo n.º 25
0
        /* The Save<T>() function is the opposite of Load<T>(). */
        public static void Save <T>(string path, T obj)
        {
            /* A new XmlWriterSettings object with Indent as true is created so that the serialized XML doesn't look horrible. */
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            /* Using a new XmlWriter and the settings, the object passed in is serialized to an XML file at the path passed in. */
            using (XmlWriter writer = XmlWriter.Create(path, settings))
            {
                IntermediateSerializer.Serialize <T>(writer, obj, null);
            }
        }
Ejemplo n.º 26
0
        public static void Teste(object o)
        {
            //GenericBuildingTest test = new GenericBuildingTest(1, 2, new Point(3, 5));

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(@"C:\teste\example" + o.GetType().ToString() + ".xml", settings))
            {
                IntermediateSerializer.Serialize(writer, o, null);
            }
        }
Ejemplo n.º 27
0
        public static void Teste()
        {
            GenericBuildingTestcs test = new GenericBuildingTestcs();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create(@"C:\teste\example.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, test, null);
            }
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            DataTypes.LevelType testData = new DataTypes.LevelType();

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;

            using (XmlWriter writer = XmlWriter.Create("tutorial2.xml", settings))
            {
                IntermediateSerializer.Serialize(writer, testData, null);
            }
        }
Ejemplo n.º 29
0
        private void SaveCurve_Click(object sender, RoutedEventArgs e)
        {
            var leaf = ((FrameworkElement)sender).DataContext as CurveTreeLeaf;

            if (leaf == null)
            {
                return;
            }

            //  Get the actual curve to save.
            var curve = leaf.Curve.Curve;

            if (curve == null)
            {
                return;
            }

            // Configure save file dialog box
            var dlg = new Microsoft.Win32.SaveFileDialog
            {
                FileName   = leaf.Curve.Name,
                DefaultExt = ".xml",
                Filter     = "Xml files (.xml)|*.xml"
            };

            // Show save file dialog box
            var result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result != true)
            {
                return;
            }

            // Write!
            using (var streamOut = new FileStream(dlg.FileName, FileMode.Create))
            {
                    #if XNA
                var settings = new XmlWriterSettings {
                    Indent = true, IndentChars = "  "
                };
                var writer = XmlWriter.Create(streamOut, settings);
                IntermediateSerializer.Serialize <Curve>(writer, curve, dlg.FileName);
                writer.Close();
                    #elif MONOGAME || FNA
                var formatter = new XmlSerializer(typeof(Curve));
                formatter.Serialize(streamOut, curve);
                    #endif
            }
        }
Ejemplo n.º 30
0
        public void OutputXml()
        {
            MemoryStream  ms = new MemoryStream();
            XmlTextWriter w  = new XmlTextWriter(ms, Encoding.UTF8);

            w.Formatting = Formatting.Indented;
            IntermediateSerializer.Serialize(w, this, "simple");
            w.Flush();
            ms.Seek(0, SeekOrigin.Begin);
            TextReader r = new StreamReader(ms);

            Console.Out.Write(r.ReadToEnd());
            Console.Out.WriteLine();
        }