private void data_Rec(XComm.Sample.Message Data) { try { this.ZoneId = Data.ZoneId; this.ZoneName = Data.ZoneName; LocationCollection temp_locationCollection = new LocationCollection(); for (int i = 0; i < Data.ZoneLocation.Count; i++) { Location temp = new Location(Data.ZoneLocation[i].Latitude, Data.ZoneLocation[i].Longitude); temp_locationCollection.Add(temp); } ZoneLocation = temp_locationCollection; this.Temperature = Data.Temperature; this.Pressure = Data.Pressure; this.Humidity = Data.Humidity; this.FireStatus = Data.FireStatus; this.Fire_Location = new Location(Data.Fire_Location.Latitude, Data.Fire_Location.Longitude); this.Rain1_Status = Data.Rain1_Status; LocationCollection temp_locationCollection1 = new LocationCollection(); for (int i = 0; i < Data.Rain1_Location.Count; i++) { Location temp = new Location(Data.Rain1_Location[i].Latitude, Data.Rain1_Location[i].Longitude); temp_locationCollection1.Add(temp); } Rain1_Location = temp_locationCollection1; //this.Rain1_Location = Data.Rain1_Location; this.Rain2_Status = Data.Rain2_Status; LocationCollection temp_locationCollection2 = new LocationCollection(); for (int i = 0; i < Data.Rain2_Location.Count; i++) { Location temp = new Location(Data.Rain2_Location[i].Latitude, Data.Rain2_Location[i].Longitude); temp_locationCollection2.Add(temp); } Rain2_Location = temp_locationCollection2; //this.Rain2_Location = Data.Rain2_Location; zone1_name.Dispatcher.BeginInvoke((Action) delegate { zone1_name.Content = ZoneName; }); lbl_temp.Dispatcher.BeginInvoke((Action) delegate { lbl_temp.Content = Temperature; }); lbl_pressure.Dispatcher.BeginInvoke((Action) delegate { lbl_pressure.Content = Pressure; }); lbl_humidity.Dispatcher.BeginInvoke((Action) delegate { lbl_humidity.Content = Humidity; }); myMap.Dispatcher.BeginInvoke((Action) delegate { // for drawing zone area NewMap.addNewPolyline(ZoneLocation); //for zone 1 fire if (Data.FireStatus == true && flag_task == false) { if (flag_task == false) { //task_fire.Start(); } NewMap.AddLabel(Fire_Location, "fire"); NewMap.AddPushpin(Fire_Location); } else if (flag_task == true) { simpleSound.Stop(); flag_task = false; } //for zone 1 rain if (Data.Rain1_Status == true) { NewMap.addNewPolygon(Rain1_Location); } if (Data.Rain2_Status == true) { NewMap.addNewPolygon(Rain2_Location); } //------------------------------------------------------------------------------------------------- myMap.Children.Clear(); //------------------------------------------------------------------------------------------------ if (Data.Rain1_Status == true) { NewMap.addNewPolygon(Rain1_Location); } if (Data.Rain2_Status == true) { NewMap.addNewPolygon(Rain2_Location); } NewMap.addNewPolyline(ZoneLocation); if (Data.FireStatus == true) { NewMap.AddLabel(Fire_Location, "fire"); NewMap.AddPushpin(Fire_Location); } }); } catch (Exception ex) { } Thread.Sleep(1000); }
private void CommunicationPort_DataReceivedEventHandler(string Data) { try { //split the serial port data string[] sd = Data.Split('|'); if (sd.Length == 7) { task_fire = new Task(onFire); if (currentDate.Hour == DateTime.Now.Hour) { DatabaseOperation.Connect(); if (sd[0] != "") { DatabaseOperation.InsertUpdateDelete("INSERT INTO Temp VALUES('" + tempSensorId + "','" + zoneId + "','" + sd[0] + "','" + DateTime.Now + "') "); } DatabaseOperation.Disconnect(); DatabaseOperation.Connect(); if (sd[1] != "") { DatabaseOperation.InsertUpdateDelete("INSERT INTO Pressure VALUES('" + presSensorId + "','" + zoneId + "','" + sd[1] + "','" + DateTime.Now + "') "); } DatabaseOperation.Disconnect(); DatabaseOperation.Connect(); if (sd[2] != "") { DatabaseOperation.InsertUpdateDelete("INSERT INTO Humidity VALUES('" + humSensorId + "','" + zoneId + "','" + sd[2] + "','" + DateTime.Now + "') "); } DatabaseOperation.Disconnect(); currentDate = currentDate.AddHours(2.0); } Message1.Temperature = sd[0]; Message1.Pressure = sd[1]; Message1.Humidity = sd[2]; //fire if (sd[3] == "1") { //border label lbl_firestatus.Dispatcher.BeginInvoke((Action) delegate { lbl_firestatus.Content = "Fire"; }); //playing alarm if (flag_task == false) { task_fire.Start(); } myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.AddLabel(new Location(21.182782, 72.808912), "fire"); NewMap.AddPushpin(new Location(21.182782, 72.808912)); }); Message1.FireStatus = true; } else if (flag_task == true) { //border label lbl_firestatus.Dispatcher.BeginInvoke((Action) delegate { lbl_firestatus.Content = "-"; }); //stop sound simpleSound.Stop(); flag_task = false; Message1.FireStatus = false; } //rain if (sd[4] == "1") { //border lbl lbl_rain1status.Dispatcher.BeginInvoke((Action) delegate { lbl_rain1status.Content = "rain1"; }); myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.addNewPolygon(zone1_rain1); }); Message1.Rain1_Status = true; } else if (sd[4] == "0") { lbl_rain1status.Dispatcher.BeginInvoke((Action) delegate { lbl_rain1status.Content = "-"; }); Message1.Rain1_Status = false; } if (sd[5] == "1") { lbl_rain2status.Dispatcher.BeginInvoke((Action) delegate { lbl_rain2status.Content = "rain2"; }); myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.addNewPolygon(zone1_rain2); }); Message1.Rain2_Status = true; } else if (sd[5] == "0") { lbl_rain2status.Dispatcher.BeginInvoke((Action) delegate { lbl_rain2status.Content = "-"; }); Message1.Rain2_Status = false; } lbl_temp.Dispatcher.BeginInvoke((Action) delegate { lbl_temp.Content = sd[0]; }); lbl_pressure.Dispatcher.BeginInvoke((Action) delegate { lbl_pressure.Content = sd[1]; }); lbl_humidity.Dispatcher.BeginInvoke((Action) delegate { lbl_humidity.Content = sd[2]; }); myMap.Dispatcher.BeginInvoke((Action) delegate { //for zone area NewMap.addNewPolyline(zone1); //map clear-------------------------------------------------------------------------------------------- myMap.Children.Clear(); //----------------------------------------------------------------------------------------------------- NewMap.addNewPolyline(zone1); }); if (sd[3] == "1") { myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.AddLabel(new Location(21.182782, 72.808912), "fire"); NewMap.AddPushpin(new Location(21.182782, 72.808912)); }); } if (sd[4] == "1") { myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.addNewPolygon(zone1_rain1); }); } if (sd[5] == "1") { myMap.Dispatcher.BeginInvoke((Action) delegate { NewMap.addNewPolygon(zone1_rain2); }); } Client_main.Send(Message1); } } catch (Exception ex) {} }