Exemple #1
0
        static void Testing()
        {
            PersonXML  p1XML  = new PersonXML("Somebody", 15);
            PersonJSON p1JSON = new PersonJSON("Somebody2", 17);

            //PersonXML p2XML = null;
            //PersonJSON p2JSON = null;

            Serialization.SerializeBinary(p1JSON, fileNameBinJSON);
            Serialization.SerializeBinary(p1XML, fileNameBinXML);
            Serialization.SerializeBinaryT(p1JSON, fileNameBinJSON);
            Serialization.SerializeBinaryT(p1XML, fileNameBinXML);
            SerializationGeneric <PersonJSON> .SerializeBinary(p1JSON, fileNameBinJSON);

            SerializationGeneric <PersonXML> .SerializeBinary(p1XML, fileNameBinXML);

            var x1 = Serialization.DeserializeBinary(fileNameBinXML);
            var j1 = Serialization.DeserializeBinary(fileNameBinJSON);
            var x2 = SerializationGeneric <PersonXML> .DeserializeBinary(fileNameBinXML);

            var j2 = SerializationGeneric <PersonJSON> .DeserializeBinary(fileNameBinJSON);

            Serialization.SerializeJSON(p1JSON, fileNameJSON);
            Serialization.SerializeXML(p1XML, fileNameXML);
            var x3 = SerializationGeneric <PersonXML> .DeserializeXML(fileNameXML);

            var j3 = SerializationGeneric <PersonJSON> .DeserializeJSON(fileNameJSON);
        }
Exemple #2
0
        // Serialize

        void Save()
        {
            int age = 0;

            int.TryParse(AgeField.text, out age);

            _Person = new PersonNormal(NameField.text, age);

            // To Serialize we took only 1 lune too. :)

            if (SerType == SerializationType.Binary)
            {
                // To binary
                BinarySerializer.Serialize(_Person, Path, IsEncrypted);
            }
            else if (SerType == SerializationType.Json)
            {
                // To JSON
                JSONSerializer.SerializeToFile(_Person, Path, IsEncrypted);
            }
            else if (SerType == SerializationType.XML)
            {
                PersonXML xmlPerson = _Person;

                // To XML
                XMLSerializer.SerializeXML(xmlPerson, Path, IsEncrypted);
            }

            Debug.Log("Saved");
        }
Exemple #3
0
        public void Deserialize()
        {
            // десериализация
            XmlSerializer formatter = new XmlSerializer(typeof(PersonXML));

            using (FileStream fs = new FileStream("persons.xml", FileMode.OpenOrCreate))
            {
                PersonXML newPerson = (PersonXML)formatter.Deserialize(fs);

                Console.WriteLine("Объект десериализован");
                Console.WriteLine("Имя: {0} --- Пароль: {1}", newPerson.Name, newPerson.Password);
            }
        }
Exemple #4
0
        public static Level loadLevelXML(String fileName)
        {
            FileStream    fileStream = new FileStream(fileName, FileMode.Open);
            XmlSerializer xml        = new XmlSerializer(typeof(LevelXML));
            LevelXML      currentXML = (LevelXML)xml.Deserialize(fileStream);
            Level         newLevel   = new Level(currentXML.sizeX, currentXML.sizeY, currentXML.Name);

            newLevel.levelGrid = new Grid(currentXML.sizeX, currentXML.sizeY);
            newLevel.LevelName = currentXML.Name;
            foreach (RowXML row in currentXML.rows)
            {
                foreach (ColumnXML column in row.columns)
                {
                    newLevel.levelGrid.GridSpaces[row.index, column.index] = new GridSpace(column.type, row.index, column.index, column.elevation, newLevel.levelGrid);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index, column.index - 1, column.costNorth);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index + 1, column.index + (row.index % 2 == 0 ? -1 : 0), column.costNorthEast);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index + 1, column.index + (row.index % 2 == 0 ? 0 : 1), column.costSouthEast);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index, column.index + 1, column.costSouth);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index - 1, column.index + (row.index % 2 == 0 ? 0 : 1), column.costSouthWest);
                    newLevel.levelGrid.setMoveCost(row.index, column.index, row.index - 1, column.index + (row.index % 2 == 0 ? -1 : 0), column.costNorthWest);
                    if (column.hero != null)
                    {
                        HeroXML h = column.hero;
                        newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Hero(h.currentHP, h.maxHP, h.currentEnergy, h.maxEnergy, h.moveSpeed, h.level, h.currentXP, h.name, new Vector2(row.index, column.index)));
                    }
                    else if (column.person != null)
                    {
                        PersonXML p = column.person;
                        newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Person(p.currentHP, p.maxHP, p.currentEnergy, p.maxEnergy, p.moveSpeed, p.name, new Vector2(row.index, column.index)));
                    }
                    else if (column.actor != null)
                    {
                        ActorXML a = column.actor;
                        newLevel.levelGrid.GridSpaces[row.index, column.index].tryPutActor(new Actor());
                    }
                }
            }
            for (int i = 0; i < currentXML.sizeX; ++i)
            {
                for (int j = 0; j < currentXML.sizeY; ++j)
                {
                    if (newLevel.levelGrid.GridSpaces[i, j] == null)
                    {
                        newLevel.levelGrid.GridSpaces[i, j] = new GridSpace(0, i, j, 0, newLevel.levelGrid);
                    }
                }
            }
            fileStream.Close();
            return(newLevel);
        }
Exemple #5
0
        public void Serialize()
        {
            // объект для сериализации
            PersonXML person = new PersonXML("Alex", 565154485);

            Console.WriteLine("Объект создан");

            // передаем в конструктор тип класса
            XmlSerializer formatter = new XmlSerializer(typeof(PersonXML));

            // получаем поток, куда будем записывать сериализованный объект
            using (FileStream fs = new FileStream("persons.xml", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fs, person);

                Console.WriteLine("Объект сериализован");
            }
        }
Exemple #6
0
 private void LoadFromFile(String filename)
 {
     this.AddAll(PersonXML.ReadFromFile(filename));
 }
Exemple #7
0
 private void SaveToFile(String filename)
 {
     PersonXML.WriteToFile(people, filename);
 }
Exemple #8
0
 public void CreateUser(String username)
 {
     PersonXML.WriteToFile(new List <Person>(), DIRECTORY + "\\" + username + ".xml");
 }