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;
|
}
|
|
}
|
/// <summary>
|
/// 获取音乐列表
|
/// </summary>
|
public List<Function> GetMusicList
|
{
|
get
|
{
|
return FunctionList.List.GetMusicList();
|
}
|
}
|
/// <summary>
|
/// 发送控制命令
|
/// </summary>
|
/// <param name="function">当前设备</param>
|
/// <param name="dic">发送控制数据</param>
|
public void SendControlCommand(Function function, Dictionary<string, string> dic)
|
{
|
new System.Threading.Thread(() =>
|
{
|
DriverLayer.Control.Ins.SendWriteCommand(function, dic,false,0);
|
})
|
{ IsBackground = true }.Start();
|
}
|
//记录歌曲播放时间
|
private int songPlayTime = -1;
|
/// <summary>
|
/// 获取设备最新的状态
|
/// </summary>
|
/// <returns></returns>
|
public void GetDeviceStatus(ref A31MusicModel a31Music, List<string> 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;
|
if (int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(UI2.FuntionControlView.Music.KeyProperty.playing_time)) != songPlayTime)
|
{
|
///歌曲记录时间和当前时间不一样,立即更新数据反馈时间
|
a31Music.LastDateTime = DateTime.Now;
|
///歌曲记录时间和当前时间不一样,立即更新歌曲播放时间
|
songPlayTime = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(UI2.FuntionControlView.Music.KeyProperty.playing_time));
|
}
|
|
}
|
catch { }
|
}
|
|
/// <summary>
|
/// 刷新设备状态
|
/// </summary>
|
/// <returns></returns>
|
public void RefreshDeviceStatus(List<string> functionIds)
|
{
|
try
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
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 { }
|
}
|
|
|
/// <summary>
|
/// 设备名称修改
|
/// </summary>
|
public string EditDeviceName(string deviceId, string deviceName)
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
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;
|
}
|
|
/// <summary>
|
/// 获取音乐列表
|
/// </summary>
|
/// <param name="music"></param>
|
/// <returns></returns>
|
public void GetPalyList(Function music)
|
{
|
try
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("deviceIds", new List<string> { 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<List<PalyListInfo>>(str);
|
if (palyLists == null)
|
{
|
palyLists = new List<PalyListInfo>();
|
}
|
if (palyLists.Count > 0)
|
{
|
///默认拿第一个列表
|
A31MusicModel.Current.palyLists = palyLists[0].playlist;
|
}
|
}
|
catch
|
{
|
}
|
|
}
|
/// <summary>
|
/// 获取列表名列表
|
/// </summary>
|
/// <param name="music"></param>
|
/// <returns></returns>
|
public List<GroupList> GetListName(Function music)
|
{
|
try
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
|
d.Add("gatewayId", DB_ResidenceData.Instance.HomeGateway.gatewayId);
|
d.Add("deviceIds", new List<string> { music.deviceId });
|
var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_GroupList);
|
if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "")
|
{
|
return new List<GroupList>();
|
}
|
//数据返序列化为Function对象
|
var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data);
|
var groupLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupList>>(str);
|
if (groupLists == null)
|
{
|
groupLists = new List<GroupList>();
|
}
|
return groupLists;
|
}
|
catch
|
{
|
return new List<GroupList>();
|
}
|
}
|
/// <summary>
|
/// 获取列表音乐
|
/// </summary>
|
/// <param name="music"></param>
|
/// <param name="listName">列表名</param>
|
/// <returns></returns>
|
public PalyList GetListMusic(Function music, string listName)
|
{
|
try
|
{
|
Dictionary<string, object> d = new Dictionary<string, object>();
|
Dictionary<string, object> d1 = new Dictionary<string, object>();
|
Dictionary<string, object> d2 = new Dictionary<string, object>();
|
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<Dictionary<string, object>> { d2 });
|
d.Add("sidGroups", new List<Dictionary<string, object>> { 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<PalyList>(str);
|
if (palyLists == null)
|
{
|
palyLists = new PalyList();
|
}
|
return palyLists;
|
}
|
catch
|
{
|
return new PalyList();
|
}
|
}
|
|
/// <summary>
|
///请求服务器(与住宅有关:例如;homeId)
|
/// </summary>
|
/// <returns></returns>
|
public ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 5)
|
{
|
var requestJson = HttpUtil.GetSignRequestJson(o);
|
return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
|
|
}
|
}
|
}
|