Exemplo n.º 1
0
        public void starter_values()
        {
            Kettle kettle = new Kettle();

            Assert.AreEqual(false, kettle.KettelOn);
            Assert.AreEqual(Color.Off, kettle.LED);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // Our main class is a car. We will create 3 cars
            Car CarNo1 = new Car("Car Number 1");
            Car CarNo2 = new Car("Car Number 2");
            Car CarNo3 = new Car("Car Number 3");

            // Sometime during the process we might want a drink
            Kettle kettle = new Kettle();


            // each car has 4 methodsm StartEngine,TurnLightsOn,TurnLightsOff and StopEngine
            // we create a command class which the broker class will use to call the correct method of the correct car.
            ICommand Car1StartEngine = new StartEngine(CarNo1);
            ICommand Car2StartEngine = new StartEngine(CarNo2);
            ICommand Car3StartEngine = new StartEngine(CarNo3);

            ICommand Car1TurnLightsOn = new TurnLightsOn(CarNo1);
            ICommand Car2TurnLightsOn = new TurnLightsOn(CarNo2);
            ICommand Car3TurnLightsOn = new TurnLightsOn(CarNo3);

            ICommand Car1TurnLightsOff = new TurnLightsOff(CarNo1);
            ICommand Car2TurnLightsOff = new TurnLightsOff(CarNo2);
            ICommand Car3TurnLightsOff = new TurnLightsOff(CarNo3);

            ICommand Car1StopEngine = new StopEngine(CarNo1);
            ICommand Car2StopEngine = new StopEngine(CarNo2);
            ICommand Car3StopEngine = new StopEngine(CarNo3);

            ICommand boilKettle = new BoilKettle(kettle);

            // we add the list of instructions into the broker class
            // if we change the order added, the order in which the methods are called changes
            // the proker class can operate in other ways aswell
            Broker Instructions = new Broker();

            Instructions.AddCommand(Car1StartEngine);
            Instructions.AddCommand(Car2StartEngine);
            Instructions.AddCommand(Car3StartEngine);

            Instructions.AddCommand(Car1TurnLightsOff);
            Instructions.AddCommand(Car2TurnLightsOff);
            Instructions.AddCommand(Car3TurnLightsOff);

            Instructions.AddCommand(Car1TurnLightsOn);
            Instructions.AddCommand(Car2TurnLightsOn);
            Instructions.AddCommand(Car3TurnLightsOn);

            // Have a brew. The Broker has no idea what it is doing
            // so a completely different type can be used in the same list
            // so long as it implemts ICommand
            Instructions.AddCommand(boilKettle);

            Instructions.AddCommand(Car1StopEngine);
            Instructions.AddCommand(Car2StopEngine);
            Instructions.AddCommand(Car3StopEngine);

            // After the broker class has been configured, we tell it to exectute all the commands
            Instructions.ExecuteCommands();
        }
Exemplo n.º 3
0
        public void Red_LED_kettle_On()
        {
            Kettle      kettle  = new Kettle();
            PowerButton power   = new PowerButton();
            WarningLED  warning = new WarningLED();

            power.PressedPowerButton(kettle, warning);

            Assert.AreEqual(Color.Red, kettle.LED);
        }
Exemplo n.º 4
0
        public void kettle_turned_on()
        {
            Kettle      kettle  = new Kettle();
            PowerButton power   = new PowerButton();
            WarningLED  warning = new WarningLED();

            power.PressedPowerButton(kettle, warning);

            Assert.AreEqual(true, kettle.KettelOn);
        }
Exemplo n.º 5
0
        public void temperature_cannot_rise_if_kettle_is_Off()
        {
            Kettle kettle = new Kettle();

            kettle.Liquid = new LiquidButton(87);
            WarningLED warning = new WarningLED();

            kettle.Liquid.IncresedLiquidTemperature(kettle, warning);
            Assert.AreEqual(false, kettle.KettelOn);
            Assert.AreEqual(87, kettle.Liquid.Temperature);
        }
