using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using Shared;
using static HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock.CommonMethod;
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
{
///
/// 萤石视频门锁数据发送
///
public class VideDoorLockSend
{
private static VideDoorLockSend send = null;
///
/// 获取当前的对象
///
public static VideDoorLockSend Current
{
get
{
if (send == null)
{
send = new VideDoorLockSend();
}
return send;
}
}
///
/// 解绑设备(萤石视频门锁)
///
/// 当前的设备
/// 回调结果
public void DelDevice(Function function, Action action)
{
new Thread(() =>
{
try
{
Dictionary d = new Dictionary();
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
d.Add("deviceSerial", function.sid);//等同门锁序列号
d.Add("platform", 1);//平台
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_DeleteDevice, "删除萤石门锁设备");
if (!this.DataChecking(responsePackNew))
{
return;
}
if (function != null)
{
action?.Invoke(false);
}
}
catch (Exception s)
{
}
})
{ IsBackground = true }.Start();
}
///
/// 获取门锁状态(萤石视频门锁)
///
/// 当前的设备
/// 返回结果不会为null
public VideoDoorLockInfo GetVideoDoorLockState(Function function, TipType tipType = TipType.flicker)
{
Dictionary d = new Dictionary();
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
d.Add("deviceId", function.deviceId);
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Lockstatus, "删除萤石视频门锁状态");
if (!this.DataChecking(responsePackNew))
{
return new VideoDoorLockInfo();
}
var videoDoorLockInfo = Newtonsoft.Json.JsonConvert.DeserializeObject(responsePackNew.Data.ToString());
if (videoDoorLockInfo == null)
{
return new VideoDoorLockInfo();
}
return videoDoorLockInfo;
}
///
/// 获取电池电量(萤石视频门锁)
///
/// 当前的设备
/// 返回结果不会为null
public CellInfo GetCellValue(Function function, TipType tipType = TipType.flicker)
{
Dictionary d = new Dictionary();
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
d.Add("deviceId", function.deviceId);
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Details, "获取萤石门锁设备电量");
if (!this.DataChecking(responsePackNew))
{
return new CellInfo();
}
var cellInfo = Newtonsoft.Json.JsonConvert.DeserializeObject(responsePackNew.Data.ToString());
if (cellInfo == null)
{
return new CellInfo();
}
return cellInfo;
}
///
/// 获取门锁用户列表(萤石视频门锁)
///
/// 当前的设备
/// /// 返回结果不会为null
public List GetVideoDoorLockUserListInfo(Function function, TipType tipType = TipType.flicker)
{
Dictionary d = new Dictionary();
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
d.Add("deviceId", function.deviceId);
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UserList, "获取萤石门锁用户列表");
if (!this.DataChecking(responsePackNew))
{
return new List();
}
var list = Newtonsoft.Json.JsonConvert.DeserializeObject>(responsePackNew.Data.ToString());
if (list == null)
{
return new List();
}
return list;
}
///
/// 获取门锁设备列表(萤石视频门锁)
///
/// 指定spk获取
///
public List GetVideoDoorLockDeviceList(string spk)
{
Dictionary d = new Dictionary();
d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
d.Add("spk", spk);
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UserList, "获取萤石门锁设备列表");
if (!this.DataChecking(responsePackNew))
{
return new List();
}
var list = Newtonsoft.Json.JsonConvert.DeserializeObject>(responsePackNew.Data.ToString());
if (list == null)
{
return new List();
}
return list;
}
///
/// 检验数据回复成功或者失败
///
/// 回复数据对象
/// 是否需要提示,默认提示
///
private bool DataChecking(ResponsePackNew responsePackNew, TipType tipType = TipType.flicker)
{
if (responsePackNew.Data == null || responsePackNew.Code != "0" || responsePackNew.Data.ToString() == "")
{
if (TipType.flicker == tipType)
{
if (responsePackNew == null)
{
responsePackNew = new ResponsePackNew { message = "没回复,请确认网络是否正常.", Code = "-1", };
}
//new Tip()
//{
// CloseTime = 1,
// Text = responsePackNew.message + "(" + responsePackNew.Code + ")",
// Direction = AMPopTipDirection.None,
//}.Show(MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1));
}
return false;
}
return true;
}
}
}