示例#1
0
        public static void Serialize(WeaponsModel obj, string fileName)
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(WeaponsModel));
            FileStream             fileStream = new FileStream(fileName, FileMode.Create);

            serializer.WriteObject(fileStream, obj);

            fileStream.Close();
        }
示例#2
0
        public static WeaponsModel Deserialize(string fileName)
        {
            FileStream             fileStream = new FileStream(fileName, FileMode.Open);
            DataContractSerializer serializer = new DataContractSerializer(typeof(WeaponsModel));

            WeaponsModel retval = (WeaponsModel)serializer.ReadObject(fileStream);

            fileStream.Close();
            return(retval);
        }
        public NewOrderWindowViewModel()
        {
            Weapons = new ObservableCollection <WeaponViewModel>();

            if (WeaponsModel.Load().Weapons != null)
            {
                foreach (var w in WeaponsModel.Load().Weapons)
                {
                    Weapons.Add(new WeaponViewModel(w));
                }
            }
            else
            {
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "Glock", Price = 2000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "AK47", Price = 5000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "M4A1", Price = 6000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "MP5", Price = 3500
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "Colt 1911", Price = 6000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "PM", Price = 2000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "Thompson M1", Price = 6000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "Karabiner Kurz 98k", Price = 12000
                }));
                Weapons.Add(new WeaponViewModel(new Weapon()
                {
                    Name = "UZI", Price = 4570
                }));
            }
            Order        = new OrderViewModel(new Order());
            Order.Weapon = Weapons.First();
        }