using System; using System.Collections.Generic; using System.Net; using System.Net.Sockets; using System.Security; using System.Text; using HDL_ON.DAL.Server; using HDL_ON.Entity; using Newtonsoft.Json.Linq; using Shared; namespace HDL_ON.UI.Music { public class SendMethod { private static SendMethod s_Current = null; public static SendMethod Current { get { if (s_Current == null) { s_Current = new SendMethod(); } return s_Current; } } /// /// 获取音乐列表 /// public List GetMusicList { get { return FunctionList.List.GetMusicList(); } } /// /// 发送控制命令 /// /// 当前设备 /// 发送控制数据 public void SendControlCommand(Function function, Dictionary dic) { new System.Threading.Thread(() => { DriverLayer.Control.Ins.SendWriteCommand(function, dic, false, 0); }) { IsBackground = true }.Start(); } /// /// 获取设备最新的状态 /// /// public void GetDeviceStatus(ref A31MusicModel a31Music, List functionIds, string sid) { try { //RefreshDeviceStatus(functionIds); a31Music.LastDateTime = DateTime.Now; ///从缓存里面查找音乐播放器对象<收到推送过来的状态会更新缓存数据> var allLocalFuntion = FunctionList.List.GetDeviceFunctionList(); var localFunction = allLocalFuntion.Find((obj) => obj.sid == sid); if (localFunction == null) { return; } ///更新的数据 a31Music.functionMusic = localFunction; } catch { } } /// /// 刷新设备状态 /// /// public void RefreshDeviceStatus(List functionIds) { try { Dictionary d = new Dictionary(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceIds", functionIds); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus, "刷新设备状态"); if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "") { return; } } catch { } } /// /// 设备名称修改 /// public string EditDeviceName(string deviceId, string deviceName) { Dictionary d = new Dictionary(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceId", deviceId); d.Add("name", deviceName); var requestJson = HttpUtil.GetSignRequestJson(d); return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDeviceName, requestJson).Code; } /// /// 获取音乐列表 /// /// /// public void GetPalyList(Function music) { try { Dictionary d = new Dictionary(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceIds", new List { music.deviceId }); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_PlayerList, "获取音乐列表"); if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "") { return; } //数据返序列化为Function对象 var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data); var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject>(str); if (palyLists == null) { palyLists =new List(); } if (palyLists.Count > 0) { ///默认拿第一个列表 A31MusicModel.Current.palyLists = palyLists[0].playlist; } } catch { } } /// /// 获取列表名列表 /// /// /// public List GetListName(Function music) { try { Dictionary d = new Dictionary(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId); d.Add("deviceIds", new List { music.deviceId }); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GroupList, "获取列表名列表"); if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "") { return new List(); } //数据返序列化为Function对象 var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data); var groupLists = Newtonsoft.Json.JsonConvert.DeserializeObject>(str); if (groupLists == null) { groupLists = new List(); } return groupLists; } catch { return new List(); } } /// /// 获取列表音乐 /// /// /// 列表名 /// public PalyList GetListMusic(Function music, string listName) { try { Dictionary d = new Dictionary(); Dictionary d1 = new Dictionary(); Dictionary d2 = new Dictionary(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId); d2.Add("group", listName); d1.Add("sid", music.sid); d1.Add("groupList", new List> { d2 }); d.Add("sidGroups", new List> { d1 }); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GroupPlayerList, "获取列表音乐"); if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "") { return new PalyList(); } //数据返序列化为Function对象 var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data); var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject>(str); if (palyLists == null) { palyLists = new List(); } if (palyLists.Count == 0) { return new PalyList(); } //默认第一个列表里面第一个音乐列表 return palyLists[0].playlist.Count > 0 ? palyLists[0].playlist[0] : new PalyList(); } catch { return new PalyList(); } } /// ///请求服务器(与住宅有关:例如;homeId) /// /// 发送数据 /// 请求地址(不是绝对地址) /// 标记->描述接口(自定义) /// public ResponsePackNew RequestServerhomeId(object o, string api_Url, string tag, int mTimeout = 5) { JObject jobject = JObject.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(o)); return UI2.Intelligence.Automation.Send.Current.RequestServerhomeId(jobject, api_Url, tag, mTimeout); } } }