예제 #1
0
        protected override void Save()
        {
            XMLAbstraction xml = new XMLAbstraction("Material");

            xml.AddNode("Shader", shader.ID.ToString());
            var uniformsNode = xml.AddNode("Uniforms");

            foreach (Shader.Uniform u in Uniforms)
            {
                if (u.value != null)
                {
                    var uniformNode = uniformsNode.AddNode("Uniform");
                    uniformNode.AddAttribute("name", u.name);
                    uniformNode.AddAttribute("type", u.type.FullName);
                    if (u.type.IsSubclassOf(typeof(Asset)))
                    {
                        TypeSerialization.SerializePrimitiveType((u.value as Asset).ID, uniformNode.node, xml.xml);
                    }
                    else
                    {
                        TypeSerialization.SerializeType(u.value, uniformNode.node, xml.xml);
                    }
                }
            }
            xml.Save(Path);
        }
예제 #2
0
    //Insert post into today's XML file
    public void InsertPost(BlogPost newPost)
    {
        TypeSerialization ts  = new TypeSerialization();
        XMLIOHandler      xio = new XMLIOHandler();

        if (String.IsNullOrEmpty(newPost.ID))
        {
            newPost.ID = GeneratePostID();
        }
        System.Collections.Generic.List <BlogPost> newPostCol = new System.Collections.Generic.List <BlogPost>();
        newPostCol.Add(newPost);
        if (System.IO.File.Exists(dataPath + "\\" + GetOwningXMLFileName(newPost.ID)))
        {
            foreach (BlogPost oldPost in ts.DeSerializePosts(xio.GetXMLString(GetOwningXMLFileName(newPost.ID))))
            {
                newPostCol.Add(oldPost);
            }
        }
        if (System.IO.File.Exists(dataPath + GetOwningXMLFileName(newPost.ID)))
        {
            xio.RmDataFile(GetOwningXMLFileName(newPost.ID));
        }
        if (newPostCol.Count > 0)
        {
            xio.WriteXML(ts.SerializeGenericObject(newPostCol), GetOwningXMLFileName(newPost.ID));
        }
    }
예제 #3
0
    public System.Collections.Generic.List <BlogPost> GetPostsForPage(int pageNumber)
    {
        XMLIOHandler      xio = new XMLIOHandler();
        TypeSerialization ts  = new TypeSerialization();

        System.Collections.Generic.List <BlogPost> postCol = new System.Collections.Generic.List <BlogPost>();
        foreach (string fileName in GetAllBlogFiles())
        {
            foreach (BlogPost tempPost in ts.DeSerializePosts(xio.GetXMLString(fileName)))
            {
                if (postCol.Count <= 10)
                {
                    postCol.Add(tempPost);
                }
                else
                {
                    break;
                }
            }
            if (postCol.Count >= 10)
            {
                break;
            }
        }
        return(postCol);
    }
예제 #4
0
 public void Setup()
 {
     m_r = new TypeRegistry();
     m_r.AddSerialization(TypeSerialization.Create(
                              Single3.Serialize
                              , new Single3.Single3Deserializer()
                              ));
 }
