예제 #1
0
        private void printRadiators()
        {
            for (int i = 0; i < 7; i++)
            {
                if (radiators.Count > i)
                {
                    Part     part  = radiators[i];
                    Radiator rad   = part.Radiator;
                    string   name  = Helper.prtlen(part.Title, 35, Helper.Align.CENTER).ToUpper();
                    string   pos   = Helper.prtlen(rad.State.ToString(), 12, Helper.Align.LEFT);                 // EXTENDED/RETRACTED/EXTENDING/RETRACTING/BROKEN
                    string   state = "";

                    IList <Module> modules = part.Modules;
                    foreach (Module m in modules)
                    {
                        if (m.Name == "ModuleActiveRadiator")
                        {
                            IDictionary <string, string> fields = m.Fields;
                            state = fields["Cooling"];
                        }
                    }

                    state = Helper.prtlen(state, 8, Helper.Align.RIGHT);

                    screenLabels[60 + (i * 2)].Text = name;
                    screenLabels[61 + (i * 2)].Text = pos + state;
                }
                else
                {
                    screenLabels[60 + (i * 2)].Text = "";
                    screenLabels[61 + (i * 2)].Text = "";
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Applied after OnSpawn runs.
 /// </summary>
 internal static void Postfix(Radiator __instance)
 {
     if (__instance != null)
     {
         __instance.gameObject.AddOrGet <RadiationGridUpdater>();
     }
 }
예제 #3
0
        private static void startTCPServer(Radiator rad)
        {
            IPAddress   ipad         = IPAddress.Any;
            TcpListener serverSocket = new TcpListener(ipad, 6789);

            serverSocket.Start();
            bool flag = true;

            while (flag)
            {
                TcpClient    connectionSocket = serverSocket.AcceptTcpClient();
                Stream       ns   = connectionSocket.GetStream();
                StreamReader sr   = new StreamReader(ns);
                string       text = sr.ReadLine();

                if (text.Substring(0, 2).Equals("ON"))
                {
                    TændRadiator(text, rad);
                }
                else if (text.Substring(0, 2).Equals("AN"))
                {
                    AngivRadiator(text, rad);
                }
                else if (text.Equals("EXIT"))
                {
                    flag = false;
                }


                sr.Close();
                ns.Close();
            }
            serverSocket.Stop();
        }
예제 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Radiator radiator = db.Radiators.Find(id);

            db.Radiators.Remove(radiator);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #5
0
    // private DAS.PlayerMovement m_playerMovement;


    void Start()
    {
        fixButton.gameObject.AddComponent <ClickableObject>();
        fixCanvas           = fixButton.transform.parent.GetComponent <Canvas>();
        buttonRectTransform = fixButton.GetComponent <RectTransform>();
        m_radiator          = GetComponent <Radiator>();
        // m_playerMovement = FindObjectOfType<DAS.PlayerMovement>();

        fixButton.gameObject.SetActive(false);
    }
예제 #6
0
 public ActionResult Edit([Bind(Include = "RadiatorID,ManufacturerRadiatorID,MaterialRadiatorID,TitleModel,ThermalPower")] Radiator radiator)
 {
     if (ModelState.IsValid)
     {
         db.Entry(radiator).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ManufacturerRadiatorID = new SelectList(db.ManufacturerRadiators, "ManufacturerRadiatorID", "TitleCompany", radiator.ManufacturerRadiatorID);
     ViewBag.MaterialRadiatorID     = new SelectList(db.MaterialRadiators, "MaterialRadiatorID", "TitleMaterialRadiator", radiator.MaterialRadiatorID);
     return(View(radiator));
 }
예제 #7
0
        public void ConstructorTest()
        {
            Radiator fixedRadiator = new Radiator();

            Assert.IsTrue(fixedRadiator.IsFixed());
            Assert.IsFalse(fixedRadiator.IsLeaking());
            fixedRadiator.CauseLeak();
            Assert.IsTrue(fixedRadiator.IsLeaking());
            Assert.IsFalse(fixedRadiator.IsFixed());
            fixedRadiator.FixRadiator();
            Assert.IsTrue(fixedRadiator.IsFixed());
            Assert.IsFalse(fixedRadiator.IsLeaking());
        }
예제 #8
0
        // GET: Radiators/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Radiator radiator = db.Radiators.Find(id);

            if (radiator == null)
            {
                return(HttpNotFound());
            }
            return(View(radiator));
        }
예제 #9
0
        // GET: Radiators/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Radiator radiator = db.Radiators.Find(id);

            if (radiator == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ManufacturerRadiatorID = new SelectList(db.ManufacturerRadiators, "ManufacturerRadiatorID", "TitleCompany", radiator.ManufacturerRadiatorID);
            ViewBag.MaterialRadiatorID     = new SelectList(db.MaterialRadiators, "MaterialRadiatorID", "TitleMaterialRadiator", radiator.MaterialRadiatorID);
            return(View(radiator));
        }
예제 #10
0
        public override void updateLocalElements(object sender, EventArgs e)
        {
            screenLabels[2].Text = "LT: " + Helper.timeString(DateTime.Now.TimeOfDay.TotalSeconds);

            if (form.form.connected && form.form.krpc.CurrentGameScene == GameScene.Flight)
            {
                double MET = screenStreams.GetData(DataType.vessel_MET);

                screenLabels[3].Text = "MET: " + Helper.timeString(MET, 3);

                parts = screenStreams.GetData(DataType.vessel_parts);

                hotParts.Clear();
                ablators.Clear();
                radiators.Clear();



                if (parts != null)
                {
                    IList <Part> partList = parts.All;
                    foreach (Part p in partList)
                    {
                        addHotPart(p);

                        Radiator rad = p.Radiator;
                        if (rad != null)
                        {
                            radiators.Add(p);
                        }

                        Resources r = p.Resources;
                        if (r.HasResource("Ablator"))
                        {
                            ablators.Add(p);
                        }
                    }
                }

                printHotParts();
                printAblators();
                printRadiators();
            }
        }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        if (!start)
        {
            return;
        }

        int RadiatorNum = 0;

        foreach (GameObject Radiator in GameObject.FindGameObjectsWithTag("radiator"))
        {
            if (Radiator.GetComponent <Brain>().isFree)
            {
                RadiatorNum++;
            }
        }

        FireInLevel = GameObject.FindGameObjectsWithTag("Fire");
        FireNum     = FireInLevel.Length;

        int brokenGenerator = 0;

        foreach (GameObject generator in GameObject.FindGameObjectsWithTag("powerSupply"))
        {
            if (generator.GetComponent <PowerSupply>().isBroken)
            {
                brokenGenerator++;
            }
        }

        if (RadiatorNum <= 0 && FireNum <= 0 && brokenGenerator <= 0)
        {
            win = true;
            ShowGameResult(win);
        }

        if (CheckEscape.GetComponent <CheckRaditors>().Escaped)
        {
            win = false;
            ShowGameResult(win);
        }
    }
예제 #12
0
 private static void TændRadiator(string text, Radiator rad)
 {
     if (text.Substring(0, 4).Equals("ON 1"))
     {
         rad.Tænd(1);
     }
     else if (text.Substring(0, 4).Equals("ON 2"))
     {
         rad.Tænd(2);
     }
     else if (text.Substring(0, 4).Equals("ON 3"))
     {
         rad.Tænd(3);
     }
     else if (text.Substring(0, 4).Equals("ON 4"))
     {
         rad.Tænd(4);
     }
     else if (text.Substring(0, 4).Equals("ON 5"))
     {
         rad.Tænd(5);
     }
 }
예제 #13
0
 private void RenameDevice(int id, string type, string name)
 {
     using (SmartHouseContext context = new SmartHouseContext())
     {
         if (context.Alarms.Any())
         {
             if (type == context.Alarms.FirstOrDefault().GetType().ToString())
             {
                 Alarm device = context.Alarms.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Conditioners.Any())
         {
             if (type == context.Conditioners.FirstOrDefault().GetType().ToString())
             {
                 Conditioner device = context.Conditioners.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Exhausters.Any())
         {
             if (type == context.Exhausters.FirstOrDefault().GetType().ToString())
             {
                 Exhauster device = context.Exhausters.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Fridges.Any())
         {
             if (type == context.Fridges.FirstOrDefault().GetType().ToString())
             {
                 Fridge device = context.Fridges.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Jalousies.Any())
         {
             if (type == context.Jalousies.FirstOrDefault().GetType().ToString())
             {
                 Jalousie device = context.Jalousies.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Lamps.Any())
         {
             if (type == context.Lamps.FirstOrDefault().GetType().ToString())
             {
                 Lamp device = context.Lamps.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Radiators.Any())
         {
             if (type == context.Radiators.FirstOrDefault().GetType().ToString())
             {
                 Radiator device = context.Radiators.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Routers.Any())
         {
             if (type == context.Routers.FirstOrDefault().GetType().ToString())
             {
                 Router device = context.Routers.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.StereoSystems.Any())
         {
             if (type == context.StereoSystems.FirstOrDefault().GetType().ToString())
             {
                 StereoSystem device = context.StereoSystems.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.TVs.Any())
         {
             if (type == context.TVs.FirstOrDefault().GetType().ToString())
             {
                 TV device = context.TVs.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
     }
     return;
 }
예제 #14
0
        private void CreateNewDevice(string type, string lampType, string name)
        {
            using (SmartHouseContext context = new SmartHouseContext())
            {
                int id = (int)Session["CurrentRoom"];
                switch (type)
                {
                case "Alarm":
                    Alarm newAlarm = new Alarm(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Alarm.Add(newAlarm);
                    break;

                case "Conditioner":
                    Conditioner newConditioner = new Conditioner(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Conditioner.Add(newConditioner);
                    break;

                case "Exhauster":
                    Exhauster newExhauster = new Exhauster(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Exhauster.Add(newExhauster);
                    break;

                case "Fridge":
                    Fridge newFridge = new Fridge(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Fridge.Add(newFridge);
                    break;

                case "Jalousie":
                    Jalousie newJalousie = new Jalousie(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Jalousie.Add(newJalousie);
                    break;

                case "Lamp":
                    Lamp newLamp = new Lamp(name, lampType);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Lamp.Add(newLamp);
                    break;

                case "Radiator":
                    Radiator newRadiator = new Radiator(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Radiator.Add(newRadiator);
                    break;

                case "Router":
                    Router newRouter = new Router(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Router.Add(newRouter);
                    break;

                case "StereoSystem":
                    StereoSystem newStereoSystem = new StereoSystem(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).StereoSystem.Add(newStereoSystem);
                    break;

                case "TV":
                    TV newTV = new TV(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).TV.Add(newTV);
                    break;

                default:
                    Alarm newAlarma = new Alarm(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Alarm.Add(newAlarma);
                    break;
                }
                context.SaveChanges();
            }
        }
예제 #15
0
 private string RegulateDevice(string onChange, bool sign, int id, string type, int roomId)
 {
     using (SmartHouseContext context = new SmartHouseContext())
     {
         if (context.Conditioners.Any())
         {
             if (type == context.Conditioners.FirstOrDefault().GetType().ToString())
             {
                 Conditioner device = context.Conditioners.Find(id);
                 if (sign)
                 {
                     device.IncreeseTemperature();
                 }
                 else
                 {
                     device.DecreeseTemperature();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentTemperature.ToString());
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Exhausters.Any())
         {
             if (type == context.Exhausters.FirstOrDefault().GetType().ToString())
             {
                 Exhauster device = context.Exhausters.Find(id);
                 if (sign)
                 {
                     device.IncreesePower();
                 }
                 else
                 {
                     device.DecreesePower();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentPower.ToString());
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Fridges.Any())
         {
             if (type == context.Fridges.FirstOrDefault().GetType().ToString())
             {
                 Fridge device = context.Fridges.Find(id);
                 if (sign)
                 {
                     device.IncreeseTemperature();
                 }
                 else
                 {
                     device.DecreeseTemperature();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentTemperature.ToString());
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Lamps.Any())
         {
             if (type == context.Lamps.FirstOrDefault().GetType().ToString())
             {
                 Lamp device = context.Lamps.Find(id);
                 if (sign)
                 {
                     device.IncreeseBrightness();
                 }
                 else
                 {
                     device.DecreeseBrightness();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentBrightness.ToString());
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Radiators.Any())
         {
             if (type == context.Radiators.FirstOrDefault().GetType().ToString())
             {
                 Radiator device = context.Radiators.Find(id);
                 if (sign)
                 {
                     device.IncreeseTemperature();
                 }
                 else
                 {
                     device.DecreeseTemperature();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentTemperature.ToString());
             }
             else
             {
             }
         }
         if (context.StereoSystems.Any())
         {
             if (type == context.StereoSystems.FirstOrDefault().GetType().ToString())
             {
                 StereoSystem device = context.StereoSystems.Find(id);
                 if (sign)
                 {
                     device.IncreeseVolume();
                 }
                 else
                 {
                     device.DecreeseVolume();
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 return(device.CurrentVolume.ToString());
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.TVs.Any())
         {
             if (type == context.TVs.FirstOrDefault().GetType().ToString())
             {
                 TV device = context.TVs.Find(id);
                 if (onChange == "volume")
                 {
                     if (sign)
                     {
                         device.IncreeseVolume();
                     }
                     else
                     {
                         device.DecreeseVolume();
                     }
                 }
                 else
                 if (onChange == "channel")
                 {
                     if (sign)
                     {
                         device.NextChannel();
                     }
                     else
                     {
                         device.PrevChannel();
                     }
                 }
                 else
                 {
                     if (sign)
                     {
                         device.IncreeseBrightness();
                     }
                     else
                     {
                         device.DecreeseBrightness();
                     }
                 }
                 device.Room = context.Rooms.Find(roomId);
                 context.SaveChanges();
                 if (onChange == "volume")
                 {
                     return(device.CurrentVolume.ToString());
                 }
                 else
                 if (onChange == "channel")
                 {
                     return(device.GetCurrentChannelName());
                 }
                 else
                 {
                     return(device.CurrentBrightness.ToString());
                 }
             }
             else
             {
             }
         }
         else
         {
         }
     }
     return(null);
 }
예제 #16
0
        private static void StartListener(Radiator rad)
        {
            bool done = false;

            var thread = new Thread(() => startTCPServer(rad));
            thread.Start();

            UdpClient listener = new UdpClient(listenPort);
            IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);

            try
            {

                while (!done)
                {
                    Console.WriteLine("Waiting for SmartHome Data");
                    byte[] bytes = listener.Receive(ref groupEP);

                    //Console.WriteLine("Received broadcast from {0} :\n {1}\n",
                    //    groupEP.ToString(),
                    //    Encoding.ASCII.GetString(bytes, 0, bytes.Length));

                    string text = Encoding.ASCII.GetString(bytes, 0, bytes.Length);

                    string[] teksts = text.Split(':');
                    string a = teksts[4].Substring(0, 5);
                    string b = teksts[5].Substring(0, 5);
                    string c = teksts[6].Substring(0, 5);
                    string e = teksts[7] +":"+ teksts[8];

                    Console.WriteLine(text);
                    Console.WriteLine(e);

                    decimal a1 = decimal.Parse(a);
                    decimal b1 = decimal.Parse(b);
                    decimal c1 = decimal.Parse(c);

                    Console.WriteLine(a1);
                    Console.WriteLine(b1);
                    Console.WriteLine(c1);

                    SqlConnection con = new SqlConnection("Data Source=ramaldb.database.windows.net;Initial Catalog=SmartHomeDB;Integrated Security=False;User ID=ramal;Password=Rs123456;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

                    con.Open();

                    var command = new SqlCommand("INSERT INTO SmartHomeData (Temperature, Fugt, Lys, Dato, Forbrug, Movement, Lyd) VALUES (@Temperature, @Fugt, @Lys, @Dato, @Forbrug, @Movement, @Lyd)", con);

                    command.Parameters.AddWithValue("@Temperature", rad.Temperatur);
                    command.Parameters.AddWithValue("@Fugt", a1);
                    command.Parameters.AddWithValue("@Lys", b1);
                    command.Parameters.AddWithValue("@Lyd", c1);
                    command.Parameters.AddWithValue("@Movement", e);
                    command.Parameters.AddWithValue("@Dato", DateTime.Now);
                    command.Parameters.AddWithValue("@Forbrug", rad.pris);

                    command.ExecuteNonQuery();
                    con.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                listener.Close();

            }
        }
예제 #17
0
 private static void AngivRadiator(string text, Radiator rad)
 {
     rad.Angiv(double.Parse(text.Substring(3, 6)));
 }
예제 #18
0
 private static void TændRadiator(string text, Radiator rad)
 {
     if (text.Substring(0, 4).Equals("ON 1"))
     {
         rad.Tænd(1);
     }
     else if (text.Substring(0, 4).Equals("ON 2"))
     {
         rad.Tænd(2);
     }
     else if (text.Substring(0, 4).Equals("ON 3"))
     {
         rad.Tænd(3);
     }
     else if (text.Substring(0, 4).Equals("ON 4"))
     {
         rad.Tænd(4);
     }
     else if (text.Substring(0, 4).Equals("ON 5"))
     {
         rad.Tænd(5);
     }
 }
예제 #19
0
        private static void startTCPServer(Radiator rad)
        {
            IPAddress ipad = IPAddress.Any;
            TcpListener serverSocket = new TcpListener(ipad, 6789);
            serverSocket.Start();
            bool flag = true;

            while (flag)
            {
                TcpClient connectionSocket = serverSocket.AcceptTcpClient();
                Stream ns = connectionSocket.GetStream();
                StreamReader sr = new StreamReader(ns);
                string text = sr.ReadLine();

                if (text.Substring(0, 2).Equals("ON"))
                {
                    TændRadiator(text, rad);
                }
                else if (text.Substring(0, 2).Equals("AN"))
                {
                    AngivRadiator(text, rad);
                }
                else if (text.Equals("EXIT"))
                {
                    flag = false;
                }

                sr.Close();
                ns.Close();
            }
            serverSocket.Stop();
        }
예제 #20
0
        public void Initialize(Device dev, int roomId)
        {
            string name       = dev.Name;
            int    id         = dev.Id;
            string deviceType = dev.GetType().ToString();
            bool   state      = dev.State;

            this.Label1.Text  = "<h3 class=\"text-center\">" + name + "</h3>";
            this.OnOff.Click += ButtonClick;
            this.OnOff.ID     = "OnOff" + " " + id.ToString() + " " + deviceType + " " + roomId.ToString();
            //            this.CheckBox1.Attributes.Add("data-id", id.ToString());
            //          this.CheckBox1.CheckedChanged += ButtonClick;
            if (state)
            {
                //            CheckBox1.Attributes.Add("checked", "true");
            }
            else
            {
            }
            //      this.CheckBox1.CssClass = "my-switch";
            //    this.CheckBox1.ID = id.ToString() + " " + "state" + " " + deviceType + " " + roomId.ToString();
            //  this.Label2.Attributes.Add("for", "MainContent_ctl00_" + id.ToString() + " " + "state" + " " + deviceType + " " + roomId.ToString());
            //MainContent_ctl00_
            //"ctl00$MainContent$ctl00$"
            this.Delete.Click += ButtonClick;
            this.Rename.Click += ButtonClick;
            this.Delete.ID     = id.ToString() + " " + "delete" + " " + deviceType + " " + roomId.ToString();
            this.Rename.ID     = id.ToString() + " " + "rename" + " " + deviceType + " " + roomId.ToString();


            using (SmartHouseContext context = new SmartHouseContext())
            {
                if (context.Alarms.Any())
                {
                    if (deviceType == context.Alarms.FirstOrDefault().GetType().ToString())
                    {
                        this.img.Attributes.Add("data-action", "Alarm");
                        this.img.Attributes.Add("data-on", "/Content/Images/Alarm_on.jpg");
                        this.img.Attributes.Add("data-off", "/Content/Images/Alarm.jpg");
                        if (state)
                        {
                            this.img.Attributes.Add("src", "/Content/Images/Alarm_on.jpg");
                        }
                        else
                        {
                            this.img.Attributes.Add("src", "/Content/Images/Alarm.jpg");
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Conditioners.Any())
                {
                    if (deviceType == context.Conditioners.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Conditioner");
                        img.Attributes.Add("data-on", "/Content/Images/Cond_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Cond.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Cond_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Cond.jpg");
                        }
                        Conditioner dev2 = (Conditioner)dev;
                        TemperatureDeviceBuilder(id, deviceType, roomId, dev2.CurrentTemperature);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Exhausters.Any())
                {
                    if (deviceType == context.Exhausters.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Exhauster");
                        img.Attributes.Add("data-on", "/Content/Images/Exhauster_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Exhauster.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Exhauster_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Exhauster.jpg");
                        }
                        Exhauster dev2 = (Exhauster)dev;
                        PowerDeviceBuilder(id, deviceType, roomId, dev2.CurrentPower);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Fridges.Any())
                {
                    if (deviceType == context.Fridges.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Fridge");
                        img.Attributes.Add("data-on", "/Content/Images/Fridge_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Fridge.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Fridge_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Fridge.jpg");
                        }
                        Fridge dev2 = (Fridge)dev;
                        TemperatureDeviceBuilder(id, deviceType, roomId, dev2.CurrentTemperature);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Jalousies.Any())
                {
                    if (deviceType == context.Jalousies.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Jalousie");
                        img.Attributes.Add("data-on", "/Content/Images/Jalousie.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Jalousie_off.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Jalousie.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Jalousie_off.jpg");
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Lamps.Any())
                {
                    if (deviceType == context.Lamps.FirstOrDefault().GetType().ToString())
                    {
                        Lamp   dev2     = (Lamp)dev;
                        string lampType = dev2.LampType;
                        img.Attributes.Add("data-action", "Lamp");
                        if (lampType == LampTypes.Chandelier.ToString())
                        {
                            img.Attributes.Add("data-on", "/Content/Images/Lamp_on.jpg");
                            img.Attributes.Add("data-off", "/Content/Images/Lamp.jpg");
                            if (state)
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_on.jpg");
                            }
                            else
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp.jpg");
                            }
                        }
                        else
                        if (lampType == LampTypes.Table.ToString())
                        {
                            img.Attributes.Add("data-on", "/Content/Images/Lamp_table_on.jpg");
                            img.Attributes.Add("data-off", "/Content/Images/Lamp_table.jpg");
                            if (state)
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_table_on.jpg");
                            }
                            else
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_table.jpg");
                            }
                        }
                        else
                        if (lampType == LampTypes.Wall.ToString())
                        {
                            img.Attributes.Add("data-on", "/Content/Images/Lamp_wall_on.jpg");
                            img.Attributes.Add("data-off", "/Content/Images/Lamp_wall.jpg");
                            if (state)
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_wall_on.jpg");
                            }
                            else
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_wall.jpg");
                            }
                        }
                        else
                        if (lampType == LampTypes.Floor.ToString())
                        {
                            img.Attributes.Add("data-on", "/Content/Images/Lamp_floor_on.jpg");
                            img.Attributes.Add("data-off", "/Content/Images/Lamp_floor.jpg");
                            if (state)
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_floor_on.jpg");
                            }
                            else
                            {
                                img.Attributes.Add("src", "/Content/Images/Lamp_floor.jpg");
                            }
                        }
                        LightDeviceBuilder(id, deviceType, roomId, dev2.CurrentBrightness);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Radiators.Any())
                {
                    if (deviceType == context.Radiators.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Radiator");
                        img.Attributes.Add("data-on", "/Content/Images/Radiator_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Radiator.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Radiator_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Radiator.jpg");
                        }
                        Radiator dev2 = (Radiator)dev;
                        TemperatureDeviceBuilder(id, deviceType, roomId, dev2.CurrentTemperature);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.Routers.Any())
                {
                    if (deviceType == context.Routers.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "Router");
                        img.Attributes.Add("data-on", "/Content/Images/Router_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/Router.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/Router_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/Router.jpg");
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.StereoSystems.Any())
                {
                    if (deviceType == context.StereoSystems.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "StereoSystem");
                        img.Attributes.Add("data-on", "/Content/Images/StereoSystem_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/StereoSystem.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/StereoSystem_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/StereoSystem.jpg");
                        }
                        StereoSystem dev2 = (StereoSystem)dev;
                        SoundDeviceBuilder(id, deviceType, roomId, dev2.CurrentVolume);
                    }
                    else
                    {
                    }
                }
                else
                {
                }
                if (context.TVs.Any())
                {
                    if (deviceType == context.TVs.FirstOrDefault().GetType().ToString())
                    {
                        img.Attributes.Add("data-action", "TV");
                        img.Attributes.Add("data-on", "/Content/Images/TV_on.jpg");
                        img.Attributes.Add("data-off", "/Content/Images/TV.jpg");
                        if (state)
                        {
                            img.Attributes.Add("src", "/Content/Images/TV_on.jpg");
                        }
                        else
                        {
                            img.Attributes.Add("src", "/Content/Images/TV.jpg");
                        }
                        TV dev2 = (TV)dev;
                        LightDeviceBuilder(id, deviceType, roomId, dev2.CurrentBrightness);
                        SoundDeviceBuilder(id, deviceType, roomId, dev2.CurrentVolume);
                        ChannelDeviceBuilder(id, deviceType, roomId, dev2.GetCurrentChannelName());
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }
        }
예제 #21
0
        private static void StartListener(Radiator rad)
        {
            bool done = false;

            var thread = new Thread(() => startTCPServer(rad));

            thread.Start();



            UdpClient  listener = new UdpClient(listenPort);
            IPEndPoint groupEP  = new IPEndPoint(IPAddress.Any, listenPort);


            try
            {
                while (!done)
                {
                    Console.WriteLine("Waiting for SmartHome Data");
                    byte[] bytes = listener.Receive(ref groupEP);

                    //Console.WriteLine("Received broadcast from {0} :\n {1}\n",
                    //    groupEP.ToString(),
                    //    Encoding.ASCII.GetString(bytes, 0, bytes.Length));

                    string text = Encoding.ASCII.GetString(bytes, 0, bytes.Length);



                    string[] teksts = text.Split(':');
                    string   a      = teksts[4].Substring(0, 5);
                    string   b      = teksts[5].Substring(0, 5);
                    string   c      = teksts[6].Substring(0, 5);
                    string   e      = teksts[7] + ":" + teksts[8];

                    Console.WriteLine(text);
                    Console.WriteLine(e);

                    decimal a1 = decimal.Parse(a);
                    decimal b1 = decimal.Parse(b);
                    decimal c1 = decimal.Parse(c);


                    Console.WriteLine(a1);
                    Console.WriteLine(b1);
                    Console.WriteLine(c1);

                    SqlConnection con = new SqlConnection("Data Source=ramaldb.database.windows.net;Initial Catalog=SmartHomeDB;Integrated Security=False;User ID=ramal;Password=Rs123456;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");


                    con.Open();

                    var command = new SqlCommand("INSERT INTO SmartHomeData (Temperature, Fugt, Lys, Dato, Forbrug, Movement, Lyd) VALUES (@Temperature, @Fugt, @Lys, @Dato, @Forbrug, @Movement, @Lyd)", con);

                    command.Parameters.AddWithValue("@Temperature", rad.Temperatur);
                    command.Parameters.AddWithValue("@Fugt", a1);
                    command.Parameters.AddWithValue("@Lys", b1);
                    command.Parameters.AddWithValue("@Lyd", c1);
                    command.Parameters.AddWithValue("@Movement", e);
                    command.Parameters.AddWithValue("@Dato", DateTime.Now);
                    command.Parameters.AddWithValue("@Forbrug", rad.pris);

                    command.ExecuteNonQuery();
                    con.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                listener.Close();
            }
        }
예제 #22
0
 private static void AngivRadiator(string text, Radiator rad)
 {
     rad.Angiv(double.Parse(text.Substring(3, 6)));
 }
예제 #23
0
 private void Awake()
 {
     radiator = GetComponentInParent <Radiator>();
 }