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 Shared;
namespace HDL_ON.UI.Music
{
public class SendMethod
{
private static SendMethod sMethod=null;
public static SendMethod mMethod
{
get
{
if (sMethod == null)
{
sMethod = new SendMethod();
}
return sMethod;
}
}
///
/// 获取音乐列表
///
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);
})
{ 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
{
}
}
///
///请求服务器(与住宅有关:例如;homeId)
///
///
public ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 5)
{
var requestJson = HttpUtil.GetSignRequestJson(o);
return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
}
}
}