예제 #5
0
        private void LoadEntity(XmlNode entityNode, Tree <Entity> .Branch <Entity> parent)
        {
            bool   active = Convert.ToBoolean(entityNode.Attributes["active"].Value);
            string name   = entityNode.Attributes["name"].Value;
            int    layer  = Convert.ToInt32(entityNode.Attributes["layer"].Value);
            int    id     = Convert.ToInt32(entityNode.Attributes["id"].Value);
            Entity entity;

            Tree <Entity> .Branch <Entity> currentBranch;
            if (parent != null)
            {
                currentBranch = parent.AddItem(new Entity(id, name));
            }
            else
            {
                currentBranch = hierarchy.AddItem(new Entity(id, name));
            }
            entity = currentBranch.Value;
            entity.SetActive(active);
            entity.Layer = layer;

            //Tags
            XmlNodeList tagNodes = entityNode.SelectNodes("Tags/Tag");

            foreach (XmlNode t in tagNodes)
            {
                entity.tags.Add(t.InnerText);
            }

            //Transform
            entity.transform.position = TypeSerialization.DeserializeVector3(entityNode.SelectSingleNode("Transform/Position"));
            entity.transform.rotation = TypeSerialization.DeserializeQuaternion(entityNode.SelectSingleNode("Transform/Rotation"));
            entity.transform.scale    = TypeSerialization.DeserializeVector3(entityNode.SelectSingleNode("Transform/Scale"));

            //Components
            XmlNodeList componentNodes = entityNode.SelectNodes("Components/*[local-name()='Component']");

            foreach (XmlNode c in componentNodes)
            {
                LoadComponent(c, entity);
            }

            //Child Entities
            XmlNodeList childNodes = entityNode.SelectNodes("Children/*[local-name()='Entity']");

            foreach (XmlNode ce in childNodes)
            {
                LoadEntity(ce, currentBranch);
            }

            entity.Init();
        }
예제 #6
0
        private void SaveEntity(Tree <Entity> .Branch <Entity> branch, XMLAbstraction.Node parent)
        {
            //Entity Header
            var entityNode = parent.AddNode("Entity");

            entityNode.AddAttribute("active", branch.Value.active.ToString());
            entityNode.AddAttribute("name", branch.Value.name.ToString());
            entityNode.AddAttribute("layer", branch.Value.Layer.ToString());
            entityNode.AddAttribute("id", branch.Value.ID.ToString());

            //Tags
            var tagsNode = entityNode.AddNode("Tags");

            foreach (string t in branch.Value.tags)
            {
                tagsNode.AddNode("Tag", t);
            }

            //Transform
            var transformNode = entityNode.AddNode("Transform");

            //Position
            TypeSerialization.SerializeVector3(branch.Value.transform.position, transformNode.AddNode("Position").node, transformNode.xml);
            //Rotation
            TypeSerialization.SerializeQuaternion(branch.Value.transform.rotation, transformNode.AddNode("Rotation").node, transformNode.xml);
            //Scale
            TypeSerialization.SerializeVector3(branch.Value.transform.scale, transformNode.AddNode("Scale").node, transformNode.xml);

            //Components
            var componentsNode = entityNode.AddNode("Components");

            foreach (Component c in branch.Value.components)
            {
                SaveComponent(c, componentsNode);
            }

            //Child Entities
            var childrenNode = entityNode.AddNode("Children");

            if (branch.BranchCount > 0)
            {
                foreach (var b in branch.Branches)
                {
                    SaveEntity(b, childrenNode);
                }
            }
        }
예제 #7
0
    //Deletes post with the ID passed.  This function reads in existing XML from owning XML file,
    //rebuilds the collection without the deleted post, deletes the owning XML file, and rewrites
    //the owning XML file with the same name.
    public void DeletePostByID(string postID)
    {
        XMLIOHandler      xio = new XMLIOHandler();
        TypeSerialization ts  = new TypeSerialization();

        System.Collections.Generic.List <BlogPost> newPostCol = new System.Collections.Generic.List <BlogPost>();
        foreach (BlogPost tempPost in ts.DeSerializePosts(xio.GetXMLString(GetOwningXMLFileName(postID))))
        {
            if (tempPost.ID != postID)
            {
                newPostCol.Add(tempPost);
            }
        }
        xio.RmDataFile(GetOwningXMLFileName(postID));
        if (newPostCol.Count > 0)
        {
            xio.WriteXML(ts.SerializeGenericObject(newPostCol), GetOwningXMLFileName(postID));
        }
    }
