示例#1
0
        /// <summary>
        /// Saves the current home configuration
        /// </summary>
        /// <param name="MyHome">Provide home object to be save for later use</param>
        public static async void SaveHome(Home MyHome)
        {
            MemoryStream _MemoryStream = new MemoryStream();
            DataContractSerializer Serializer = new DataContractSerializer(typeof(Home));
            Serializer.WriteObject(_MemoryStream, MyHome);

            StorageFile _File = await ApplicationData.Current.LocalFolder.CreateFileAsync("Home.bin", CreationCollisionOption.ReplaceExisting);
            
            using (Stream fileStream = await _File.OpenStreamForWriteAsync())
            {
                _MemoryStream.Seek(0, SeekOrigin.Begin);
                await _MemoryStream.CopyToAsync(fileStream);
                await fileStream.FlushAsync();
                fileStream.Dispose();
            }
        }
        private void Test_Save()
        {
            Library.Core.Home _Home = new Library.Core.Home();
            _Home.Name = "Upwan Row House";

            _Home.Rooms = new List <Library.Core.Room>();

            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "MummyPappa", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower1.png", I2C_Slave_Address = "0x40"
            });
            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "Kalpan", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower2.png", I2C_Slave_Address = "0x41"
            });
            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "Anurag", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower3.png", I2C_Slave_Address = "0x42"
            });
            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "Kitchen", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Kitchen.png", I2C_Slave_Address = "0x43"
            });
            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "Garden", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower3.png", I2C_Slave_Address = "0x44"
            });
            _Home.Rooms.Add(new Library.Core.Room()
            {
                RoomName = "Backyard", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower2.png", I2C_Slave_Address = "0x45"
            });

            _Home.Rooms[2].Devices = new List <Library.Core.Device>();
            _Home.Rooms[2].Devices.Add(new Library.Core.Device()
            {
                Id = 0, ImagePath = "ms-appx:///Resource/Images/Devices/Fan_130.png", Name = "Light", Pin = Library.Core.Device.PinsEnum.A2, Status = Library.Core.Device.StatusEnum.Off
            });
            _Home.Rooms[2].Devices.Add(new Library.Core.Device()
            {
                Id = 1, ImagePath = "ms-appx:///Resource/Images/Devices/Fan_130.png", Name = "Fan", Pin = Library.Core.Device.PinsEnum.D1, Status = Library.Core.Device.StatusEnum.On
            });

            Library.Core.Home.SaveHome(_Home);
        }
        private void Test_Save()
        {
            Library.Core.Home _Home = new Library.Core.Home();
            _Home.Name = "Upwan Row House";

            _Home.Rooms = new List<Library.Core.Room>();

            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "MummyPappa", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower1.png", I2C_Slave_Address="0x40" });
            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "Kalpan", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower2.png", I2C_Slave_Address = "0x41" });
            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "Anurag", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower3.png", I2C_Slave_Address = "0x42" });
            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "Kitchen", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Kitchen.png", I2C_Slave_Address = "0x43" });
            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "Garden", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower3.png", I2C_Slave_Address = "0x44" });
            _Home.Rooms.Add(new Library.Core.Room() { RoomName = "Backyard", RoomImagePath = "ms-appx:///Resource/Images/RoomTile/Flower2.png", I2C_Slave_Address = "0x45" });

            _Home.Rooms[2].Devices = new List<Library.Core.Device>();
            _Home.Rooms[2].Devices.Add(new Library.Core.Device() { Id = 0, ImagePath = "ms-appx:///Resource/Images/Devices/Fan_130.png", Name = "Light", Pin = Library.Core.Device.PinsEnum.A2, Status = Library.Core.Device.StatusEnum.Off });
            _Home.Rooms[2].Devices.Add(new Library.Core.Device() { Id = 1, ImagePath = "ms-appx:///Resource/Images/Devices/Fan_130.png", Name = "Fan", Pin = Library.Core.Device.PinsEnum.D1, Status = Library.Core.Device.StatusEnum.On });

            Library.Core.Home.SaveHome(_Home);
        }
 public static void Test_Load()
 {
     _Home = Library.Core.Home.LoadHome().Result;
 }
 public static void Test_Load()
 {
     _Home = Library.Core.Home.LoadHome().Result;
 }