using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Newtonsoft.Json.Linq;
|
|
namespace ZigBee.Device
|
{
|
[System.Serializable]
|
public class Safeguard
|
{
|
/// <summary>
|
/// 当前主网关的ID
|
/// </summary>
|
public string GateWayId;
|
|
/// <summary>
|
/// 网关返回场景的命令标识
|
/// </summary>
|
public int DataID;
|
|
/// <summary>
|
/// 网关反馈的时间戳
|
/// </summary>
|
public int Time;
|
|
/// <summary>
|
/// 等待从网关接收数据的时间
|
/// </summary>
|
/// <value>The wait receive data time.</value>
|
public static int WaitReceiveDataTime
|
{
|
get
|
{
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
return 3000;
|
}
|
else if (mainGateway.IsVirtual)
|
{
|
return 6000;
|
}
|
else
|
{
|
return 3000;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 网关信息错误反馈内容
|
/// </summary>
|
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 *管理员密码登陆;
|
///<summary >
|
/// *管理员密码登陆.(仅用于主网关接口).
|
/// <para>password:管理员密码,初始化密码为“admin”。</para>
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。</para>
|
/// <para>返回结果Result</para>
|
/// <para>0:登陆成功</para>
|
/// <para>1:密码错误,登陆失败。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<AdminLoginResponAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(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;
|
});
|
}
|
|
/// <summary>
|
/// 管理员密码登陆的数据,网关反馈信息
|
/// </summary>
|
public AdminLoginResponAllData adminLoginResponAllData;
|
/// <summary>
|
/// 管理员密码登陆返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AdminLoginResponAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 返回结果Result
|
/// <para>0:登陆成功</para>
|
/// <para>1:密码错误,登陆失败。</para>
|
/// </summary>
|
public int Result = 999;
|
/// <summary>
|
/// 返回错误结果
|
/// <para>1:网关不是主网关,无法进行该操作。</para>
|
/// <para>2:该操作需要安防管理员权限,需先以管理员身份进行登陆。</para>
|
/// </summary>
|
public int Error;
|
}
|
|
#endregion
|
|
#region 20修改管理员密码.
|
/// <summary>
|
/// 修改管理员密码(仅用于主网关接口)
|
/// </summary>
|
/// <returns>The admin password async.</returns>
|
/// <param name="password">新管理员密码 </param>
|
/// <param name="oldPassword">旧密码/param>
|
public static async System.Threading.Tasks.Task<ChangeAdminPasswordResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var changeAdminPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ChangeAdminPasswordResponseData>(jobject["Data"].ToString());
|
if (changeAdminPasswordResponseData != null)
|
{
|
d = new ChangeAdminPasswordResponseAllData { changeAdminPasswordResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 修改管理员密码返回的数据,网关反馈信息
|
/// </summary>
|
public ChangeAdminPasswordResponseAllData changeAdminPasswordResponseAllData;
|
/// <summary>
|
/// 修改管理员密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class ChangeAdminPasswordResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 修改管理员密码返回的数据
|
/// </summary>
|
public ChangeAdminPasswordResponseData changeAdminPasswordResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 修改管理员密码返回的数据
|
/// </summary>
|
public ChangeAdminPasswordResponseData changeAdminPasswordResponseData;
|
/// <summary>
|
/// 修改管理员密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class ChangeAdminPasswordResponseData
|
{
|
/// <summary>
|
/// 0:修改成功
|
///<para>1:修改失败,原密码错误</para>
|
///<para>2:修改失败,密码长度不正确</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 新密码,最大32个字符。(当Result = 0时存在。)
|
/// </summary>
|
public string NewPassword;
|
|
}
|
#endregion
|
|
#region 16查看延时时间;
|
///<summary >
|
/// 查看延时时间(仅用于主网关接口)
|
/// </summary>
|
public static async System.Threading.Tasks.Task<CatDelayTimeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 catDelayTimeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CatDelayTimeResponseData>(jobject["Data"].ToString());
|
if (catDelayTimeResponseData == null)
|
{
|
d = new CatDelayTimeResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new CatDelayTimeResponseAllData { catDelayTimeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 查看延时时间返回的数据,网关反馈信息
|
/// </summary>
|
public CatDelayTimeResponseAllData catDelayTimeResponseAllData;
|
/// <summary>
|
/// 查看延时时间返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class CatDelayTimeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看延时时间返回的数据
|
/// </summary>
|
public CatDelayTimeResponseData catDelayTimeResponseData;
|
|
}
|
|
/// <summary>
|
/// 查看延时时间返回的数据
|
/// </summary>
|
public CatDelayTimeResponseData catDelayTimeResponseData;
|
/// <summary>
|
/// 查看延时时间返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class CatDelayTimeResponseData
|
{
|
/// <summary>
|
/// 进入延时时间,单位秒 范围:0-65535
|
/// </summary>
|
public int EntranceDelayTime;
|
/// <summary>
|
/// 外出延时时间,单位秒 范围:0-65535
|
/// </summary>
|
public int GoOutDelayTime;
|
|
}
|
#endregion
|
|
#region 17*设置出入防区延时时;
|
///<summary >
|
/// *设置出入防区延时时间(需要管理员权限))
|
/// <para>entranceDelayTime:进入延时时间,单位秒范围:0-65535</para>
|
/// <para>goOutDelayTime:外出延时时间,单位秒范围:0-65535</para>
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<SetDelayTimeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 setDelayTimeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetDelayTimeResponseData>(jobject["Data"].ToString());
|
if (setDelayTimeResponseData == null)
|
{
|
d = new SetDelayTimeResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new SetDelayTimeResponseAllData { setDelayTimeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 设置延时时间返回的数据,网关反馈信息
|
/// </summary>
|
public SetDelayTimeResponseAllData setDelayTimeResponseAllData;
|
/// <summary>
|
/// 设置延时时间返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class SetDelayTimeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 设置延时时间返回的数据
|
/// </summary>
|
public SetDelayTimeResponseData setDelayTimeResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 设置延时时间返回的数据
|
/// </summary>
|
public SetDelayTimeResponseData setDelayTimeResponseData;
|
/// <summary>
|
/// 设置延时时间返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class SetDelayTimeResponseData
|
{
|
/// <summary>
|
/// 进入延时时间,单位秒 范围:0-65535
|
/// </summary>
|
public int EntranceDelayTime;
|
/// <summary>
|
/// 外出延时时间,单位秒 范围:0-65535
|
/// </summary>
|
public int GoOutDelayTime;
|
|
}
|
#endregion
|
|
#region 21*查看用户密码和胁迫密码.;
|
///<summary >
|
/// *查看用户密码和胁迫密码(需要管理员权限)
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<CatUserPasswordResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 catUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CatUserPasswordResponseData>(jobject["Data"].ToString());
|
if (catUserPasswordResponseData == null)
|
{
|
d = new CatUserPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new CatUserPasswordResponseAllData { catUserPasswordResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 查看用户密码和胁迫密码返回的数据,网关反馈信息
|
/// </summary>
|
public CatUserPasswordResponseAllData catUserPasswordResponseAllData;
|
/// <summary>
|
/// 查看用户密码和胁迫密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class CatUserPasswordResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看用户密码和胁迫密码返回的数据
|
/// </summary>
|
public CatUserPasswordResponseData catUserPasswordResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 查看用户密码和胁迫密码返回的数据
|
/// </summary>
|
public CatUserPasswordResponseData catUserPasswordResponseData;
|
/// <summary>
|
/// 查看用户密码和胁迫密码返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class CatUserPasswordResponseData
|
{
|
/// <summary>
|
/// 用户密码列表
|
/// </summary>
|
public List<UserPasswordListObj> UserPasswordList = new List<UserPasswordListObj>();
|
|
}
|
|
/// <summary>
|
/// 用户密码列表数据
|
/// </summary>
|
[System.Serializable]
|
public class UserPasswordListObj
|
{
|
|
/// <summary>
|
/// 用户id。Id为5时为胁迫密码
|
/// </summary>
|
public int UserId;
|
/// <summary>
|
/// 最少4个字符,最大32个字符
|
/// </summary>
|
public string Password;
|
/// <summary>
|
/// 用户密码提示语
|
/// </summary>
|
public string PassWordTips = string.Empty;
|
}
|
#endregion
|
|
#region 22*新增或重设用户密码.;
|
/// <summary>
|
/// *新增或重设用户密码(需要管理员权限)
|
/// <para>userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
|
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。</para>
|
/// <para>password:新管理员密码</para>
|
/// <para>passWordTips:密码提示</para>
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<SetUserPasswordResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var setUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetUserPasswordResponseData>(jobject["Data"].ToString());
|
if (setUserPasswordResponseData != null)
|
{
|
d = new SetUserPasswordResponseAllData { setUserPasswordResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// *新增或重设用户密码(需要管理员权限)
|
/// <para>userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
|
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。</para>
|
/// <para>password:新管理员密码</para>
|
/// <para>passWordTips:密码提示</para>
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<SetUserPasswordResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var setUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetUserPasswordResponseData>(jobject["Data"].ToString());
|
if (setUserPasswordResponseData != null)
|
{
|
d = new SetUserPasswordResponseAllData { setUserPasswordResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 新增或重设用户密码返回的数据,网关反馈信息
|
/// </summary>
|
public SetUserPasswordResponseAllData setUserPasswordResponseAllData;
|
/// <summary>
|
/// 新增或重设用户密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class SetUserPasswordResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 修改管理员密码返回的数据
|
/// </summary>
|
public SetUserPasswordResponseData setUserPasswordResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 新增或重设用户密码返回的数据
|
/// </summary>
|
public SetUserPasswordResponseData setUserPasswordResponseData;
|
/// <summary>
|
/// 新增或重设用户密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class SetUserPasswordResponseData
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,用户密码数已满(最大4个)</para>
|
///<para>2:失败,密码长度不正确。</para>
|
///<para>3:失败,密码和已存在的用户密码重复,4个用户密码不能相同。</para>
|
/// </summary>
|
public int Result = 999;
|
/// <summary>
|
/// 用户id
|
/// </summary>
|
public int UserId;
|
/// <summary>
|
/// 新密码 ,最大32个字符,至少4个字符。
|
/// </summary>
|
public string password;
|
|
}
|
#endregion
|
|
#region 23*删除用户密码.
|
/// <summary>
|
/// *删除用户密码(需要管理员权限)
|
/// <para>userId:用户id 如果用户id存在,则修改密码。如果用户id不存在,则为该id新增密码
|
/// 为0时,自动分配新的用户id。为5时,则修改胁迫密码。取值范围0-5。</para>
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<DelUserPasswordResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 delUserPasswordResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelUserPasswordResponseData>(jobject["Data"].ToString());
|
if (delUserPasswordResponseData != null)
|
{
|
d = new DelUserPasswordResponseAllData { delUserPasswordResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 删除用户密码返回的数据,网关反馈信息
|
/// </summary>
|
public DelUserPasswordResponseAllData delUserPasswordResponseAllData;
|
/// <summary>
|
/// 删除用户密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class DelUserPasswordResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 删除用户密码返回的数据
|
/// </summary>
|
public DelUserPasswordResponseData delUserPasswordResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 删除用户密码返回的数据
|
/// </summary>
|
public DelUserPasswordResponseData delUserPasswordResponseData;
|
/// <summary>
|
/// 删除用户密码返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class DelUserPasswordResponseData
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,用户id不存在。</para>
|
/// </summary>
|
public int Result = 999;
|
/// <summary>
|
/// 用户id
|
/// </summary>
|
public int UserId;
|
|
}
|
#endregion
|
|
//#region 新建或修改防区.
|
///// <summary>
|
///// 新建或修改防区。
|
///// </summary>
|
///// <returns>The new zone async.</returns>
|
///// <param name="addNewZoneData">新建或修改防区的数据</param>
|
//public static async System.Threading.Tasks.Task<AddNewZoneDataResponseAllData> AddNewZoneAsync(AddNewZoneData addNewZoneData)
|
//{
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// var d = new AddNewZoneDataResponseAllData { };
|
// if (ZbGateway.MainGateWay == null)
|
// {
|
// d.errorMessageBase = "当前没有主网关";
|
// return d;
|
// }
|
// Action<string, string> 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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.GwId };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Data_ID"), GateWayId = ZbGateway.MainGateWay.CurrentGateWayId };
|
// security.addNewZoneDataResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddNewZoneDataResponseData>(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;
|
// });
|
//}
|
|
///// <summary>
|
///// 新建或修改防区返回的数据 ,网关反馈信息
|
///// </summary>
|
//public AddNewZoneDataResponseAllData addNewZoneDataResponseAllData;
|
///// <summary>
|
///// 新建或修改防区返回的数据,网关反馈信息
|
///// </summary>
|
//[System.Serializable]
|
//public class AddNewZoneDataResponseAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// ///新建或修改防区返回的数据
|
// /// </summary>
|
// public AddNewZoneDataResponseData addNewZoneDataResponseData;
|
//}
|
|
///// <summary>
|
///// 新建或修改防区返回的数据
|
///// </summary>
|
//public AddNewZoneDataResponseData addNewZoneDataResponseData;
|
///// <summary>
|
///// 新建或修改防区返回的数据
|
///// </summary>
|
//[System.Serializable]
|
//public class AddNewZoneDataResponseData
|
//{
|
// /// <summary>
|
// /// 返回结果
|
// /// <para>0:添加或修改成功</para>
|
// /// <para>1:失败,防区不存在</para>
|
// /// </summary>
|
// //public int Result = 2;
|
|
// /// <summary>
|
// /// 局部设防列表id
|
// /// </summary>
|
// public int ZoneId;
|
|
// /// <summary>
|
// /// 防区名称 ,最大32个字符(当Result = 0时才存在)
|
// /// </summary>
|
// public string ZoneName;
|
|
// /// <summary>
|
// /// 布防防区类型:(当Result = 0时才存在)
|
// ///<para>当Type=1时,该字段才存在。</para>
|
// ///<para>1:24小时防区。</para>
|
// ///<para>2:24小时静音防区。</para>
|
// ///<para>3:出入防区。</para>
|
// ///<para>4:内部防区。</para>
|
// ///<para>5:跟随防区。</para>
|
// ///<para>6:周界防区。</para>
|
// ///<para>7:周界延时防区。</para>
|
// /// </summary>
|
// public int ZoneType;
|
|
// /// <summary>
|
// /// 是否允许旁路(当Result = 0时才存在)
|
// ///<para>0:不允许旁路</para>
|
// ///<para>1:允许旁路</para>
|
// /// </summary>
|
// public int Bypass;
|
|
// /// <summary>
|
// /// 是否允许弹性旁路:(当Result = 0时才存在)
|
// ///<para>0:不允许弹性旁路</para>
|
// ///<para>1:允许弹性旁路</para>
|
// /// </summary>
|
// public int ElasticBypass;
|
//}
|
|
///// <summary>
|
///// 新建或修改防区的数据
|
///// </summary>
|
//public AddNewZoneData addNewZone;
|
///// <summary>
|
///// 新建或修改防区的数据
|
///// </summary>
|
//[System.Serializable]
|
//public class AddNewZoneData
|
//{
|
// /// <summary>
|
// /// 防区id。
|
// /// <para>0:0:新增防区</para>
|
// /// <para>其他:要修改的防区id</para>
|
// /// </summary>
|
// public int ZoneId;
|
|
// /// <summary>
|
// /// 防区名称 ,最大32个字符
|
// /// </summary>
|
// public string ZoneName;
|
|
// /// <summary>
|
// /// 防区类型:
|
// ///<para>当Type=1时,该字段才存在。</para>
|
// ///<para>1:24小时防区。</para>
|
// ///<para>2:24小时静音防区。</para>
|
// ///<para>3:出入防区。</para>
|
// ///<para>4:内部防区。</para>
|
// ///<para>5:跟随防区。</para>
|
// ///<para>6:周界防区。</para>
|
// ///<para>7:周界延时防区。</para>
|
// ///<para>如果为24小时(静音)类型防区将自动加入24小时布防模式中,并从自定义模式中清除该防区。如果原来是24小时(静音)类型防区修改为非24小时类型,将原防区将自动从24小时布防模式中清除。</para>
|
// /// </summary>
|
// public int ZoneType;
|
|
// /// <summary>
|
// /// 是否允许旁路
|
// ///<para>0:不允许旁路</para>
|
// ///<para>1:允许旁路</para>
|
// ///<para>若类型为24小时防区或24小时静音防区将不允许旁路,该字段将被忽略。</para>
|
// /// </summary>
|
// public int Bypass;
|
|
// /// <summary>
|
// /// 是否允许弹性旁路:
|
// ///<para>0:不允许弹性旁路</para>
|
// ///<para>1:允许弹性旁路</para>
|
// ///<para>若类型为24小时防区或24小时静音防区将不允许弹性旁路,该字段将被忽略。</para>
|
// /// </summary>
|
// public int ElasticBypass;
|
//}
|
//#endregion
|
|
#region 2 *设备加入防区.;
|
/// <summary>
|
/// *设备加入防区(需要管理员权限)
|
/// <para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。如果登陆成功,网关将记录该标识,app需要管理员权限的指令都应该带有该标识,网关会根据该标识来判断是否为管理员操作,如果标识错误,将返回“Security/Error_Respon”主题数据。 。</para>
|
/// </summary>
|
/// <returns>The device to zone async.</returns>
|
/// <param name="addDeviceToZoneData">设备加入防区的数据</param>
|
public static async System.Threading.Tasks.Task<AddDeviceToZoneResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
|
if (result == 0)
|
{
|
var addDeviceToZoneResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddDeviceToZoneResponseData>(jobject["Data"].ToString());
|
if (addDeviceToZoneResponseData != null)
|
{
|
d = new AddDeviceToZoneResponseAllData { addDeviceToPartResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 设备加入防区的返回数据 ,网关反馈信息
|
/// </summary>
|
public AddDeviceToZoneResponseAllData addDeviceToPartResponseAllData;
|
/// <summary>
|
/// 设备加入防区的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AddDeviceToZoneResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 设备加入防区的返回数据
|
/// </summary>
|
public AddDeviceToZoneResponseData addDeviceToPartResponseData;
|
}
|
|
/// <summary>
|
/// 设备加入防区的返回数据
|
/// </summary>
|
public AddDeviceToZoneResponseData addDeviceToZoneResponseData;
|
/// <summary>
|
/// 设备加入防区的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class AddDeviceToZoneResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:添加失败。(局部布防列表id不存在)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 防区id
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 安防设备列表(Result=0时存在)
|
/// </summary>
|
public List<DeviceListResponseObj> DeviceList = new List<DeviceListResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 安防设备列表回复的数据
|
/// </summary>
|
[System.Serializable]
|
public class DeviceListResponseObj
|
{
|
/// <summary>
|
/// 0:添加成功
|
///<para>1:失败,设备不存在。</para>
|
///<para>2:失败,设备已经加入了其他防区。</para>
|
/// </summary>
|
public int Status;
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
/// <summary>
|
/// 设备上报的状态是否为瞬间状态,用于配合下面的TriggerZoneStatus值使用。
|
///<pata>0:非瞬间状态,该设备上报的安防状态可持续,直到状态被改变会再次报告安防状态信息。如门磁设备的开状态和关状态(开和关状态是能持续的)。</pata>
|
///<pata>1:表示安防状态为瞬间量,设备警告激活状态才上报安防信息,设备恢复常态不发送通知。如人体红外传感器(当有人时触发警告,但人走了后,不会发送消除警告信息。无法知道人还在不在)</pata>
|
/// </summary>
|
public int MomentStatus;
|
/// <summary>
|
/// <pata>当MomentStatus为0时,安防设备被触发上报安防信息的ZoneStatus值和TriggerZoneStatus进行与运算(&)结果不为0时激活防区警报,为0时解除激活。例如门磁设备,如果有人开门入侵将激活防区报警,可将TriggerZoneStatus设置为17,开门时上报的ZoneStatus值为1,(17 & 1)>0,此时说明有入侵,防区将被激活,发送警告信息到客户端和服务器并执行设定的警戒动作。</pata>
|
/// <pata>当MomentStatus为1时,说明安防设备的激活状态只是瞬间的,只有在上报ZoneStatus值(和TriggerZoneStatus相与不为0时)的瞬间激活,激活后将立即自动恢复为常态。</pata>
|
/// <pata>设置布防时,如果安防设备被触发,防区处于警告状态,要解除激活才能布防成功。如果上面MomentStatus为0,则需要安防设备再次上报的ZoneStatus值和TriggerZoneStatus值进行与运算结果为0才能解除激活状态 。如果MomentStatus为1,则说明设备已经自动恢复常态,布防可以成功。</pata>
|
/// <pata>如门磁设备关门时上报的ZoneStatus值为32,(32&1)=0。则说明门已经关上,防区激活状态将解除,可对防区进行布防。如果MomentStatus为1,则忽略该设备的最近警告状态进行布防。</pata>
|
/// </summary>
|
public int TriggerZoneStatus;
|
}
|
|
/// <summary>
|
/// 新建或修改防区的数据
|
/// </summary>
|
public AddDeviceToZoneData addDeviceToZoneData;
|
/// <summary>
|
/// 设备加入防区的数据
|
/// </summary>
|
[System.Serializable]
|
public class AddDeviceToZoneData
|
{
|
/// <summary>
|
/// 防区id。
|
///<para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>3:出入防区。</para>
|
///<para>4:内部防区。</para>
|
///<para>5:周界防区。</para>
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 安防设备列表
|
/// </summary>
|
public List<DeviceListObj> DeviceList = new List<DeviceListObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
|
/// <summary>
|
/// 安防设备列表数据
|
/// </summary>
|
[System.Serializable]
|
public class DeviceListObj
|
{
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
/// <summary>
|
/// 设备上报的状态是否为瞬间状态,用于配合下面的TriggerZoneStatus值使用。
|
///<pata>0:非瞬间状态,该设备上报的安防状态可持续,直到状态被改变会再次报告安防状态信息。如门磁设备的开状态和关状态(开和关状态是能持续的)。</pata>
|
///<pata>1:表示安防状态为瞬间量,设备警告激活状态才上报安防信息,设备恢复常态不发送通知。如人体红外传感器(当有人时触发警告,但人走了后,不会发送消除警告信息。无法知道人还在不在)</pata>
|
/// </summary>
|
public int MomentStatus;
|
/// <summary>
|
///
|
/// <pata>当MomentStatus为0时,安防设备被触发上报安防信息的ZoneStatus值和TriggerZoneStatus进行与运算(&)结果不为0时激活防区警报,为0时解除激活。例如门磁设备,如果有人开门入侵将激活防区报警,可将TriggerZoneStatus设置为17,开门时上报的ZoneStatus值为1,(17 & 1)>0,此时说明有入侵,防区将被激活,发送警告信息到客户端和服务器并执行设定的警戒动作。</pata>
|
/// <pata>当MomentStatus为1时,说明安防设备的激活状态只是瞬间的,只有在上报ZoneStatus值(和TriggerZoneStatus相与不为0时)的瞬间激活,激活后将立即自动恢复为常态。</pata>
|
/// <pata>设置布防时,如果安防设备被触发,防区处于警告状态,要解除激活才能布防成功。如果上面MomentStatus为0,则需要安防设备再次上报的ZoneStatus值和TriggerZoneStatus值进行与运算结果为0才能解除激活状态 。如果MomentStatus为1,则说明设备已经自动恢复常态,布防可以成功。</pata>
|
/// <pata>如门磁设备关门时上报的ZoneStatus值为32,(32&1)=0。则说明门已经关上,防区激活状态将解除,可对防区进行布防。如果MomentStatus为1,则忽略该设备的最近警告状态进行布防。</pata>
|
/// </summary>
|
public int TriggerZoneStatus;
|
}
|
#endregion
|
|
#region 3 *新建或修改布防模式;
|
/// <summary>
|
/// *新建或修改布防模(需要管理员权限).
|
/// </summary>
|
/// <returns>The new mode async.</returns>
|
/// <param name="addNewModeData">新建或修改布防模式的数据.</param>
|
public static async System.Threading.Tasks.Task<AddNewModeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
|
if (result == 0)
|
{
|
var addNewModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddNewModeResponseData>(jobject["Data"].ToString());
|
if (addNewModeResponseData != null)
|
{
|
d = new AddNewModeResponseAllData { addNewModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 新建或修改防区返回的数据 ,网关反馈信息
|
/// </summary>
|
public AddNewModeResponseAllData addNewModeResponseAllData;
|
/// <summary>
|
/// 新建或修改布防模式返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AddNewModeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
///新建或修改布防模式返回的数据
|
/// </summary>
|
public AddNewModeResponseData addNewModeResponseData;
|
}
|
|
/// <summary>
|
/// 新建或修改布防模式返回的数据
|
/// </summary>
|
public AddNewModeResponseData addNewModeResponseData;
|
/// <summary>
|
/// 新建或修改布防模式返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class AddNewModeResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// 0:成功,修改或新增成功
|
///<para>1:失败,修改的布防模式不存在</para>
|
///<para>2:失败,24小时布防模式不允许修改。(当修改ModeId为255时,将返回该错误)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 布防模式ID
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 布防模式名称 ,最大32个字符。
|
/// </summary>
|
public string ModeName;
|
|
/// <summary>
|
/// 允许失能。
|
///<para>0:不允许失能。</para>
|
///<para>1:允许失能</para>
|
/// </summary>
|
public int AllowDisable;
|
}
|
|
/// <summary>
|
/// 新建或修改布防模式的数据
|
/// </summary>
|
public AddNewModeData addNewModeData;
|
/// <summary>
|
/// 新建或修改布防模式的数据
|
/// </summary>
|
[System.Serializable]
|
public class AddNewModeData
|
{
|
/// <summary>
|
/// 要修改的布防模式ID。
|
///<para>如果为0,则为新增布防模式。</para>
|
///<para>系统内置了两种布防模式,分别为在家布防(ModeId为1)、离家布防(ModeId为2)。两种内置模式不可删除。</para>
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 布防模式名称 ,最大32个字符。
|
///<para>不需要修改可忽略该字段。</para>
|
/// </summary>
|
public string ModeName;
|
|
/// <summary>
|
/// 允许失能。
|
///<para>0:不允许失能。</para>
|
///<para>1:允许失能</para>
|
///<para>如果不需要修改可忽略该字段。新增布防时,默认为0。 </para>
|
/// </summary>
|
public int AllowDisable;
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
#endregion
|
|
#region 4 *防区加入布防模式.
|
/// <summary>
|
/// *防区加入布防模式(需要管理员权限).
|
/// </summary>
|
/// <returns>The join mode async.</returns>
|
/// <param name="zoneJoinModeData">防区加入布防模式的数据</param>
|
public static async System.Threading.Tasks.Task<ZoneJoinModeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["ModeId"].ToString());
|
if (result == 0)
|
{
|
var zoneJoinModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ZoneJoinModeResponseData>(jobject["Data"].ToString());
|
if (zoneJoinModeResponseData != null)
|
{
|
d = new ZoneJoinModeResponseAllData { zoneJoinModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 防区加入布防模式返回的数据 ,网关反馈信息
|
/// </summary>
|
public ZoneJoinModeResponseAllData zoneJoinModeResponseAllData;
|
/// <summary>
|
/// 防区加入布防模式返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class ZoneJoinModeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
///防区加入布防模式返回的数据
|
/// </summary>
|
public ZoneJoinModeResponseData zoneJoinModeResponseData;
|
}
|
|
/// <summary>
|
/// 防区加入布防模式返回的数据
|
/// </summary>
|
public ZoneJoinModeResponseData zoneJoinModeResponseData;
|
/// <summary>
|
/// 防区加入布防模式返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class ZoneJoinModeResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:失败,防区ID不存在。</para>
|
/// <para>2:24小时布防模式,不允许主动加入防区。(当ModeId设置为255时,将返回该错误)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 布防模式ID
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 防区列表(当Result = 0时存在。)
|
/// </summary>
|
public List<ZoneListResponseObj> ZoneList = new List<ZoneListResponseObj>();
|
|
}
|
/// <summary>
|
/// 防区列表
|
/// </summary>
|
[System.Serializable]
|
public class ZoneListResponseObj
|
{
|
/// <summary>
|
/// 返回结果0:加入成功
|
///<para>1:失败,防区不存在</para>
|
///<para>2:失败,防区已在模式中存在</para>
|
///<para>3:失败,防区为24小时(静音)防区类型。</para>
|
/// </summary>
|
public int Status = 999;
|
/// <summary>
|
/// 防区ID
|
/// </summary>
|
public int ZoneId;
|
|
}
|
|
/// <summary>
|
/// 防区加入布防模式的数据
|
/// </summary>
|
public ZoneJoinModeData zoneJoinModeData;
|
/// <summary>
|
/// 防区加入布防模式的数据
|
/// </summary>
|
[System.Serializable]
|
public class ZoneJoinModeData
|
{
|
/// <summary>
|
/// 布防模式ID。
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 防区列表
|
/// <para>不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,不加入任何一种模式。</para>
|
/// </summary>
|
public List<ZoneListObj> ZoneList = new List<ZoneListObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
|
/// <summary>
|
/// 防区列表
|
/// </summary>
|
[System.Serializable]
|
public class ZoneListObj
|
{
|
/// <summary>
|
/// 防区ID
|
/// </summary>
|
public int ZoneId;
|
|
}
|
#endregion
|
|
#region 5 *从布防模式中移除防区.
|
/// <summary>
|
/// *从布防模式中移除防区(需要管理员权限).
|
/// </summary>
|
/// <returns>removeZoneFromModeData:从布防模式中移除防区的数据</returns>
|
/// <param name="removeZoneFromModeData">Remove zone from mode data.</param>
|
public static async System.Threading.Tasks.Task<RemoveZoneFromModeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["ModeId"].ToString());
|
|
if (result == 0)
|
{
|
var removeZoneFromModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveZoneFromModeResponseData>(jobject["Data"].ToString());
|
if (removeZoneFromModeResponseData != null)
|
{
|
d = new RemoveZoneFromModeResponseAllData { removeZoneFromModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 从布防模式中移除防区返回的数据 ,网关反馈信息
|
/// </summary>
|
public RemoveZoneFromModeResponseAllData removeZoneFromModeResponseAllData;
|
/// <summary>
|
/// 从布防模式中移除防区返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class RemoveZoneFromModeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
///从布防模式中移除防区返回的数据
|
/// </summary>
|
public RemoveZoneFromModeResponseData removeZoneFromModeResponseData;
|
}
|
|
/// <summary>
|
/// 从布防模式中移除防区返回的数据
|
/// </summary>
|
public RemoveZoneFromModeResponseData removeZoneFromModeResponseData;
|
/// <summary>
|
/// 从布防模式中移除防区返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveZoneFromModeResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:失败,防区ID不存在。</para>
|
/// <para>2:24小时布防模式,不允许主动加入防区。(当ModeId设置为255时,将返回该错误)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 布防模式ID
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 防区列表(当Result = 0时存在。)
|
/// </summary>
|
public List<RemoveZoneListResponseObj> ZoneList = new List<RemoveZoneListResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 防区列表
|
/// </summary>
|
[System.Serializable]
|
public class RemoveZoneListResponseObj
|
{
|
/// <summary>
|
/// 返回结果0:移除成功
|
///<para>1:移除失败</para>
|
/// </summary>
|
public int Status;
|
/// <summary>
|
/// 防区ID
|
/// </summary>
|
public int ZoneId;
|
|
}
|
|
/// <summary>
|
/// 从布防模式中移除防区
|
/// </summary>
|
public RemoveZoneFromModeData removeZoneFromModeData;
|
/// <summary>
|
/// 从布防模式中移除防区
|
/// </summary>
|
[System.Serializable]
|
public class RemoveZoneFromModeData
|
{
|
/// <summary>
|
/// 布防模式ID。
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 防区列表
|
/// <para>不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,不加入任何一种模式。</para>
|
/// </summary>
|
public List<ZoneListObj> ZoneList = new List<ZoneListObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
#endregion
|
|
#region 6 *添加模式指示动作;
|
/// <summary>
|
/// *安防模式触发动作添加(需要管理员权限).
|
/// </summary>
|
/// <returns>The scene all info async.</returns>
|
/// <param name="addModeActonData">安防模式触发动作添加的数据.</param>
|
public static async System.Threading.Tasks.Task<AddModeActonResponAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["ModeId"].ToString());
|
var actionType = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["ActionType"].ToString());
|
|
if (result == 0)
|
{
|
var addModeActonResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddModeActonResponData>(jobject["Data"].ToString());
|
if (addModeActonResponData != null)
|
{
|
d = new AddModeActonResponAllData { addModeActonResponData = 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;
|
});
|
}
|
/// <summary>
|
/// 安防模式触发动作添加的返回数据数据,网关反馈信息
|
/// </summary>
|
public AddModeActonResponAllData addModeActonResponAllData;
|
/// <summary>
|
/// 安防模式触发动作添加的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AddModeActonResponAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 安防模式触发动作添加的数据
|
/// </summary>
|
public AddModeActonResponData addModeActonResponData;
|
}
|
|
/// <summary>
|
/// 安防模式触发动作添加的回复数据
|
/// </summary>
|
public AddModeActonResponData addModeActonResponData;
|
/// <summary>
|
/// 安防模式触发动作添加的回复数据
|
/// </summary>
|
[System.Serializable]
|
public class AddModeActonResponData
|
{
|
/// <summary>
|
/// 0:默认
|
///<para>1:失败,模式不存在。</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 要修改的布防模式ID。
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 1:布防成功指示动作
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
///<para>5:延时防区、周界延时防区被触发进入延时指示动作。如果延时过后还没撤防将触发模式安防动作。</para>
|
///<para>6:模式安防动作,安防被最终激活后的报警动作(如延时防区被触发延时过后还没撤防、周界防区被触发、出入防区没触发却触发了内部防区等情况将执行该动作)。</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 布防成功指示动作。
|
///<para>如果不需要修改或新增时候可忽略该字段。</para>
|
/// </summary>
|
public List<ActionsResponseData> Actions = new List<ActionsResponseData>();
|
}
|
/// <summary>
|
/// 布防成功指示动作数据
|
/// </summary>
|
public class ActionsResponseData
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:成功</para>
|
///<para>1:失败,设备或场景不存在</para>
|
/// </summary>
|
public int Status = 999;
|
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type;
|
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。(当Type=0和Status = 0时存在)
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
|
/// <summary>
|
/// 设备或场景名称,Status = 0时存在
|
/// </summary>
|
public string ESName;
|
|
}
|
/// <summary>
|
/// 安防模式触发动作添加的数据
|
/// </summary>
|
public AddModeActionData addModeActionData;
|
/// <summary>
|
/// 安防模式触发动作添加的数据
|
/// </summary>
|
[System.Serializable]
|
public class AddModeActionData
|
{
|
/// <summary>
|
/// 要修改的布防模式ID。
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 1:布防成功指示动作
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 布防成功指示动作。
|
///<para>如果不需要修改或新增时候可忽略该字段。</para>
|
/// </summary>
|
public List<ActionsData> Actions = new List<ActionsData>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
/// <summary>
|
/// 布防成功指示动作数据
|
/// </summary>
|
public class ActionsData
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type = 999;
|
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。当Type=0时存在
|
///<para>同一个设备最多可设置8个动作。</para>
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
|
}
|
/// <summary>
|
/// 任务列表中的数据
|
/// </summary>
|
[System.Serializable]
|
public class TaskListInfo
|
{
|
/// <summary>
|
/// 任务类型。
|
///<para>1:开关 (设备具有开关功能时可用)</para>
|
///<para>3:亮度调整(设备具有亮度调节功能时可用)</para>
|
///<para>4:颜色调整 (设备具有颜色调节功能时可用)</para>
|
///<para>5:恒温器(设备具有恒温器功能时可用)</para>
|
///<para>6: 窗帘设备(设备具有窗帘功能时可用)</para>
|
///<para>7:设备identify识别。</para>
|
///<para>8:开关报警模式 </para>
|
///<para>9:squawk command</para>
|
///</summary>
|
public int TaskType;
|
/// <summary>
|
/// Data1取值
|
/// <para>开关 :Data1(数值): 0关/1开</para>
|
///<para>亮度调整 Data1(数值):亮度值</para>
|
///<para>颜色调整 Data1(数值):色调</para>
|
/// <para>恒温器 Data1(数值): 0加热/1制冷/2自动调节/3 设置工作模式/4 设置加热度数 5/设置制冷度数 6/设置风扇模式</para>
|
/// <para>窗帘设备 Data1(数值): 0 打开/ 1关闭/ 2 停止转动/ 4 调整到指定高度/ 5 调整到指定的百分比处位置 / 7 调整到指定倾斜角/ 8 调整到指定的百分比倾斜度</para>
|
/// <para>设备identify识别。Data1为identify闪烁闪烁时间(0-65535秒)。</para>
|
/// <para>开关报警模式 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。</para>
|
/// <para>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。</para>
|
/// </summary>
|
public int Data1;
|
/// <summary>
|
/// Data2取值
|
/// <para>开关 Data2(数值): 0</para>
|
/// <para>亮度调整 Data2(数值): 0</para>
|
/// <para>颜色调整 Data2(数值):饱和度 </para>
|
///<para> 恒温器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】 </para>
|
///<para>窗帘设备,Data2数值如下
|
///【当Data1=4或7,Data2为调整的高度或倾斜角度 倾斜角度单位为0.1°】。
|
///【当Data1=5 或 8,Data2为百分比,0-100表示0%-100%】</para>
|
///<para>设备identify识别。Data2(数值): 0 </para>
|
///<para>开关报警模式 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。</para>
|
///<para>squawk command:Data2(数值): 0 </para>
|
/// </summary>
|
/// <value>The type of the task.</value>
|
public int Data2;
|
|
}
|
#endregion
|
|
#region 7 *将动作从布防模式中移除.
|
/// <summary>
|
/// *将动作从布防模式中移除(需要管理员权限).
|
/// </summary>
|
/// <returns>The acton from mode async.</returns>
|
/// <param name="removeActonFromModeData"> 将动作从布防模式中移除的数据</param>
|
public static async System.Threading.Tasks.Task<RemoveActionFromModeAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var removeActonFromModeResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveActionFromModeResponData>(jobject["Data"].ToString());
|
if (removeActonFromModeResponData != null)
|
{
|
d = new RemoveActionFromModeAllData { removeActonFromModeResponData = 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;
|
});
|
}
|
/// <summary>
|
/// 将动作从布防模式中移除的数据,网关反馈信息
|
/// </summary>
|
public RemoveActionFromModeAllData removeActonFromModeAllData;
|
/// <summary>
|
/// 将动作从布防模式中移除的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class RemoveActionFromModeAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 将动作从布防模式中移除的回复数据
|
/// </summary>
|
public RemoveActionFromModeResponData removeActonFromModeResponData;
|
}
|
|
/// <summary>
|
/// 将动作从布防模式中移除的回复数据
|
/// </summary>
|
public RemoveActionFromModeResponData removeActonFromModeResponData;
|
/// <summary>
|
/// 将动作从布防模式中移除的回复数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveActionFromModeResponData
|
{
|
/// <summary>
|
/// 0:默认
|
///<para>1:失败,模式不存在。</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 模式id
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 1:布防成功指示动作
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 动作列表
|
/// </summary>
|
public List<RemoveActionsResponData> Actions = new List<RemoveActionsResponData>();
|
}
|
/// <summary>
|
/// 布防成功指示动作数据
|
/// </summary>
|
public class RemoveActionsResponData
|
{
|
/// <summary>
|
///<para>0:成功</para>
|
///<para>1:失败,设备或场景不存在</para>
|
/// </summary>
|
public int Status = 999;
|
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:场景</para>
|
/// </summary>
|
public int Type;
|
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
}
|
/// <summary>
|
/// 将动作从布防模式中移除的数据
|
/// </summary>
|
public RemoveActonFromModeData removeActonFromModeData;
|
/// <summary>
|
/// 将动作从布防模式中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveActonFromModeData
|
{
|
/// <summary>
|
/// 要修改的布防模式ID。
|
/// <para>如果为0,则为新增布防模式。</para>
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 1:布防成功指示动作
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 动作列表
|
/// </summary>
|
public List<RemoveActionsData> Actions = new List<RemoveActionsData>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
/// <summary>
|
/// 动作列表的数据
|
/// </summary>
|
public class RemoveActionsData
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type = 999;
|
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
|
}
|
|
#endregion
|
|
#region 8 获取布防(安防)模式列表.;
|
///<summary >
|
/// 获取布防模式列表.(仅用于主网关接口)
|
/// </summary>
|
public static async System.Threading.Tasks.Task<GetModeListAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 getModeListData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetModeListData>(jobject["Data"].ToString());
|
if (getModeListData == null)
|
{
|
d = new GetModeListAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new GetModeListAllData { getModeListData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 获取布防模式列表返回的数据,网关反馈信息
|
/// </summary>
|
public GetModeListAllData getModeListAllData;
|
/// <summary>
|
/// 获取布防模式列表返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class GetModeListAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 获取布防模式列表返回的数据
|
/// </summary>
|
public GetModeListData getModeListData;
|
|
}
|
|
/// <summary>
|
/// 获取布防模式列表返回的数据
|
/// </summary>
|
public GetModeListData getModeListData;
|
/// <summary>
|
/// 获取布防模式列表返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class GetModeListData
|
{
|
/// <summary>
|
/// 布防模式总数
|
/// </summary>
|
public int ModeSum;
|
|
/// <summary>
|
/// 动作列表
|
/// </summary>
|
public List<ModeListData> ModeList = new List<ModeListData>();
|
}
|
/// <summary>
|
/// 布防模式列表数据
|
/// </summary>
|
public class ModeListData
|
{
|
/// <summary>
|
///布防模式ID
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 布防模式名称 ,最大32个字符
|
/// </summary>
|
public string ModeName;
|
|
/// <summary>
|
/// 允许失能。
|
///<para>0:不允许失能。</para>
|
///<para>1:允许失能</para>
|
/// </summary>
|
public string AllowDisable;
|
|
/// <summary>
|
/// 模式当前布撤防状态
|
///<para>0:撤防</para>
|
///<para>1:布防</para>
|
///<para>2:使能一次</para>
|
///<para>3:失能一次</para>
|
/// </summary>
|
public int Setting;
|
}
|
#endregion
|
|
#region 9 通过布防模式ID查看模式信息.
|
///<summary >
|
/// 通过布防模式ID查看模式信息.(仅用于主网关接口)
|
/// <para>modeId:布防模式id</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<GetModeInfoByIdResponAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var getModeInfoByIdResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetModeInfoByIdResponData>(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;
|
});
|
}
|
|
/// <summary>
|
/// 通过布防模式ID查看模式信息的数据,网关反馈信息
|
/// </summary>
|
public GetModeInfoByIdResponAllData getModeInfoByIdResponAllData;
|
/// <summary>
|
/// 通过布防模式ID查看模式信息的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class GetModeInfoByIdResponAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 通过布防模式ID查看模式信息返回的数据
|
/// </summary>
|
public GetModeInfoByIdResponData getModeInfoByIdResponData;
|
}
|
|
/// <summary>
|
/// 通过布防模式ID查看模式信息返回的数据
|
/// </summary>
|
public GetModeInfoByIdResponData getModeInfoByIdResponData;
|
/// <summary>
|
/// 通过布防模式ID查看模式信息返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class GetModeInfoByIdResponData
|
{
|
/// <summary>
|
/// 0:默认
|
///<para>1:失败,布防模式不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 布防模式ID
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 布防模式名称 ,最大32个字符
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public string ModeName;
|
|
/// <summary>
|
/// 允许失能。
|
///<para>0:不允许失能。</para>
|
///<para>1:允许失能</para>
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public int AllowDisable = 100;
|
|
/// <summary>
|
/// 模式当前布撤防状态
|
///<para>0:撤防</para>
|
///<para>1:布防</para>
|
///<para>2:使能一次</para>
|
///<para>3:失能一次</para>
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public int Setting = 100;
|
|
/// <summary>
|
/// 加入模式的防区数量
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public int ZoneNum;
|
|
/// <summary>
|
/// 加入成功的防区列表,不包括24小时防区、和24小时静音防区。24小时防区和24小时静音防区是脱离布防模式不受布撤防影响的运行,加入任何一种模式。
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ZoneListData> ZoneList = new List<ZoneListData>();
|
|
/// <summary>
|
/// 布防成功指示动作。
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ActionsInfo> ProtectionSucceedActions = new List<ActionsInfo>();
|
/// <summary>
|
/// 布防失败指示动作。
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ActionsInfo> ProtectionFailActions = new List<ActionsInfo>();
|
|
/// <summary>
|
/// 撤防成功指示动作。
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ActionsInfo> WithdrawSucceedActions = new List<ActionsInfo>();
|
/// <summary>
|
/// 撤防失败指示动作。
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ActionsInfo> WithdrawFailActions = new List<ActionsInfo>();
|
|
}
|
|
/// <summary>
|
/// 加入成功的防区列表的数据
|
/// </summary>
|
[System.Serializable]
|
public class ZoneListData
|
{
|
/// <summary>
|
/// 防区ID
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 防区名称
|
/// </summary>
|
public string ZoneName;
|
|
}
|
|
/// <summary>
|
/// 布防成功指示动作数据
|
/// </summary>
|
public class ActionsInfo
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type = 999;
|
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。当Type=0时存在
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
|
/// <summary>
|
/// 设备或场景名称
|
/// </summary>
|
public string ESName;
|
}
|
#endregion
|
|
#region 10查看当前正在使用的布防模.
|
///<summary >
|
/// 查看当前正在使用的布防模式.(仅用于主网关接口)
|
/// </summary>
|
public static async System.Threading.Tasks.Task<GetModeUsingResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var getModeInfoByIdResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetModeUsingResponseData>(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;
|
});
|
}
|
|
/// <summary>
|
/// 查看当前正在使用的布防模式返回的数据,网关反馈信息
|
/// </summary>
|
public GetModeUsingResponseAllData getModeUsingResponseAllData;
|
/// <summary>
|
/// 查看当前正在使用的布防模式返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class GetModeUsingResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看当前正在使用的布防模式返回的数据
|
/// </summary>
|
public GetModeUsingResponseData getModeUsingResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 查看当前正在使用的布防模式返回的数据
|
/// </summary>
|
public GetModeUsingResponseData getModeUsingResponseData;
|
/// <summary>
|
/// 查看当前正在使用的布防模式返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class GetModeUsingResponseData
|
{
|
/// <summary>
|
/// 0:默认
|
/// <para>1:系统当前没有进行布防</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 启用的布防模式id
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 模式名称(Result =0时存在)
|
/// </summary>
|
public string ModeName;
|
/// <summary>
|
/// 设置 (Result = 0时存在)
|
/// <para>1:永久布防,直到撤防</para>
|
/// <para>2:使能一次,触发一次后将撤防。</para>
|
/// <para>3:失能一次,第一次被激活不警告不触发动作。</para>
|
/// </summary>
|
public int Setting;
|
|
}
|
#endregion
|
|
#region 11布防 ;
|
///<summary >
|
/// 布防 (仅用于主网关接口)
|
/// <para>EnableModeData:布防的数据</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<EnableModeResponAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
var modeId = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["ModeId"].ToString());
|
var enableModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<EnableModeResponseData>(jobject["Data"].ToString());
|
if (enableModeResponseData == null)
|
{
|
d = new EnableModeResponAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new EnableModeResponAllData { enableModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 布防返回的数据,,网关反馈信息
|
/// </summary>
|
public EnableModeResponAllData enableModeResponAllData;
|
/// <summary>
|
/// 布防返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class EnableModeResponAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 布防返回的数据
|
/// </summary>
|
public EnableModeResponseData enableModeResponseData;
|
}
|
|
/// <summary>
|
/// 布防返回的数据
|
/// </summary>
|
public EnableModeResponseData enableModeResponseData;
|
/// <summary>
|
/// 布防返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class EnableModeResponseData
|
{
|
/// <summary>
|
/// 0:设置成功
|
///<para>1:设置失败,布防模式不存在</para>
|
///<para>2:设置失败,用户密码错误。</para>
|
///<para>3:布防失败,安防设备未就绪。</para>
|
///<para>4:布防失败,有其他布防模式正在启用(只能使用一种布防模式,需将正在启用的布防模式撤防才能布防新模式)。</para>
|
///<para>5:失败,模式属性不允许失能(如果新建布防模式时,AllowDisable设置为0,则布防Setting值不能为2或3,否则将报告该错误)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 启用的布防模式id
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 模式名称(Result =0时存在)
|
/// </summary>
|
public string ModeName;
|
/// <summary>
|
/// 设置
|
/// <para>1:永久布防,直到撤防</para>
|
/// <para>2:使能一次,触发一次后将撤防。</para>
|
/// <para>3:失能一次,第一次被激活不警告不触发动作。</para>
|
/// </summary>
|
public int Setting;
|
|
/// <summary>
|
///当前正在启用的布防模式ID(当Result = 4时存在。)
|
/// </summary>
|
public int ModeIdBeUsing;
|
|
/// <summary>
|
///未就绪设备的mac地址(当Result =3时存在)
|
/// </summary>
|
public string IASMac;
|
|
/// <summary>
|
///未就绪设备的端口号(当Result = 3时存在。)
|
/// </summary>
|
public int IASEpoint;
|
|
/// <summary>
|
///未就绪设备名称(当Result = 3时存在)
|
/// </summary>
|
public string IASName;
|
|
/// <summary>
|
///设备最近一次上报的安防状态值(当Result=3时存在)
|
/// </summary>
|
public int IASStatus;
|
/// <summary>
|
///未就绪设备所在防区(当Result=3时存在)
|
/// </summary>
|
public int ZoneId;
|
/// <summary>
|
///未就绪设备所在防区(当Result=3时存在当Result = 3时存在)
|
/// </summary>
|
public string ZoneName;
|
}
|
|
/// <summary>
|
/// 布防
|
/// </summary>
|
public EnableModeData enableModeData;
|
/// <summary>
|
/// 布防
|
/// </summary>
|
[System.Serializable]
|
public class EnableModeData
|
{
|
/// <summary>
|
/// 1;永久布防,直到撤防
|
///<para>2:使能一次,触发一次后将撤防。</para>
|
///<para>3:失能一次,第一次被激活不警告不触发动作。</para>
|
/// </summary>
|
public int Setting;
|
|
/// <summary>
|
/// 启用的布防模式id
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
///检查防区设备最近上报的安防信息状态进行布防。
|
///<para>0:不检查</para>
|
///<para>1:检查</para>
|
/// </summary>
|
public int CheckIASStatus;
|
|
/// <summary>
|
///用户密码,最大32个字符
|
/// </summary>
|
public string UserPassword;
|
}
|
|
#endregion
|
|
#region 12撤防.;
|
///<summary >
|
/// 撤防.(仅用于主网关接口)
|
/// </summary>
|
public static async System.Threading.Tasks.Task<WithdrawModeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 withdrawModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<WithdrawModeResponseData>(jobject["Data"].ToString());
|
if (withdrawModeResponseData == null)
|
{
|
d = new WithdrawModeResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new WithdrawModeResponseAllData { withdrawModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 撤防返回的数据,网关反馈信息
|
/// </summary>
|
public WithdrawModeResponseAllData withdrawModeResponseAllData;
|
/// <summary>
|
/// 撤防返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class WithdrawModeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 撤防返回的数据
|
/// </summary>
|
public WithdrawModeResponseData withdrawModeResponseData;
|
|
}
|
|
/// <summary>
|
/// 撤防返回的数据
|
/// </summary>
|
public WithdrawModeResponseData withdrawModeResponseData;
|
/// <summary>
|
/// 撤防返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class WithdrawModeResponseData
|
{
|
/// <summary>
|
/// 0:撤防成功。
|
///<para>1:失败,当前不存在布防。</para>
|
///<para>2:撤防失败,密码错误。</para>
|
///<para>3:撤防失败,模式不可撤防。(新建模式时,模式属性设为不可撤防则布防后将不能撤防)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 被撤防的模式
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 被撤防的模式名称
|
/// </summary>
|
public string ModeName;
|
/// <summary>
|
/// 撤防所用的密码类型:
|
///<para>0:用户密码</para>
|
///<para>1:胁迫密码</para>
|
/// </summary>
|
public int PasswordType;
|
|
}
|
#endregion
|
|
#region 13删除布防模式.
|
///<summary >
|
/// 删除布防模式(需要管理员权限).
|
/// </summary>
|
public static async System.Threading.Tasks.Task<RemoveModeResponseAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(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 removeModeResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveModeResponseData>(jobject["Data"].ToString());
|
if (removeModeResponseData == null)
|
{
|
d = new RemoveModeResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
}
|
else
|
{
|
d = new RemoveModeResponseAllData { removeModeResponseData = 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;
|
});
|
}
|
|
/// <summary>
|
/// 删除布防模式返回的数据,网关反馈信息
|
/// </summary>
|
public RemoveModeResponseAllData removeModeResponseAllData;
|
/// <summary>
|
/// 删除布防模式返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class RemoveModeResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 删除布防模式返回的数据
|
/// </summary>
|
public RemoveModeResponseData removeModeResponseData;
|
|
}
|
|
|
/// <summary>
|
/// 删除布防模式返回的数据
|
/// </summary>
|
public RemoveModeResponseData removeModeResponseData;
|
/// <summary>
|
/// 删除布防模式返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveModeResponseData
|
{
|
/// <summary>
|
/// 0:删除成功。
|
///<para>1:失败,不存在该布防模式。</para>
|
///<para>2:删除失败,不允许删除。(当ModeId为1或2时,离家布防和在家布防模式不允许删除)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 模式id
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 模式名 (当Result=0时存在)。
|
/// </summary>
|
public string ModeName;
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
#endregion
|
|
#region *14将设备从防区中移除.
|
/// <summary>
|
/// *将设备从防区中移除(需要管理员权限).
|
/// </summary>
|
/// <returns>The device to zone async.</returns>
|
/// <param name="removeEqToZoneData">将设备从防区中移除的数据.</param>
|
public static async System.Threading.Tasks.Task<RemoveDeviceToZoneAllData> 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<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new RemoveDeviceToZoneAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new RemoveDeviceToZoneAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
d = new RemoveDeviceToZoneAllData { };
|
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/RemoveEqToZone_Respon")
|
{
|
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var removeDeviceToZoneResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveDeviceToZoneResponseData>(jobject["Data"].ToString());
|
if (removeDeviceToZoneResponseData != null)
|
{
|
d = new RemoveDeviceToZoneAllData { removeDeviceToZoneResponseData = removeDeviceToZoneResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
}
|
else
|
{
|
d = new RemoveDeviceToZoneAllData { };
|
var r = new RemoveDeviceToZoneResponseData();
|
r.Result = result;
|
d.removeDeviceToZoneResponseData = r;
|
System.Console.WriteLine("已收到通知返回");
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/RemoveEqToZone_Actions启动_{System.DateTime.Now.ToString()}");
|
|
try
|
{
|
if (removeEqToZoneData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4016 } };
|
var deviceList = new JArray { };
|
foreach (var deviceInfo in removeEqToZoneData.RemoveDeviceList)
|
{
|
var dInfo = new JObject{
|
{ "MacAddr", deviceInfo.MacAddr},
|
{ "Epoint",deviceInfo.Epoint}
|
};
|
deviceList.Add(dInfo);
|
}
|
var data = new JObject
|
{
|
{ "ZoneId", removeEqToZoneData.ZoneId },
|
{ "RemoveDeviceList", deviceList},
|
{ "LoginToken", removeEqToZoneData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/RemoveEqToZone_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 RemoveDeviceToZoneAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/RemoveEqToZone_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 将设备从防区中移除的返回数据 ,网关反馈信息
|
/// </summary>
|
public RemoveDeviceToZoneAllData removeDeviceToZoneAllData;
|
/// <summary>
|
/// 将设备从防区中移除的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class RemoveDeviceToZoneAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 将设备从防区中移除的返回数据
|
/// </summary>
|
public RemoveDeviceToZoneResponseData removeDeviceToZoneResponseData;
|
}
|
|
/// <summary>
|
/// 将设备从防区中移除的返回数据
|
/// </summary>
|
public RemoveDeviceToZoneResponseData removeDeviceToZoneResponseData;
|
/// <summary>
|
/// 将设备从防区中移除的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveDeviceToZoneResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:添加失败。(局部布防列表id不存在)</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 安防设备列表(Result=0时存在)
|
/// </summary>
|
public List<RemoveDeviceListResponseObj> RemoveDeviceList = new List<RemoveDeviceListResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveDeviceListResponseObj
|
{
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
/// <summary>
|
/// 设备被移除状态
|
/// </summary>
|
public int Status;
|
}
|
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
public RemoveEqToZoneData removeEqToZoneData;
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveEqToZoneData
|
{
|
/// <summary>
|
/// 局部设防列表id
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 安防设备列表
|
/// </summary>
|
public List<RemoveDeviceListObj> RemoveDeviceList = new List<RemoveDeviceListObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class RemoveDeviceListObj
|
{
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
}
|
#endregion
|
|
//#region 获取防区信息.
|
/////<summary >
|
///// 获取防区信息.(仅用于主网关接口)
|
///// </summary>
|
//public static async System.Threading.Tasks.Task<GetZoneInfoResponAllData> GetZoneInfoAsync()
|
//{
|
// return await System.Threading.Tasks.Task.Run(async () =>
|
// {
|
// var d = new GetZoneInfoResponAllData { };
|
// if (ZbGateway.MainGateWay == null)
|
// {
|
// d.errorMessageBase = "当前没有主网关";
|
// return d;
|
// }
|
|
// Action<string, string> 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<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = ZbGateway.MainGateWay.GwId };
|
// var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
// if (temp == null)
|
// {
|
// d.errorMessageBase = "网关错误回复,且数据是空";
|
// }
|
// else
|
// {
|
// d.errorResponData = temp;
|
// d.errorMessageBase = ErrorMess(temp.Error);
|
// }
|
// }
|
|
// if (topic == gatewayID + "/" + "Security/GetZoneInfo_Respon")
|
// {
|
// var security = new Safeguard() { DataID = jobject.Value<int>("Data_ID"), GateWayId = ZbGateway.MainGateWay.CurrentGateWayId };
|
// security.getZoneInfoResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetZoneInfoResponData>(jobject["Data"].ToString());
|
// if (security.getZoneInfoResponData == null)
|
// {
|
// d.errorMessageBase = "网关返回的数据为空";
|
// }
|
// else
|
// {
|
// d.getZoneInfoResponData = security.getZoneInfoResponData;
|
// System.Console.WriteLine($"收到通知后的主题_{topic}");
|
// }
|
// }
|
// };
|
// ZbGateway.MainGateWay.Actions += action;
|
// System.Console.WriteLine("Security/GetZoneInfo_Actions 启动" + System.DateTime.Now.ToString());
|
|
// var jObject = new Newtonsoft.Json.Linq.JObject() {
|
// { "Cluster_ID", 0 },
|
// { "Command", 4017 }
|
// };
|
// ZbGateway.MainGateWay?.Send("Security/GetZoneInfo", jObject.ToString());
|
|
// var dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalMilliseconds < 1000)
|
// {
|
// await System.Threading.Tasks.Task.Delay(10);
|
// if (d.getZoneInfoResponData != null)
|
// {
|
// break;
|
// }
|
// }
|
// if ((DateTime.Now - dateTime).TotalMilliseconds > 10000)
|
// {
|
// d.errorMessageBase = " 回复超时,请重新操作";
|
// }
|
// ZbGateway.MainGateWay.Actions -= action;
|
// System.Console.WriteLine("Security/GetZoneInfo_Actions 退出" + System.DateTime.Now.ToString());
|
|
// return d;
|
// });
|
//}
|
|
///// <summary>
|
///// 获取防区信息返回的数据,网关反馈信息
|
///// </summary>
|
//public GetZoneInfoResponAllData getZoneInfoResponAllData;
|
///// <summary>
|
///// 获取防区信息返回的数据,网关反馈信息
|
///// </summary>
|
//[System.Serializable]
|
//public class GetZoneInfoResponAllData
|
//{
|
// /// <summary>
|
// /// 错误信息
|
// /// </summary>
|
// public string errorMessageBase;
|
// /// <summary>
|
// /// 网关信息错误反馈
|
// /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
|
// /// </summary>
|
// public ErrorResponData errorResponData;
|
// /// <summary>
|
// /// 获取防区信息返回的数据
|
// /// </summary>
|
// public GetZoneInfoResponData getZoneInfoResponData;
|
|
//}
|
|
///// <summary>
|
///// 获取防区信息返回的数据
|
///// </summary>
|
//public GetZoneInfoResponData getZoneInfoResponData;
|
///// <summary>
|
///// 获取防区信息返回的数据
|
///// </summary>
|
//[System.Serializable]
|
//public class GetZoneInfoResponData
|
//{
|
// /// <summary>
|
// /// 防区总数
|
// /// </summary>
|
// public int ZoneNum;
|
|
// /// <summary>
|
// /// 防区信息列表
|
// /// </summary>
|
// public List<ZoneInfoListData> ZoneList = new List<ZoneInfoListData>();
|
//}
|
///// <summary>
|
///// 防区信息列表数据
|
///// </summary>
|
//public class ZoneInfoListData
|
//{
|
// /// <summary>
|
// ///局部设防列表id
|
// /// </summary>
|
// public int ZoneId;
|
|
// /// <summary>
|
// /// 布防防区名称 ,最大32个字符
|
// /// </summary>
|
// public string ZoneName;
|
|
// /// <summary>
|
// /// 防区类型:
|
// ///<para>1:24小时防区。</para>
|
// ///<para>2:24小时静音防区。</para>
|
// ///<para>3:出入防区。</para>
|
// ///<para>4:内部防区。</para>
|
// ///<para>5:跟随防区。</para>
|
// ///<para>6:周界防区。</para>
|
// ///<para>7:周界延时防区。</para>
|
// /// </summary>
|
// public int ZoneType;
|
|
// /// <summary>
|
// /// 是否允许旁路
|
// ///<para>0:不允许旁路</para>
|
// ///<para>1:允许旁路</para>
|
// ///<para>若类型为24小时防区或24小时静音防区将不允许旁路,该字段将被忽略。</para>
|
// /// </summary>
|
// public int Bypass;
|
|
// /// <summary>
|
// /// 是否允许弹性旁路:
|
// ///<para>0:不允许弹性旁路</para>
|
// ///<para>1:允许弹性旁路</para>
|
// ///<para>若类型为24小时防区或24小时静音防区将不允许弹性旁路,该字段将被忽略。</para>
|
// /// </summary>
|
// public int ElasticBypass;
|
//}
|
//#endregion
|
|
#region 15通过防区ID查看防区设备列表.;
|
///<summary >
|
/// 通过防区ID查看防区设备列表.(仅用于主网关接口)
|
/// <para>zoneId:布防模式id</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<GetZoneDeviceListByIdResponAllData> getZoneDeviceListByIdAsync(int zoneId)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
GetZoneDeviceListByIdResponAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new GetZoneDeviceListByIdResponAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new GetZoneDeviceListByIdResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new GetZoneDeviceListByIdResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
if (topic == gatewayID + "/" + "Security/GetZoneDeviceListById_Respon")
|
{
|
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var getZoneDeviceListByIdResponData = Newtonsoft.Json.JsonConvert.DeserializeObject<GetZoneDeviceListByIdResponData>(jobject["Data"].ToString());
|
if (getZoneDeviceListByIdResponData != null)
|
{
|
d = new GetZoneDeviceListByIdResponAllData { getZoneDeviceListByIdResponData = getZoneDeviceListByIdResponData };
|
}
|
System.Console.WriteLine($"UI已收到通知的主题_{topic}");
|
}
|
else
|
{
|
d = new GetZoneDeviceListByIdResponAllData { };
|
var r = new GetZoneDeviceListByIdResponData();
|
r.Result = result;
|
d.getZoneDeviceListByIdResponData = r;
|
System.Console.WriteLine("已收到通知返回");
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine("Security/GetZoneDeviceListById_Actions 启动" + System.DateTime.Now.ToString());
|
try
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4018 }
|
};
|
var data = new JObject { { "ZoneId", zoneId } };
|
jObject.Add("Data", data);
|
mainGateway.Send("Security/GetZoneDeviceListById", 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 GetZoneDeviceListByIdResponAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
mainGateway.Actions -= action;
|
System.Console.WriteLine("Security/GetZoneDeviceListById_Actions 退出" + System.DateTime.Now.ToString());
|
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 通过防区ID查看防区设备列表的数据,网关反馈信息
|
/// </summary>
|
public GetZoneDeviceListByIdResponAllData getZoneDeviceListByIdResponAllData;
|
/// <summary>
|
/// 通过布防模式ID查看模式信息的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class GetZoneDeviceListByIdResponAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 通过布防模式ID查看模式信息返回的数据
|
/// </summary>
|
public GetZoneDeviceListByIdResponData getZoneDeviceListByIdResponData;
|
}
|
|
/// <summary>
|
/// 通过防区ID查看防区设备列表返回的数据
|
/// </summary>
|
public GetZoneDeviceListByIdResponData getZoneDeviceListByIdResponData;
|
/// <summary>
|
/// 通过防区ID查看防区设备列表返回的数据
|
/// </summary>
|
[System.Serializable]
|
public class GetZoneDeviceListByIdResponData
|
{
|
/// <summary>
|
/// 0:默认
|
///<para>1:失败,布防模式不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 防区id
|
///<para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>3:出入防区。</para>
|
///<para>4:内部防区。</para>
|
///<para>5:周界防区。v
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 防区名称 ,最大32个字符
|
/// </summary>
|
public string ZoneName;
|
|
/// <summary>
|
/// 是否禁用信息推送:
|
///<para>0:不禁用</para>
|
///<para>1:禁用</para>
|
///<para>当防区的信息推送被禁用时,防区被触发时不会发送18小节的”防区被触发是报告”的主题信息。</para>
|
/// </summary>
|
public int IsDisablePushMessage = 0;
|
|
/// <summary>
|
/// 安防设备列表
|
///<para> (Result=0时值有效)</para>
|
/// </summary>
|
public List<ZoneDeviceListData> DeviceList = new List<ZoneDeviceListData>();
|
|
}
|
|
/// <summary>
|
/// 通过防区ID查看防区设备列表的数据
|
/// </summary>
|
[System.Serializable]
|
public class ZoneDeviceListData
|
{
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 设备上报的状态是否为瞬间状态,用于配合下面的TriggerZoneStatus值使用。
|
///<pata>0:非瞬间状态,该设备上报的安防状态可持续,直到状态被改变会再次报告安防状态信息。如门磁设备的开状态和关状态(开和关状态是能持续的)。</pata>
|
///<pata>1:表示安防状态为瞬间量,设备警告激活状态才上报安防信息,设备恢复常态不发送通知。如人体红外传感器(当有人时触发警告,但人走了后,不会发送消除警告信息。无法知道人还在不在)</pata>
|
/// </summary>
|
public int MomentStatus;
|
/// <summary>
|
/// <pata>当MomentStatus为0时,安防设备被触发上报安防信息的ZoneStatus值和TriggerZoneStatus进行与运算(&)结果不为0时激活防区警报,为0时解除激活。例如门磁设备,如果有人开门入侵将激活防区报警,可将TriggerZoneStatus设置为17,开门时上报的ZoneStatus值为1,(17 & 1)>0,此时说明有入侵,防区将被激活,发送警告信息到客户端和服务器并执行设定的警戒动作。</pata>
|
/// <pata>当MomentStatus为1时,说明安防设备的激活状态只是瞬间的,只有在上报ZoneStatus值(和TriggerZoneStatus相与不为0时)的瞬间激活,激活后将立即自动恢复为常态。</pata>
|
/// <pata>设置布防时,如果安防设备被触发,防区处于警告状态,要解除激活才能布防成功。如果上面MomentStatus为0,则需要安防设备再次上报的ZoneStatus值和TriggerZoneStatus值进行与运算结果为0才能解除激活状态 。如果MomentStatus为1,则说明设备已经自动恢复常态,布防可以成功。</pata>
|
/// <pata>如门磁设备关门时上报的ZoneStatus值为32,(32&1)=0。则说明门已经关上,防区激活状态将解除,可对防区进行布防。如果MomentStatus为1,则忽略该设备的最近警告状态进行布防。</pata>
|
/// </summary>
|
public int TriggerZoneStatus;
|
|
/// <summary>
|
/// 是否旁路
|
///<para>0:不旁路</para>
|
///<para>1:旁路</para>
|
/// </summary>
|
public int IsBypass = 999;
|
}
|
|
#endregion
|
|
#region 24*执行安防模式动作.
|
/// <summary>
|
/// *执行安防模式动作(需要管理员权限).
|
///<para>modeId:布防模式ID</para>
|
///<para>actionType:动作类型</para>
|
///<para>1:布防成功指示动作</para>
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
///<para>loginToken:登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
///</summary>
|
public static async System.Threading.Tasks.Task<ActionTestResponseAllData> ActionTestAsync(int modeId, int actionType, string loginToken)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
ActionTestResponseAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new ActionTestResponseAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new ActionTestResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new ActionTestResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var securityTemp = new Safeguard() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.GwId };
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new ActionTestResponseAllData { };
|
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/ActionTest_Respon")
|
{
|
var actionTestResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ActionTestResponseData>(jobject["Data"].ToString());
|
if (actionTestResponseData != null)
|
{
|
d = new ActionTestResponseAllData { actionTestResponseData = actionTestResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
|
}
|
else
|
{
|
d = new ActionTestResponseAllData { errorMessageBase = "网关返回的数据为空" };
|
System.Console.WriteLine($"回复数据为空");
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine("Security/ActionTest_Actions 启动" + System.DateTime.Now.ToString());
|
|
try
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4027}
|
};
|
var data = new JObject
|
{
|
{ "ModeId", modeId },
|
{ "ActionType", actionType},
|
{ "LoginToken", loginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send("Security/ActionTest", 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 ActionTestResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
mainGateway.Actions -= action;
|
System.Console.WriteLine("Security/ActionTest_Actions 退出" + System.DateTime.Now.ToString());
|
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 执行安防模式动作返回的数据,网关反馈信息
|
/// </summary>
|
public ActionTestResponseAllData actionTestResponseAllData;
|
/// <summary>
|
/// 执行安防模式动作返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class ActionTestResponseAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 执行安防模式动作返回的数据
|
/// </summary>
|
public ActionTestResponseData actionTestResponseData;
|
|
}
|
|
/// <summary>
|
/// 执行安防模式动作返回的数据
|
/// </summary>
|
public ActionTestResponseData actionTestResponseData;
|
/// <summary>
|
/// 执行安防模式动作返回的数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class ActionTestResponseData
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,安防模式不存在</para>
|
/// </summary>
|
public int Result = 999;
|
/// <summary>
|
/// 安防模式id
|
/// </summary>
|
public int ModeId;
|
/// <summary>
|
/// 1:布防成功指示动作
|
///<para>2:布防失败指示动作。</para>
|
///<para>3:撤防成功指示动作。</para>
|
///<para>4:撤防失败指示动作</para>
|
/// </summary>
|
public int ActionType;
|
}
|
|
/// <summary>
|
/// 执行安防模式动作(仅用于主网关接口)
|
///<para>modeId:布防模式ID</para>
|
///<para>actionType:动作类型</para>
|
///<para>1:布防成功指示动作</para>
|
///<para>2:布防失败指示动作</para>
|
///<para>3:撤防成功指示动作</para>
|
///<para>4:撤防失败指示动作</para>
|
/// </summary>
|
public static void ActionTest(int modeId, int actionType)
|
{
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
return;
|
}
|
|
Action<string, string> action = (topic, message) => { };
|
|
mainGateway.Actions += action;
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4027}
|
};
|
var data = new JObject
|
{
|
{ "ModeId", modeId },
|
{ "ActionType", actionType}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send("Security/ActionTest", jObject.ToString());
|
mainGateway.Actions -= action;
|
}
|
#endregion
|
|
#region 18防区被触发时报告
|
/// <summary>
|
/// 防区被触发时报告
|
/// </summary>
|
public ZoneTriggerReportData zoneTriggerReportData;
|
/// <summary>
|
/// 防区被触发时报告
|
/// <para>布防模式下的非旁路防区被触发时将反馈触发信息</para>
|
/// </summary>
|
[System.Serializable]
|
public class ZoneTriggerReportData
|
{
|
/// <summary>
|
/// 防区id
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 是否为强迫密码撤防触发静音防区
|
///<para>0:不是</para>
|
///<para>1:是</para>
|
/// </summary>
|
public int ForceToWithdraw;
|
|
/// <summary>
|
/// 触发设备的mac地址,当ForceToWithdraw为0时存在
|
/// </summary>
|
public string MacAddr;
|
|
/// <summary>
|
/// 触发设备的端口号,当ForceToWithdraw为0时存在
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
///触发设备上报的ZoneStatus值,当ForceToWithdraw为0时存在
|
/// </summary>
|
public int ZoneStatus;
|
|
}
|
#endregion
|
|
#region 19模式安防动作被最终激活时发送报警信息
|
/// <summary>
|
/// 防区被触发时报告
|
/// </summary>
|
public ModeTriggerReportData modeTriggerReportData;
|
/// <summary>
|
/// 模式安防动作被最终激活时发送报警信息
|
/// <para>如延时防区被触发延时过后还没撤防、周界防区被触发、出入防区没触发却触发了内部防区等情况都将激活模式安防动作,将发送以下给警报。</para>
|
/// </summary>
|
[System.Serializable]
|
public class ModeTriggerReportData
|
{
|
/// <summary>
|
/// 当前布防模式id
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 报警时最后被激活的防区
|
/// </summary>
|
public string ModeName;
|
|
/// <summary>
|
/// 报警时最后被激活的防区
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 是否为强迫密码撤防触发静音防区
|
///<para>0:不是</para>
|
///<para>1:是</para>
|
/// </summary>
|
public int ForceToWithdraw;
|
|
/// <summary>
|
/// 报警设备的mac地址(ForceToWithdraw为0时才存在)
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 报警设备的端口号(ForceToWithdraw为0时才存在)
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 报警设备的名称 (ForceToWithdraw为0时才存在)
|
/// </summary>
|
public string DeviceName;
|
/// <summary>
|
/// 报警设备上报的ZoneStatus值
|
/// </summary>
|
public int ZoneStatus;
|
/// <summary>
|
/// 信息推送目标
|
/// </summary>
|
public List<PushTargetInfo> PushTarget = new List<PushTargetInfo>();
|
|
}
|
#endregion
|
|
#region 25通过外部方式布防撤防成功时报告
|
/// <summary>
|
/// 通过外部方式布防撤防成功时报告
|
/// </summary>
|
public EnOrWithdrawSucceedReportData enOrWithdrawSucceedReportData;
|
/// <summary>
|
/// 通过外部方式布防撤防成功时报告
|
/// <para>当用户通过外部方式(非app或云端操作,如逻辑触发执行撤防布防,按键操作布防撤防)进行布防撤防成功</para>
|
/// </summary>
|
[System.Serializable]
|
public class EnOrWithdrawSucceedReportData
|
{
|
/// <summary>
|
/// 0:布防成功
|
///<para>1:撤防成功</para>
|
/// </summary>
|
public int EnOrWithdraw;
|
|
/// <summary>
|
/// 安防模式id。
|
/// </summary>
|
public int ModeId;
|
|
/// <summary>
|
/// 外部布撤防方式:
|
///<para>0:执行逻辑动作</para>
|
///<para>1:按键操作</para>
|
/// </summary>
|
public int OperationWay;
|
}
|
#endregion
|
|
#region 26*对防区安防设备进行旁路或撤销旁路;
|
/// <summary>
|
/// *对防区安防设备进行旁路或撤销旁路(需要管理员权限).
|
/// </summary>
|
/// <returns>The device to zone async.</returns>
|
/// <param name="removeEqToZoneData">将设备从防区中移除的数据.</param>
|
public static async System.Threading.Tasks.Task<EqByPassAllData> EqByPassAllDataAsync(EqByPassData eqByPassData)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
EqByPassAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new EqByPassAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new EqByPassAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new EqByPassAllData { errorMessageBase = ErrorMess(temp.Error), errorResponData = temp };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new EqByPassAllData { };
|
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/EqByPass_Respon")
|
{
|
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
|
if (result == 0)
|
{
|
var eqByPassResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<EqByPassResponseData>(jobject["Data"].ToString());
|
if (eqByPassResponseData != null)
|
{
|
d = new EqByPassAllData { eqByPassResponseData = eqByPassResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
}
|
else
|
{
|
var r = new EqByPassResponseData();
|
r.Result = result;
|
d = new EqByPassAllData { eqByPassResponseData = r };
|
|
System.Console.WriteLine("已收到通知返回");
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/EqByPass_Actions启动_{System.DateTime.Now.ToString()}");
|
|
try
|
{
|
if (eqByPassData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4029 } };
|
|
var data = new JObject
|
{
|
{ "ZoneId", eqByPassData.ZoneId },
|
{ "MacAddr", eqByPassData.MacAddr },
|
{ "Epoint", eqByPassData.Epoint },
|
{ "IsByPass", eqByPassData.IsByPass},
|
{ "LoginToken", eqByPassData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/EqByPass"), 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 EqByPassAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/EqByPass_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的返回数据 ,网关反馈信息
|
/// </summary>
|
public EqByPassAllData eqByPassAllData;
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class EqByPassAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的返回数据
|
/// </summary>
|
public EqByPassResponseData eqByPassResponseData;
|
}
|
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的返回数据
|
/// </summary>
|
public EqByPassResponseData eqByPassResponseData;
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class EqByPassResponseData
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,防区不存在</para>
|
///<para>2:失败,设备不在防区中</para>
|
///<para>3:失败,系统当前处于撤防状态。</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 防区id。
|
///<para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>3:出入防区。</para>
|
///<para>4:内部防区。</para>
|
///<para>5:周界防区。</para>
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
/// <summary>
|
/// 0:不旁路
|
///<para>1:旁路设备</para>
|
/// </summary>
|
public int IsByPass;
|
|
}
|
|
/// <summary>
|
/// 对防区安防设备进行旁路或撤销旁路的数据
|
/// </summary>
|
public EqByPassData eqByPassData;
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class EqByPassData
|
{
|
/// <summary>
|
/// 防区id。
|
///<para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>3:出入防区。</para>
|
///<para>4:内部防区。</para>
|
///<para>5:周界防区。</para>
|
/// </summary>
|
public int ZoneId;
|
|
/// <summary>
|
/// 设备mac地址
|
/// </summary>
|
public string MacAddr;
|
/// <summary>
|
/// 设备端口号
|
/// </summary>
|
public int Epoint;
|
/// <summary>
|
/// 0:不旁路
|
///<para>1:旁路设备</para>
|
/// </summary>
|
public int IsByPass = 999;
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
#endregion
|
|
#region 27*添加防区报警目标;
|
/// <summary>
|
/// *添加防区报警目标(需要管理员权限).
|
/// </summary>
|
public static async System.Threading.Tasks.Task<AddZoneActionAllData> AddZoneActionAsync(AddZoneActionData addZoneActionData)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
AddZoneActionAllData d = null;
|
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new AddZoneActionAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new AddZoneActionAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new AddZoneActionAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new AddZoneActionAllData { };
|
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/AddZoneAction_Respon")
|
{
|
var addZoneActionResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddZoneActionResponseData>(jobject["Data"].ToString());
|
if (addZoneActionResponseData != null)
|
{
|
d = new AddZoneActionAllData { addZoneActionResponseData = addZoneActionResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new AddZoneActionAllData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/AddZoneAction_Actions启动_{System.DateTime.Now.ToString()}");
|
|
try
|
{
|
if (addZoneActionData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4030 } };
|
var actionsList = new JArray { };
|
foreach (var act in addZoneActionData.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}
|
};
|
actionsList.Add(a);
|
}
|
else if (act.Type == 1)
|
{
|
var b = new JObject {
|
{ "Type",act.Type},
|
{ "ScenesId", act.ScenesId}
|
};
|
actionsList.Add(b);
|
}
|
}
|
var data = new JObject
|
{
|
{ "ActionType", addZoneActionData.ActionType },
|
{ "Actions", actionsList},
|
{ "LoginToken", addZoneActionData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/AddZoneAction"), 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 AddZoneActionAllData { errorMessageBase = " 回复超时,请重新操作" };
|
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/AddZoneAction_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 添加防区报警目标的返回数据 ,网关反馈信息
|
/// </summary>
|
public AddZoneActionAllData addZoneActionAllData;
|
/// <summary>
|
/// 添加防区报警目标的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AddZoneActionAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 添加防区报警目标的返回数据
|
/// </summary>
|
public AddZoneActionResponseData addZoneActionResponseData;
|
}
|
|
/// <summary>
|
/// 添加防区报警目标的返回数据
|
/// </summary>
|
public AddZoneActionResponseData addZoneActionResponseData;
|
/// <summary>
|
/// 添加防区报警目标的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class AddZoneActionResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:失败,ActionType不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 1:24小时防区触发动作。
|
///<para>2:24小时静音防区触发动作。</para>
|
///<para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public int ActionType;
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<AlarmActionResponseObj> Actions = new List<AlarmActionResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 添加防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class AlarmActionResponseObj
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,设备或场景不存在</para>
|
/// </summary>
|
public string Status;
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
///<para>2:信息推送</para>
|
/// </summary>
|
public string Type;
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。(当Type=0和Status = 0时存在)
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
/// <summary>
|
/// 设备或场景名称,Status = 0时存在
|
/// </summary>
|
public string ESName;
|
}
|
|
/// <summary>
|
/// 添加防区报警目标的数据
|
/// </summary>
|
public AddZoneActionData addZoneActionData;
|
/// <summary>
|
/// 将设备从防区中移除的数据
|
/// </summary>
|
[System.Serializable]
|
public class AddZoneActionData
|
{
|
/// <summary>
|
/// 1:24小时防区触发动作。
|
///<para>2:24小时静音防区触发动作。</para>
|
///<para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<AlarmActionObj> Actions = new List<AlarmActionObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
|
/// <summary>
|
/// 添加防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class AlarmActionObj
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type;
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。(当Type=0和Status = 0时存在)
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
}
|
|
#endregion
|
|
#region 28*删除防区报警目;
|
/// <summary>
|
/// *删除防区报警目标(需要管理员权限).
|
/// </summary>
|
public static async System.Threading.Tasks.Task<DelZoneActionResposeAllData> DelZoneActionAsync(DelZoneActionData delZoneActionData)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
DelZoneActionResposeAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new DelZoneActionResposeAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new DelZoneActionResposeAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new DelZoneActionResposeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new DelZoneActionResposeAllData { };
|
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/DelZoneAction_Respon")
|
{
|
var delZoneActionResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelZoneActionResponseData>(jobject["Data"].ToString());
|
if (delZoneActionResponseData != null)
|
{
|
d = new DelZoneActionResposeAllData { delZoneActionResponseData = delZoneActionResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new DelZoneActionResposeAllData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/DelZoneAction_Actions启动_{System.DateTime.Now.ToString()}");
|
|
try
|
{
|
if (delZoneActionData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4031 } };
|
var actionsList = new JArray { };
|
foreach (var act in delZoneActionData.Actions)
|
{
|
if (act.Type == 0)
|
{
|
var a = new JObject {
|
{ "Type",act.Type},
|
{ "DeviceAddr", act.DeviceAddr} ,
|
{ "Epoint",act.Epoint}
|
};
|
actionsList.Add(a);
|
}
|
else if (act.Type == 1)
|
{
|
var b = new JObject {
|
{ "Type",act.Type},
|
{ "ScenesId", act.ScenesId}
|
};
|
actionsList.Add(b);
|
}
|
}
|
var data = new JObject
|
{
|
{ "ActionType", delZoneActionData.ActionType },
|
{ "Actions", actionsList},
|
{ "LoginToken", delZoneActionData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/DelZoneAction"), 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 DelZoneActionResposeAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/DelZoneAction_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 删除防区报警目标的返回数据 ,网关反馈信息
|
/// </summary>
|
public DelZoneActionResposeAllData delZoneActionResposeAllData;
|
/// <summary>
|
/// 删除防区报警目标的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class DelZoneActionResposeAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 删除防区报警目标的返回数据
|
/// </summary>
|
public DelZoneActionResponseData delZoneActionResponseData;
|
}
|
|
/// <summary>
|
/// 删除防区报警目标的返回数据
|
/// </summary>
|
public DelZoneActionResponseData delZoneActionResponseData;
|
/// <summary>
|
/// 删除防区报警目标的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class DelZoneActionResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:成功</para>
|
/// <para>1:失败,ActionType不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 1:24小时防区触发动作。
|
///<para>2:24小时静音防区触发动作。</para>
|
///<para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public int ActionType;
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<DelAlarmActionResponseObj> Actions = new List<DelAlarmActionResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 删除防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class DelAlarmActionResponseObj
|
{
|
/// <summary>
|
/// 0:成功
|
///<para>1:失败,设备或场景不存在</para>
|
/// </summary>
|
public string Status;
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public string Type;
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
}
|
|
/// <summary>
|
/// 删除防区报警目标的数据
|
/// </summary>
|
public DelZoneActionData delZoneActionData;
|
/// <summary>
|
/// 删除防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class DelZoneActionData
|
{
|
/// <summary>
|
/// 1:24小时防区触发动作。
|
///<para>2:24小时静音防区触发动作。</para>
|
///<para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<DelAlarmActionObj> Actions = new List<DelAlarmActionObj>();
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
}
|
|
/// <summary>
|
/// 删除防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class DelAlarmActionObj
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type;
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
}
|
#endregion
|
|
#region 29查看防区报警目标;
|
/// <summary>
|
/// 查看防区报警目标
|
/// <para>1:24小时防区触发动作。</para>
|
/// <para>2:24小时静音防区触发动作。</para>
|
/// <para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<CatZoneActionResposeAllData> CatZoneActionAsync(int actionType)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
CatZoneActionResposeAllData d = null;
|
var mainGateWay = ZbGateway.MainGateWay;
|
if (mainGateWay == null)
|
{
|
d = new CatZoneActionResposeAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new CatZoneActionResposeAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new CatZoneActionResposeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/CatZoneAction_Respon")
|
{
|
var catZoneActionResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CatZoneActionResponseData>(jobject["Data"].ToString());
|
if (catZoneActionResponseData != null)
|
{
|
d = new CatZoneActionResposeAllData { catZoneActionResponseData = catZoneActionResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new CatZoneActionResposeAllData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateWay.Actions += action;
|
System.Console.WriteLine($"Security/CatZoneAction_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4032 }
|
};
|
var data = new JObject
|
{
|
{ "ActionType", actionType }
|
};
|
jObject.Add("Data", data);
|
mainGateWay.Send("Security/CatZoneAction", 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 CatZoneActionResposeAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateWay.Actions -= action;
|
System.Console.WriteLine($"Security/CatZoneAction_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 查看防区报警目标的返回数据 ,网关反馈信息
|
/// </summary>
|
public CatZoneActionResposeAllData catZoneActionResposeAllData;
|
/// <summary>
|
/// 查看防区报警目标的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class CatZoneActionResposeAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
public CatZoneActionResponseData catZoneActionResponseData;
|
}
|
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
public CatZoneActionResponseData catZoneActionResponseData;
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class CatZoneActionResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:失败,ActionType不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 1:24小时防区触发动作。
|
///<para>2:24小时静音防区触发动作。</para>
|
///<para>3:其他防区(出入防区、内部防区、周界防区)触发动作。</para>
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 是否禁用信息推送:
|
///<para>0:不禁用</para>
|
///<para>1:禁用</para>
|
///<para>当防区的信息推送被禁用时,防区被触发时不会发送18小节的”防区被触发是报告”的主题信息。</para>
|
/// </summary>
|
public int IsDisablePushMessage = 999;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<CatActionResponseObj> Actions = new List<CatActionResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 查看防区报警目标的数据
|
/// </summary>
|
[System.Serializable]
|
public class CatActionResponseObj
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>0:节点设备动作</para>
|
///<para>1:打开场景</para>
|
/// </summary>
|
public int Type;
|
/// <summary>
|
/// 设备mac地址 ,
|
///<para>当Type=0时存在。</para>
|
/// </summary>
|
public string DeviceAddr;
|
|
/// <summary>
|
/// 设备端口号
|
///<para>设备端口号 和mac地址共同标识唯一的zigbee设备 数值范围0-255。 当Type=0时存在。</para>
|
/// </summary>
|
public int Epoint;
|
|
/// <summary>
|
/// 动作参数列表。(当Type=0时存在)
|
/// </summary>
|
public List<TaskListInfo> TaskList = new List<TaskListInfo>();
|
|
|
/// <summary>
|
/// 场景ID 。当Type=1时存在
|
/// </summary>
|
public int ScenesId;
|
|
/// <summary>
|
/// 设备或场景名称(当Type=0 或Type=1时存在。)
|
/// </summary>
|
public string ESName;
|
}
|
|
#endregion
|
|
#region 30*设置胁迫状态下被通知的联系号码;
|
/// <summary>
|
/// *设置胁迫状态下被通知的联系号码(需要管理员权限).
|
/// </summary>
|
public static async System.Threading.Tasks.Task<SetCoercePhoneNumberAllResponseData> SetCoercePhoneNumberAsync(SetCoercePhoneNumberData setCoercePhoneNumberData)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
SetCoercePhoneNumberAllResponseData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new SetCoercePhoneNumberAllResponseData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new SetCoercePhoneNumberAllResponseData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new SetCoercePhoneNumberAllResponseData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new SetCoercePhoneNumberAllResponseData { };
|
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/AddZoneAction_Respon")
|
{
|
var setCoercePhoneNumberResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetCoercePhoneNumberResponseData>(jobject["Data"].ToString());
|
if (setCoercePhoneNumberResponseData != null)
|
{
|
d = new SetCoercePhoneNumberAllResponseData { setCoercePhoneNumberResponseData = setCoercePhoneNumberResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new SetCoercePhoneNumberAllResponseData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/AddZoneAction(设置胁迫状态下的电话号码)_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
if (setCoercePhoneNumberData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4030 } };
|
var actionsList = new JArray { };
|
foreach (var act in setCoercePhoneNumberData.Actions)
|
{
|
if (act.Type == 2)
|
{
|
var pushTargetList = new JArray { };
|
foreach (var pushInfo in act.PushTarget)
|
{
|
var pInfo = new JObject{
|
{ "PushNumber", pushInfo.PushNumber}
|
};
|
pushTargetList.Add(pInfo);
|
}
|
var c = new JObject {
|
{ "Type",act.Type},
|
{ "PushTarget", pushTargetList}
|
};
|
actionsList.Add(c);
|
}
|
}
|
var data = new JObject
|
{
|
{ "ActionType", 253},
|
{ "Actions", actionsList},
|
{ "LoginToken", setCoercePhoneNumberData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/AddZoneAction"), 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 SetCoercePhoneNumberAllResponseData { errorMessageBase = " 回复超时,请重新操作" };
|
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/AddZoneAction(设置胁迫状态下的电话号码)_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// *设置胁迫状态下被通知的联系号码的备注(需要管理员权限). -2:主网关丢失
|
/// </summary>
|
/// <param name="strPhone">地区码-联系方式</param>
|
/// <param name="strNote">备注,最大63byte</param>
|
/// <returns></returns>
|
public static async System.Threading.Tasks.Task<SetCoercePhoneNumberResponseData> SetCoercePhoneNumberNoteAsync(string strPhone, string strNote)
|
{
|
SetCoercePhoneNumberResponseData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new SetCoercePhoneNumberResponseData();
|
d.Result = -2;
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
if (topic == gatewayID + "/" + "Security/AddPushNumberNote_Respon")
|
{
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
d = Newtonsoft.Json.JsonConvert.DeserializeObject<SetCoercePhoneNumberResponseData>(jobject["Data"].ToString());
|
}
|
};
|
|
mainGateway.Actions += action;
|
try
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4038 } };
|
var data = new JObject
|
{
|
{ "ActionType", 253},
|
{ "LoginToken", Shared.Phone.HdlSafeguardLogic.Current.GetLoginToken()},
|
{ "PushNumber", strPhone},
|
{ "PushNumberNote", strNote}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send("Security/AddPushNumberNote", jObject.ToString());
|
}
|
catch { }
|
|
int timeOut = 0;
|
while (timeOut <= 60)
|
{
|
await System.Threading.Tasks.Task.Delay(50);
|
if (d != null)
|
{
|
break;
|
}
|
timeOut++;
|
}
|
|
mainGateway.Actions -= action;
|
return d;
|
}
|
|
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的返回数据 ,网关反馈信息
|
/// </summary>
|
public SetCoercePhoneNumberAllResponseData setCoercePhoneNumberAllResponseData;
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class SetCoercePhoneNumberAllResponseData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public SetCoercePhoneNumberResponseData setCoercePhoneNumberResponseData;
|
}
|
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public SetCoercePhoneNumberResponseData setCoercePhoneNumberResponseData;
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class SetCoercePhoneNumberResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 类型
|
/// </summary>
|
public int ActionType;
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionResponseObj> Actions = new List<PushTargetActionResponseObj>();
|
|
}
|
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
[System.Serializable]
|
public class PushTargetActionResponseObj
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>2:信息推送</para>
|
/// </summary>
|
public string Type;
|
|
/// <summary>
|
/// 信息推送目标,当Type=2时存在。
|
/// </summary>
|
public List<PushTargetInfo> PushTarget = new List<PushTargetInfo>();
|
}
|
|
/// <summary>
|
/// 任务列表中的数据
|
/// </summary>
|
[System.Serializable]
|
public class PushTargetInfo
|
{
|
/// <summary>
|
/// 推送信息的目标手机号码
|
///</summary>
|
public string PushNumber;
|
/// <summary>
|
/// 备注信息
|
/// </summary>
|
public string PushNumberNote;
|
}
|
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
public SetCoercePhoneNumberData setCoercePhoneNumberData;
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
[System.Serializable]
|
public class SetCoercePhoneNumberData
|
{
|
/// <summary>
|
/// 动作类型
|
/// 设置胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
//public int ActionType = 253;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionObj> Actions = new List<PushTargetActionObj>();
|
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
|
/// <summary>
|
/// 设置胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
[System.Serializable]
|
public class PushTargetActionObj
|
{
|
/// <summary>
|
/// 动作类型
|
///<para>2:信息推送</para>
|
/// </summary>
|
public int Type;
|
|
/// <summary>
|
/// 信息推送目标,当Type=2时存在。
|
/// </summary>
|
public List<PushTargetInfo> PushTarget = new List<PushTargetInfo>();
|
}
|
#endregion
|
|
#region 31*删除胁迫状态下被通知的联系号码;
|
/// <summary>
|
/// *删除胁迫状态下被通知的联系号码(需要管理员权限).
|
/// </summary>
|
public static async System.Threading.Tasks.Task<DelCoercePhoneNumberAllResponseData> DelCoercePhoneNumberAsync(DelCoercePhoneNumberData delCoercePhoneNumberData)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
DelCoercePhoneNumberAllResponseData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new DelCoercePhoneNumberAllResponseData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new DelCoercePhoneNumberAllResponseData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new DelCoercePhoneNumberAllResponseData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
d = new DelCoercePhoneNumberAllResponseData { };
|
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/DelZoneAction_Respon")
|
{
|
var delCoercePhoneNumberResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DelCoercePhoneNumberResponseData>(jobject["Data"].ToString());
|
if (delCoercePhoneNumberResponseData != null)
|
{
|
d = new DelCoercePhoneNumberAllResponseData { delCoercePhoneNumberResponseData = delCoercePhoneNumberResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new DelCoercePhoneNumberAllResponseData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/AddZoneAction(删除胁迫状态下的电话号码)_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
if (delCoercePhoneNumberData != null)
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4031 } };
|
var actionsList = new JArray { };
|
foreach (var act in delCoercePhoneNumberData.Actions)
|
{
|
if (act.Type == 2)
|
{
|
var pushTargetList = new JArray { };
|
foreach (var pushInfo in act.PushTarget)
|
{
|
var pInfo = new JObject{
|
{ "PushNumber", pushInfo.PushNumber}
|
};
|
pushTargetList.Add(pInfo);
|
}
|
var c = new JObject {
|
{ "Type",act.Type},
|
{ "PushTarget", pushTargetList}
|
};
|
actionsList.Add(c);
|
}
|
}
|
var data = new JObject
|
{
|
{ "ActionType", 253},
|
{ "Actions", actionsList},
|
{ "LoginToken", delCoercePhoneNumberData.LoginToken}
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/DelZoneAction"), 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 DelCoercePhoneNumberAllResponseData { errorMessageBase = " 回复超时,请重新操作" };
|
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/AddZoneAction(删除胁迫状态下的电话号码)_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的返回数据 ,网关反馈信息
|
/// </summary>
|
public DelCoercePhoneNumberAllResponseData delCoercePhoneNumberAllResponseData;
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class DelCoercePhoneNumberAllResponseData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public DelCoercePhoneNumberResponseData delCoercePhoneNumberResponseData;
|
}
|
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public DelCoercePhoneNumberResponseData delCoercePhoneNumberResponseData;
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class DelCoercePhoneNumberResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 类型
|
/// </summary>
|
public int ActionType;
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionResponseObj> Actions = new List<PushTargetActionResponseObj>();
|
|
}
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
public DelCoercePhoneNumberData delCoercePhoneNumberData;
|
/// <summary>
|
/// 删除胁迫状态下被通知的联系号码的数据
|
/// </summary>
|
[System.Serializable]
|
public class DelCoercePhoneNumberData
|
{
|
/// <summary>
|
/// 动作类型
|
/// </summary>
|
//public int ActionType = 253;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionObj> Actions = new List<PushTargetActionObj>();
|
|
/// <summary>
|
/// 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。
|
/// </summary>
|
public string LoginToken;
|
|
}
|
#endregion
|
|
#region 32查看胁迫状态下被通知的联系人;
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码
|
/// </summary>
|
public static async System.Threading.Tasks.Task<CheckCoercePhoneNumberAllResponseData> CheckCoercePhoneNumberAsync(int actionType = 253)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
CheckCoercePhoneNumberAllResponseData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new CheckCoercePhoneNumberAllResponseData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new CheckCoercePhoneNumberAllResponseData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new CheckCoercePhoneNumberAllResponseData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/CatZoneAction_Respon")
|
{
|
var checkCoercePhoneNumberResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CheckCoercePhoneNumberResponseData>(jobject["Data"].ToString());
|
if (checkCoercePhoneNumberResponseData != null)
|
{
|
d = new CheckCoercePhoneNumberAllResponseData { checkCoercePhoneNumberResponseData = checkCoercePhoneNumberResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new CheckCoercePhoneNumberAllResponseData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/CatZoneAction(查看胁迫状态下的电话号码)_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 4032 } };
|
var actionsList = new JArray { };
|
var data = new JObject
|
{
|
{ "ActionType", actionType }
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/CatZoneAction"), 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 CheckCoercePhoneNumberAllResponseData { errorMessageBase = " 回复超时,请重新操作" };
|
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/CatZoneAction(查看胁迫状态下的电话号码)_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码的返回数据 ,网关反馈信息
|
/// </summary>
|
public CheckCoercePhoneNumberAllResponseData checkCoercePhoneNumberAllResponseData;
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class CheckCoercePhoneNumberAllResponseData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public CheckCoercePhoneNumberResponseData checkCoercePhoneNumberResponseData;
|
}
|
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
public CheckCoercePhoneNumberResponseData checkCoercePhoneNumberResponseData;
|
/// <summary>
|
/// 查看胁迫状态下被通知的联系号码的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class CheckCoercePhoneNumberResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:默认</para>
|
/// <para>1:失败,ActionType不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 类型
|
/// </summary>
|
public int ActionType;
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionResponseObj> Actions = new List<PushTargetActionResponseObj>();
|
|
}
|
|
#endregion
|
|
#region 33胁迫密码撤防时短信推送;
|
/// <summary>
|
/// 胁迫密码撤防时短信推送
|
/// <para>当使用胁迫密码撤防时,网关将发送该信息到云端。(仅向云端发送)</para>
|
/// </summary>
|
public CoercedPWDWithdrawReportData coercedPWDWithdrawReportData;
|
/// <summary>
|
/// 胁迫密码撤防时短信推送
|
/// <para>当用户通过外部方式(非app或云端操作,如逻辑触发执行撤防布防,按键操作布防撤防)进行布防撤防成功</para>
|
/// </summary>
|
[System.Serializable]
|
public class CoercedPWDWithdrawReportData
|
{
|
/// <summary>
|
/// 253:胁迫密码撤防触发推送短信
|
/// </summary>
|
public int ActionType;
|
|
/// <summary>
|
/// 报警目标列表
|
/// </summary>
|
public List<PushTargetActionResponseObj> Actions = new List<PushTargetActionResponseObj>();
|
|
}
|
#endregion
|
|
#region 34禁用或启用防区被触发时信息推送.
|
/// <summary>
|
/// 查看防区报警目标
|
/// <para>ZoneType:防区ID。</para>
|
/// <para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>3:其他防区</para>
|
/// <para>isDisablePushMessage:是否禁用防区被触发时信息推送</para>
|
///<para>0:不禁用</para>
|
///<para>1:禁用</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<DisablePushMessageResposeAllData> DisablePushMessageAsync(int zoneType, int isDisablePushMessage)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
DisablePushMessageResposeAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new DisablePushMessageResposeAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new DisablePushMessageResposeAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new DisablePushMessageResposeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/DisablePushMessage_Respon")
|
{
|
var disablePushMessageResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<DisablePushMessageResponseData>(jobject["Data"].ToString());
|
if (disablePushMessageResponseData != null)
|
{
|
d = new DisablePushMessageResposeAllData { disablePushMessageResponseData = disablePushMessageResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new DisablePushMessageResposeAllData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/DisablePushMessage_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4034 }
|
};
|
var data = new JObject
|
{
|
{ "ZoneType", zoneType },
|
{ "IsDisablePushMessage", isDisablePushMessage }
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/DisablePushMessage"), 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 DisablePushMessageResposeAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/DisablePushMessage_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 查看防区报警目标的返回数据 ,网关反馈信息
|
/// </summary>
|
public DisablePushMessageResposeAllData disablePushMessageResposeAllData;
|
/// <summary>
|
/// 查看防区报警目标的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class DisablePushMessageResposeAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
public DisablePushMessageResponseData disablePushMessageResponseData;
|
}
|
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
public DisablePushMessageResponseData disablePushMessageResponseData;
|
/// <summary>
|
/// 查看防区报警目标的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class DisablePushMessageResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:正常</para>
|
/// <para>1:防区不存在</para>
|
/// </summary>
|
public int Result = 999;
|
|
/// <summary>
|
/// 防区ID
|
/// <para>1:24小时防区。</para>
|
///<para>2:24小时静音防区。</para>
|
///<para>其它防区。</para>
|
/// </summary>
|
public int ZoneType;
|
/// <summary>
|
/// 是否禁用防区被触发时信息推送
|
///<para>0:不禁用</para>
|
///<para>1:禁用</para>
|
/// </summary>
|
public int IsDisablePushMessage;
|
|
}
|
#endregion
|
|
#region 35 退出管理员登陆(app通过该指令将退出管理员登陆,原来的“LoginToken”字段将失效。)
|
/// <summary>
|
/// 退出管理员登陆(app通过该指令将退出管理员登陆,原来的“LoginToken”字段将失效。)
|
///<para>loginToken: 登陆标识,最大32个字符。由app自动生成的唯一标识。与管理员登陆指令的“LoginToken”一致,否则将返回“Security/Error_Respon”错误。</para>
|
/// </summary>
|
public static async System.Threading.Tasks.Task<AdminLogOutResposeAllData> AdminLogOutAsync(string loginToken)
|
{
|
return await System.Threading.Tasks.Task.Run(async () =>
|
{
|
AdminLogOutResposeAllData d = null;
|
var mainGateway = ZbGateway.MainGateWay;
|
if (mainGateway == null)
|
{
|
d = new AdminLogOutResposeAllData { errorMessageBase = "当前没有主网关" };
|
return d;
|
}
|
Action<string, string> action = (topic, message) =>
|
{
|
var gatewayID = topic.Split('/')[0];
|
var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
|
if (topic == gatewayID + "/" + "Error_Respon")
|
{
|
var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
|
|
if (temp == null)
|
{
|
d = new AdminLogOutResposeAllData { errorMessageBase = "网关错误回复,且数据是空" };
|
}
|
else
|
{
|
d = new AdminLogOutResposeAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
|
}
|
}
|
|
if (topic == gatewayID + "/" + "Security/AdminLogOut_Respon")
|
{
|
var adminLogOutResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<AdminLogOutResponseData>(jobject["Data"].ToString());
|
if (adminLogOutResponseData != null)
|
{
|
d = new AdminLogOutResposeAllData { adminLogOutResponseData = adminLogOutResponseData };
|
System.Console.WriteLine($"UI收到通知后的主题_{topic}");
|
}
|
else
|
{
|
d = new AdminLogOutResposeAllData { errorMessageBase = "网关回复数据是空" };
|
}
|
}
|
};
|
mainGateway.Actions += action;
|
System.Console.WriteLine($"Security/AdminLogOut_Actions启动_{System.DateTime.Now.ToString()}");
|
try
|
{
|
var jObject = new Newtonsoft.Json.Linq.JObject() {
|
{ "Cluster_ID", 0 },
|
{ "Command", 4035 }
|
};
|
var data = new JObject
|
{
|
{ "LoginToken", loginToken }
|
};
|
jObject.Add("Data", data);
|
mainGateway.Send(("Security/AdminLogOut"), 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 AdminLogOutResposeAllData { errorMessageBase = " 回复超时,请重新操作" };
|
}
|
|
mainGateway.Actions -= action;
|
System.Console.WriteLine($"Security/AdminLogOut_Actions 退出_{System.DateTime.Now.ToString()}");
|
return d;
|
});
|
}
|
|
/// <summary>
|
/// 退出管理员登陆的返回数据 ,网关反馈信息
|
/// </summary>
|
public DisablePushMessageResposeAllData adminLogOutResposeAllData;
|
/// <summary>
|
/// 退出管理员登陆的返回数据,网关反馈信息
|
/// </summary>
|
[System.Serializable]
|
public class AdminLogOutResposeAllData : CommonDevice.ErrorResponCommon
|
{
|
/// <summary>
|
/// 退出管理员登陆的返回数据
|
/// </summary>
|
public AdminLogOutResponseData adminLogOutResponseData;
|
}
|
|
/// <summary>
|
/// 退出管理员登陆的返回数据
|
/// </summary>
|
public AdminLogOutResponseData adminLogOutResponseData;
|
/// <summary>
|
/// 退出管理员登陆的返回数据
|
/// </summary>
|
[System.Serializable]
|
public class AdminLogOutResponseData
|
{
|
/// <summary>
|
/// 返回结果
|
/// <para>0:成功</para>
|
/// <para>1:错误,不存在该“LoginToken”。</para>
|
/// </summary>
|
public int Result = -1;
|
}
|
#endregion
|
}
|
}
|