예제 #8
0
    public System.Collections.Generic.List <BlogPost> GetPostsForDay(System.DateTime requestedDate)
    {
        XMLIOHandler      xio = new XMLIOHandler();
        TypeSerialization ts  = new TypeSerialization();

        System.Collections.Generic.List <BlogPost> retPosts = new System.Collections.Generic.List <BlogPost>();
        if (System.IO.File.Exists(dataPath + "\\" + GetXMLFileForDay(requestedDate)))
        {
            retPosts = ts.DeSerializePosts(xio.GetXMLString(GetXMLFileForDay(requestedDate)));
        }
        if (retPosts.Count > 0)
        {
            return(retPosts);
        }
        else
        {
            return(ts.DeSerializePosts(xio.GetXMLString("20070101.xml")));
        }
    }
예제 #9
0
    //Gets post from passed ID
    public BlogPost GetPostById(string postID)
    {
        XMLIOHandler      xio       = new XMLIOHandler();
        TypeSerialization ts        = new TypeSerialization();
        BlogPost          sorryPost = new BlogPost();

        foreach (BlogPost tempPost in ts.DeSerializePosts(xio.GetXMLString(GetOwningXMLFileName(postID))))
        {
            if (tempPost.ID == postID)
            {
                return(tempPost);
            }
            else
            {
                sorryPost.Title = "Post Not Found";
                sorryPost.Text  = "The post you requested was not found";
            }
        }
        return(sorryPost);
    }
예제 #10
0
        private void SaveComponent(Component c, XMLAbstraction.Node parentNode)
        {
            var componentNode = parentNode.AddNode("Component");

            componentNode.AddAttribute("enabled", c.enabled.ToString());
            componentNode.AddAttribute("name", c.GetType().FullName);

            //Fields
            var fieldsNode = componentNode.AddNode("Fields");

            foreach (var f in c.GetType().GetFields())
            {
                if (f.Name != "transform" && f.Name != "enabled")
                {
                    var fieldNode = fieldsNode.AddNode("Field");
                    fieldNode.AddAttribute("name", f.Name);
                    fieldNode.AddAttribute("type", f.FieldType.FullName);
                    TypeSerialization.SerializeField(f, c, fieldNode.node, fieldNode.xml);
                }
            }
        }
예제 #11
0
        public static bool Serialize(TypeSerialization type)
        {
            if (_game.UserShipBoard != null && _game.UserShootingBoard != null)
            {
                switch (type)
                {
                case TypeSerialization.Xml:
                    _game.XmlSerialize();
                    break;

                case TypeSerialization.JSON:
                    _game.JsonSerialize();
                    break;

                case TypeSerialization.Binary:
                    _game.BinarySerialize();
                    break;
                }
                return(true);
            }
            return(false);
        }
예제 #12
0
        private void LoadComponent(XmlNode componentNode, Entity e)
        {
            bool enabled = Convert.ToBoolean(componentNode.Attributes["enabled"].Value);
            Type type    = UserCodeDatabase.GetType(componentNode.Attributes["name"].Value);

            if (type == null)
            {
                Logging.LogWarning(this, $"The component {componentNode.Attributes["name"].Value} could not be found!");
                return;
            }
            Component c = e.AddComponent(type) as Component;

            c.enabled = enabled;

            //Fields
            XmlNodeList fieldNodes = componentNode.SelectNodes("Fields/*[local-name()='Field']");

            foreach (XmlNode f in fieldNodes)
            {
                FieldInfo field = c.GetType().GetField(f.Attributes["name"].Value);
                TypeSerialization.DeserializeField(f, field, c);
            }
        }
