using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;
namespace ZigBee.Device
{
[System.Serializable]
public class Safeguard
{
///
/// 当前主网关的ID
///
public string GateWayId;
///
/// 网关返回场景的命令标识
///
public int DataID;
///
/// 网关反馈的时间戳
///
public int Time;
///
/// 等待从网关接收数据的时间
///
/// The wait receive data time.
public static int WaitReceiveDataTime
{
get
{
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
return 3000;
}else if (mainGateway.IsVirtual)
{
return 6000;
}
else
{
return 3000;
}
}
}
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
ErrorResponData errResponData;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
[System.Serializable]
public class ErrorResponData
{
///
/// Error参数含义
///1:网关无法解析命令数据。
///2:协调器正在升级或备份/恢复数据
///3:操作设备/组/场景不存在
///4:其他错误
///5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)
///
public int Error;
}
///
/// 网关信息错误反馈内容
///
static string ErrorMess(int err)
{
string message = "";
switch (err)
{
case 1:
message = " 网关无法解析命令数据。";
break;
case 2:
message = " 协调器正在升级或备份 / 恢复数据。";
break;
case 3:
message = "操作设备 / 组 / 场景不存在";
break;
case 4:
message = " 其他错误";
break;
case 5:
message = " 数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)";
break;
default:
break;
}
return message;
}
#region *管理员密码登陆;
///
/// *管理员密码登陆.(仅用于主网关接口).
/// password:管理员密码,初始化密码为“admin”。
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。
/// 返回结果Result
/// 0:登陆成功
/// 1:密码错误,登陆失败。
///
public static async System.Threading.Tasks.Task AdminLoginResponAsync(string password, string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
AdminLoginResponAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new AdminLoginResponAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new AdminLoginResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new AdminLoginResponAllData { errorResponData = temp , errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new AdminLoginResponAllData { };
if (temp == null)
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。" ;
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。" ;
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
if (topic == gatewayID + "/" + "Security/AdminLogin_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (tempData == null)
{
d = new AdminLoginResponAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new AdminLoginResponAllData { Result = tempData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/AdminLogin_Actions 启动" + System.DateTime.Now.ToString());
try
{
var bytes = new byte[32];
var reamarkGwBytes = System.Text.Encoding.UTF8.GetBytes(password);
System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length);
password = System.Text.Encoding.UTF8.GetString(bytes);
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4001 }
};
var data = new JObject { { "Password", password }, { "LoginToken", loginToken } };
jObject.Add("Data", data);
mainGateway.Send("Security/AdminLogin", jObject.ToString());
}
catch{}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d!= null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new AdminLoginResponAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/AdminLogin_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 管理员密码登陆的数据,网关反馈信息
///
public AdminLoginResponAllData adminLoginResponAllData;
///
/// 管理员密码登陆返回的数据,网关反馈信息
///
[System.Serializable]
public class AdminLoginResponAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 返回结果Result
/// 0:登陆成功
/// 1:密码错误,登陆失败。
///
public int Result = 999;
///
/// 返回错误结果
/// 1:网关不是主网关,无法进行该操作。
/// 2:该操作需要安防管理员权限,需先以管理员身份进行登陆。
///
public int Error;
}
#endregion
#region 20修改管理员密码.
///
/// 修改管理员密码(仅用于主网关接口)
///
/// The admin password async.
/// 新管理员密码
/// 旧密码/param>
public static async System.Threading.Tasks.Task ChangeAdminPasswordAsync(string oldPassword, string password)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
ChangeAdminPasswordResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new ChangeAdminPasswordResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new ChangeAdminPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new ChangeAdminPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/ChangeAdminPassword_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.changeAdminPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.changeAdminPasswordResponseData != null)
{
d = new ChangeAdminPasswordResponseAllData { changeAdminPasswordResponseData = security.changeAdminPasswordResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
else
{
d = new ChangeAdminPasswordResponseAllData { };
var r = new ChangeAdminPasswordResponseData();
if (result == 1)
{
r.Result = result;
d.errorMessageBase = "修改失败,原密码错误";
}
if (result == 2)
{
r.Result = result;
d.errorMessageBase = "2:修改失败,密码长度不正确";
}
d.changeAdminPasswordResponseData = r;
System.Console.WriteLine($"UI收到通知后的主题");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/ChangeAdminPassword_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4023}
};
var data = new JObject
{
{ "OldPassword", oldPassword },
{ "Password", password}
};
jObject.Add("Data", data);
mainGateway.Send("Security/ChangeAdminPassword", jObject.ToString());
}
catch { }
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new ChangeAdminPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/ChangeAdminPassword_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 修改管理员密码返回的数据,网关反馈信息
///
public ChangeAdminPasswordResponseAllData changeAdminPasswordResponseAllData;
///
/// 修改管理员密码返回的数据,网关反馈信息
///
[System.Serializable]
public class ChangeAdminPasswordResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 修改管理员密码返回的数据
///
public ChangeAdminPasswordResponseData changeAdminPasswordResponseData;
}
///
/// 修改管理员密码返回的数据
///
public ChangeAdminPasswordResponseData changeAdminPasswordResponseData;
///
/// 修改管理员密码返回的数据,网关反馈信息
///
[System.Serializable]
public class ChangeAdminPasswordResponseData
{
///
/// 0:修改成功
///1:修改失败,原密码错误
///2:修改失败,密码长度不正确
///
public int Result = 999;
///
/// 新密码,最大32个字符。(当Result = 0时存在。)
///
public string NewPassword;
}
#endregion
#region 16查看延时时间;
///
/// 查看延时时间(仅用于主网关接口)
///
public static async System.Threading.Tasks.Task CatDelayTimeAsync()
{
return await System.Threading.Tasks.Task.Run(async () =>
{
CatDelayTimeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new CatDelayTimeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new CatDelayTimeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new CatDelayTimeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/CatDelayTime_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.catDelayTimeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.catDelayTimeResponseData == null)
{
d = new CatDelayTimeResponseAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new CatDelayTimeResponseAllData { catDelayTimeResponseData = security.catDelayTimeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/CatDelayTime_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4019}
};
mainGateway.Send("Security/CatDelayTime", jObject.ToString());
}
catch{}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new CatDelayTimeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/CatDelayTime_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 查看延时时间返回的数据,网关反馈信息
///
public CatDelayTimeResponseAllData catDelayTimeResponseAllData;
///
/// 查看延时时间返回的数据,网关反馈信息
///
[System.Serializable]
public class CatDelayTimeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 查看延时时间返回的数据
///
public CatDelayTimeResponseData catDelayTimeResponseData;
}
///
/// 查看延时时间返回的数据
///
public CatDelayTimeResponseData catDelayTimeResponseData;
///
/// 查看延时时间返回的数据
///
[System.Serializable]
public class CatDelayTimeResponseData
{
///
/// 进入延时时间,单位秒 范围:0-65535
///
public int EntranceDelayTime;
///
/// 外出延时时间,单位秒 范围:0-65535
///
public int GoOutDelayTime;
}
#endregion
#region 17*设置出入防区延时时;
///
/// *设置出入防区延时时间(需要管理员权限))
/// entranceDelayTime:进入延时时间,单位秒范围:0-65535
/// goOutDelayTime:外出延时时间,单位秒范围:0-65535
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。
///
public static async System.Threading.Tasks.Task SetDelayTimeAsync(int entranceDelayTime,int goOutDelayTime,string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
SetDelayTimeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new SetDelayTimeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new SetDelayTimeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new SetDelayTimeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new SetDelayTimeResponseAllData { };
if (temp == null)
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/SetDelayTime_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.setDelayTimeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.setDelayTimeResponseData == null)
{
d = new SetDelayTimeResponseAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new SetDelayTimeResponseAllData { setDelayTimeResponseData = security.setDelayTimeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/SetDelayTime_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4020}
};
var data = new JObject
{
{ "EntranceDelayTime", entranceDelayTime},
{ "GoOutDelayTime", goOutDelayTime},
{ "LoginToken", loginToken}
};
jObject.Add("Data", data);
mainGateway.Send("Security/SetDelayTime", jObject.ToString());
}catch { }
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new SetDelayTimeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/SetDelayTime_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 设置延时时间返回的数据,网关反馈信息
///
public SetDelayTimeResponseAllData setDelayTimeResponseAllData;
///
/// 设置延时时间返回的数据,网关反馈信息
///
[System.Serializable]
public class SetDelayTimeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 设置延时时间返回的数据
///
public SetDelayTimeResponseData setDelayTimeResponseData;
}
///
/// 设置延时时间返回的数据
///
public SetDelayTimeResponseData setDelayTimeResponseData;
///
/// 设置延时时间返回的数据
///
[System.Serializable]
public class SetDelayTimeResponseData
{
///
/// 进入延时时间,单位秒 范围:0-65535
///
public int EntranceDelayTime;
///
/// 外出延时时间,单位秒 范围:0-65535
///
public int GoOutDelayTime;
}
#endregion
#region 21*查看用户密码和胁迫密码.;
///
/// *查看用户密码和胁迫密码(需要管理员权限)
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public static async System.Threading.Tasks.Task CatUserPasswordAsync(string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
CatUserPasswordResponseAllData d =null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new CatUserPasswordResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new CatUserPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new CatUserPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new CatUserPasswordResponseAllData { };
if (temp == null)
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/CatUserPassword_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.catUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.catUserPasswordResponseData == null)
{
d = new CatUserPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new CatUserPasswordResponseAllData { catUserPasswordResponseData = security.catUserPasswordResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/CatUserPassword_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4024}
};
var data = new JObject
{
{ "LoginToken", loginToken}
};
jObject.Add("Data", data);
mainGateway.Send("Security/CatUserPassword", jObject.ToString());
}
catch {
}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new CatUserPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/CatDelayTime_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 查看用户密码和胁迫密码返回的数据,网关反馈信息
///
public CatUserPasswordResponseAllData catUserPasswordResponseAllData;
///
/// 查看用户密码和胁迫密码返回的数据,网关反馈信息
///
[System.Serializable]
public class CatUserPasswordResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 查看用户密码和胁迫密码返回的数据
///
public CatUserPasswordResponseData catUserPasswordResponseData;
}
///
/// 查看用户密码和胁迫密码返回的数据
///
public CatUserPasswordResponseData catUserPasswordResponseData;
///
/// 查看用户密码和胁迫密码返回的数据
///
[System.Serializable]
public class CatUserPasswordResponseData
{
///
/// 用户密码列表
///
public List UserPasswordList = new List();
}
///
/// 用户密码列表数据
///
[System.Serializable]
public class UserPasswordListObj
{
///
/// 用户id。Id为5时为胁迫密码
///
public int UserId;
///
/// 最少4个字符,最大32个字符
///
public string Password;
///
/// 用户密码提示语
///
public string PassWordTips = string.Empty;
}
#endregion
#region 22*新增或重设用户密码.;
///
/// *新增或重设用户密码(需要管理员权限)
/// userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。
/// password:新管理员密码
/// passWordTips:密码提示
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public static async System.Threading.Tasks.Task SetUserPasswordAsync(int userId, string password, string passWordTips, string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
SetUserPasswordResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new SetUserPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new SetUserPasswordResponseAllData { };
if (temp == null)
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/SetUserPassword_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.setUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.setUserPasswordResponseData != null)
{
d = new SetUserPasswordResponseAllData { setUserPasswordResponseData = security.setUserPasswordResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
else
{
d = new SetUserPasswordResponseAllData { };
var r = new SetUserPasswordResponseData();
r.Result = result;
d.setUserPasswordResponseData = r;
System.Console.WriteLine($"失败设置,收到通知后的主题");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/SetUserPassword_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4025}
};
var data = new JObject
{
{ "UserId", userId },
{ "Password", password},
{ "PassWordTips", passWordTips},
{ "LoginToken", loginToken}
};
jObject.Add("Data", data);
mainGateway.Send("Security/SetUserPassword", jObject.ToString());
}
catch{
}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/SetUserPassword_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// *新增或重设用户密码(需要管理员权限)
/// userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。
/// password:新管理员密码
/// passWordTips:密码提示
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public static async System.Threading.Tasks.Task SetPassWordTipsAsync(int userId, string password, string passWordTips, string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
SetUserPasswordResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new SetUserPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new SetUserPasswordResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/AddPassWordTips_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.setUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.setUserPasswordResponseData != null)
{
d = new SetUserPasswordResponseAllData { setUserPasswordResponseData = security.setUserPasswordResponseData };
}
}
else
{
d = new SetUserPasswordResponseAllData { };
var r = new SetUserPasswordResponseData();
r.Result = result;
d.setUserPasswordResponseData = r;
}
}
};
mainGateway.Actions += action;
try
{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4037}
};
var data = new JObject
{
{ "UserId", userId },
{ "Password", password},
{ "PassWordTips", passWordTips},
{ "LoginToken", loginToken}
};
jObject.Add("Data", data);
mainGateway.Send("Security/AddPassWordTips", jObject.ToString());
}
catch
{
}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new SetUserPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
return d;
});
}
///
/// 新增或重设用户密码返回的数据,网关反馈信息
///
public SetUserPasswordResponseAllData setUserPasswordResponseAllData;
///
/// 新增或重设用户密码返回的数据,网关反馈信息
///
[System.Serializable]
public class SetUserPasswordResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 修改管理员密码返回的数据
///
public SetUserPasswordResponseData setUserPasswordResponseData;
}
///
/// 新增或重设用户密码返回的数据
///
public SetUserPasswordResponseData setUserPasswordResponseData;
///
/// 新增或重设用户密码返回的数据,网关反馈信息
///
[System.Serializable]
public class SetUserPasswordResponseData
{
///
/// 0:成功
///1:失败,用户密码数已满(最大4个)
///2:失败,密码长度不正确。
///3:失败,密码和已存在的用户密码重复,4个用户密码不能相同。
///
public int Result = 999;
///
/// 用户id
///
public int UserId;
///
/// 新密码 ,最大32个字符,至少4个字符。
///
public string password;
}
#endregion
#region 23*删除用户密码.
///
/// *删除用户密码(需要管理员权限)
/// userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public static async System.Threading.Tasks.Task DelUserPasswordAsync(int userId,string loginToken)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
DelUserPasswordResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new DelUserPasswordResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new DelUserPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new DelUserPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new DelUserPasswordResponseAllData { };
if (temp == null)
{
d .errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/DelUserPassword_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.delUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.delUserPasswordResponseData != null)
{
d = new DelUserPasswordResponseAllData { delUserPasswordResponseData = security.delUserPasswordResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
else
{
d = new DelUserPasswordResponseAllData { errorMessageBase = "返回数据为空" };
System.Console.WriteLine("返回数据为空");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/DelUserPassword_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4026}
};
var data = new JObject
{
{ "UserId", userId },
{ "LoginToken", loginToken}
};
jObject.Add("Data", data);
mainGateway.Send("Security/DelUserPassword", jObject.ToString());
}
catch{}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new DelUserPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/DelUserPassword_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 删除用户密码返回的数据,网关反馈信息
///
public DelUserPasswordResponseAllData delUserPasswordResponseAllData;
///
/// 删除用户密码返回的数据,网关反馈信息
///
[System.Serializable]
public class DelUserPasswordResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 删除用户密码返回的数据
///
public DelUserPasswordResponseData delUserPasswordResponseData;
}
///
/// 删除用户密码返回的数据
///
public DelUserPasswordResponseData delUserPasswordResponseData;
///
/// 删除用户密码返回的数据,网关反馈信息
///
[System.Serializable]
public class DelUserPasswordResponseData
{
///
/// 0:成功
///1:失败,用户id不存在。
///
public int Result = 999;
///
/// 用户id
///
public int UserId;
}
#endregion
//#region 新建或修改防区.
/////
///// 新建或修改防区。
/////
///// The new zone async.
///// 新建或修改防区的数据
//public static async System.Threading.Tasks.Task AddNewZoneAsync(AddNewZoneData addNewZoneData)
//{
// return await System.Threading.Tasks.Task.Run(async () =>
// {
// var d = new AddNewZoneDataResponseAllData { };
// if (ZbGateway.MainGateWay == null)
// {
// d.errorMessageBase = "当前没有主网关";
// return d;
// }
// Action action = (topic, message) =>
// {
// var gatewayID = topic.Split('/')[0];
// var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
// if (topic == gatewayID + "/" + "Error_Respon")
// {
// var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID };
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
// if (temp == null)
// {
// d.errorMessageBase = "网关错误回复,且数据是空";
// }
// else
// {
// d.errorResponData = temp;
// d.errorMessageBase = ErrorMess(temp.Error);
// }
// }
// if (topic == gatewayID + "/" + "Security/AddNewZone_Respon")
// {
// var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = ZbGateway.MainGateWay.CurrentGateWayId };
// security.addNewZoneDataResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
// if (security.addNewZoneDataResponseData != null)
// {
// d.addNewZoneDataResponseData = security.addNewZoneDataResponseData;
// System.Console.WriteLine($"收到通知后的主题_{ topic}");
// }
// else
// {
// d.errorMessageBase = "网关返回的数据为空";
// }
// }
// };
// ZbGateway.MainGateWay.Actions += action;
// System.Console.WriteLine("Security/AddNewZone_Actions 启动" + System.DateTime.Now.ToString());
// if (addNewZoneData != null)
// {
// var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4002 } };
// var data = new JObject
// {
// { "ZoneId", addNewZoneData.ZoneId },
// { "ZoneName", addNewZoneData.ZoneName },
// { "ZoneType", addNewZoneData.ZoneType },
// { "Bypass", addNewZoneData.Bypass },
// { "ElasticBypass", addNewZoneData.ElasticBypass }
// };
// jObject.Add("Data", data);
// ZbGateway.MainGateWay?.Send(("Security/AddNewZone"), jObject.ToString());
// }
// var dateTime = DateTime.Now;
// while ((DateTime.Now - dateTime).TotalMilliseconds < 1000)
// {
// await System.Threading.Tasks.Task.Delay(10);
// if (d.addNewZoneDataResponseData != null)
// {
// break;
// }
// }
// if ((DateTime.Now - dateTime).TotalMilliseconds > 10000)
// {
// d.errorMessageBase = " 回复超时,请重新操作";
// }
// ZbGateway.MainGateWay.Actions -= action;
// System.Console.WriteLine("Security/AddNewZone_Actions 退出" + System.DateTime.Now.ToString());
// return d;
// });
//}
/////
///// 新建或修改防区返回的数据 ,网关反馈信息
/////
//public AddNewZoneDataResponseAllData addNewZoneDataResponseAllData;
/////
///// 新建或修改防区返回的数据,网关反馈信息
/////
//[System.Serializable]
//public class AddNewZoneDataResponseAllData
//{
// ///
// /// 错误信息
// ///
// public string errorMessageBase;
// ///
// /// 网关信息错误反馈
// /// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
// ///
// public ErrorResponData errorResponData;
// ///
// ///新建或修改防区返回的数据
// ///
// public AddNewZoneDataResponseData addNewZoneDataResponseData;
//}
/////
///// 新建或修改防区返回的数据
/////
//public AddNewZoneDataResponseData addNewZoneDataResponseData;
/////
///// 新建或修改防区返回的数据
/////
//[System.Serializable]
//public class AddNewZoneDataResponseData
//{
// ///
// /// 返回结果
// /// 0:添加或修改成功
// /// 1:失败,防区不存在
// ///
// //public int Result = 2;
// ///
// /// 局部设防列表id
// ///
// public int ZoneId;
// ///
// /// 防区名称 ,最大32个字符(当Result = 0时才存在)
// ///
// public string ZoneName;
// ///
// /// 布防防区类型:(当Result = 0时才存在)
// ///当Type=1时,该字段才存在。
// ///1:24小时防区。
// ///2:24小时静音防区。
// ///3:出入防区。
// ///4:内部防区。
// ///5:跟随防区。
// ///6:周界防区。
// ///7:周界延时防区。
// ///
// public int ZoneType;
// ///
// /// 是否允许旁路(当Result = 0时才存在)
// ///0:不允许旁路
// ///1:允许旁路
// ///
// public int Bypass;
// ///
// /// 是否允许弹性旁路:(当Result = 0时才存在)
// ///0:不允许弹性旁路
// ///1:允许弹性旁路
// ///
// public int ElasticBypass;
//}
/////
///// 新建或修改防区的数据
/////
//public AddNewZoneData addNewZone;
/////
///// 新建或修改防区的数据
/////
//[System.Serializable]
//public class AddNewZoneData
//{
// ///
// /// 防区id。
// /// 0:0:新增防区
// /// 其他:要修改的防区id
// ///
// public int ZoneId;
// ///
// /// 防区名称 ,最大32个字符
// ///
// public string ZoneName;
// ///
// /// 防区类型:
// ///当Type=1时,该字段才存在。
// ///1:24小时防区。
// ///2:24小时静音防区。
// ///3:出入防区。
// ///4:内部防区。
// ///5:跟随防区。
// ///6:周界防区。
// ///7:周界延时防区。
// ///如果为24小时(静音)类型防区将自动加入24小时布防模式中,并从自定义模式中清除该防区。如果原来是24小时(静音)类型防区修改为非24小时类型,将原防区将自动从24小时布防模式中清除。
// ///
// public int ZoneType;
// ///
// /// 是否允许旁路
// ///0:不允许旁路
// ///1:允许旁路
// ///若类型为24小时防区或24小时静音防区将不允许旁路,该字段将被忽略。
// ///
// public int Bypass;
// ///
// /// 是否允许弹性旁路:
// ///0:不允许弹性旁路
// ///1:允许弹性旁路
// ///若类型为24小时防区或24小时静音防区将不允许弹性旁路,该字段将被忽略。
// ///
// public int ElasticBypass;
//}
//#endregion
#region 2 *设备加入防区.;
///
/// *设备加入防区(需要管理员权限)
/// loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。
///
/// The device to zone async.
/// 设备加入防区的数据
public static async System.Threading.Tasks.Task AddDeviceToZoneAsync(AddDeviceToZoneData addDeviceToZoneData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
AddDeviceToZoneResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new AddDeviceToZoneResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new AddDeviceToZoneResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new AddDeviceToZoneResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new AddDeviceToZoneResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空" ;
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。" ;
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。" ;
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp ;
}
}
if (topic == gatewayID + "/" + "Security/AddEqToZone_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.addDeviceToZoneResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if(security.addDeviceToZoneResponseData!=null){
d = new AddDeviceToZoneResponseAllData { addDeviceToPartResponseData = security.addDeviceToZoneResponseData };
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
else
{
d = new AddDeviceToZoneResponseAllData { errorMessageBase = "添加失败" };
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine($"Security/AddEqToZone_Actions启动_{System.DateTime.Now.ToString()}");
try{
if (addDeviceToZoneData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4003 } };
var deviceList = new JArray { };
foreach (var deviceInfo in addDeviceToZoneData.DeviceList)
{
var dInfo = new JObject{
{ "MacAddr", deviceInfo.MacAddr},
{ "Epoint",deviceInfo.Epoint},
{ "MomentStatus",deviceInfo.MomentStatus},
{ "TriggerZoneStatus",deviceInfo.TriggerZoneStatus}
};
deviceList.Add(dInfo);
}
var data = new JObject
{
{ "ZoneId", addDeviceToZoneData.ZoneId },
{ "DeviceList", deviceList},
{ "LoginToken", addDeviceToZoneData.LoginToken}
};
jObject.Add("Data", data);
mainGateway.Send(("Security/AddEqToZone_Actions 启动"), jObject.ToString());
}
}
catch {
}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new AddDeviceToZoneResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine($"Security/AddEqToZone_Actions 退出_{System.DateTime.Now.ToString()}");
return d;
});
}
///
/// 设备加入防区的返回数据 ,网关反馈信息
///
public AddDeviceToZoneResponseAllData addDeviceToPartResponseAllData;
///
/// 设备加入防区的返回数据,网关反馈信息
///
[System.Serializable]
public class AddDeviceToZoneResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 设备加入防区的返回数据
///
public AddDeviceToZoneResponseData addDeviceToPartResponseData;
}
///
/// 设备加入防区的返回数据
///
public AddDeviceToZoneResponseData addDeviceToZoneResponseData;
///
/// 设备加入防区的返回数据
///
[System.Serializable]
public class AddDeviceToZoneResponseData
{
///
/// 返回结果
/// 0:默认
/// 1:添加失败。(局部布防列表id不存在)
///
public int Result = 999;
///
/// 防区id
///
public int ZoneId;
///
/// 安防设备列表(Result=0时存在)
///
public List DeviceList = new List();
}
///
/// 安防设备列表回复的数据
///
[System.Serializable]
public class DeviceListResponseObj
{
///
/// 0:添加成功
///1:失败,设备不存在。
///2:失败,设备已经加入了其他防区。
///
public int Status;
///
/// 设备mac地址
///
public string MacAddr;
///
/// 设备端口号
///
public int Epoint;
///
/// 设备上报的状态是否为瞬间状态,用于配合下面的TriggerZoneStatus值使用。
///0:非瞬间状态,该设备上报的安防状态可持续,直到状态被改变会再次报告安防状态信息。如门磁设备的开状态和关状态(开和关状态是能持续的)。
///1:表示安防状态为瞬间量,设备警告激活状态才上报安防信息,设备恢复常态不发送通知。如人体红外传感器(当有人时触发警告,但人走了后,不会发送消除警告信息。无法知道人还在不在)
///
public int MomentStatus;
///
/// 当MomentStatus为0时,安防设备被触发上报安防信息的ZoneStatus值和TriggerZoneStatus进行与运算(&)结果不为0时激活防区警报,为0时解除激活。例如门磁设备,如果有人开门入侵将激活防区报警,可将TriggerZoneStatus设置为17,开门时上报的ZoneStatus值为1,(17 & 1)>0,此时说明有入侵,防区将被激活,发送警告信息到客户端和服务器并执行设定的警戒动作。
/// 当MomentStatus为1时,说明安防设备的激活状态只是瞬间的,只有在上报ZoneStatus值(和TriggerZoneStatus相与不为0时)的瞬间激活,激活后将立即自动恢复为常态。
/// 设置布防时,如果安防设备被触发,防区处于警告状态,要解除激活才能布防成功。如果上面MomentStatus为0,则需要安防设备再次上报的ZoneStatus值和TriggerZoneStatus值进行与运算结果为0才能解除激活状态 。如果MomentStatus为1,则说明设备已经自动恢复常态,布防可以成功。
/// 如门磁设备关门时上报的ZoneStatus值为32,(32&1)=0。则说明门已经关上,防区激活状态将解除,可对防区进行布防。如果MomentStatus为1,则忽略该设备的最近警告状态进行布防。
///
public int TriggerZoneStatus;
}
///
/// 新建或修改防区的数据
///
public AddDeviceToZoneData addDeviceToZoneData;
///
/// 设备加入防区的数据
///
[System.Serializable]
public class AddDeviceToZoneData
{
///
/// 防区id。
///1:24小时防区。
///2:24小时静音防区。
///3:出入防区。
///4:内部防区。
///5:周界防区。
///
public int ZoneId;
///
/// 安防设备列表
///
public List DeviceList = new List();
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
///
/// 安防设备列表数据
///
[System.Serializable]
public class DeviceListObj
{
///
/// 设备mac地址
///
public string MacAddr;
///
/// 设备端口号
///
public int Epoint;
///
/// 设备上报的状态是否为瞬间状态,用于配合下面的TriggerZoneStatus值使用。
///0:非瞬间状态,该设备上报的安防状态可持续,直到状态被改变会再次报告安防状态信息。如门磁设备的开状态和关状态(开和关状态是能持续的)。
///1:表示安防状态为瞬间量,设备警告激活状态才上报安防信息,设备恢复常态不发送通知。如人体红外传感器(当有人时触发警告,但人走了后,不会发送消除警告信息。无法知道人还在不在)
///
public int MomentStatus;
///
///
/// 当MomentStatus为0时,安防设备被触发上报安防信息的ZoneStatus值和TriggerZoneStatus进行与运算(&)结果不为0时激活防区警报,为0时解除激活。例如门磁设备,如果有人开门入侵将激活防区报警,可将TriggerZoneStatus设置为17,开门时上报的ZoneStatus值为1,(17 & 1)>0,此时说明有入侵,防区将被激活,发送警告信息到客户端和服务器并执行设定的警戒动作。
/// 当MomentStatus为1时,说明安防设备的激活状态只是瞬间的,只有在上报ZoneStatus值(和TriggerZoneStatus相与不为0时)的瞬间激活,激活后将立即自动恢复为常态。
/// 设置布防时,如果安防设备被触发,防区处于警告状态,要解除激活才能布防成功。如果上面MomentStatus为0,则需要安防设备再次上报的ZoneStatus值和TriggerZoneStatus值进行与运算结果为0才能解除激活状态 。如果MomentStatus为1,则说明设备已经自动恢复常态,布防可以成功。
/// 如门磁设备关门时上报的ZoneStatus值为32,(32&1)=0。则说明门已经关上,防区激活状态将解除,可对防区进行布防。如果MomentStatus为1,则忽略该设备的最近警告状态进行布防。
///
public int TriggerZoneStatus;
}
#endregion
#region 3 *新建或修改布防模式;
///
/// *新建或修改布防模(需要管理员权限).
///
/// The new mode async.
/// 新建或修改布防模式的数据.
public static async System.Threading.Tasks.Task AddNewModeAsync(AddNewModeData addNewModeData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
AddNewModeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new AddNewModeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new AddNewModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new AddNewModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new AddNewModeResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/AddNewMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.addNewModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.addNewModeResponseData != null)
{
d = new AddNewModeResponseAllData { addNewModeResponseData = security.addNewModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
}
}
else
{
d = new AddNewModeResponseAllData { errorMessageBase = "新建或修改模式失败" };
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/AddNewMode_Actions 启动" + System.DateTime.Now.ToString());
try{
if (addNewModeData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4004 } };
var data = new JObject
{
{ "ModeId", addNewModeData.ModeId },
{ "ModeName", addNewModeData.ModeName },
{ "AllowDisable", addNewModeData.AllowDisable },
{ "LoginToken", addNewModeData.LoginToken }
};
jObject.Add("Data", data);
mainGateway.Send(("Security/AddNewMode"), jObject.ToString());
}
}
catch {}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime )
{
d = new AddNewModeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/AddNewMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 新建或修改防区返回的数据 ,网关反馈信息
///
public AddNewModeResponseAllData addNewModeResponseAllData;
///
/// 新建或修改布防模式返回的数据,网关反馈信息
///
[System.Serializable]
public class AddNewModeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
///新建或修改布防模式返回的数据
///
public AddNewModeResponseData addNewModeResponseData;
}
///
/// 新建或修改布防模式返回的数据
///
public AddNewModeResponseData addNewModeResponseData;
///
/// 新建或修改布防模式返回的数据
///
[System.Serializable]
public class AddNewModeResponseData
{
///
/// 返回结果
/// 0:成功,修改或新增成功
///1:失败,修改的布防模式不存在
///2:失败,24小时布防模式不允许修改。(当修改ModeId为255时,将返回该错误)
///
public int Result = 999;
///
/// 布防模式ID
///
public int ModeId;
///
/// 布防模式名称 ,最大32个字符。
///
public string ModeName;
///
/// 允许失能。
///0:不允许失能。
///1:允许失能
///
public int AllowDisable;
}
///
/// 新建或修改布防模式的数据
///
public AddNewModeData addNewModeData;
///
/// 新建或修改布防模式的数据
///
[System.Serializable]
public class AddNewModeData
{
///
/// 要修改的布防模式ID。
///如果为0,则为新增布防模式。
///系统内置了两种布防模式,分别为在家布防(ModeId为1)、离家布防(ModeId为2)。两种内置模式不可删除。
///
public int ModeId;
///
/// 布防模式名称 ,最大32个字符。
///不需要修改可忽略该字段。
///
public string ModeName;
///
/// 允许失能。
///0:不允许失能。
///1:允许失能
///如果不需要修改可忽略该字段。新增布防时,默认为0。
///
public int AllowDisable;
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
#endregion
#region 4 *防区加入布防模式.
///
/// *防区加入布防模式(需要管理员权限).
///
/// The join mode async.
/// 防区加入布防模式的数据
public static async System.Threading.Tasks.Task ZoneJoinModeAsync(ZoneJoinModeData zoneJoinModeData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
ZoneJoinModeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new ZoneJoinModeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new ZoneJoinModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new ZoneJoinModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new ZoneJoinModeResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/ZoneJoinMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["ModeId"].ToString());
if (result == 0)
{
security.zoneJoinModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.zoneJoinModeResponseData != null)
{
d = new ZoneJoinModeResponseAllData { zoneJoinModeResponseData = security.zoneJoinModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
}
}
else
{
d = new ZoneJoinModeResponseAllData { };
var r = new ZoneJoinModeResponseData();
r.Result = result;
r.ModeId = modeId;
d.zoneJoinModeResponseData = r;
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/ZoneJoinMode_Actions 启动" + System.DateTime.Now.ToString());
try{
if (zoneJoinModeData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4005 } };
var zoneList = new JArray { };
foreach (var a in zoneJoinModeData.ZoneList)
{
var dInfo = new JObject{
{ "ZoneId", a.ZoneId}
};
zoneList.Add(dInfo);
}
var data = new JObject
{
{ "ModeId", zoneJoinModeData.ModeId },
{ "ZoneList", zoneList },
{ "LoginToken", zoneJoinModeData.LoginToken }
};
jObject.Add("Data", data);
mainGateway.Send(("Security/ZoneJoinMode"), jObject.ToString());
}
}
catch{}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new ZoneJoinModeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/ZoneJoinMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 防区加入布防模式返回的数据 ,网关反馈信息
///
public ZoneJoinModeResponseAllData zoneJoinModeResponseAllData;
///
/// 防区加入布防模式返回的数据,网关反馈信息
///
[System.Serializable]
public class ZoneJoinModeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
///防区加入布防模式返回的数据
///
public ZoneJoinModeResponseData zoneJoinModeResponseData;
}
///
/// 防区加入布防模式返回的数据
///
public ZoneJoinModeResponseData zoneJoinModeResponseData;
///
/// 防区加入布防模式返回的数据
///
[System.Serializable]
public class ZoneJoinModeResponseData
{
///
/// 返回结果
/// 0:默认
/// 1:失败,防区ID不存在。
/// 2:24小时布防模式,不允许主动加入防区。(当ModeId设置为255时,将返回该错误)
///
public int Result = 999;
///
/// 布防模式ID
///
public int ModeId;
///
/// 防区列表(当Result = 0时存在。)
///
public List ZoneList = new List();
}
///
/// 防区列表
///
[System.Serializable]
public class ZoneListResponseObj
{
///
/// 返回结果0:加入成功
///1:失败,防区不存在
///2:失败,防区已在模式中存在
///3:失败,防区为24小时(静音)防区类型。
///
public int Status=999;
///
/// 防区ID
///
public int ZoneId;
}
///
/// 防区加入布防模式的数据
///
public ZoneJoinModeData zoneJoinModeData;
///
/// 防区加入布防模式的数据
///
[System.Serializable]
public class ZoneJoinModeData
{
///
/// 布防模式ID。
///
public int ModeId;
///
/// 防区列表
/// 不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,不加入任何一种模式。
///
public List ZoneList = new List();
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
///
/// 防区列表
///
[System.Serializable]
public class ZoneListObj
{
///
/// 防区ID
///
public int ZoneId;
}
#endregion
#region 5 *从布防模式中移除防区.
///
/// *从布防模式中移除防区(需要管理员权限).
///
/// removeZoneFromModeData:从布防模式中移除防区的数据
/// Remove zone from mode data.
public static async System.Threading.Tasks.Task RemoveZoneFromModeAsync(RemoveZoneFromModeData removeZoneFromModeData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
RemoveZoneFromModeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new RemoveZoneFromModeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new RemoveZoneFromModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new RemoveZoneFromModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new RemoveZoneFromModeResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/RemoveZoneFromMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["ModeId"].ToString());
if (result == 0)
{
security.removeZoneFromModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.removeZoneFromModeResponseData != null)
{
d = new RemoveZoneFromModeResponseAllData { removeZoneFromModeResponseData = security.removeZoneFromModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
}
}
else
{
d = new RemoveZoneFromModeResponseAllData { };
var r = new RemoveZoneFromModeResponseData();
r.ModeId = modeId;
r.Result = result;
System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/RemoveZoneFromMode_Actions 启动" + System.DateTime.Now.ToString());
try{
if (removeZoneFromModeData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4006 } };
var zoneList = new JArray { };
foreach (var a in removeZoneFromModeData.ZoneList)
{
var dInfo = new JObject{
{ "ZoneId", a.ZoneId}
};
zoneList.Add(dInfo);
}
var data = new JObject
{
{ "ModeId", removeZoneFromModeData.ModeId },
{ "ZoneList", zoneList },
{ "LoginToken", removeZoneFromModeData.LoginToken }
};
jObject.Add("Data", data);
mainGateway.Send(("Security/RemoveZoneFromMode"), jObject.ToString());
}
}
catch { }
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new RemoveZoneFromModeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/RemoveZoneFromMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 从布防模式中移除防区返回的数据 ,网关反馈信息
///
public RemoveZoneFromModeResponseAllData removeZoneFromModeResponseAllData;
///
/// 从布防模式中移除防区返回的数据,网关反馈信息
///
[System.Serializable]
public class RemoveZoneFromModeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
///从布防模式中移除防区返回的数据
///
public RemoveZoneFromModeResponseData removeZoneFromModeResponseData;
}
///
/// 从布防模式中移除防区返回的数据
///
public RemoveZoneFromModeResponseData removeZoneFromModeResponseData;
///
/// 从布防模式中移除防区返回的数据
///
[System.Serializable]
public class RemoveZoneFromModeResponseData
{
///
/// 返回结果
/// 0:默认
/// 1:失败,防区ID不存在。
/// 2:24小时布防模式,不允许主动加入防区。(当ModeId设置为255时,将返回该错误)
///
public int Result = 999;
///
/// 布防模式ID
///
public int ModeId;
///
/// 防区列表(当Result = 0时存在。)
///
public List ZoneList = new List();
}
///
/// 防区列表
///
[System.Serializable]
public class RemoveZoneListResponseObj
{
///
/// 返回结果0:移除成功
///1:移除失败
///
public int Status;
///
/// 防区ID
///
public int ZoneId;
}
///
/// 从布防模式中移除防区
///
public RemoveZoneFromModeData removeZoneFromModeData;
///
/// 从布防模式中移除防区
///
[System.Serializable]
public class RemoveZoneFromModeData
{
///
/// 布防模式ID。
///
public int ModeId;
///
/// 防区列表
/// 不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,不加入任何一种模式。
///
public List ZoneList = new List();
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
#endregion
#region 6 *添加模式指示动作;
///
/// *安防模式触发动作添加(需要管理员权限).
///
/// The scene all info async.
/// 安防模式触发动作添加的数据.
public static async System.Threading.Tasks.Task AddModeActonAsync(AddModeActionData addModeActonData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
AddModeActonResponAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new AddModeActonResponAllData { errorMessageBase = "当前没有主网关" };
return d;
}
var dateTime = DateTime.Now;
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new AddModeActonResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new AddModeActonResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new AddModeActonResponAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/AddModeActon_Respon")
{
dateTime = DateTime.Now;
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["ModeId"].ToString());
var actionType = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["ActionType"].ToString());
if (result == 0)
{
security.addModeActonResponData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.addModeActonResponData != null)
{
d = new AddModeActonResponAllData { addModeActonResponData = security.addModeActonResponData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
else
{
d = new AddModeActonResponAllData {};
var r = new AddModeActonResponData();
r.Result = result;
r.ModeId = modeId;
r.ActionType = actionType;
d.addModeActonResponData = r;
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/AddModeActon_Actions 启动" + System.DateTime.Now.ToString());
try{
if (addModeActonData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4007 } };
var acList = new JArray { };
foreach (var act in addModeActonData.Actions)
{
if (act.Type == 0)
{
var taskList = new JArray { };
foreach (var taskInfo in act.TaskList)
{
var tInfo = new JObject{
{ "TaskType", taskInfo.TaskType},
{ "Data1", taskInfo.Data1},
{ "Data2",taskInfo.Data2}
};
taskList.Add(tInfo);
}
var a = new JObject {
{ "Type",act.Type},
{ "DeviceAddr", act.DeviceAddr} ,
{ "Epoint",act.Epoint} ,
{ "TaskList", taskList}
};
acList.Add(a);
}
else if (act.Type == 1)
{
var b = new JObject {
{ "Type",act.Type},
{ "ScenesId", act.ScenesId}
};
acList.Add(b);
}
}
var data = new JObject {
{ "ModeId",addModeActonData.ModeId},
{ "ActionType", addModeActonData.ActionType} ,
{ "Actions", acList},
{ "LoginToken", addModeActonData.LoginToken}
};
jObject.Add("Data", data);
mainGateway.Send(("Security/AddModeActon"), jObject.ToString());
}
}
catch { }
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/AddModeActon_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 安防模式触发动作添加的返回数据数据,网关反馈信息
///
public AddModeActonResponAllData addModeActonResponAllData;
///
/// 安防模式触发动作添加的数据,网关反馈信息
///
[System.Serializable]
public class AddModeActonResponAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 安防模式触发动作添加的数据
///
public AddModeActonResponData addModeActonResponData;
}
///
/// 安防模式触发动作添加的回复数据
///
public AddModeActonResponData addModeActonResponData;
///
/// 安防模式触发动作添加的回复数据
///
[System.Serializable]
public class AddModeActonResponData
{
///
/// 0:默认
///1:失败,模式不存在。
///
public int Result=999;
///
/// 要修改的布防模式ID。
///
public int ModeId;
///
/// 1:布防成功指示动作
///2:布防失败指示动作
///3:撤防成功指示动作
///4:撤防失败指示动作
///5:延时防区、周界延时防区被触发进入延时指示动作。如果延时过后还没撤防将触发模式安防动作。
///6:模式安防动作,安防被最终激活后的报警动作(如延时防区被触发延时过后还没撤防、周界防区被触发、出入防区没触发却触发了内部防区等情况将执行该动作)。
///
public int ActionType;
///
/// 布防成功指示动作。
///如果不需要修改或新增时候可忽略该字段。
///
public List Actions = new List();
}
///
/// 布防成功指示动作数据
///
public class ActionsResponseData
{
///
/// 动作类型
///0:成功
///1:失败,设备或场景不存在
///
public int Status=999;
///
/// 动作类型
///0:节点设备动作
///1:打开场景
///
public int Type;
///
/// 设备mac地址 ,
///当Type=0时存在。
///
public string DeviceAddr;
///
/// 设备端口号
///设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。
///
public int Epoint;
///
/// 动作参数列表。(当Type=0和Status = 0时存在)
///
public List TaskList = new List();
///
/// 场景ID 。当Type=1时存在
///
public int ScenesId;
///
/// 设备或场景名称,Status = 0时存在
///
public string ESName;
}
///
/// 安防模式触发动作添加的数据
///
public AddModeActionData addModeActionData;
///
/// 安防模式触发动作添加的数据
///
[System.Serializable]
public class AddModeActionData
{
///
/// 要修改的布防模式ID。
///
public int ModeId;
///
/// 1:布防成功指示动作
///2:布防失败指示动作
///3:撤防成功指示动作
///4:撤防失败指示动作
///
public int ActionType;
///
/// 布防成功指示动作。
///如果不需要修改或新增时候可忽略该字段。
///
public List Actions = new List();
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
///
/// 布防成功指示动作数据
///
public class ActionsData
{
///
/// 动作类型
///0:节点设备动作
///1:打开场景
///
public int Type = 999;
///
/// 设备mac地址 ,
///当Type=0时存在。
///
public string DeviceAddr;
///
/// 设备端口号
///设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。
///
public int Epoint;
///
/// 动作参数列表。当Type=0时存在
///同一个设备最多可设置8个动作。
///
public List TaskList = new List();
///
/// 场景ID 。当Type=1时存在
///
public int ScenesId;
}
///
/// 任务列表中的数据
///
[System.Serializable]
public class TaskListInfo
{
///
/// 任务类型。
///1:开关 (设备具有开关功能时可用)
///3:亮度调整(设备具有亮度调节功能时可用)
///4:颜色调整 (设备具有颜色调节功能时可用)
///5:恒温器(设备具有恒温器功能时可用)
///6: 窗帘设备(设备具有窗帘功能时可用)
///7:设备identify识别。
///8:开关报警模式
///9:squawk command
///
public int TaskType;
///
/// Data1取值
/// 开关 :Data1(数值): 0关/1开
///亮度调整 Data1(数值):亮度值
///颜色调整 Data1(数值):色调
/// 恒温器 Data1(数值): 0加热/1制冷/2自动调节/3 设置工作模式/4 设置加热度数 5/设置制冷度数 6/设置风扇模式
/// 窗帘设备 Data1(数值): 0 打开/ 1关闭/ 2 停止转动/ 4 调整到指定高度/ 5 调整到指定的百分比处位置 / 7 调整到指定倾斜角/ 8 调整到指定的百分比倾斜度
/// 设备identify识别。Data1为identify闪烁闪烁时间(0-65535秒)。
/// 开关报警模式 Data1(数值,4字节整型)第1字节(bit0-bit7)表示报警模式,字节值0:停止蜂鸣器1:盗窃报警 2:火灾报警 3:紧急情况报警 4:警车发出的报警 5:消防车发出的报警 6:备用的报警。第2字节(bit8-bit15)表示是否启用报警灯,字节值 0:不启用 1:启用。第3字节(bit16-bit23)表示报警音量,字节值0:Low,1:Medium,2:high,3:very high。
/// squawk command Data1(数值,4字节整型)第1字节(bit0-bit7)表示报警模式,字节值0:安防系统“布防”音效” ,1:安防系统“撤防”音效。第2字节(bit8-bit15)表示是否启动报警灯,字节值0:不启动,1:启动。第3字节(bit16-bit23)表示报警音量,字节值0:Low ,1:Medium ,2:high ,3: very high。
///
public int Data1;
///
/// Data2取值
/// 开关 Data2(数值): 0
/// 亮度调整 Data2(数值): 0
/// 颜色调整 Data2(数值):饱和度
/// 恒温器Data2数值如下:
/// 【当Data1=0|1|2时,Data2为要变化的度数,单位:0.1℃ 。】
///【若Data1=3,Data2为要设定的空调模式(0-9),0:off,1:auto,3:cool, 4:heat ,5:emergency heating, 6:precooling,7:fan only ,8:dry,9:sleep。】
///【若Data1=4|5,Data2为加热或制冷度数,单位0.01摄氏度。】
///【若Data1=6,Data2为要设定的风扇模式(0-6),0:off,1:low,2:medium,3:high,4:on,5:auto,6:smart】
///窗帘设备,Data2数值如下
///【当Data1=4或7,Data2为调整的高度或倾斜角度 倾斜角度单位为0.1°】。
///【当Data1=5 或 8,Data2为百分比,0-100表示0%-100%】
///设备identify识别。Data2(数值): 0
///开关报警模式 Data2(数值,4字节整型)第1、2字节(bit0-bit15)表示报警时长,字节值 0-65535,单位:秒。第3字节(bit16-bit23)表示闪烁占空比,字节值0-100。第4字节(bit16-bit23)表示报警灯亮度,字节值0:Low ,1:Medium ,2:high ,3: very high。
///squawk command:Data2(数值): 0
///
/// The type of the task.
public int Data2;
}
#endregion
#region 7 *将动作从布防模式中移除.
///
/// *将动作从布防模式中移除(需要管理员权限).
///
/// The acton from mode async.
/// 将动作从布防模式中移除的数据
public static async System.Threading.Tasks.Task RemoveActionFromModeAsync(RemoveActonFromModeData removeActonFromModeData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
RemoveActionFromModeAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new RemoveActionFromModeAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new RemoveActionFromModeAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new RemoveActionFromModeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new RemoveActionFromModeAllData {};
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/RemoveActonFromMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
security.removeActonFromModeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.removeActonFromModeResponData != null)
{
d = new RemoveActionFromModeAllData { removeActonFromModeResponData = security.removeActonFromModeResponData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
else
{
d = new RemoveActionFromModeAllData { errorMessageBase = "网关返回的数据为空" };
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/RemoveActonFromMode_Actions 启动" + System.DateTime.Now.ToString());
try{
if (removeActonFromModeData != null)
{
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4008 } };
var acList = new JArray { };
foreach (var act in removeActonFromModeData.Actions)
{
if (act.Type == 0)
{
var a = new JObject {
{ "Type",act.Type},
{ "DeviceAddr", act.DeviceAddr} ,
{ "Epoint",act.Epoint}
};
acList.Add(a);
}
else if (act.Type == 1)
{
var b = new JObject {
{ "Type",act.Type},
{ "ScenesId", act.ScenesId}
};
acList.Add(b);
}
}
var data = new JObject {
{ "ModeId",removeActonFromModeData.ModeId},
{ "ActionType", removeActonFromModeData.ActionType} ,
{ "Actions", acList},
{ "LoginToken", removeActonFromModeData.LoginToken}
};
jObject.Add("Data", data);
mainGateway.Send(("Security/RemoveActonFromMode"), jObject.ToString());
}
}
catch{
}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new RemoveActionFromModeAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/RemoveActonFromMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 将动作从布防模式中移除的数据,网关反馈信息
///
public RemoveActionFromModeAllData removeActonFromModeAllData;
///
/// 将动作从布防模式中移除的数据,网关反馈信息
///
[System.Serializable]
public class RemoveActionFromModeAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 将动作从布防模式中移除的回复数据
///
public RemoveActionFromModeResponData removeActonFromModeResponData;
}
///
/// 将动作从布防模式中移除的回复数据
///
public RemoveActionFromModeResponData removeActonFromModeResponData;
///
/// 将动作从布防模式中移除的回复数据
///
[System.Serializable]
public class RemoveActionFromModeResponData
{
///
/// 0:默认
///1:失败,模式不存在。
///
public int Result = 999;
///
/// 模式id
///
public int ModeId;
///
/// 1:布防成功指示动作
///2:布防失败指示动作
///3:撤防成功指示动作
///4:撤防失败指示动作
///
public int ActionType;
///
/// 动作列表
///
public List Actions = new List();
}
///
/// 布防成功指示动作数据
///
public class RemoveActionsResponData
{
///
///0:成功
///1:失败,设备或场景不存在
///
public int Status=999;
///
/// 动作类型
///0:节点设备动作
///1:场景
///
public int Type;
///
/// 设备mac地址 ,
///当Type=0时存在。
///
public string DeviceAddr;
///
/// 设备端口号
///设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。
///
public int Epoint;
///
/// 场景ID 。当Type=1时存在
///
public int ScenesId;
}
///
/// 将动作从布防模式中移除的数据
///
public RemoveActonFromModeData removeActonFromModeData;
///
/// 将动作从布防模式中移除的数据
///
[System.Serializable]
public class RemoveActonFromModeData
{
///
/// 要修改的布防模式ID。
/// 如果为0,则为新增布防模式。
///
public int ModeId;
///
/// 1:布防成功指示动作
///2:布防失败指示动作
///3:撤防成功指示动作
///4:撤防失败指示动作
///
public int ActionType;
///
/// 动作列表
///
public List Actions = new List();
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
///
/// 动作列表的数据
///
public class RemoveActionsData
{
///
/// 动作类型
///0:节点设备动作
///1:打开场景
///
public int Type = 999;
///
/// 设备mac地址 ,
///当Type=0时存在。
///
public string DeviceAddr;
///
/// 设备端口号
///设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。
///
public int Epoint;
///
/// 场景ID 。当Type=1时存在
///
public int ScenesId;
}
#endregion
#region 8 获取布防(安防)模式列表.;
///
/// 获取布防模式列表.(仅用于主网关接口)
///
public static async System.Threading.Tasks.Task GetModeListAsync()
{
return await System.Threading.Tasks.Task.Run(async () =>
{
GetModeListAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new GetModeListAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new GetModeListAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new GetModeListAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/GetModeList_Repon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.getModeListData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.getModeListData == null)
{
d = new GetModeListAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new GetModeListAllData { getModeListData = security.getModeListData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/GetModeList_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4009 }
};
mainGateway.Send("Security/GetModeList", jObject.ToString());
}catch{ }
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new GetModeListAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/GetModeList_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 获取布防模式列表返回的数据,网关反馈信息
///
public GetModeListAllData getModeListAllData;
///
/// 获取布防模式列表返回的数据,网关反馈信息
///
[System.Serializable]
public class GetModeListAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 获取布防模式列表返回的数据
///
public GetModeListData getModeListData;
}
///
/// 获取布防模式列表返回的数据
///
public GetModeListData getModeListData;
///
/// 获取布防模式列表返回的数据
///
[System.Serializable]
public class GetModeListData
{
///
/// 布防模式总数
///
public int ModeSum;
///
/// 动作列表
///
public List ModeList = new List();
}
///
/// 布防模式列表数据
///
public class ModeListData
{
///
///布防模式ID
///
public int ModeId;
///
/// 布防模式名称 ,最大32个字符
///
public string ModeName;
///
/// 允许失能。
///0:不允许失能。
///1:允许失能
///
public string AllowDisable;
///
/// 模式当前布撤防状态
///0:撤防
///1:布防
///2:使能一次
///3:失能一次
///
public int Setting;
}
#endregion
#region 9 通过布防模式ID查看模式信息.
///
/// 通过布防模式ID查看模式信息.(仅用于主网关接口)
/// modeId:布防模式id
///
public static async System.Threading.Tasks.Task GetModeInfoByIdAsync(int modeId)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
GetModeInfoByIdResponAllData d =null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new GetModeInfoByIdResponAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new GetModeInfoByIdResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new GetModeInfoByIdResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/GetModeInfoById_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
var getModeInfoByIdResponData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (getModeInfoByIdResponData != null)
{
d = new GetModeInfoByIdResponAllData { getModeInfoByIdResponData = getModeInfoByIdResponData };
}
System.Console.WriteLine("已收到通知返回");
}
else
{
d = new GetModeInfoByIdResponAllData { };
var r = new GetModeInfoByIdResponData();
r.Result = result;
d.getModeInfoByIdResponData = r;
System.Console.WriteLine("已收到通知返回");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/GetModeInfoById_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4010 }
};
var data = new JObject { { "ModeId", modeId } };
jObject.Add("Data", data);
mainGateway.Send("Security/GetModeInfoById", jObject.ToString());
}
catch {}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new GetModeInfoByIdResponAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/GetModeInfoById_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 通过布防模式ID查看模式信息的数据,网关反馈信息
///
public GetModeInfoByIdResponAllData getModeInfoByIdResponAllData;
///
/// 通过布防模式ID查看模式信息的数据,网关反馈信息
///
[System.Serializable]
public class GetModeInfoByIdResponAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 通过布防模式ID查看模式信息返回的数据
///
public GetModeInfoByIdResponData getModeInfoByIdResponData;
}
///
/// 通过布防模式ID查看模式信息返回的数据
///
public GetModeInfoByIdResponData getModeInfoByIdResponData;
///
/// 通过布防模式ID查看模式信息返回的数据
///
[System.Serializable]
public class GetModeInfoByIdResponData
{
///
/// 0:默认
///1:失败,布防模式不存在
///
public int Result=999;
///
/// 布防模式ID
///
public int ModeId;
///
/// 布防模式名称 ,最大32个字符
/// (Result=0时值有效)
///
public string ModeName;
///
/// 允许失能。
///0:不允许失能。
///1:允许失能
/// (Result=0时值有效)
///
public int AllowDisable = 100;
///
/// 模式当前布撤防状态
///0:撤防
///1:布防
///2:使能一次
///3:失能一次
/// (Result=0时值有效)
///
public int Setting = 100;
///
/// 加入模式的防区数量
/// (Result=0时值有效)
///
public int ZoneNum;
///
/// 加入成功的防区列表,不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,加入任何一种模式。
/// (Result=0时值有效)
///
public List ZoneList = new List();
///
/// 布防成功指示动作。
/// (Result=0时值有效)
///
public List ProtectionSucceedActions = new List();
///
/// 布防失败指示动作。
/// (Result=0时值有效)
///
public List ProtectionFailActions = new List();
///
/// 撤防成功指示动作。
/// (Result=0时值有效)
///
public List WithdrawSucceedActions = new List();
///
/// 撤防失败指示动作。
/// (Result=0时值有效)
///
public List WithdrawFailActions = new List();
}
///
/// 加入成功的防区列表的数据
///
[System.Serializable]
public class ZoneListData
{
///
/// 防区ID
///
public int ZoneId;
///
/// 防区名称
///
public string ZoneName;
}
///
/// 布防成功指示动作数据
///
public class ActionsInfo
{
///
/// 动作类型
///0:节点设备动作
///1:打开场景
///
public int Type = 999;
///
/// 设备mac地址 ,
///当Type=0时存在。
///
public string DeviceAddr;
///
/// 设备端口号
///设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。
///
public int Epoint;
///
/// 动作参数列表。当Type=0时存在
///
public List TaskList = new List();
///
/// 场景ID 。当Type=1时存在
///
public int ScenesId;
///
/// 设备或场景名称
///
public string ESName;
}
#endregion
#region 10查看当前正在使用的布防模.
///
/// 查看当前正在使用的布防模式.(仅用于主网关接口)
///
public static async System.Threading.Tasks.Task GetModeUsingAsync()
{
return await System.Threading.Tasks.Task.Run(async () =>
{
GetModeUsingResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new GetModeUsingResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new GetModeUsingResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new GetModeUsingResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/GetModeUsing_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
if (result == 0)
{
var getModeInfoByIdResponData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (getModeInfoByIdResponData != null)
{
d = new GetModeUsingResponseAllData { getModeUsingResponseData = getModeInfoByIdResponData };
}
System.Console.WriteLine("已收到正确的通知返回");
}
else
{
d = new GetModeUsingResponseAllData {};
var r = new GetModeUsingResponseData();
r.Result = result;
d.getModeUsingResponseData = r;
System.Console.WriteLine("已收到通知返回");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/GetModeUsing_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4011}
};
mainGateway.Send("Security/GetModeUsing", jObject.ToString());
}
catch {}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new GetModeUsingResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/GetModeUsing_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 查看当前正在使用的布防模式返回的数据,网关反馈信息
///
public GetModeUsingResponseAllData getModeUsingResponseAllData;
///
/// 查看当前正在使用的布防模式返回的数据,网关反馈信息
///
[System.Serializable]
public class GetModeUsingResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 查看当前正在使用的布防模式返回的数据
///
public GetModeUsingResponseData getModeUsingResponseData;
}
///
/// 查看当前正在使用的布防模式返回的数据
///
public GetModeUsingResponseData getModeUsingResponseData;
///
/// 查看当前正在使用的布防模式返回的数据
///
[System.Serializable]
public class GetModeUsingResponseData
{
///
/// 0:默认
/// 1:系统当前没有进行布防
///
public int Result=999;
///
/// 启用的布防模式id
///
public int ModeId;
///
/// 模式名称(Result =0时存在)
///
public string ModeName;
///
/// 设置 (Result = 0时存在)
/// 1:永久布防,直到撤防
/// 2:使能一次,触发一次后将撤防。
/// 3:失能一次,第一次被激活不警告不触发动作。
///
public int Setting;
}
#endregion
#region 11布防 ;
///
/// 布防 (仅用于主网关接口)
/// EnableModeData:布防的数据
///
public static async System.Threading.Tasks.Task EnableModeAsync(EnableModeData enableModeData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
EnableModeResponAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new EnableModeResponAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new EnableModeResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new EnableModeResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/EnableMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["ModeId"].ToString());
security.enableModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.enableModeResponseData == null)
{
d = new EnableModeResponAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new EnableModeResponAllData { enableModeResponseData = security.enableModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/EnableMode_Actions 启动" + System.DateTime.Now.ToString());
try{
if (enableModeData != null)
{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4012 }
};
var data = new JObject
{
{ "Setting", enableModeData.Setting },
{ "ModeId", enableModeData .ModeId},
{ "CheckIASStatus", enableModeData.CheckIASStatus},
{ "UserPassword", enableModeData .UserPassword }
};
jObject.Add("Data", data);
mainGateway.Send("Security/EnableMode", jObject.ToString());
}
}
catch{}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new EnableModeResponAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/EnableMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 布防返回的数据,,网关反馈信息
///
public EnableModeResponAllData enableModeResponAllData;
///
/// 布防返回的数据,网关反馈信息
///
[System.Serializable]
public class EnableModeResponAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 布防返回的数据
///
public EnableModeResponseData enableModeResponseData;
}
///
/// 布防返回的数据
///
public EnableModeResponseData enableModeResponseData;
///
/// 布防返回的数据
///
[System.Serializable]
public class EnableModeResponseData
{
///
/// 0:设置成功
///1:设置失败,布防模式不存在
///2:设置失败,用户密码错误。
///3:布防失败,安防设备未就绪。
///4:布防失败,有其他布防模式正在启用(只能使用一种布防模式,需将正在启用的布防模式撤防才能布防新模式)。
///5:失败,模式属性不允许失能(如果新建布防模式时,AllowDisable设置为0,则布防Setting值不能为2或3,否则将报告该错误)
///
public int Result=999;
///
/// 启用的布防模式id
///
public int ModeId;
///
/// 模式名称(Result =0时存在)
///
public string ModeName;
///
/// 设置
/// 1:永久布防,直到撤防
/// 2:使能一次,触发一次后将撤防。
/// 3:失能一次,第一次被激活不警告不触发动作。
///
public int Setting;
///
///当前正在启用的布防模式ID(当Result = 4时存在。)
///
public int ModeIdBeUsing;
///
///未就绪设备的mac地址(当Result =3时存在)
///
public string IASMac;
///
///未就绪设备的端口号(当Result = 3时存在。)
///
public int IASEpoint;
///
///未就绪设备名称(当Result = 3时存在)
///
public string IASName;
///
///设备最近一次上报的安防状态值(当Result=3时存在)
///
public int IASStatus;
///
///未就绪设备所在防区(当Result=3时存在)
///
public int ZoneId;
///
///未就绪设备所在防区(当Result=3时存在当Result = 3时存在)
///
public string ZoneName;
}
///
/// 布防
///
public EnableModeData enableModeData;
///
/// 布防
///
[System.Serializable]
public class EnableModeData
{
///
/// 1;永久布防,直到撤防
///2:使能一次,触发一次后将撤防。
///3:失能一次,第一次被激活不警告不触发动作。
///
public int Setting;
///
/// 启用的布防模式id
///
public int ModeId;
///
///检查防区设备最近上报的安防信息状态进行布防。
///0:不检查
///1:检查
///
public int CheckIASStatus;
///
///用户密码,最大32个字符
///
public string UserPassword;
}
#endregion
#region 12撤防.;
///
/// 撤防.(仅用于主网关接口)
///
public static async System.Threading.Tasks.Task WithdrawModeAsync(string userPassword)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
WithdrawModeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new WithdrawModeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new WithdrawModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new WithdrawModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/WithdrawMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.withdrawModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.withdrawModeResponseData == null)
{
d = new WithdrawModeResponseAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new WithdrawModeResponseAllData { withdrawModeResponseData = security.withdrawModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/WithdrawMode_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4013}
};
var data = new JObject
{
{ "UserPassword", userPassword}
};
jObject.Add("Data", data);
mainGateway.Send("Security/WithdrawMode", jObject.ToString());
}
catch {}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new WithdrawModeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/WithdrawMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 撤防返回的数据,网关反馈信息
///
public WithdrawModeResponseAllData withdrawModeResponseAllData;
///
/// 撤防返回的数据,网关反馈信息
///
[System.Serializable]
public class WithdrawModeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 撤防返回的数据
///
public WithdrawModeResponseData withdrawModeResponseData;
}
///
/// 撤防返回的数据
///
public WithdrawModeResponseData withdrawModeResponseData;
///
/// 撤防返回的数据
///
[System.Serializable]
public class WithdrawModeResponseData
{
///
/// 0:撤防成功。
///1:失败,当前不存在布防。
///2:撤防失败,密码错误。
///3:撤防失败,模式不可撤防。(新建模式时,模式属性设为不可撤防则布防后将不能撤防)
///
public int Result=999;
///
/// 被撤防的模式
///
public int ModeId;
///
/// 被撤防的模式名称
///
public string ModeName;
///
/// 撤防所用的密码类型:
///0:用户密码
///1:胁迫密码
///
public int PasswordType;
}
#endregion
#region 13删除布防模式.
///
/// 删除布防模式(需要管理员权限).
///
public static async System.Threading.Tasks.Task RemoveModeAsync(int modeId)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
RemoveModeResponseAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new RemoveModeResponseAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (temp == null)
{
d = new RemoveModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
}
else
{
d = new RemoveModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
}
}
if (topic == gatewayID + "/" + "Security/Error_Respon")
{
var securityTemp = new Safeguard() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID };
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
d = new RemoveModeResponseAllData { };
if (temp == null)
{
d.errorMessageBase = "网关错误回复,且数据是空";
}
else
{
if (temp.Error == 1)
{
d.errorMessageBase = "网关不是主网关,无法进行该操作。";
}
else if (temp.Error == 2)
{
d.errorMessageBase = "该操作需要安防管理员权限,需先以管理员身份进行登陆。";
}
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
d.errorResponData = temp;
}
}
if (topic == gatewayID + "/" + "Security/RemoveMode_Respon")
{
var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = mainGateway.CurrentGateWayId };
security.removeModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
if (security.removeModeResponseData == null)
{
d = new RemoveModeResponseAllData { errorMessageBase = "网关返回的数据为空" };
}
else
{
d = new RemoveModeResponseAllData { removeModeResponseData = security.removeModeResponseData };
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
}
}
};
mainGateway.Actions += action;
System.Console.WriteLine("Security/RemoveMode_Actions 启动" + System.DateTime.Now.ToString());
try{
var jObject = new Newtonsoft.Json.Linq.JObject() {
{ "Cluster_ID", 0 },
{ "Command", 4014}
};
var data = new JObject
{
{ "ModeId", modeId}
};
jObject.Add("Data", data);
mainGateway.Send("Security/RemoveMode", jObject.ToString());
}
catch {}
var dateTime = DateTime.Now;
while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
{
await System.Threading.Tasks.Task.Delay(10);
if (d != null)
{
break;
}
}
if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
{
d = new RemoveModeResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
}
mainGateway.Actions -= action;
System.Console.WriteLine("Security/RemoveMode_Actions 退出" + System.DateTime.Now.ToString());
return d;
});
}
///
/// 删除布防模式返回的数据,网关反馈信息
///
public RemoveModeResponseAllData removeModeResponseAllData;
///
/// 删除布防模式返回的数据,网关反馈信息
///
[System.Serializable]
public class RemoveModeResponseAllData
{
///
/// 错误信息
///
public string errorMessageBase;
///
/// 网关信息错误反馈
/// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
///
public ErrorResponData errorResponData;
///
/// 删除布防模式返回的数据
///
public RemoveModeResponseData removeModeResponseData;
}
///
/// 删除布防模式返回的数据
///
public RemoveModeResponseData removeModeResponseData;
///
/// 删除布防模式返回的数据
///
[System.Serializable]
public class RemoveModeResponseData
{
///
/// 0:删除成功。
///1:失败,不存在该布防模式。
///2:删除失败,不允许删除。(当ModeId为1或2时,离家布防和在家布防模式不允许删除)
///
public int Result=999;
///
/// 模式id
///
public int ModeId;
///
/// 模式名 (当Result=0时存在)。
///
public string ModeName;
///
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
///
public string LoginToken;
}
#endregion
//#region 删除防区.
/////
///// 删除防区.(仅用于主网关接口).
/////
//public static async System.Threading.Tasks.Task RemoveZoneAsync(int zoneId)
//{
// return await System.Threading.Tasks.Task.Run(async () =>
// {
// var d = new RemoveZoneResponseAllData { };
// if (ZbGateway.MainGateWay == null)
// {
// d.errorMessageBase = "当前没有主网关";
// return d;
// }
// Action action = (topic, message) =>
// {
// var gatewayID = topic.Split('/')[0];
// var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
// if (topic == gatewayID + "/" + "Error_Respon")
// {
// var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID };
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
// if (temp == null)
// {
// d.errorMessageBase = "网关错误回复,且数据是空";
// }
// else
// {
// d.errorResponData = temp;
// d.errorMessageBase = ErrorMess(temp.Error);
// }
// }
// if (topic == gatewayID + "/" + "Security/RemoveZone_Respon")
// {
// var security = new Safeguard() { DataID = jobject.Value("Data_ID"), GateWayId = ZbGateway.MainGateWay.CurrentGateWayId };
// var result = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"]["Result"].ToString());
// if (result == 0)
// {
// security.removeZoneResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject(jobject["Data"].ToString());
// if (security.removeZoneResponseData != null)
// {
// d.removeZoneResponseData = security.removeZoneResponseData;
// System.Console.WriteLine($"收到通知后的主题_{topic}");
// }
// }
// else
// {
// var r = new RemoveZoneResponseData();
// r.Result = result;
// d.removeZoneResponseData = r;
// System.Console.WriteLine($"收到通知后的主题_{topic}");
// }
// }
// };
// ZbGateway.MainGateWay.Actions += action;
// System.Console.WriteLine("Security/RemoveZone_Actions 启动" + System.DateTime.Now.ToString());
// var jObject = new Newtonsoft.Json.Linq.JObject() {
// { "Cluster_ID", 0 },
// { "Command", 4015}
// };
// var data = new JObject
// {
// { "ZoneId", zoneId}
// };
// jObject.Add("Data", data);
// ZbGateway.MainGateWay?.Send("Security/RemoveZone", jObject.ToString());
// var dateTime = DateTime.Now;
// while ((DateTime.Now - dateTime).TotalMilliseconds < 1000)
// {
// await System.Threading.Tasks.Task.Delay(10);
// if (d.removeZoneResponseData != null)
// {
// break;
// }
// }
// if ((DateTime.Now - dateTime).TotalMilliseconds > 10000)
// {
// d.errorMessageBase = " 回复超时,请重新操作";
// }
// ZbGateway.MainGateWay.Actions -= action;
// System.Console.WriteLine("Security/RemoveZone_Actions 退出" + System.DateTime.Now.ToString());
// return d;
// });
//}
/////
///// 删除防区,网关反馈信息
/////
//public RemoveZoneResponseAllData removeZoneResponseAllData;
/////
///// 删除防区,网关反馈信息
/////
//[System.Serializable]
//public class RemoveZoneResponseAllData
//{
// ///
// /// 错误信息
// ///
// public string errorMessageBase;
// ///
// /// 网关信息错误反馈
// /// 当网关接收到客户端信息后,出现以下异常情况将反馈错误。
// ///
// public ErrorResponData errorResponData;
// ///
// /// 删除防区返回的数据
// ///
// public RemoveZoneResponseData removeZoneResponseData;
//}
/////
///// 删除防区返回的数据
/////
//public RemoveZoneResponseData removeZoneResponseData;
/////
///// 删除防区返回的数据
/////
//[System.Serializable]
//public class RemoveZoneResponseData
//{
// ///
// /// 0:删除成功。
// ///1:失败,防区不存在。
// ///
// public int Result = 999;
// ///
// /// 防区id
// ///
// public int ZoneId;
// ///
// /// 防区名称,当Result=0时存在。
// ///
// public string ZoneName;
//}
//#endregion
#region *14将设备从防区中移除.
///
/// *将设备从防区中移除(需要管理员权限).
///
/// The device to zone async.
/// 将设备从防区中移除的数据.
public static async System.Threading.Tasks.Task RemoveDeviceToZoneAsync(RemoveEqToZoneData removeEqToZoneData)
{
return await System.Threading.Tasks.Task.Run(async () =>
{
RemoveDeviceToZoneAllData d = null;
var mainGateway = ZbGateway.MainGateWay;
if (mainGateway == null)
{
d = new RemoveDeviceToZoneAllData { errorMessageBase = "当前没有主网关" };
return d;
}
Action action = (topic, message) =>
{
var gatewayID = topic.Split('/')[0];
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
if (topic == gatewayID + "/" + "Error_Respon")
{
var gatewayTemp = new ZbGateway() { Time = jobject.Value("Time"), DataID = jobject.Value