Esempio n. 1
0
        public void LoadDownloadList()
        {
            var storageContainer = StorageManager.RequiredCurrentStorageContainer;

            if (!storageContainer.FileExists(downloadListPath))
            {
                return;
            }

            using (var stream = storageContainer.OpenFile(downloadListPath, FileMode.Open))
            {
                var definition = (DownloadListDefinition)downloadListSerializer.Deserialize(stream, null);
                if (ArrayHelper.IsNullOrEmpty(definition.Entries))
                {
                    return;
                }

                for (int i = 0; i < definition.Entries.Length; i++)
                {
                    var downloadInfo = new DownloadInfo(definition.Entries[i].Uri)
                    {
                        LastModified = definition.Entries[i].LastModified
                    };
                    downloadInfoCollection.Add(downloadInfo);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //================================================================
            // Test polymorphic objects

            var animalManager = new AnimalManager();

            animalManager.Animals = new IAnimal[]
            {
                new Dog {
                    Name = "Pochi", DogProperty = "Wan wan"
                },
                new Cat {
                    Name = "Tama", CatProperty = "Nya nya"
                }
            };

            // Output file path.
            var path = Path.Combine(Directory.GetCurrentDirectory(), "AnimalManager.xml");

            var serializer = new XmlSerializerAdapter(typeof(AnimalManager));

            serializer.WriterSettings.Indent = true;

            // Serialize.
            using (var stream = File.Create(path))
            {
                serializer.Serialize(stream, animalManager);
            }
            Console.WriteLine("Serialize:");
            Console.WriteLine(path);

            using (var stream = File.Open(path, FileMode.Open))
                using (var reader = new StreamReader(stream))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                }
            Console.WriteLine();

            // Deserialize.
            AnimalManager loadedObject;

            using (var stream = File.Open(path, FileMode.Open))
            {
                loadedObject = serializer.Deserialize(stream, null) as AnimalManager;
            }
            Console.WriteLine("Deserialize:");
            Console.WriteLine(loadedObject);
            Console.WriteLine();

            // Exit.
            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //================================================================
            // Test polymorphic objects

            var animalManager = new AnimalManager();
            animalManager.Animals = new IAnimal[]
            {
                new Dog { Name = "Pochi", DogProperty = "Wan wan" },
                new Cat { Name = "Tama", CatProperty = "Nya nya" }
            };

            // Output file path.
            var path = Path.Combine(Directory.GetCurrentDirectory(), "AnimalManager.xml");

            var serializer = new XmlSerializerAdapter(typeof(AnimalManager));
            serializer.WriterSettings.Indent = true;

            // Serialize.
            using (var stream = File.Create(path))
            {
                serializer.Serialize(stream, animalManager);
            }
            Console.WriteLine("Serialize:");
            Console.WriteLine(path);

            using (var stream = File.Open(path, FileMode.Open))
            using (var reader = new StreamReader(stream))
            {
                string line;
                while ((line = reader.ReadLine()) != null) Console.WriteLine(line);
            }
            Console.WriteLine();

            // Deserialize.
            AnimalManager loadedObject;
            using (var stream = File.Open(path, FileMode.Open))
            {
                loadedObject = serializer.Deserialize(stream, null) as AnimalManager;
            }
            Console.WriteLine("Deserialize:");
            Console.WriteLine(loadedObject);
            Console.WriteLine();

            // Exit.
            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            //================================================================
            //
            // Shared ComponentTypeRegistory
            //

            var typeRegistory = new ComponentTypeRegistory();

            typeRegistory.SetTypeDefinitionName(typeof(SCurve5));
            typeRegistory.SetTypeDefinitionName(typeof(Perlin));
            typeRegistory.SetTypeDefinitionName(typeof(SumFractal));
            typeRegistory.SetTypeDefinitionName(typeof(ScaleBias));

            //================================================================
            //
            // ComponentInfoManager
            //

            var componentInfoManager = new ComponentInfoManager(typeRegistory);

            //================================================================
            //
            // ComponentBundleBuilder
            //

            var myNoise = new ScaleBias
            {
                Scale  = 0.5f,
                Bias   = 0.5f,
                Source = new SumFractal
                {
                    Source = new Perlin
                    {
                        Seed      = 300,
                        FadeCurve = new SCurve5()
                    }
                }
            };

            var builder = new ComponentBundleBuilder(componentInfoManager);

            builder.Add("scaleBias", myNoise);

            //================================================================
            //
            // Serialization
            //

            ComponentBundleDefinition definition;

            builder.BuildDefinition(out definition);

            var xmlSerializer = new XmlSerializerAdapter(typeof(ComponentBundleDefinition));

            xmlSerializer.WriterSettings.Indent             = true;
            xmlSerializer.WriterSettings.OmitXmlDeclaration = true;

            var resource = FileResourceLoader.Instance.LoadResource("file:///" + Directory.GetCurrentDirectory() + "/Noise.xml");

            using (var stream = resource.Create())
            {
                xmlSerializer.Serialize(stream, definition);
            }

            //================================================================
            //
            // Deserialization
            //

            ComponentBundleDefinition deserializedDefinition;

            using (var stream = resource.Open())
            {
                deserializedDefinition = (ComponentBundleDefinition)xmlSerializer.Deserialize(stream, null);
            }

            //================================================================
            //
            // Exit
            //

            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();
        }