Exemplo n.º 1
0
        public virtual void Load(SerializationReader SR)
        {
            SR.ReadStartElement();
            int version = SR.ReadVersion();

            switch (version)
            {
            case 0:
            {
                Name    = SR.ReadString();
                Owner   = SR.ReadString();
                NbrX    = SR.ReadInt();
                NbrY    = SR.ReadInt();
                Entitys = new Entity[NbrX * NbrY];
                for (int i = 0; i < NbrX * NbrY; i++)
                {
                    if (SR.IsEmptyElement)
                    {
                        SR.Read();
                    }
                    else
                    {
                        Entity entity = SR.ReadType() as Entity;
                        entity.Load(SR);
                        Entitys[i] = entity;
                    }
                }
                break;
            }
            }
            SR.ReadEndElement();
        }
Exemplo n.º 2
0
        public static Channel Load(string path)
        {
            if (!File.Exists(path + @"Channel" + Info.extension))
            {
                return(null);
            }
            SerializationReader SR = new SerializationReader(path + @"Channel" + Info.extension);

            SR.Read();
            SR.ReadDeclaration();
            SR.ReadStartElement();
            Channel channel = new Channel();

            channel.Load(SR);
            SR.Close();

            channel.Appearances = Info.LoadFileAppearances(path + @"Appearances" + Info.extension);

            if (!Directory.Exists(path + @"\Channel\"))
            {
                Directory.CreateDirectory(path + @"\Channel\");
            }
            DirectoryInfo dir = new DirectoryInfo(path + @"/Channel");

            foreach (FileInfo file in dir.GetFiles())
            {
                WebTVJSON webjson = LoadFileWebTVJSON(file.FullName);
                channel.Add(webjson);
            }

            channel.ForumList.Load(path + @"/Forum");

            return(channel);
        }
Exemplo n.º 3
0
        public void TestUTF16Chars()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new UnicodeEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new UnicodeEncoding()))
            {
                for (int i = 0; i < 55296; i++)
                    sw.Write((char)i);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < 55296; i++)
                    Assert.AreEqual((char)i, sr.Read<char>());
            }
        }
Exemplo n.º 4
0
        public void TestASCIIString()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms, new ASCIIEncoding()))
            using (SerializationReader sr = new SerializationReader(ms, new ASCIIEncoding()))
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 128; i++)
                    sb.Append((char)i);
                string res = sb.ToString();
                sw.Write(res);

                sw.Flush();
                ms.Position = 0;

                Assert.AreEqual(res, sr.Read<string>());
            }
        }
Exemplo n.º 5
0
        public static WebTVJSON LoadFileWebTVJSON(string path)
        {
            WebTVJSON           webtvjson = new WebTVJSON();
            SerializationReader SR        = new SerializationReader(path);

            SR.Read();
            SR.ReadDeclaration();
            SR.ReadStartElement();
            SR.ReadStartElement();
            int version = SR.ReadVersion();

            switch (version)
            {
            case 0:
            {
                //webtvjson.Hourly.Title = SR.ReadString();
                //webtvjson.Media.VideoPlayer = SR.ReadString();
                //webtvjson.Media.Source = SR.ReadString();
                //webtvjson.Media.Duration = SR.ReadInt();
                //webtvjson.Media.StartSeconds = SR.ReadInt();
                //webtvjson.Media.Quality = SR.ReadString();
                //webtvjson.Hourly.Category = SR.ReadString();
                //webtvjson.Hourly.Subcategory = SR.ReadString();
                //webtvjson.Note.Like = SR.ReadInt();
                //webtvjson.Note.Dislike = SR.ReadInt();
                //webtvjson.Note.NumberView = SR.ReadInt();
                //webtvjson.Hourly.Description = SR.ReadString();
                //webtvjson.Hourly.ImageUrl = SR.ReadString();
                //webtvjson.Hourly.BackGroundUrl = SR.ReadString();
                //webtvjson.Social.WebSite = SR.ReadString();
                //webtvjson.Social.Youtube = SR.ReadString();
                //webtvjson.Social.Facebook = SR.ReadString();
                //webtvjson.Social.Twitter = SR.ReadString();
                //webtvjson.Social.Google = SR.ReadString();
                //webtvjson.Social.Dailymotion = SR.ReadString();
                //webtvjson.Social.Vimeo = SR.ReadString();
                //webtvjson.Social.Email = SR.ReadString();
                break;
            }
            }
            SR.ReadEndElement();
            SR.Close();
            return(webtvjson);
        }
