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, TipType tipType = TipType.flicker)
{
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, tipType))
{
return;
}
if (function != null)
{
action?.Invoke(true);
}
}
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,tipType))
{
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,tipType))
{
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, tipType))
{
return new List();
}
var list = Newtonsoft.Json.JsonConvert.DeserializeObject>(responsePackNew.Data.ToString());
if (list == null)
{
return new List();
}
return list;
}
///
/// 获取门锁设备列表(萤石视频门锁)
///
/// 指定spk获取
/// 是否需要提示,默认提示
/// 返回结果不会为null
public List GetVideoDoorLockDeviceList(string spk, TipType tipType = TipType.flicker)
{
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_GetDevcieList, "获取萤石门锁设备列表");
if (!this.DataChecking(responsePackNew, tipType))
{
return new List();
}
var doorLockList = Newtonsoft.Json.JsonConvert.DeserializeObject(responsePackNew.Data.ToString());
if (doorLockList == null)
{
return new DoorLockList().list;
}
return doorLockList.list;
}
///
/// 获取门锁型号列表(萤石视频门锁)
///
/// 是否需要提示,默认提示
/// 返回结果不会为null
public LockModels GetVideoDoorLockLockModelsList(TipType tipType = TipType.flicker)
{
var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(new object { }, NewAPI.Api_Post_Lock_Models, "获取萤石门锁型号列表");
if (!this.DataChecking(responsePackNew, tipType))
{
return new LockModels();
}
var lockModels = Newtonsoft.Json.JsonConvert.DeserializeObject(responsePackNew.Data.ToString());
if (lockModels == null)
{
return new LockModels();
}
return lockModels;
}
///
/// 先获取萤石云子账号token
///
/// 是否需要提示,默认提示
public string GetEZGetChildToken(TipType tipType = TipType.flicker)
{
//先获取萤石云子账号token
var responsePackNew = new HttpServerRequest().EZGetChildToken();
if (!this.DataChecking(responsePackNew, tipType))
{
return "";
}
return responsePackNew.Data.ToString();
}
///
/// 检验数据回复成功或者失败
///
/// 回复数据对象
/// 是否需要提示
///
private bool DataChecking(ResponsePackNew responsePackNew, TipType tipType)
{
if (responsePackNew.Data == null || responsePackNew.Code != "0" || responsePackNew.Data.ToString() == "")
{
if (TipType.flicker == tipType)
{
if (responsePackNew == null)
{
responsePackNew = new ResponsePackNew { message = "没回复,请确认网络是否正常.", Code = "-1", };
}
Application.RunOnMainThread(() =>
{
//new Tip()
//{
// CloseTime = 1,
// Text = responsePackNew.message + "(" + responsePackNew.Code + ")",
// Direction = AMPopTipDirection.None,
//}.Show(MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1));
CommonMethod.Current.ShowTip(responsePackNew.message + "(" + responsePackNew.Code + ")");
});
}
return false;
}
return true;
}
}
}