using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json.Linq;
namespace Shared.Phone.UserCenter
{
///
/// 全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
///
public class HdlGatewayReceiveLogic
{
#region ■ 全局接收___________________________
///
/// 全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
///
/// 网关ID
/// 主题
/// 接收的数据
public static void GatewayOverallMsgReceive(string gatewayId, string topic, JObject receiveData)
{
if (topic == "AppNoLogin")
{
HdlThreadLogic.Current.RunMain(() =>
{
//登录密匙已经过期,请重新登录
string msg = Language.StringByID(R.MyInternationalizationString.uTokenIsOldAndLoginAgain);
var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
contr.Show();
UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
});
}
else if (topic == "BeingSqueezedOffline")
{
HdlThreadLogic.Current.RunMain(() =>
{
//此帐号已在别处登录,您被迫下线
string msg = Language.StringByID(R.MyInternationalizationString.uHadBeenLoginAndOffLine);
var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
contr.Show();
UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
});
}
try
{
if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
{
//不是自己绑定的网关,则不处理
return;
}
//门锁上报
if (topic == gatewayId + "/Alarms/SendAlarmInform")
{
//保存门锁报警信息到本地
HdlAlarmsLogic.Current.SaveDoorLockAlarmInfo(receiveData);
}
//通过外部方式布防撤防成功时报告
else if (topic == gatewayId + "/Security/EnOrWithdrawSucceedReport")
{
SecurityEnOrWithdrawSucceedReport(receiveData);
}
}
catch (Exception ex)
{
//Log出力
HdlLogLogic.Current.WriteLog(ex);
}
}
#endregion
#region ■ 通过外部方式布防撤防_______________
///
/// 通过外部方式布防撤防
///
/// 接收的数据
private static void SecurityEnOrWithdrawSucceedReport(JObject receiveData)
{
var data = Newtonsoft.Json.JsonConvert.DeserializeObject(receiveData["Data"].ToString());
if (data.EnOrWithdraw == -1 || data.ModeId == -1 || data.OperationWay == -1)
{
return;
}
var garrison = GarrisonMode.None;
if (data.EnOrWithdraw == 0)
{
//在家布防
if (data.ModeId == 1) { garrison = GarrisonMode.AtHome; }
//离家布防
else if (data.ModeId == 2) { garrison = GarrisonMode.RemoveHome; }
}
else if (data.EnOrWithdraw == 1)
{
//撤防
garrison = GarrisonMode.RemoveGarrison;
}
string appendText = string.Empty;
//自动化
if (data.OperationWay == 0) { appendText = "(" + Language.StringByID(R.MyInternationalizationString.uLogicOperation) + ")"; }
//按键操作
else if (data.OperationWay == 1) { appendText = "(" + Language.StringByID(R.MyInternationalizationString.uPanelOperation) + ")"; }
//保存报警信息然后推送到界面上
HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison, appendText, true);
}
///
/// 通过外部方式布防撤防的接收结果
///
private class SecurityEnOrWithdrawResult
{
///
/// 0:布防成功 1:撤防成功
///
public int EnOrWithdraw = -1;
///
/// 安防模式id
///
public int ModeId = -1;
///
/// 外部布撤防方式-> 0:执行逻辑动作 1:按键操作
///
public int OperationWay = -1;
}
#endregion
}
}