Exemplo n.º 6
0
        private static Kettle BoilKettle()
        {
            var kettle = new Kettle();

            WriteMessage("Fill Kettle With Water");
            Task.Delay(kettle.Filltime).Wait();
            WriteMessage("Boil Kettle");
            Task.Delay(kettle.BoilTime).Wait();
            WriteMessage("Hot Water ready");
            return(kettle);
        }
Exemplo n.º 7
0
        public void turn_off_a_turned_on_kettle()
        {
            Kettle      kettle      = new Kettle();
            PowerButton powerButton = new PowerButton();
            WarningLED  warning     = new WarningLED();

            powerButton.PressedPowerButton(warning, kettle);
            powerButton.PressedPowerButton(warning, kettle);

            Assert.AreEqual(false, kettle.KettelOn);
        }
Exemplo n.º 8
0
        public void cannot_turn_on_a_turned_on_kettle()
        {
            Kettle      kettle      = new Kettle();
            PowerButton powerButton = new PowerButton();
            WarningLED  warning     = new WarningLED();

            powerButton.PressedPowerButton(warning, kettle);
            powerButton.PressedPowerButton(warning, kettle);

            Assert.AreNotEqual(true, kettle.KettelOn);
        }
Exemplo n.º 9
0
 private static Tea MakeTea(Kettle hotwater)
 {
     WriteMessage("Place Tea bag in Cup");
     Task.Delay(500).Wait();
     WriteMessage("Pour Water into Cup");
     Task.Delay(500).Wait();
     WriteMessage("Take out tea bag");
     Task.Delay(500).Wait();
     WriteMessage("add milk to brew");
     WriteMessage("Tea is ready");
     return(new Tea());
 }
Exemplo n.º 10
0
        public void temperature_cannot_rise_if_kettle_is_Off()
        {
            Kettle kettle = new Kettle();

            Assert.AreEqual(15, kettle.Temperature);

            LiquidButton liquidButton = new LiquidButton();
            WarningLED   warning      = new WarningLED();

            liquidButton.IncresedLiquidTemperature(warning, kettle);

            Assert.AreEqual(15, kettle.Temperature);
        }
Exemplo n.º 11
0
        public void temperature_rise_when_kettle_is_On()
        {
            Kettle      kettle = new Kettle();
            PowerButton power  = new PowerButton();

            kettle.Liquid = new LiquidButton(87);
            WarningLED warning = new WarningLED();

            power.PressedPowerButton(kettle, warning);
            kettle.Liquid.IncresedLiquidTemperature(kettle, warning);
            Assert.AreEqual(true, kettle.KettelOn);
            Assert.AreEqual(97, kettle.Liquid.Temperature);
        }
Exemplo n.º 12
0
    private void OnTriggerExit2D(Collider2D other)
    {
        //if (other.GetComponent<Item>() == itemYouAreOnTopOf)
        itemYouAreOnTopOf = null;

        //if (!(itemYouAreOnTopOf is null) && other.GetComponent< Potion >() == itemYouAreOnTopOf )
        //    itemYouAreOnTopOf = null;

        if (other.GetComponent <Kettle>() == currentLocation)
        {
            currentLocation = null;
        }
    }
Exemplo n.º 13
0
        public void reset_values_when_turn_off()
        {
            Kettle      kettle  = new Kettle();
            PowerButton power   = new PowerButton();
            WarningLED  warning = new WarningLED();

            power.PressedPowerButton(kettle, warning);
            power.PressedPowerButton(kettle, warning);

            Assert.AreEqual(false, kettle.KettelOn);
            Assert.AreEqual(Color.Off, kettle.LED);
            Assert.AreEqual(null, kettle.Liquid);
        }
Exemplo n.º 14
0
        public void temperature_cannot_rise_if_there_is_no_liquid_in_the_kettle()
        {
            Kettle      kettle = new Kettle();
            PowerButton power  = new PowerButton();

            kettle.Liquid = null;
            LiquidButton liquid  = new LiquidButton(85);
            WarningLED   warning = new WarningLED();


            power.PressedPowerButton(kettle, warning);
            kettle.Liquid.IncresedLiquidTemperature(kettle, warning);
        }
