private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.SaveData: { if (mDevice.DeviceID > 0) { DevicePresenter.UpdateDevice(mDevice); } else { DevicePresenter.InsertDevice(mDevice); } } break; default: break; } }
private void bwAsync_DoWork(object sender, DoWorkEventArgs e) { Stopwatch mStopWatch = new Stopwatch(); mStopWatch.Start(); SanitaLogEx.d(TAG, "Start database cache..."); PostMessage("Start database cache ..."); IsCacheCompleted = false; try { //Update timer SystemInfo.NOW = SoftUpdatePresenter.GetCurrentTime(null, null); //Kiểm tra và nâng cấp cấu trúc database Splasher.Status = "Check and update database..."; SoftUpdatePresenter.DoUpdateDatabaseSQL(); using (IDbConnection connection = SoftUpdatePresenter.GetConnection()) { //Open connection connection.Open(); //Begin transtation using (IDbTransaction trans = connection.BeginTransaction()) { Splasher.Status = "Đang xử lý : Danh sách danh mục...".Translate(); DM_Intent_Type.InitDefaultList(DM_Intent_TypePresenter.GetDM_Intent_Types(connection, trans)); MyVar.mListDM_Intent_Type = DM_Intent_Type.GetDefaultList(0).OrderBy(p => p.DM_Intent_TypeID).ToList(); DM_Entity_Type.InitDefaultList(DM_Entity_TypePresenter.GetDM_Entity_Types(connection, trans)); MyVar.mListDM_Entity_Type = DM_Entity_Type.GetDefaultList(0).OrderBy(p => p.DM_Entity_TypeID).ToList(); MyVar.mListUser = UserPresenter.GetUsers(connection, trans); MyVar.mListHome = HomePresenter.GetHomes(connection, trans); MyVar.mListRoom = RoomPresenter.GetRooms(connection, trans); MyVar.mListDevice = DevicePresenter.GetDevices(connection, trans); //----------------------------------------------------------------------------- //Commit transtation trans.Commit(); //Close connection connection.Close(); } } SanitaLogEx.d(TAG, "End database cache..."); } catch (Exception ex) { SanitaLogEx.e(TAG, "bwAsync_DoWork error !", ex); } IsCacheCompleted = true; }
public DeviceView() { InitializeComponent(); devicePresenter = new DevicePresenter(this); DataContext = devicePresenter; PeripheralDeviceMethods per = new PeripheralDeviceMethods(); ComboBox_Devies.ItemsSource = per.GetAllPeripheralDevAsStringArray(); ComboBox_Devies.SelectedIndex = 0; }
private void btnXoa_Click(object sender, EventArgs e) { Device data = mListViewData.SelectedObject as Device; if (data != null && data.DeviceID > 0) { if (SanitaMessageBox.Show("Bạn có chắc chắn muốn xóa thiết bị này không ?", "Thông Báo", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { if (DevicePresenter.DeleteDevice(data) > 0) { DoRefresh(); } } } }
private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.LoadData: { mListDevice = DevicePresenter.GetDevices(); } break; default: break; } }
void Update() { if (active && DevicePresenterOfSelectedDevice == null) { if (Input.GetMouseButtonDown(0)) { Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit myHitInfo = new RaycastHit(); if (GetComponent <BoxCollider>().Raycast(inputRay, out myHitInfo, 10000f)) { //if device is registered if (DeviceCollection.DeviceCollectionInstance.GetRegisteredDeviceByDeviceId(devicePresenter.Device.Id) != null) { DevicePresenterOfSelectedDevice = devicePresenter; meshRenderer.enabled = true; if (onCollision != null) { onCollision.Invoke(); } } } } } if (Input.GetMouseButtonUp(0)) { Reset(); if (onStopCollision != null) { onStopCollision.Invoke(); } } }
private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.LoadData: { mListUser = UserPresenter.GetUsers(null, null); MyVar.mListUser = mListUser; } break; case ProcessingType.PhanQuyenHome: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListHomeID)) { foreach (String strID in ListHomeID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Home home in MyVar.mListHome) { if (_list_id.Contains(home.HomeID)) { if (home.UserID != mUser.UserID) { home.UserID = mUser.UserID; HomePresenter.UpdateHome(home); } } else { if (home.UserID == mUser.UserID) { home.UserID = 0; HomePresenter.UpdateHome(home); } } } } break; case ProcessingType.PhanQuyenPhong: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListRoomID)) { foreach (String strID in ListRoomID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Room mRoom in MyVar.mListRoom) { if (_list_id.Contains(mRoom.HomeID)) { if (mRoom.UserID != mUser.UserID) { mRoom.UserID = mUser.UserID; RoomPresenter.UpdateRoom(mRoom); } } else { if (mRoom.UserID == mUser.UserID) { mRoom.UserID = 0; RoomPresenter.UpdateRoom(mRoom); } } } } break; case ProcessingType.PhanQuyenThietBi: { IList <int> _list_id = new List <int>(); if (!String.IsNullOrEmpty(ListDeviceID)) { foreach (String strID in ListDeviceID.Split(';')) { int id = 0; int.TryParse(strID, out id); if (id > 0) { _list_id.Add(id); } } } foreach (Device mDevice in MyVar.mListDevice) { if (_list_id.Contains(mDevice.HomeID)) { if (mDevice.UserID != mUser.UserID) { mDevice.UserID = mUser.UserID; DevicePresenter.UpdateDevice(mDevice); } } else { if (mDevice.UserID == mUser.UserID) { mDevice.UserID = 0; DevicePresenter.UpdateDevice(mDevice); } } } } break; default: break; } }
private void ChangeCurrentRow(DevicePresenter devicePresenter, DeviceEditPresenter deviceEdit, DeviceModel obj) { DeviceModel device = ((DeviceModel)deviceEdit.View.DataContext); obj.comment = device.comment; obj.id = device.id; obj.id_fixed_asset = device.id_fixed_asset; obj.id_peripheral_device = device.id_peripheral_device; obj.ip_address = device.ip_address; obj.mac_address = device.mac_address; obj.model = device.model; obj.name_peripheral_device = device.name_peripheral_device; obj.producer = device.producer; obj.serial_number = device.serial_number; devicePresenter.View.dataGridDevices.Items.Refresh(); }
public API_TroLyAoData_Out TroLyAo_Execute(API_TroLyAoData_In data) { //Output API_TroLyAoData_Out mAPI_TroLyAoData_Out = new API_TroLyAoData_Out(); mAPI_TroLyAoData_Out.Language = "vi-VN"; //Kiểm tra data if (data == null) { mAPI_TroLyAoData_Out.Data = "Bạn hãy hỏi gì đi..."; mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); return(mAPI_TroLyAoData_Out); } //Kiểm tra device Device mDevice = DevicePresenter.GetDevice(data.DeviceID); if (mDevice.DeviceID <= 0) { mAPI_TroLyAoData_Out.Data = "Thiết bị của bạn chưa được đăng ký."; mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); return(mAPI_TroLyAoData_Out); } //Kiểm tra user User mUser = UserPresenter.GetUser(mDevice.UserID); if (mUser.APIKey != data.API_Key) { mAPI_TroLyAoData_Out.Data = "API key không đúng."; mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); return(mAPI_TroLyAoData_Out); } if (!MyVar.mListDevice.Any(p => p.DeviceID == mDevice.DeviceID)) { MyVar.mListDevice.Add(mDevice); } mDevice = MyVar.mListDevice.FirstOrDefault(p => p.DeviceID == mDevice.DeviceID); mDevice.mUser = mUser; //Xử lý input data.Data = XuLyDuLieu(data.Data); //Lấy danh sách request IList <Intent_Request> mListRequest = Intent_RequestPresenter.GetIntent_Requests(data.Data); //Lọc theo bối cảnh hiện tại IList <Intent_Request> mListRequest_Current = mListRequest.Where(p => p.Current_DM_Entity_TypeID == mDevice.Current_DM_Entity_TypeID && p.Current_DM_Intent_TypeID == mDevice.Current_DM_Intent_TypeID).ToList(); if (mListRequest_Current.Count == 0) { mListRequest_Current = mListRequest.Where(p => p.Current_DM_Entity_TypeID == 0 && p.Current_DM_Intent_TypeID == 0).ToList(); } if (mListRequest_Current.Count > 0) { mListRequest = mListRequest_Current; } //Sắp xếp IList <Intent_Request> mListRequest_NoneParam = mListRequest.Where(p => !p.Data.Contains("<") && !p.Data.Contains(">")).OrderByDescending(p => p.Data.Length).ToList(); IList <Intent_Request> mListRequest_Param = mListRequest.Where(p => p.Data.Contains("<") && p.Data.Contains(">")).OrderByDescending(p => p.Data.Length).ToList(); mListRequest = mListRequest_NoneParam.Concat(mListRequest_Param).ToList(); Intent_Request mIntent_Request = new Intent_Request(); foreach (Intent_Request request in mListRequest) { String request_data = request.Data; request_data = request_data ?? ""; request_data = request_data.Replace("<*>", "(.*)"); request_data = request_data.Replace("<", "(?<"); request_data = request_data.Replace(">", ">(.+))"); request_data = "^" + request_data + "$"; Regex mRegex = new Regex(request_data, RegexOptions.IgnoreCase | RegexOptions.Singleline); if (mRegex.IsMatch(data.Data)) { mIntent_Request = request; mDevice.Current_DM_Intent_TypeID = mIntent_Request.DM_Intent_TypeID; mDevice.Current_DM_Entity_TypeID = mIntent_Request.DM_Entity_TypeID; GroupCollection groups = mRegex.Match(data.Data).Groups; foreach (string groupName in mRegex.GetGroupNames()) { EntityParam mEntityParam = new EntityParam(); mEntityParam.Name = groupName; mEntityParam.Value = groups[groupName].Value; mIntent_Request.mListParam.Add(mEntityParam); } } } //Set device mIntent_Request.mDevice = mDevice; //Xử lý request String response_request = XuLyRequest(mIntent_Request); if (!String.IsNullOrEmpty(response_request)) { mAPI_TroLyAoData_Out.Data = response_request; mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); return(mAPI_TroLyAoData_Out); } //Get response Intent_Response mIntent_Response = Intent_ResponsePresenter.GetIntent_Response_Request(mIntent_Request); if (String.IsNullOrEmpty(mIntent_Response.Data)) { mIntent_Response.Data = "Xin lỗi... Tôi không hiểu !"; } //Update global if (mIntent_Response.Data.Contains("<") && mIntent_Response.Data.Contains(">")) { mIntent_Response.Data.Replace("<thoi_gian_hien_tai>", String.Format("{0:HH:mm}", SystemInfo.NOW)); mIntent_Response.Data.Replace("<ngay_hien_tai>", String.Format("{0:dd/MM/yyyy}", SystemInfo.NOW)); mIntent_Response.Data.Replace("<thu_hien_tai>", String.Format("{0}", SystemInfo.NOW.GetThu())); mIntent_Response.Data.Replace("<ngay_mai>", String.Format("{0:dd/MM/yyyy}", SystemInfo.NOW.AddDays(1))); mIntent_Response.Data.Replace("<thu_mai>", String.Format("{0}", SystemInfo.NOW.AddDays(1).GetThu())); } //Return mAPI_TroLyAoData_Out.Data = mIntent_Response.Data; mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); return(mAPI_TroLyAoData_Out); #if false //Check if (data.Data.Contains("thời tiết") && data.Data.Contains("hôm nay")) { String thu = ""; if (SystemInfo.NOW.DayOfWeek == DayOfWeek.Sunday) { thu = String.Format("chủ nhật"); } else { thu = String.Format("thứ {0}", (int)SystemInfo.NOW.DayOfWeek + 1); } mAPI_TroLyAoData_Out.Data = String.Format("Dự báo thời tiết hôm nay ở Quan Khê, Hải Dương {0} ngày {1:dd/MM} có mưa rào nhẹ, nhiệt độ từ 26 đến 32 độ, độ ẩm 94%", thu, SystemInfo.NOW); } else if ((data.Data.Contains("thời tiết") && data.Data.Contains("ngày mai")) || data.Data.Contains("còn ngày mai")) { String thu = ""; if (SystemInfo.NOW.AddDays(1).DayOfWeek == DayOfWeek.Sunday) { thu = String.Format("chủ nhật"); } else { thu = String.Format("thứ {0}", (int)SystemInfo.NOW.AddDays(1).DayOfWeek + 1); } mAPI_TroLyAoData_Out.Data = String.Format("Dự báo thời tiết ngày mai ở Quan Khê, Hải Dương {0} ngày {1:dd/MM} trời nhiều mây và nắng nhẹ, nhiệt độ từ 26 đến 33 độ, độ ẩm 76%", thu, SystemInfo.NOW.AddDays(1)); } else if (data.Data.Contains("mấy giờ rồi") || data.Data.Contains("bây giờ là mấy giờ")) { mAPI_TroLyAoData_Out.Data = String.Format("Thời gian là {0:HH:mm} phút", SystemInfo.NOW); } else if (data.Data.Contains("hôm nay") && data.Data.Contains("thứ mấy")) { if (SystemInfo.NOW.DayOfWeek == DayOfWeek.Sunday) { mAPI_TroLyAoData_Out.Data = String.Format("Hôm nay là chủ nhật"); } else { mAPI_TroLyAoData_Out.Data = String.Format("Hôm nay là thứ {0}", (int)SystemInfo.NOW.DayOfWeek + 1); } } else if (data.Data.Contains("ngày mai") && data.Data.Contains("thứ mấy")) { if (SystemInfo.NOW.AddDays(1).DayOfWeek == DayOfWeek.Sunday) { mAPI_TroLyAoData_Out.Data = String.Format("Ngày mai là chủ nhật"); } else { mAPI_TroLyAoData_Out.Data = String.Format("Ngày mai là thứ {0}", (int)SystemInfo.NOW.AddDays(1).DayOfWeek + 1); } } else if (data.Data.EqualText("bạn là ai") || data.Data.EqualText("bạn là cái gì")) { mAPI_TroLyAoData_Out.Data = "Tôi là trợ lý ảo của bạn đây"; } else if (data.Data.EqualText("tên bạn là gì")) { mAPI_TroLyAoData_Out.Data = "Tôi chưa tự giới thiệu sao ? Tên tôi là Daisy !"; } else if (data.Data.Contains("bạn biết hát không") || data.Data.Contains("bạn có biết hát không") || data.Data.Contains("hát cho tôi nghe")) { mAPI_TroLyAoData_Out.Data += "<speak>"; mAPI_TroLyAoData_Out.Data += "<p>"; mAPI_TroLyAoData_Out.Data += "<s>Xin lỗi, giờ tôi vẫn chưa biết hát.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Thay vào đó, tôi có thể đọc lời bài hát cho bạn tự tưởng tượng theo.</s>"; mAPI_TroLyAoData_Out.Data += "<break time=\"300ms\"/>"; mAPI_TroLyAoData_Out.Data += "<s>Kìa con bướm vàng.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Kìa con bướm vàng.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Xòe đôi cánh.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Xòe đôi cánh.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Tung cánh bay năm ba vòng.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Tung cánh bay năm ba vòng.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Em ngồi xem...</s>"; mAPI_TroLyAoData_Out.Data += "<s>Em ngồi xem...</s>"; mAPI_TroLyAoData_Out.Data += "</p>"; mAPI_TroLyAoData_Out.Data += "</speak>"; } else if (data.Data.Contains("bạn đang ở đâu")) { mAPI_TroLyAoData_Out.Data += "<speak>"; mAPI_TroLyAoData_Out.Data += "<p>"; mAPI_TroLyAoData_Out.Data += "<s>Tôi ở trong thiết bị này.</s>"; mAPI_TroLyAoData_Out.Data += "<s>cả máy tính bảng có ngay khi cần.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Google home cũng có phần.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Ôi nhiều nhà quá phân vân chọn hoài.</s>"; mAPI_TroLyAoData_Out.Data += "</p>"; mAPI_TroLyAoData_Out.Data += "</speak>"; } else if (data.Data.Contains("truyện cười") || data.Data.Contains("chuyện cười")) { mAPI_TroLyAoData_Out.Data += "<speak>"; mAPI_TroLyAoData_Out.Data += "<p>"; mAPI_TroLyAoData_Out.Data += "<s>Được, bạn nghe nhé !</s>"; mAPI_TroLyAoData_Out.Data += "<break time=\"300ms\"/>"; mAPI_TroLyAoData_Out.Data += "<s>Trong giờ địa lý, thầy hỏi trò.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Em hãy nói ba lý do khiến em chắc rằng trái đất hình cầu.</s>"; mAPI_TroLyAoData_Out.Data += "<s>Thưa thầy, bố em nói thế, mẹ em nói thế và thầy cũng nói thế ạ !</s>"; mAPI_TroLyAoData_Out.Data += "<audio src=\"https://ia601507.us.archive.org/31/items/google_cuoi/google_cuoi.ogg\"/>"; mAPI_TroLyAoData_Out.Data += "</p>"; mAPI_TroLyAoData_Out.Data += "</speak>"; } else if (data.Data.Contains("truyện khác") || data.Data.Contains("chuyện khác")) { mAPI_TroLyAoData_Out.Data += "<speak>"; mAPI_TroLyAoData_Out.Data += "<p>"; mAPI_TroLyAoData_Out.Data += "<s>Được, nghe tôi kể đây này !</s>"; mAPI_TroLyAoData_Out.Data += "<break time=\"300ms\"/>"; mAPI_TroLyAoData_Out.Data += "<s>Ngày đầu tiên bé đi học về, bố mẹ hỏi. Ở lớp thế nào con ?</s>"; mAPI_TroLyAoData_Out.Data += "<s>Vui lắm bố ạ, cô giáo con xinh lắm !</s>"; mAPI_TroLyAoData_Out.Data += "<s>Thế cô dạy con những gì ?</s>"; mAPI_TroLyAoData_Out.Data += "<s>Cô chẳng biết gì cả ! Cái gì cũng phải hỏi : Em nào cho cô biết nào.</s>"; mAPI_TroLyAoData_Out.Data += "<audio src=\"https://ia601507.us.archive.org/31/items/google_cuoi/google_cuoi.ogg\"/>"; mAPI_TroLyAoData_Out.Data += "</p>"; mAPI_TroLyAoData_Out.Data += "</speak>"; } else if (data.Data.EqualText("bật đèn phòng khách")) { mAPI_TroLyAoData_Out.Data = "OK, đã bật đèn phòng khách"; } else if (data.Data.EqualText("tắt đèn phòng khách")) { mAPI_TroLyAoData_Out.Data = "OK, đã tắt đèn phòng khách"; } else if (data.Data.EqualText("bật điều hòa") || data.Data.EqualText("tôi nóng quá")) { mAPI_TroLyAoData_Out.Data = "OK, đã bật điều hòa"; } else if (data.Data.EqualText("để điều hòa 26 độ")) { mAPI_TroLyAoData_Out.Data = "OK, đã để điều hòa 26 độ C"; } //Return if (String.IsNullOrEmpty(mAPI_TroLyAoData_Out.Data)) { mAPI_TroLyAoData_Out.Data = "Xin lỗi... Tôi không hiểu !"; } mAPI_TroLyAoData_Out.ID = Sanita.Utility.Encryption.CryptorEngine.CreateMD5Hash(mAPI_TroLyAoData_Out.Data); mAPI_TroLyAoData_Out.Language = "vi-VN"; return(mAPI_TroLyAoData_Out); #endif }
public String ExecuteCommand(Intent_Request data) { EntityParam thiet_bi = data.mListParam.FirstOrDefault(p => p.Name == "thiet_bi"); if (thiet_bi == null) { return("<speak><p><s>Bạn hãy nói tên thiết bị</s></p></speak>"); } //Danh sách thiết bị IList <Device> mListDevice = DevicePresenter.GetDevices(null, null); IList <Room> mListRoom = RoomPresenter.GetRooms(null, null); foreach (Device device in mListDevice) { device.mRoom = mListRoom.FirstOrDefault(p => p.RoomID == device.RoomID); device.mRoom = device.mRoom ?? new Room(); } Device mDevice = null; while (true) { //Tìm thiết bị trùng khớp //ví dụ "đèn ngủ 1" { mDevice = mListDevice.FirstOrDefault(p => p.DeviceName.EqualTextNoCase(thiet_bi.Value)); if (mDevice != null) { break; } } //Tìm thiết bị gồm tên thiết bị (đầy đủ) + tên phòng //ví dụ "đèn ngủ 1 phòng khách" { mDevice = mListDevice.FirstOrDefault(p => (p.DeviceName + " " + p.mRoom.RoomName).EqualTextNoCase(thiet_bi.Value)); if (mDevice != null) { break; } } //Tìm thiết bị gồm tên thiết bị (ngắn gọn) + tên phòng //ví dụ "đèn phòng khách" { mDevice = mListDevice.FirstOrDefault(p => (p.DeviceName_Short + " " + p.mRoom.RoomName).EqualTextNoCase(thiet_bi.Value)); if (mDevice != null) { break; } } //Tìm thiết bị cùng phòng (tên đầy đủ) { mListDevice = mListDevice.Where(p => p.RoomID == data.mDevice.RoomID).ToList(); { mDevice = mListDevice.FirstOrDefault(p => p.DeviceName.EqualTextNoCase(thiet_bi.Value)); if (mDevice != null) { break; } } //Tìm thiết bị cùng phòng (tên ngắn gọn) { mDevice = mListDevice.FirstOrDefault(p => p.DeviceName_Short.EqualTextNoCase(thiet_bi.Value)); if (mDevice != null) { break; } } } break; } if (mDevice != null) { switch (data.DM_Entity_TypeID) { case DM_Entity_Type.HOME_CONTROL_BAT_THIET_VI: { if (UtilityHassIO.mInstance.Switch_Turn_OnOff(data.mDevice.mUser.HassIO_URL, data.mDevice.mUser.HassIO_KEY, mDevice.DeviceCode, "on")) { return(String.Format("<speak><p><s>Đã bật {0}</s></p></speak>", mDevice.DeviceName)); } else { return(String.Format("<speak><p><s>Xin lỗi, tôi không thực hiện được yêu cầu của bạn</s></p></speak>", mDevice.DeviceName)); } } case DM_Entity_Type.HOME_CONTROL_TAT_THIET_VI: { if (UtilityHassIO.mInstance.Switch_Turn_OnOff(data.mDevice.mUser.HassIO_URL, data.mDevice.mUser.HassIO_KEY, mDevice.DeviceCode, "off")) { return(String.Format("<speak><p><s>Đã tắt {0}</s></p></speak>", mDevice.DeviceName)); } else { return(String.Format("<speak><p><s>Xin lỗi, tôi không thực hiện được yêu cầu của bạn</s></p></speak>", mDevice.DeviceName)); } } default: break; } } else { return("<speak><p><s>Tôi không tìm được thiết bị trong nhà của bạn</s></p></speak>"); } return(""); }
private void Reset() { DevicePresenterOfSelectedDevice = null; meshRenderer.enabled = false; active = true; }
private void bwAsync_Worker(object sender, DoWorkEventArgs e) { ProcessingType type = (ProcessingType)e.Argument; e.Result = type; switch (type) { case ProcessingType.LoadData: { mListData_Flat = DevicePresenter.GetDevices(null, null); MyVar.mListDevice = mListData_Flat; //Update dữ liệu mListData = new List <Device>(); foreach (Home nhom in MyVar.mListHome) { if (mListData_Flat.Any(p => p.HomeID == nhom.HomeID)) { Device group_Device = new Device(); group_Device.HomeID = nhom.HomeID; group_Device.DeviceID = -1; group_Device.DeviceCode = nhom.HomeName; group_Device.mListSubData = new List <Device>(); mListData.Add(group_Device); IList <Room> ListRoom = MyVar.mListRoom.Where(p => p.HomeID == nhom.HomeID).ToList(); if (ListRoom.Count == 0) { group_Device.mListSubData = mListData_Flat.Where(p => p.HomeID == nhom.HomeID).ToList(); group_Device.mListSubData = group_Device.mListSubData.Select(p => { p.mParent = group_Device; return(p); }).ToList(); } else { foreach (Room mRoom in ListRoom) { if (mListData_Flat.Any(p => p.RoomID == mRoom.RoomID && p.HomeID == mRoom.HomeID)) { Device type_service = new Device(); type_service.HomeID = nhom.HomeID; type_service.RoomID = mRoom.RoomID; type_service.DeviceID = -2; type_service.DeviceCode = mRoom.RoomName; type_service.mListSubData = mListData_Flat.Where(p => p.RoomID == mRoom.RoomID && p.HomeID == mRoom.HomeID).ToList(); type_service.mListSubData = type_service.mListSubData.Select(p => { p.mParent = type_service; return(p); }).ToList(); if (type_service.mListSubData.Count > 0) { group_Device.mListSubData.Add(type_service); } } } } } } //Update danh sách { mListThongTinDanhSachDevice = new List <ThongTinDanhSachDevice>(); mListThongTinDanhSachDevice_Flat = new List <ThongTinDanhSachDevice>(); ThongTinDanhSachDevice.ThongTinDanhSachDeviceID_Index = 1; //Add tất cả nhóm dịch vụ ThongTinDanhSachDevice root = new ThongTinDanhSachDevice(); root.ThongTinDanhSachDeviceType = (int)ThongTinDanhSachDevice.TYPE.ROOT; root.mListData = mListData; root.ThongTinDanhSachDeviceName = String.Format("Tất cả Thiết Bị ({0})".Translate(), mListData_Flat.Count()); mListThongTinDanhSachDevice.Add(root); mListThongTinDanhSachDevice_Flat.Add(root); foreach (Home nhom_dich_vu in MyVar.mListHome) { Device group_service = mListData.FirstOrDefault(p => p.HomeID == nhom_dich_vu.HomeID && p.DeviceID == -1); if (group_service != null) { ThongTinDanhSachDevice mData = new ThongTinDanhSachDevice(); mData.ThongTinDanhSachDeviceType = (int)ThongTinDanhSachDevice.TYPE.GROUP; mData.HomeID = nhom_dich_vu.HomeID; mData.mListSubData = new List <ThongTinDanhSachDevice>(); mData.mListData = group_service.mListSubData; mData.ThongTinDanhSachDeviceName = nhom_dich_vu.HomeName + " (" + mListData_Flat.Where(p => p.HomeID == mData.HomeID).Count() + ")"; mListThongTinDanhSachDevice.Add(mData); mListThongTinDanhSachDevice_Flat.Add(mData); //Add loại dịch vụ { IList <Room> list_sub = MyVar.mListRoom.Where(p => p.HomeID == nhom_dich_vu.HomeID).ToList(); list_sub = list_sub.OrderBy(p => p.HomeID).ThenBy(p => p.RoomName).ToList(); foreach (Room sub_data in list_sub) { Device type_service = group_service.mListSubData.FirstOrDefault(p => p.RoomID == sub_data.RoomID && p.DeviceID == -2 && p.HomeID == sub_data.HomeID); if (type_service != null) { ThongTinDanhSachDevice mSubData = new ThongTinDanhSachDevice(); mSubData.ThongTinDanhSachDeviceType = (int)ThongTinDanhSachDevice.TYPE.SUB_GROUP; mSubData.HomeID = mData.HomeID; mSubData.RoomID = sub_data.RoomID; mSubData.mListData = group_service.mListSubData.Where(p => p.RoomID == sub_data.RoomID && p.HomeID == sub_data.HomeID).ToList(); mSubData.ThongTinDanhSachDeviceName = sub_data.RoomName + " (" + mListData_Flat.Where(p => p.HomeID == mSubData.HomeID && p.RoomID == mSubData.RoomID).Count() + ")"; if (mSubData.mListData.Count > 0) { mData.mListSubData.Add(mSubData); mListThongTinDanhSachDevice_Flat.Add(mSubData); } } } } } } } } break; default: break; } }