예제 #13
0
        public Material(string path) : base(path)
        {
            shader   = null;
            Uniforms = new List <Shader.Uniform>();
            XMLAbstraction xml        = new XMLAbstraction("Material", path);
            var            shaderNode = xml.GetNode("//Material/Shader");

            if (shaderNode != null)
            {
                SetShader(AssetDatabase.GetAsset(Convert.ToInt32(shaderNode.InnerText)) as Shader);
            }
            foreach (var n in xml.GetNodes("//Material/Uniforms/Uniform"))
            {
                Type t = Type.GetType(n.GetAttribute("type"));
                if (t.IsSubclassOf(typeof(Asset)))
                {
                    SetUniform(n.GetAttribute("name"), AssetDatabase.GetAsset(TypeSerialization.DeserializePrimitiveType <int>(n.node)));
                }
                else
                {
                    SetUniform(n.GetAttribute("name"), TypeSerialization.DeserializeType(n.node, t));
                }
            }
        }
예제 #14
0
        public static void Deserialize(TypeSerialization type)
        {
            try
            {
                switch (type)
                {
                case TypeSerialization.Xml:
                    _game.XmlDeserialize();
                    break;

                case TypeSerialization.JSON:
                    _game.JsonDeserialize();
                    break;

                case TypeSerialization.Binary:
                    _game.BinaryDeserialize();
                    break;
                }
            }
            catch {
                Console.Clear();
                throw new SeaBattleException("No data to start a saved application.");
            }
        }
예제 #15
0
        static void Main(string[] args)
        {
            Console.Title         = "Sea Battle";
            Console.CursorVisible = false;


            TypeSerialization typeSerializ = TypeSerialization.Xml;


            IDraw gameView = new ViewManager();
            IGameActions <ConsoleKeyInfo> gameState = new ViewManager();

            bool InGame = false;

            while (true)
            {
                ViewInputMenu();

                if (_numMenu == 1)
                {
                    gameState.Restart();
                    Console.Clear();
                    InGame = true;

                    ViewGameControlInfo();
                }

                if (_numMenu == 2)
                {
                    if (ViewManager.Serialize(typeSerializ))
                    {
                        Console.SetCursorPosition(13, 2);
                        Console.Write("(game saved)");
                        Console.ReadKey(true);
                    }
                }

                if (_numMenu == 3)
                {
                    ViewManager.Deserialize(typeSerializ);
                    gameState.ResetComputerPlayer();
                    Console.Clear();
                    InGame = true;

                    ViewGameControlInfo();
                }

                while (InGame)
                {
                    gameView.PrintUserBoard();
                    gameView.PrintUserShootingBoard();

                    bool viewComputerBoard = true;

                    while (true)
                    {
                        ConsoleKeyInfo inputKey = Console.ReadKey(true);
                        gameState.UserInput(inputKey);

                        if (inputKey.Key == ConsoleKey.Q && viewComputerBoard)
                        {
                            gameView.PrintComputerBoard();
                            viewComputerBoard = false;
                        }
                        else if (inputKey.Key == ConsoleKey.Q && !viewComputerBoard)
                        {
                            Console.Clear();
                            viewComputerBoard = true;
                        }

                        if (inputKey.Key == ConsoleKey.Spacebar || inputKey.Key == ConsoleKey.Q)
                        {
                            gameView.PrintUserBoard();
                            gameView.PrintUserShootingBoard();
                        }

                        if (gameState.WinnerExist())
                        {
                            Console.ReadKey(true);
                            return;
                        }

                        if (inputKey.Key == ConsoleKey.Escape)
                        {
                            Console.Clear();
                            InGame = false;
                            break;
                        }
                    }
                }

                if (_numMenu == 4)
                {
                    Console.Clear();
                    Console.WriteLine();
                    ViewGameResults();
                    Console.ReadKey(true);
                    Console.Clear();
                }

                if (_numMenu == 5)
                {
                    Console.Clear();
                    Console.WriteLine("\nThis game was developed by Alexey Ovsanicoff thanks to DBBest." +
                                      "\n\nArchitecture feature  of application is the fact that due to realization" +
                                      "\nof Xml serialization the encapsulation was completely killed." +
                                      "\n\n (Press \'Esc\' for back to main menu)");
                    Console.ReadKey(true);
                    Console.Clear();
                }
            }
        }