Exemplo n.º 15
0
        public void one_kettle_can_have_only_one_liquid()
        {
            Kettle       kettle  = new Kettle();
            LiquidButton liquid1 = new LiquidButton(15);
            LiquidButton liquid2 = new LiquidButton(30);

            kettle.Liquid = liquid1;
            Assert.AreEqual(liquid1, kettle.Liquid);

            kettle.Liquid = liquid2;
            Assert.AreNotSame(liquid1, liquid2);
            Assert.AreEqual(liquid2, kettle.Liquid);
            Assert.AreNotEqual(liquid1, kettle.Liquid);
        }
Exemplo n.º 16
0
        public void Green_LED_when_temperature_is_over_100()
        {
            Kettle      kettle = new Kettle();
            PowerButton power  = new PowerButton();

            kettle.Liquid = new LiquidButton(87);
            WarningLED warning = new WarningLED();

            power.PressedPowerButton(kettle, warning);
            kettle.Liquid.IncresedLiquidTemperature(kettle, warning);
            kettle.Liquid.IncresedLiquidTemperature(kettle, warning);
            Assert.AreEqual(true, kettle.KettelOn);
            Assert.AreEqual(107, kettle.Liquid.Temperature);
            Assert.AreEqual(Color.Green, kettle.LED);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 发布-订阅
        /// </summary>
        void publishser()
        {
            var kettle = new Kettle();

            kettle.TurnOn();


            return;

            var publishser = new Publishser();
            var subscriber = new Subscriber();

            publishser.NumberChanged += subscriber.OnNumberChanged;
            publishser.DoSomething();
        }
Exemplo n.º 18
0
        public void Green_LED_when_temperature_is_over_100()
        {
            Kettle       kettle       = new Kettle();
            PowerButton  powerButton  = new PowerButton();
            LiquidButton liquidButton = new LiquidButton();
            WarningLED   warning      = new WarningLED();

            powerButton.PressedPowerButton(warning, kettle);

            for (int i = 0; i < 9; i++)
            {
                liquidButton.IncresedLiquidTemperature(warning, kettle);
            }

            Assert.AreEqual(Color.Green, kettle.LED);
        }
Exemplo n.º 19
0
        public async Task <string> Subscribe()
        {
            var kettle       = new Kettle();                       //初始化热水壶
            var subscribeRef = kettle.Subscribe(new Alter());      //订阅

            var boilTask   = kettle.StartBoilWaterAsync();         //启动开始烧水任务
            var timoutTask = Task.Delay(TimeSpan.FromSeconds(15)); //定义15s超时任务
            //等待,如果超时任务先返回则取消订阅
            var firstReturnTask = await Task.WhenAny(boilTask, timoutTask);

            if (firstReturnTask == timoutTask)
            {
                subscribeRef.Dispose();
            }

            return("Subscribe");
        }
Exemplo n.º 20
0
        public void temperature_rise_when_kettle_is_On()
        {
            Kettle       kettle       = new Kettle();
            PowerButton  powerButton  = new PowerButton();
            LiquidButton liquidButton = new LiquidButton();
            WarningLED   warning      = new WarningLED();

            powerButton.PressedPowerButton(warning, kettle);
            liquidButton.IncresedLiquidTemperature(warning, kettle);

            Assert.AreEqual(true, kettle.KettelOn);
            Assert.AreEqual(25, kettle.Temperature);

            liquidButton.IncresedLiquidTemperature(warning, kettle);

            Assert.AreEqual(35, kettle.Temperature);
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            Appliance app1 = new Fridge("Washer", "Samsung", 750, "SamsungStore", 150, 180, 75, "White");

            Appliance app2 = new Kettle("Kettle", "Xiaomi", 100, true, 6, "Plastic", "Plastic", "White");

            Appliance app3 = new Tv("TV", "Samsung", 400, 55, "IPS", "4K", 60, true);

            Appliance app4 = new Washer("Washer", "Asus", 40, 7, 1500, 14, 45, 74);

            Basket basket = new Basket();

            basket.Add(app1);
            basket.Add(app2);
            basket.Add(app3);
            basket.Add(app4);
            Console.WriteLine(basket);
            Console.WriteLine(Assistance.CalculateTotalPower(basket));
        }
Exemplo n.º 22
0
        public void reset_values_when_turn_off()
        {
            Kettle       kettle       = new Kettle();
            PowerButton  powerButton  = new PowerButton();
            LiquidButton liquidButton = new LiquidButton();
            WarningLED   warning      = new WarningLED();

            powerButton.PressedPowerButton(warning, kettle);

            for (int i = 0; i < 9; i++)
            {
                liquidButton.IncresedLiquidTemperature(warning, kettle);
            }

            powerButton.PressedPowerButton(warning, kettle);

            Assert.AreEqual(false, kettle.KettelOn);
            Assert.AreEqual(Color.Off, kettle.LED);
            Assert.AreEqual(15, kettle.Temperature);
        }
Exemplo n.º 23
0
        public OOPTest()
        {
            //var water = new Water();
            //var lcdScreen = new LCDScreen();
            //var speaker = new Speaker();
            //var kettle = new Kettle(lcdScreen, speaker);
            //kettle.Boil(water);



            var lcdScreen = new LCDScreen();
            var speaker   = new Speaker();

            var kettle = new Kettle();

            kettle.OnBoilHandle += (t) => { lcdScreen.Display(t.ToString()); };
            kettle.OnBoilHandle += (t) => { if (t > 96)
                                            {
                                                speaker.Speak(t.ToString());
                                            }
            };
        }
Exemplo n.º 24
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.TryGetComponent <Potion>(out var potion))
        {
            itemYouAreOnTopOf = potion.gameObject;
        }
        else if (other.TryGetComponent <Ingredient>(out var ingredient))
        {
            itemYouAreOnTopOf = ingredient.gameObject;
        }
        else if (other.TryGetComponent <Kettle>(out var kettle))
        {
            currentLocation = kettle;
        }

        if (other.gameObject.tag == "Explosion")
        {
            Camera.main.gameObject.GetComponent <ScreenShake>().Shake(.5f);
            GameObject.FindGameObjectWithTag("Sound").GetComponent <SoundManager>().PlaySound("glass");

            switch (other.gameObject.GetComponent <Explosion>().TypeOfExplosion)
            {
            case Explosion.ExplosionType.Fire:
                currentHealth -= 20;
                healthbar.transform.DOPunchScale(new Vector3(1, 1, 1), .2f);
                Debug.Log("DAMAGE");
                break;

            case Explosion.ExplosionType.Slime:
                StartCoroutine(slowingDown());
                break;

            case Explosion.ExplosionType.Poison:
                StartCoroutine(DamageOverTime());
                break;
            }
        }
    }
        public ActionResult Del(int id, string chanel)
        {
            try
            {
                switch (chanel)
                {
                case "cond":

                    Conditioner c = dbconnect.Conditioner.Find(id);

                    dbconnect.Conditioner.Remove(c);
                    dbconnect.SaveChanges();

                    break;

                case "tr":

                    TapRecoder tr = dbconnect.TapeReoder.Find(id);
                    dbconnect.TapeReoder.Remove(tr);
                    dbconnect.SaveChanges();
                    break;

                case "lamp":

                    Lamp l = dbconnect.Lamp.Find(id);
                    dbconnect.Lamp.Remove(l);
                    dbconnect.SaveChanges();

                    break;

                case "fridge":

                    Fridge f = dbconnect.Fridge.Find(id);
                    dbconnect.Fridge.Remove(f);
                    dbconnect.SaveChanges();

                    break;

                case "kettle":

                    Kettle k = dbconnect.Kettle.Find(id);
                    dbconnect.Kettle.Remove(k);
                    dbconnect.SaveChanges();

                    break;

                case "tv":


                    TeleVision tv = dbconnect.TeleVision.Include(p => p.DVDs).Where(p => p.Id == id).FirstOrDefault();
                    dbconnect.TeleVision.Remove(tv);
                    dbconnect.SaveChanges();

                    break;
                }

                IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>();
                return(View("Index", filtrDevice));
            }
            catch
            {
                IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>();
                return(View("Index", filtrDevice));
            }
        }