Exemplo n.º 6
0
        public void TestBytes()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                byte[] values = new byte[Config.MULTI_TEST_COUNT];
                rand.NextBytes(values);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    sw.Write(values[i]);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<byte>());
            }
        }
Exemplo n.º 7
0
        public void TestBasicList()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                List<int> list = new List<int>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    list.Add(rand.Next(int.MinValue, int.MaxValue));
                sw.Write(list);

                sw.Flush();
                ms.Position = 0;

                List<int> ret = sr.Read<List<int>>();
                for (int i = 0; i < list.Count; i++)
                    Assert.AreEqual(list[i], ret[i]);
            }
        }
Exemplo n.º 8
0
        public void TestBasicDictionary()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                Dictionary<int, float> dict = new Dictionary<int, float>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    dict[rand.Next(int.MinValue, int.MaxValue)] = (float)rand.NextDouble();
                sw.Write(dict);

                sw.Flush();
                ms.Position = 0;

                Dictionary<int, float> ret = sr.Read<Dictionary<int, float>>();
                foreach (KeyValuePair<int, float> kvp in dict)
                    Assert.AreEqual(kvp.Value, ret[kvp.Key]);
            }
        }
Exemplo n.º 9
0
        public void TestBasicArray()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                int[] array = new int[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    array[i] = rand.Next(int.MinValue, int.MaxValue);
                sw.Write(array);

                sw.Flush();
                ms.Position = 0;

                int[] ret = sr.Read<int[]>();
                for (int i = 0; i < ret.Length; i++)
                    Assert.AreEqual(array[i], ret[i]);
            }
        }
Exemplo n.º 10
0
        public void TestBools()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                bool[] values = new bool[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    values[i] = rand.Next(0, 2) == 1;
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<bool>());
            }
        }
Exemplo n.º 11
0
        public void TestDateTimes()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                DateTime[] values = new DateTime[Config.MULTI_TEST_COUNT];

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    values[i] = new DateTime(rand.Next(1970, 5623), rand.Next(1, 13), rand.Next(1, 29), rand.Next(0, 24), rand.Next(0, 60), rand.Next(0, 60), DateTimeKind.Utc);
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<DateTime>());
            }
        }
Exemplo n.º 12
0
        public void TestFloats()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                float[] values = new float[Config.MULTI_TEST_COUNT];
                byte[] bytes = new byte[4];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    rand.NextBytes(bytes);
                    values[i] = BitConverter.ToSingle(bytes, 0);
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    float result = sr.Read<float>();
                    Assert.IsTrue(values[i] != values[i] || result == values[i]);
                }
            }
        }
Exemplo n.º 13
0
        public void TestObjects()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                object[] values = new object[6];
                values[0] = rand.Next(int.MinValue, int.MaxValue);
                values[1] = "test";
                values[2] = EnumTests.ByteEnum.h;
                values[3] = 0.0002f;
                values[4] = 0.1234d;
                values[5] = (decimal)1000;
                sw.Write(values[0]);
                sw.Write(values[1]);
                sw.Write(values[2]);
                sw.Write(values[3]);
                sw.Write(values[4]);
                sw.Write(values[5]);

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < values.Length; i++)
                {
                    if (i == 2)
                        Assert.AreEqual(values[i], (EnumTests.ByteEnum)sr.Read<object>());
                    else
                        Assert.AreEqual(values[i], sr.Read<object>());
                }
            }
        }
Exemplo n.º 14
0
        public void TestComplexArray()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                SIBFClass[] array = new SIBFClass[Config.MULTI_TEST_COUNT];
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    array[i] = new SIBFClass()
                    {
                        S = "test" + i,
                        IBF = new IBFClass()
                        {
                            I = rand.Next(int.MinValue, int.MaxValue),
                            B = rand.Next(2) == 1,
                            F = (float)rand.NextDouble()
                        }
                    };
                }
                sw.Write(array);

                sw.Flush();
                ms.Position = 0;

                SIBFClass[] ret = sr.Read<SIBFClass[]>();
                for (int i = 0; i < ret.Length; i++)
                {
                    Assert.AreEqual(array[i].S, ret[i].S);
                    Assert.AreEqual(array[i].IBF.I, ret[i].IBF.I);
                    Assert.AreEqual(array[i].IBF.B, ret[i].IBF.B);
                    Assert.AreEqual(array[i].IBF.F, ret[i].IBF.F);
                }
            }
        }