Exemplo n.º 26
0
        static async Task Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Make Breakfast using differnt levels asynchronicity");
                Console.WriteLine("Enter 1 for sync");
                Console.WriteLine("Enter 2 for sync over async");
                Console.WriteLine("Enter 3 for async");

                var line = Console.ReadLine() ?? "3";

                DateTime start;
                TimeSpan difference;

                switch (line)
                {
                case "1":

                    WriteMessage("sync selected");
                    start = DateTime.UtcNow;
                    Kettle hotwater = BoilKettle();
                    Egg    eggs     = FryEgg(2);
                    Bacon  bacon    = FryBacon(3);
                    Toast  toast    = MakeToast(3);
                    ButterToast(toast);
                    Tea tea = MakeTea(hotwater);
                    WriteMessage("Breakfast is ready!");
                    difference = DateTime.UtcNow.Subtract(start);
                    WriteMessage($"Time taken {difference.TotalSeconds} (seconds)");
                    break;

                case "2":
                    WriteMessage("sync over async");
                    start = DateTime.UtcNow;
                    Task <Kettle> hotwaterAsync = BoilKettleAsync();
                    Task <Egg>    eggsaAsync    = FryEggAsync(2);
                    Task <Bacon>  baconAsync    = FryBaconAsync(3);
                    Task <Toast>  toastAsync    = MakeToastAsync(3);

                    /*
                     * We are calling ButterToast synchronously
                     * i.e we have to await the result of toastAsync
                     * to pass it ButterToast affectlying making the process
                     * syncronously
                     */
                    WriteMessage("Awaiting Toast");
                    var toastready = await toastAsync;
                    ButterToast(toastready);

                    /*
                     * We are calling MakeTea synchronously
                     * i.e we have to await the result of hotwaterAsync
                     * to pass it MakeTea affectlying making the process
                     * syncronously
                     */
                    WriteMessage("Awaiting Kettle");
                    var hotwaterready = await hotwaterAsync;
                    MakeTea(hotwaterready);

                    WriteMessage("Awaiting Breakfast");
                    await Task.WhenAll(hotwaterAsync, eggsaAsync, baconAsync, toastAsync);

                    WriteMessage("Breakfast is ready!");
                    difference = DateTime.UtcNow.Subtract(start);
                    WriteMessage($"Time taken {difference.TotalSeconds} (seconds)");
                    break;

                case "3":

                    WriteMessage("async");
                    start = DateTime.UtcNow;
                    Task <Kettle> hotwaterFullAsync = BoilKettleAsync();
                    Task <Egg>    eggsFullAsync     = FryEggAsync(2);
                    Task <Bacon>  baconFullAsync    = FryBaconAsync(3);
                    Task <Toast>  toastFullAsync    = MakeToastAsync(3);

                    /*
                     * We pass the Task returned from MakeToastAsync to ToastWithButter so the thread can continue
                     * processing. ToastWithButter awaits the Task.
                     */
                    toastFullAsync = ToastWithButter(toastFullAsync);

                    /*
                     * We pass the Task returned from hotwaterFullAsync to TeaWithHotWater so the thread can continue
                     * processing. TeaWithHotWater awaits the Task.
                     */
                    Task <Tea> teaFullAsync = TeaWithHotWater(hotwaterFullAsync);
                    WriteMessage("Awaiting Breakfast");
                    await Task.WhenAll(hotwaterFullAsync, eggsFullAsync, baconFullAsync, toastFullAsync, teaFullAsync);

                    WriteMessage("Breakfast is ready!");
                    difference = DateTime.UtcNow.Subtract(start);
                    WriteMessage($"Time taken {difference.TotalSeconds} (seconds)");
                    break;
                }
            }
        }
        public ActionResult Add(string type, string Namedevice)
        {
            switch (type)
            {
            case "cond":

                Device d = new Device {
                    Type = "cond", img = "~/Content/Images/MainScreen/cond.jpg"
                };
                Conditioner c = new Conditioner {
                    Name = Namedevice, State = false, Programm = 2, Device = d
                };


                Session["Filtr"] = type;
                dbconnect.Conditioner.Add(c);
                dbconnect.SaveChanges();


                break;

            case "tr":

                Device d1 = new Device {
                    Type = "tr", img = "~/Content/Images/MainScreen/TR.jpg"
                };
                TapRecoder tr = new TapRecoder {
                    Name = Namedevice, State = false, Mode = false, Volume = 20, Device = d1
                };

                Session["Filtr"] = type;
                dbconnect.TapeReoder.Add(tr);
                dbconnect.SaveChanges();
                break;

            case "lamp":

                Device d2 = new Device {
                    Type = "lamp", img = "~/Content/Images/MainScreen/lamp.jpg"
                };
                Lamp l = new Lamp {
                    Name = Namedevice, State = false, Brightness = 20, CurrentColor = 1, Device = d2
                };

                Session["Filtr"] = type;
                dbconnect.Lamp.Add(l);
                dbconnect.SaveChanges();

                break;

            case "fridge":

                Device d3 = new Device {
                    Type = "fridge", img = "~/Content/Images/MainScreen/fridge.jpg"
                };
                Fridge f = new Fridge {
                    Name = Namedevice, State = false, StateFrize = false, Programm = 1, Device = d3
                };

                Session["Filtr"] = type;
                dbconnect.Fridge.Add(f);
                dbconnect.SaveChanges();

                break;

            case "kettle":

                Device d4 = new Device {
                    Type = "kettle", img = "~/Content/Images/MainScreen/kettle.jpg"
                };
                Kettle k = new Kettle {
                    Name = Namedevice, State = false, Device = d4
                };

                Session["Filtr"] = type;
                dbconnect.Kettle.Add(k);
                dbconnect.SaveChanges();

                break;

            case "tv":

                Device d5 = new Device {
                    Type = "tv", img = "~/Content/Images/MainScreen/tv.jpg"
                };
                TeleVision tv = new TeleVision {
                    Name   = Namedevice, State = false, CurrentChanel = "ICTV",
                    Volume = 20, Brightness = 30, Mode = false, Device = d5
                };
                DVD dvd = new DVD {
                    State = false, IsDiskboxOpen = false, IsPlay = false, TeleVision = tv
                };

                Session["Filtr"] = type;
                dbconnect.TeleVision.Add(tv);
                dbconnect.DVD.Add(dvd);
                dbconnect.SaveChanges();

                break;
            }



            IDictionary <int, Models.Devices.Device> filtrDevice = new SortedDictionary <int, Models.Devices.Device>();

            return(View("Index", filtrDevice));
        }
Exemplo n.º 28
0
 // Use this for initialization
 void Start()
 {
     startRotation = transform.rotation;
     kettle        = GetComponent <Kettle>();
     controller    = GameObject.FindGameObjectWithTag("GameController").GetComponent <Controller>();
 }
Exemplo n.º 29
0
        private void SaveChange(int id, string type, IDictionary <int, Models.Devices.Device> device)
        {
            switch (type)
            {
            case "cond":

                Conditioner cond = dbconnect.Conditioner.Find(id);

                cond.Programm = ((Models.Devices.Conditioner)device[0]).Programm;
                cond.State    = ((Models.Devices.Conditioner)device[0]).State;

                dbconnect.SaveChanges();

                break;

            case "tr":



                TapRecoder tr = dbconnect.TapeReoder.Find(id);

                tr.State  = ((Models.Devices.TapRecoder)device[0]).State;
                tr.Mode   = ((Models.Devices.TapRecoder)device[0]).Mode;
                tr.Volume = ((Models.Devices.TapRecoder)device[0]).Volume;

                dbconnect.SaveChanges();
                break;

            case "lamp":

                Lamp lamp = dbconnect.Lamp.Find(id);

                lamp.State        = ((Models.Devices.Lamp)device[0]).State;
                lamp.CurrentColor = ((Models.Devices.Lamp)device[0]).currentcolor;
                lamp.Brightness   = ((Models.Devices.Lamp)device[0]).Brightness;

                dbconnect.SaveChanges();

                break;

            case "fridge":

                Fridge fridge = dbconnect.Fridge.Find(id);

                fridge.Programm   = ((Models.Devices.Fridge)device[0]).Programm;
                fridge.State      = ((Models.Devices.Fridge)device[0]).State;
                fridge.StateFrize = ((Models.Devices.Fridge)device[0]).StateFrize;

                dbconnect.SaveChanges();

                break;

            case "kettle":

                Kettle kettle = dbconnect.Kettle.Find(id);

                kettle.State = ((Models.Devices.Kettle)device[0]).State;
                dbconnect.SaveChanges();

                break;

            case "tv":

                TeleVision tv = dbconnect.TeleVision.Find(id);

                tv.State         = ((Models.Devices.TeleVision)device[0]).State;
                tv.Mode          = ((Models.Devices.TeleVision)device[0]).Mode;
                tv.Volume        = ((Models.Devices.TeleVision)device[0]).Volume;
                tv.CurrentChanel = ((Models.Devices.TeleVision)device[0]).Chanel.ToString();
                tv.Brightness    = ((Models.Devices.TeleVision)device[0]).Brightness;


                dbconnect.SaveChanges();

                break;
            }
        }