Exemplo n.º 15
0
 public void ReadFromStream(SerializationReader sr)
 {
     S = sr.Read<string>();
     IBF = sr.Read<IBFClass>();
 }
Exemplo n.º 16
0
 public void ReadFromStream(SerializationReader sr)
 {
     I = sr.Read<int>();
     B = sr.Read<bool>();
     F = sr.Read<float>();
 }
Exemplo n.º 17
0
        public void TestComplexList()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                List<SIBFClass> list = new List<SIBFClass>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    list.Add(new SIBFClass()
                    {
                        S = "test" + i,
                        IBF = new IBFClass()
                        {
                            I = rand.Next(int.MinValue, int.MaxValue),
                            B = rand.Next(2) == 1,
                            F = (float)rand.NextDouble()
                        }
                    });
                }
                sw.Write(list);

                sw.Flush();
                ms.Position = 0;

                List<SIBFClass> ret = sr.Read<List<SIBFClass>>();
                for (int i = 0; i < list.Count; i++)
                {
                    Assert.AreEqual(list[i].S, ret[i].S);
                    Assert.AreEqual(list[i].IBF.I, ret[i].IBF.I);
                    Assert.AreEqual(list[i].IBF.B, ret[i].IBF.B);
                    Assert.AreEqual(list[i].IBF.F, ret[i].IBF.F);
                }
            }
        }
Exemplo n.º 18
0
        public void TestComplexDictionary()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                Dictionary<int, SIBFClass> dict = new Dictionary<int, SIBFClass>(Config.MULTI_TEST_COUNT);
                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    dict[rand.Next(int.MinValue, int.MaxValue)] = new SIBFClass()
                    {
                        S = "test" + i,
                        IBF = new IBFClass()
                        {
                            I = rand.Next(int.MinValue, int.MaxValue),
                            B = rand.Next(2) == 1,
                            F = (float)rand.NextDouble()
                        }
                    };
                }
                sw.Write(dict);

                sw.Flush();
                ms.Position = 0;

                Dictionary<int, SIBFClass> ret = sr.Read<Dictionary<int, SIBFClass>>();
                foreach (KeyValuePair<int, SIBFClass> kvp in dict)
                {
                    Assert.AreEqual(kvp.Value.S, ret[kvp.Key].S);
                    Assert.AreEqual(kvp.Value.IBF.I, ret[kvp.Key].IBF.I);
                    Assert.AreEqual(kvp.Value.IBF.B, ret[kvp.Key].IBF.B);
                    Assert.AreEqual(kvp.Value.IBF.F, ret[kvp.Key].IBF.F);
                }
            }
        }
Exemplo n.º 19
0
        public void TestOutOfRange()
        {
            using (MemoryStream ms = new MemoryStream())
            using (SerializationReader sr = new SerializationReader(ms))
            {
                sr.Read<bool>();
                sr.Read<byte>();
                sr.Read<char>();
                sr.Read<short>();
                sr.Read<int>();
                sr.Read<long>();
                sr.Read<float>();
                sr.Read<double>();
                sr.Read<decimal>();
                sr.Read<DateTime>();
                sr.Read<string>();
                sr.Read<TestEnum>();

                sr.Read<string[]>();
                sr.Read<List<string>>();
                sr.Read<Dictionary<int, string>>();

                sr.Read<TestSerializable>();
            }
        }
Exemplo n.º 20
0
        public void TestShorts()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                short[] values = new short[Config.MULTI_TEST_COUNT];
                byte[] bytes = new byte[2];

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    rand.NextBytes(bytes);
                    values[i] = BitConverter.ToInt16(bytes, 0);
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<short>());
            }
        }
Exemplo n.º 21
0
        public void TestDecimals()
        {
            Random rand = new Random();

            using (MemoryStream ms = new MemoryStream())
            using (SerializationWriter sw = new SerializationWriter(ms))
            using (SerializationReader sr = new SerializationReader(ms))
            {
                decimal[] values = new decimal[Config.MULTI_TEST_COUNT];

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                {
                    values[i] = new decimal(rand.Next(0, int.MaxValue), rand.Next(0, int.MaxValue), rand.Next(0, int.MaxValue), rand.Next(0, 2) == 1, (byte)rand.Next(0, 29));
                    sw.Write(values[i]);
                }

                sw.Flush();
                ms.Position = 0;

                for (int i = 0; i < Config.MULTI_TEST_COUNT; i++)
                    Assert.AreEqual(values[i], sr.Read<decimal>());
            }
        }