Exemplo n.º 30
0
        protected override void Seed(DevicesContext context)
        {
            Device d1 = new Device {
                Type = "tv", img = "~/Content/Images/MainScreen/tv.jpg"
            };
            Device d2 = new Device {
                Type = "lamp", img = "~/Content/Images/MainScreen/lamp.jpg"
            };
            Device d3 = new Device {
                Type = "tr", img = "~/Content/Images/MainScreen/TR.jpg"
            };
            Device d4 = new Device {
                Type = "kettle", img = "~/Content/Images/MainScreen/kettle.jpg"
            };
            Device d5 = new Device {
                Type = "fridge", img = "~/Content/Images/MainScreen/fridge.jpg"
            };
            Device d6 = new Device {
                Type = "cond", img = "~/Content/Images/MainScreen/cond.jpg"
            };

            context.Device.Add(d1);
            context.Device.Add(d2);
            context.Device.Add(d3);
            context.Device.Add(d4);
            context.Device.Add(d5);
            context.Device.Add(d6);


            TeleVision tv = new TeleVision {
                Name = "Телевизор", State = false, CurrentChanel = "ICTV", Volume = 20, Brightness = 30, Mode = false, Device = d1
            };

            context.TeleVision.Add(tv);

            Conditioner c = new Conditioner {
                Name = "Кондиционер", State = false, Programm = 2, Device = d6
            };
            DVD d = new DVD {
                State = false, IsDiskboxOpen = false, IsPlay = false, TeleVision = tv
            };
            Fridge f = new Fridge {
                Name = "Холодильник", State = false, StateFrize = false, Programm = 1, Device = d5
            };
            Kettle k = new Kettle {
                Name = "Чайник", State = false, Device = d4
            };
            TapRecoder tr = new TapRecoder {
                Name = "Музыкальный центр", State = false, Mode = false, Volume = 20, Device = d3
            };
            Lamp l = new Lamp {
                Name = "Лампа", State = false, Brightness = 20, CurrentColor = 1, Device = d2
            };

            context.Conditioner.Add(c);
            context.DVD.Add(d);
            context.Fridge.Add(f);
            context.Kettle.Add(k);
            context.TapeReoder.Add(tr);
            context.Lamp.Add(l);

            context.SaveChanges();
        }