Evoyo.Home1.1.0120111601_Release
| | |
| | |
|
| | | namespace com.hdl.home |
| | | { |
| | | |
| | | [Activity(Name = "com.hdl.home.wxapi.WXEntryActivity", Exported = true, Theme = "@android:style/Theme.Translucent", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)] |
| | | class WXEntryActivity : Android.App.Activity, IWXAPIEventHandler |
| | | { |
| | |
| | | public class Application : Android.App.Application
|
| | | {
|
| | | public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测内存泄露的东西
|
| | | /// </summary> |
| | | ///private Square.LeakCanary.RefWatcher _refWatcher;
|
| | |
|
| | | public override void OnCreate()
|
| | | { |
| | | //如果不是App的主进程,则不需要处理 |
| | |
| | | //调试:记录系统异常
|
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteOtherText(Shared.Phone.UserCenter.DirNameResourse.SystemLogFile, ex.Message + "\r\n" + ex.StackTrace, true, false);
|
| | | }
|
| | | base.OnCreate(); |
| | | // 通过WXAPIFactory工厂,获取IWXAPI的实例 |
| | | //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true); |
| | | base.OnCreate();
|
| | | // 通过WXAPIFactory工厂,获取IWXAPI的实例
|
| | | //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true);
|
| | |
|
| | | //检测内存泄露的东西
|
| | | //if (Square.LeakCanary.LeakCanaryXamarin.IsInAnalyzerProcess(this) == false)
|
| | | //{
|
| | | // _refWatcher = Square.LeakCanary.LeakCanaryXamarin.Install(this);
|
| | | // _refWatcher.Watch(this);
|
| | | //} |
| | | |
| | | // 将应用的appId注册到微信 |
| | | api?.RegisterApp("wx2ec8f53f6fa36e82"); |
| | |
| | | var req = new SendAuth.Req { Scope = "snsapi_userinfo", State = "ZigbeeApp" }; |
| | | api?.SendReq(req); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 所有初始化全部在这个方法实现 |
| | | /// </summary> |
| | | void initAll()
|
| | | {
|
| | | Shared.Application.IsGpsEnable = System.IO.File.Exists(Shared.Phone.UserCenter.DirNameResourse.OpenGbsFile);
|
| | | //取消屏幕常亮
|
| | | BaseActivity.KeepScreenON = false;
|
| | | //隐藏底部软按键
|
| | | BaseActivity.IsHideVirualButtons = true;
|
| | |
|
| | |
| | | 16165=过户失败 |
| | | 16166=恭喜{0}成为「{1}」管理员 |
| | | 16167=检测到还没有备份,请先备份 |
| | | 16168=替换 |
| | | 16169=替换网关 |
| | | 16170=请选择被替换的网关 |
| | | |
| | | ;★★★★下面这些是接口的返回信息翻译,从18000开始★★★★
|
| | | 18004=指定网关已经被绑定
|
| | |
| | | <Reference Include="FastAndroidCamera, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
| | | <HintPath>..\packages\FastAndroidCamera.2.0.0\lib\MonoAndroid403\FastAndroidCamera.dll</HintPath>
|
| | | </Reference>
|
| | | <Reference Include="LeakCanary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
| | | <HintPath>..\packages\LeakCanaryBinding.1.5.1.1\lib\MonoAndroid10\LeakCanary.dll</HintPath>
|
| | | </Reference>
|
| | | <Reference Include="LeakCanary.Analyzer, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
| | | <HintPath>..\packages\LeakCanaryBinding.1.5.1.1\lib\MonoAndroid10\LeakCanary.Analyzer.dll</HintPath>
|
| | | </Reference>
|
| | | <Reference Include="LeakCanary.Watcher, Version=1.5.1.0, Culture=neutral, processorArchitecture=MSIL">
|
| | | <HintPath>..\packages\LeakCanaryBinding.1.5.1.1\lib\MonoAndroid10\LeakCanary.Watcher.dll</HintPath>
|
| | | </Reference>
|
| | | <Reference Include="Microsoft.AppCenter, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
| | | <HintPath>..\packages\Microsoft.AppCenter.1.14.0\lib\MonoAndroid403\Microsoft.AppCenter.dll</HintPath>
|
| | | </Reference>
|
| | |
| | | <ItemGroup>
|
| | | <AndroidAsset Include="Assets\Phone\SmartSound\Sibici.png" />
|
| | | </ItemGroup>
|
| | | <ItemGroup>
|
| | | <AndroidAsset Include="Assets\Phone\Item\ReplaceIconSelected.png" />
|
| | | </ItemGroup>
|
| | | <Import Project="..\Shared\Shared.projitems" Label="Shared" Condition="Exists('..\Shared\Shared.projitems')" />
|
| | | <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
|
| | | <Import Project="..\packages\Xamarin.Android.Support.Annotations.26.0.2\build\MonoAndroid80\Xamarin.Android.Support.Annotations.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Annotations.26.0.2\build\MonoAndroid80\Xamarin.Android.Support.Annotations.targets')" />
|
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.evoyo.home" android:versionCode="0120101001" android:installLocation="auto" android:versionName="1.1.0120101001"> |
| | | <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.evoyo.home" android:versionCode="0120111601" android:installLocation="auto" android:versionName="1.1.0120111601"> |
| | | <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="26" /> |
| | | <permission android:name="com.evoyo.home.permission.JPUSH_MESSAGE" android:protectionLevel="signature" /> |
| | | <uses-permission android:name="android.permission.WAKE_LOCK" /> |
| | |
| | | <packages>
|
| | | <package id="BouncyCastle.Crypto.dll" version="1.8.1" targetFramework="monoandroid60" />
|
| | | <package id="FastAndroidCamera" version="2.0.0" targetFramework="monoandroid80" />
|
| | | <package id="LeakCanaryBinding" version="1.5.1.1" targetFramework="monoandroid80" />
|
| | | <package id="Microsoft.AppCenter" version="1.14.0" targetFramework="monoandroid60" />
|
| | | <package id="Microsoft.AppCenter.Analytics" version="1.14.0" targetFramework="monoandroid60" />
|
| | | <package id="Microsoft.AppCenter.Crashes" version="1.14.0" targetFramework="monoandroid60" />
|
| | |
| | | 16165=过户失败 |
| | | 16166=恭喜{0}成为「{1}」管理员 |
| | | 16167=检测到还没有备份,请先备份 |
| | | 16168=替换 |
| | | 16169=替换网关 |
| | | 16170=请选择被替换的网关 |
| | | |
| | | ;★★★★下面这些是接口的返回信息翻译,从18000开始★★★★
|
| | | 18004=指定网关已经被绑定
|
| | |
| | | AddChidren(Phone.UserView.HomePage.Instance); |
| | | Application.MainPage.AddChidren(Loading); |
| | | |
| | | Phone.UserView.HomePage.Instance.InitPage(); |
| | | Phone.UserView.HomePage.Instance.InitPage();
|
| | |
|
| | | //设置顶部状态栏文字为黑色
|
| | | Application.SetStatusBarTextBlack(true); |
| | | } |
| | | |
| | | //public static string RequestHttpsHost = "https://global.hdlcontrol.com/HangZhouHdlCloudApi"; |
| | |
| | | /// <summary> |
| | | /// 版本号 |
| | | /// </summary> |
| | | public static string CodeIDString = "1.1.0120101001"; |
| | | public static string CodeIDString = "1.1.0120111601"; |
| | | /// <summary> |
| | | /// 注册来源(0:HDL On 1:Zigbee) |
| | | /// </summary> |
| | |
| | | /// 设备的总回路(keys:Mac地址 value:全部端口号)
|
| | | /// </summary>
|
| | | private Dictionary<string, HashSet<int>> dicDeviceEpoint = new Dictionary<string, HashSet<int>>();
|
| | | /// <summary>
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceRoomId = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | //成员身份的时候,删除掉非法的网关文件 |
| | | this.DeleteGatewayFileByMemberModel(); |
| | | //初始化物理设备所属房间的记录 |
| | | this.InitRealDeviceRoomId(); |
| | | HdlRoomLogic.Current.InitRealDeviceRoomId(); |
| | |
|
| | | #if DEBUG
|
| | | if (UserCenterResourse.HideOption.CenterHideMenu == 1)
|
| | |
| | | if (listDeleteMac.Count > 0)
|
| | | {
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(listDeleteMac);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listDeleteMac);
|
| | | }
|
| | |
|
| | | return statu;
|
| | |
| | | {
|
| | | this.DeleteMemmoryDevice(device);
|
| | | }
|
| | | //移除真实设备的房间索引
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(listdevice[0]);
|
| | |
|
| | | if (this.dicDeviceRoomId.ContainsKey(listdevice[0].DeviceAddr) == true)
|
| | | {
|
| | | //移除真实设备的房间索引
|
| | | this.dicDeviceRoomId.Remove(listdevice[0].DeviceAddr);
|
| | | this.SaveRealDeviceRoomId(null, null);
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | info.ConcreteType = DeviceConcreteType.Sensor_DoorWindow;
|
| | | info.ConcreteText = Language.StringByID(R.MyInternationalizationString.uSensorDoorWindow);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 物理设备所属房间___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化物理设备所属房间的记录
|
| | | /// </summary>
|
| | | private void InitRealDeviceRoomId()
|
| | | {
|
| | | this.dicDeviceRoomId = new Dictionary<string, string>();
|
| | | string fullName = DirNameResourse.DeviceRoomIdFile;
|
| | | var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
|
| | | if (strData != null)
|
| | | {
|
| | | this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取全部物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public Dictionary<string, string> GetAllRealDeviceRoomData()
|
| | | {
|
| | | return this.dicDeviceRoomId;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <param name="listDevice">需要保存的设备对象</param>
|
| | | /// <param name="roomId">需要保存的哪个设备的房间ID</param>
|
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | if (listDevice == null || listDevice.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice.Count == 1)
|
| | | {
|
| | | if ((listDevice[0] is OTADevice) == false)
|
| | | {
|
| | | //ota设备不需要处理
|
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | }
|
| | | bool save = false;
|
| | | if (roomId == string.Empty)
|
| | | {
|
| | | //选择的是未分配
|
| | | this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //2020.05.18追加:如果记录的房间ID是不存在的话,则重新覆盖
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
|
| | | if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (save == true)
|
| | | {
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备的房间名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public string GeteRealDeviceRoomName(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | }
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | return HdlRoomLogic.Current.GetRoomName(room);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备属于哪个房间
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public Room GeteRealDeviceRoom(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="device">随便一个回路</param>
|
| | | public void DeleteRealDeviceFromRoom(CommonDevice device)
|
| | | {
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(new List<string>() { device.DeviceAddr });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="listMac">设备Mac地址</param>
|
| | | public void DeleteRealDeviceFromRoom(List<string> listMac)
|
| | | {
|
| | | bool save = false;
|
| | | foreach (var deviceMacAddr in listMac)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
|
| | | {
|
| | | this.dicDeviceRoomId.Remove(deviceMacAddr);
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | if (save == false)
|
| | | {
|
| | | //没有改变,不需要保存
|
| | | return;
|
| | | }
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | /// </summary>
|
| | | /// <param name="i_RoomId"></param>
|
| | | public void DeleteRealDeviceByRoomId(string i_RoomId)
|
| | | {
|
| | | var listDeleteKey = new List<string>();
|
| | | foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
|
| | | {
|
| | | if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
|
| | | && listDeleteKey.Contains(deviceAddr) == false)
|
| | | {
|
| | | listDeleteKey.Add(deviceAddr);
|
| | | }
|
| | | }
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(listDeleteKey);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | 关闭定位服务 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.Application.IsStatusBarBlack"> |
| | | <summary> |
| | | 当前是否设置顶部状态栏字体颜色 |
| | | </summary> |
| | | </member> |
| | | <member name="M:Shared.Application.SetStatusBarTextBlack(System.Boolean)"> |
| | | <summary> |
| | | 设置顶部状态栏字体颜色 |
| | | </summary> |
| | | <param name="isBlack">是否设置黑色</param> |
| | | </member> |
| | | <member name="T:Shared.Button"> |
| | | <summary> |
| | | Button 按键 |
| | |
| | | Y轴坐标 |
| | | </summary> |
| | | </member> |
| | | <member name="M:Shared.BaseActivity.HideVirtualButtons(Android.App.Activity)"> |
| | | <summary> |
| | | HideVirtualButtons |
| | | </summary> |
| | | <param name="activity"></param> |
| | | </member> |
| | | <member name="M:Shared.BaseActivity.SetImagePermission(System.Action{System.Boolean})"> |
| | | <summary> |
| | | |
| | |
| | | </summary> |
| | | <value>是否可以滑动</value> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.CurtainPaddingLeftRight"> |
| | | <summary> |
| | | 进度条与左右边框边距 |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.CurtainPaddingTop"> |
| | | <summary> |
| | | 顶部padding |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.IsOffline"> |
| | | <summary> |
| | | 是否离线 离线的话禁止滑动并绘制背景遮挡层 |
| | |
| | | </summary> |
| | | <value>X坐标</value> |
| | | </member> |
| | | <member name="P:Shared.DiyImageSeekBar.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.DiyImageSeekBar.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | </summary> |
| | | <value>X坐标</value> |
| | | </member> |
| | | <member name="P:Shared.CurtainSeekBarOn.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.CurtainSeekBarOn.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | 设置是否为百叶窗样式 |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBarOn.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.CurtainRollSeekBarOn.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | 关闭定位服务 |
| | | </summary> |
| | | </member> |
| | | <member name="M:Shared.Application.SetStatusBarTextBlack(System.Boolean)"> |
| | | <summary> |
| | | 设置顶部状态栏字体颜色 |
| | | </summary> |
| | | <param name="isBlack">是否设置黑色</param> |
| | | </member> |
| | | <member name="T:Shared.Button"> |
| | | <summary> |
| | | Button 按键 |
| | |
| | | </summary> |
| | | <value>进度值</value> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.CurtainPaddingLeftRight"> |
| | | <summary> |
| | | 进度条与左右边框边距 |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.CurtainPaddingTop"> |
| | | <summary> |
| | | 顶部padding |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBar.IsOffline"> |
| | | <summary> |
| | | 是否离线 离线的话禁止滑动并绘制背景遮挡层 |
| | |
| | | </summary> |
| | | <value>X坐标</value> |
| | | </member> |
| | | <member name="P:Shared.DiyImageSeekBar.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.DiyImageSeekBar.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | 设置是否为百叶窗样式 |
| | | </summary> |
| | | </member> |
| | | <member name="P:Shared.CurtainRollSeekBarOn.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.CurtainRollSeekBarOn.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | </summary> |
| | | <value>X坐标</value> |
| | | </member> |
| | | <member name="P:Shared.CurtainSeekBarOn.IsInvertedProgress"> |
| | | <summary> |
| | | 进度值是否取反 |
| | | </summary> |
| | | </member> |
| | | <member name="F:Shared.CurtainSeekBarOn.OnProgressChangedEvent"> |
| | | <summary> |
| | | EventHandler |
| | |
| | | }
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | int sendCount = 0;
|
| | | while (listView.Parent != null)
|
| | | {
|
| | | bool hadSend = false;
|
| | |
| | | //发送获取状态的命令
|
| | | listContr[i].SendStatuComand();
|
| | | hadSend = true;
|
| | | System.Threading.Thread.Sleep(200);
|
| | | System.Threading.Thread.Sleep(300);
|
| | | }
|
| | | }
|
| | | if (hadSend == false)
|
| | |
| | | //如果已经全部回路都接收了网关回复,则不再二次发送
|
| | | break;
|
| | | }
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | sendCount++;
|
| | | if (sendCount == 2)
|
| | | {
|
| | | //就发2次
|
| | | break;
|
| | | }
|
| | | System.Threading.Thread.Sleep(5000);
|
| | | }
|
| | |
|
| | | }, ShowErrorMode.NO);
|
| | |
| | | #endregion |
| | | string strname = ""; |
| | | //到达地点点击事件 |
| | | athomeView.clickviewBtn.MouseUpEventHandler += (sender, e) => { |
| | | athomeView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
|
| | | { |
| | | |
| | | strname = athomeView.titleBtn.Text; |
| | | leaveView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor; |
| | |
| | | athomeView.selectedIconBtn.Visible = true; |
| | | }; |
| | | //离开地点点击事件 |
| | | leaveView.clickviewBtn.MouseUpEventHandler += (sender, e) => { |
| | | leaveView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
|
| | | { |
| | | strname = leaveView.titleBtn.Text; |
| | | leaveView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor; |
| | | athomeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor; |
| | | leaveView.selectedIconBtn.Visible = true; |
| | | athomeView.selectedIconBtn.Visible = false; |
| | | }; |
| | | |
| | | };
|
| | |
|
| | | double latitude = Config.Instance.Home.Latitude;//纬度 |
| | | double longitude = Config.Instance.Home.Longitude;//经度 |
| | | int r = 500;//半径 |
| | |
| | | LocationConditionsInfo.Remove("AtHome"); |
| | | } |
| | | LocationConditionsInfo.Add("AtHome", "1"); |
| | | } |
| | | |
| | | //调用方法,跳转页面 |
| | | GDMapKit.Show((mLatitude, mLongitude, mRadius, name) => |
| | | { |
| | | //截取字符串后第6位; |
| | | //var len = name.Substring(name.Length - 6, 6); |
| | | |
| | | //点击保存按钮,回调当前选择的纬度,经度,半径范围 |
| | | }
|
| | |
|
| | | #if Android
|
| | | //申请定位权限
|
| | | ((BaseActivity)Application.Activity).SetGPSLocationPermission((result1) =>
|
| | | {
|
| | | if (result1 == false) { return; }
|
| | |
|
| | | //申请允许程序写入外部存储,如SD卡上写文件
|
| | | ((BaseActivity)Application.Activity).SetPermission((result2) =>
|
| | | {
|
| | | if (result2 == false) { return; }
|
| | | //读取电话状态权限
|
| | | ((BaseActivity)Application.Activity).SetPermission((result3) =>
|
| | | {
|
| | | if (result3 == false) { return; }
|
| | |
|
| | | //调用方法,跳转页面
|
| | | GDMapKit.Show((mLatitude, mLongitude, mRadius, name) =>
|
| | | {
|
| | | //截取字符串后第6位;
|
| | | //var len = name.Substring(name.Length - 6, 6);
|
| | |
|
| | | //点击保存按钮,回调当前选择的纬度,经度,半径范围
|
| | | var latitudW = (int)Math.Truncate(mLatitude * 1000000);
|
| | | var longitudeH = (int)Math.Truncate(mLongitude * 1000000);
|
| | | Dictionary<string, string> accounts = new Dictionary<string, string>();
|
| | | if (accounts.ContainsKey("Account"))
|
| | | {
|
| | | accounts.Remove("Account");
|
| | | }
|
| | | if (accounts.ContainsKey("Type"))
|
| | | {
|
| | | accounts.Remove("Type");
|
| | | }
|
| | | if (accounts.ContainsKey("Latitude"))
|
| | | {
|
| | | accounts.Remove("latitude");
|
| | | }
|
| | | if (accounts.ContainsKey("Longitude"))
|
| | | {
|
| | | accounts.Remove("Longitude");
|
| | | }
|
| | | if (accounts.ContainsKey("Radius"))
|
| | | {
|
| | | accounts.Remove("radius");
|
| | | }
|
| | | accounts.Add("Account", Config.Instance.Guid);
|
| | | accounts.Add("Type", "7");
|
| | | accounts.Add("Latitude", latitudW.ToString());
|
| | | accounts.Add("Longitude", longitudeH.ToString());
|
| | | accounts.Add("Radius", mRadius.ToString());
|
| | |
|
| | | LogicIfon.Addaccounts(accounts);
|
| | | LogicIfon.AddLocationconditions(LocationConditionsInfo);
|
| | |
|
| | | var logicCommunalPage = new LogicCommunalPage();
|
| | | UserView.HomePage.Instance.AddChidren(logicCommunalPage);
|
| | | UserView.HomePage.Instance.PageIndex += 1;
|
| | | logicCommunalPage.Show(() => { });
|
| | | }, strname, Language.StringByID(R.MyInternationalizationString.uSave), true, latitude, longitude, r);
|
| | |
|
| | | }, "android.permission.READ_PHONE_STATE");
|
| | |
|
| | | }, "android.permission.WRITE_EXTERNAL_STORAGE");
|
| | | });
|
| | | #endif
|
| | | #if iOS
|
| | | //调用方法,跳转页面
|
| | | GDMapKit.Show((mLatitude, mLongitude, mRadius, name) =>
|
| | | {
|
| | | //截取字符串后第6位;
|
| | | //var len = name.Substring(name.Length - 6, 6);
|
| | |
|
| | | //点击保存按钮,回调当前选择的纬度,经度,半径范围
|
| | | var latitudW = (int)Math.Truncate(mLatitude * 1000000); |
| | | var longitudeH = (int)Math.Truncate(mLongitude * 1000000); |
| | | Dictionary<string, string> accounts = new Dictionary<string, string>(); |
| | |
| | | UserView.HomePage.Instance.AddChidren(logicCommunalPage); |
| | | UserView.HomePage.Instance.PageIndex += 1; |
| | | logicCommunalPage.Show(() => { }); |
| | | }, strname, Language.StringByID(R.MyInternationalizationString.uSave), true, latitude, longitude, r); |
| | | }, strname, Language.StringByID(R.MyInternationalizationString.uSave), true, latitude, longitude, r);
|
| | | #endif
|
| | | }; |
| | | } |
| | | |
| | |
| | | }; |
| | | var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestObj); |
| | | var revertObj = RequestHttpsZigbeeAsync("ProcessRange/ReceiveAppLatAndLon", System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | |
| | | if (UserCenter.UserCenterResourse.HideOption.WriteGpsPoint == 1)
|
| | | {
|
| | | string flage = revertObj == null ? "false" : revertObj.StateCode;
|
| | | string txtvalue = "lon:" + lon + " lat:" + lat + " " + flage;
|
| | | HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, txtvalue);
|
| | | UserCenter.HdlLogLogic.Current.WriteLog(-1, "经纬度上报 " + txtvalue);
|
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | |
| | | SeekBarSiphonateCurtain.Progress = (device as Rollershade).WcdCurrentPositionLiftPercentage;
|
| | | frameWhiteBack.AddChidren(SeekBarSiphonateCurtain);
|
| | | SeekBarSiphonateCurtain.IsProgressTextShow = false;
|
| | | SeekBarSiphonateCurtain.CurtainPaddingTop = Application.GetRealHeight(110);
|
| | |
|
| | | //卷帘控件里面的那个显示百分比的控件
|
| | | int progressY = SeekBarSiphonateCurtain.Y - Application.GetMinReal(204);
|
| | |
| | | }
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | int sendCount = 0;
|
| | | while (listDeviceBackContr.Parent != null)
|
| | | {
|
| | | bool hadSend = false;
|
| | |
| | | //发送获取状态的命令
|
| | | listContr[i].SendStatuComand();
|
| | | hadSend = true;
|
| | | System.Threading.Thread.Sleep(200);
|
| | | System.Threading.Thread.Sleep(300);
|
| | | }
|
| | | }
|
| | | if (hadSend == false)
|
| | |
| | | //如果已经全部回路都接收了网关回复,则不再二次发送
|
| | | break;
|
| | | }
|
| | | System.Threading.Thread.Sleep(2000);
|
| | | sendCount++;
|
| | | if (sendCount == 2)
|
| | | {
|
| | | //就发2次
|
| | | break;
|
| | | }
|
| | | System.Threading.Thread.Sleep(5000);
|
| | | }
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | |
| | | var room = HdlRoomLogic.Current.GetRoomById(selectId); |
| | | this.SaveSelectDeviceAndScene(room);
|
| | | //分类界面需要刷新
|
| | | UserPage.Instance.RefreshCategoryForm = true; |
| | | //上传空间区域信息 |
| | | UserPage.Instance.RefreshCategoryForm = true;
|
| | | //上传空间区域信息
|
| | | HdlRoomLogic.Current.SetRoomInfoToGateway(); |
| | | });
|
| | | };
|
| | |
| | | dicRealRoom[gateway.GwId] = gateway.RoomId;
|
| | | }
|
| | | //获取全部物理设备所属房间的记录
|
| | | var dicDeviceRoom = Common.LocalDevice.Current.GetAllRealDeviceRoomData();
|
| | | var dicDeviceRoom = HdlRoomLogic.Current.GetAllRealDeviceRoomData();
|
| | | foreach (var strMac in dicDeviceRoom.Keys)
|
| | | {
|
| | | dicRealRoom[strMac] = dicDeviceRoom[strMac];
|
| | |
| | | //更改物理设备所在的房间
|
| | | if (this.modelData.dicDeviceTemplateRealRoom.ContainsKey(targetMac) == true)
|
| | | {
|
| | | Common.LocalDevice.Current.SaveRealDeviceRoomId(listDevice, this.modelData.dicDeviceTemplateRealRoom[targetMac], false);
|
| | | HdlRoomLogic.Current.SaveRealDeviceRoomId(listDevice, this.modelData.dicDeviceTemplateRealRoom[targetMac], false);
|
| | | }
|
| | |
|
| | | //记录缓存
|
| | |
| | | //变更网关房间
|
| | | if (this.modelData.dicDeviceTemplateRealRoom.ContainsKey(targetGwid) == true)
|
| | | {
|
| | | HdlGatewayLogic.Current.ChangedGatewayRoom(sourceGwid, this.modelData.dicDeviceTemplateRealRoom[targetGwid]);
|
| | | HdlRoomLogic.Current.ChangedGatewayRoom(sourceGwid, this.modelData.dicDeviceTemplateRealRoom[targetGwid]);
|
| | | }
|
| | | //变更网关名字
|
| | | //if (this.modelData.dicGatewayInfo.ContainsKey(targetGwid) == true)
|
| | |
| | | {
|
| | | return false;
|
| | | }
|
| | | if (int.Parse(versionResult.FirmwareVersion.Replace(".", "")) > int.Parse(CommonPage.CodeIDString.Replace(".", "")))
|
| | | if (versionResult.FirmwareVersion.CompareTo(CommonPage.CodeIDString) > 0)
|
| | | {
|
| | | distributedMark = versionResult.DistributedMark;
|
| | | return true;
|
| | |
| | | try
|
| | | {
|
| | | var webClient = new WebClient { };
|
| | | var result = await webClient.DownloadDataTaskAsync("https://itunes.apple.com/lookup?id=1461693569");
|
| | | var result = await webClient.DownloadDataTaskAsync("https://itunes.apple.com/lookup?id=1528702586");
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | |
| | | /// </summary>
|
| | | public void OpenUrl()
|
| | | {
|
| | | Uri url = new Uri("https://itunes.apple.com/cn/app/hdl-home/id1461693569?mt=8");
|
| | | Uri url = new Uri("https://itunes.apple.com/cn/app/hdl-home/id1528702586?mt=8");
|
| | | UIKit.UIApplication.SharedApplication.OpenUrl(url);
|
| | | }
|
| | | #elif Android
|
| | |
| | | {
|
| | | return null;
|
| | | }
|
| | | int MaxIndex = 0;
|
| | | int NewVersion = 0;
|
| | |
|
| | | Common.ResponseEntity.ApkInfoOBJ apkInfoOBJ = null;
|
| | | for (int i = 0; i < responeData.pageData.Count; i++)
|
| | | {
|
| | | var apkInfo = responeData.pageData[i];
|
| | | var version = int.Parse(apkInfo.FirmwareVersion.Replace(".", ""));
|
| | | if (version > NewVersion)
|
| | | if (apkInfoOBJ == null || apkInfoOBJ.FirmwareVersion.CompareTo(apkInfo.FirmwareVersion) > 0)
|
| | | {
|
| | | NewVersion = version;
|
| | | MaxIndex = i;
|
| | | apkInfoOBJ = apkInfo;
|
| | | }
|
| | | }
|
| | | return responeData.pageData[MaxIndex];
|
| | | return apkInfoOBJ;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
| | | /// 是否使用以前旧的设备列表获取方式 1->使用
|
| | | /// </summary>
|
| | | public int UseOldSearchDeviceMethord = 0;
|
| | | /// <summary>
|
| | | /// 是否记录上报的gbs坐标 1->记录
|
| | | /// </summary>
|
| | | public int WriteGpsPoint = 0;
|
| | | }
|
| | | #endregion
|
| | |
|
| | |
| | | /// </summary>
|
| | | Admin = 2
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 是否写Log
|
| | | /// </summary>
|
| | | public enum WriteLogMode
|
| | | {
|
| | | /// <summary>
|
| | | /// 写Log
|
| | | /// </summary>
|
| | | YES = 1,
|
| | | /// <summary>
|
| | | /// 不写Log
|
| | | /// </summary>
|
| | | NO = 2
|
| | | }
|
| | | }
|
| | |
| | | /// <param name="i_gateway">网关对象</param>
|
| | | public void InitControl(string i_caption, ZigBee.Device.ZbGateway i_gateway)
|
| | | {
|
| | | var room = HdlGatewayLogic.Current.GetRoomByGateway(i_gateway);
|
| | | var room = HdlRoomLogic.Current.GetRoomByGateway(i_gateway);
|
| | | this.DoInitControl(i_caption, room);
|
| | | }
|
| | |
|
| | |
| | | /// <param name="i_listDevice">设备对象</param>
|
| | | public void InitControl(string i_caption, List<ZigBee.Device.CommonDevice> i_listDevice)
|
| | | {
|
| | | var room = Common.LocalDevice.Current.GeteRealDeviceRoom(i_listDevice[0]);
|
| | | var room = HdlRoomLogic.Current.GeteRealDeviceRoom(i_listDevice[0]);
|
| | | this.DoInitControl(i_caption, room);
|
| | | }
|
| | |
|
| | |
| | | //图标
|
| | | var btnIcon = rowFrame.AddLeftIcon(81);
|
| | | btnIcon.UnSelectedImagePath = unSelectPic;
|
| | | btnIcon.SelectedImagePath = selectPic;
|
| | | if (selectPic != null)
|
| | | {
|
| | | btnIcon.SelectedImagePath = selectPic;
|
| | | }
|
| | | //显示文字
|
| | | var btnText = rowFrame.AddLeftCaption(TextValue, RowWidth - 173);
|
| | | btnText.X = Application.GetRealWidth(173);
|
| | |
| | | var btnIcon = (IconViewControl)frame.GetChildren(0);
|
| | | if (btnIcon != null)
|
| | | {
|
| | | btnIcon.IsSelected = select;
|
| | | if (select == true && string.IsNullOrEmpty(btnIcon.SelectedImagePath) == true)
|
| | | {
|
| | | //如果不设置这张图片,则什么都不做
|
| | | }
|
| | | else
|
| | | {
|
| | | btnIcon.IsSelected = select;
|
| | | }
|
| | | }
|
| | | //文本
|
| | | var btnText = (NormalViewControl)frame.GetChildren(1);
|
| | |
| | | frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEvent);
|
| | |
|
| | | //房间
|
| | | string roomName = Common.LocalDevice.Current.GeteRealDeviceRoomName(listDevice[0]);
|
| | | string roomName = HdlRoomLogic.Current.GeteRealDeviceRoomName(listDevice[0]);
|
| | | btnDeviceRoom = frameTable.AddBottomView(roomName, 800);
|
| | |
|
| | | //底线
|
| | |
| | | //设备
|
| | | btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
|
| | | //设备房间
|
| | | btnDeviceRoom.Text = Common.LocalDevice.Current.GeteRealDeviceRoomName(listDevice[0]);
|
| | | btnDeviceRoom.Text = HdlRoomLogic.Current.GeteRealDeviceRoomName(listDevice[0]);
|
| | | }
|
| | |
|
| | |
|
| | |
| | |
|
| | | //重新刷新住宅对象
|
| | | UserCenterLogic.RefreshHomeObject();
|
| | | //根据模板文件,恢复数据
|
| | | TemplateData.TemplateCommonLogic.Current.RecoverDataByTemplateBinFile();
|
| | | //强制生成设备和网关文件
|
| | | TemplateData.TemplateCommonLogic.Current.CreatDeviceAndGatewayFileFromMemoryByForce();
|
| | |
|
| | | //关闭进度条
|
| | | ProgressFormBar.Current.Close();
|
| | |
| | | listReceiptTopic[i] = gatewayID + "/" + listReceiptTopic[i];
|
| | | }
|
| | |
|
| | | //接收数
|
| | | int receiptCount = 0;
|
| | | //蓝才刚整了个同一个主题可能会推送多个过来的机能
|
| | | var listCheckTopic = new HashSet<string>();
|
| | | Action<string, string> receiptAction = (topic, message) =>
|
| | | {
|
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
|
| | |
| | | {
|
| | | if (topic == listReceiptTopic[i])
|
| | | {
|
| | | if (listCheckTopic.Contains(topic) == true)
|
| | | {
|
| | | //这里写这个东西是有点用处的
|
| | | continue;
|
| | | }
|
| | | string deviceMac = jobject["DeviceAddr"].ToString();
|
| | | int deviceEpoint = 200;
|
| | | if (jobject.Property("Epoint") != null)
|
| | |
| | | jobject.Remove("Time");
|
| | | }
|
| | | reResult.JsonData[i] = jobject.ToString();
|
| | | receiptCount++;
|
| | | if (listCheckTopic.Contains(topic) == false)
|
| | | {
|
| | | //加到检测主题对象中
|
| | | listCheckTopic.Add(topic);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | //超时时间
|
| | | int TimeOut = 0;
|
| | | waitTime = 20 * waitTime;
|
| | | while (receiptCount != listReceiptTopic.Count && TimeOut < waitTime)
|
| | | while (listCheckTopic.Count != listReceiptTopic.Count && TimeOut < waitTime)
|
| | | {
|
| | | //全部接收才退出
|
| | | System.Threading.Thread.Sleep(50);
|
| | |
| | | }
|
| | | myGateway.Actions -= receiptAction;
|
| | | receiptAction = null;
|
| | | if (receiptCount != listReceiptTopic.Count)
|
| | | if (listCheckTopic.Count != listReceiptTopic.Count)
|
| | | {
|
| | | reResult.ErrorMsgDiv = 0;
|
| | | }
|
| | |
| | | /// 用来递增生成Mac用的
|
| | | /// </summary>
|
| | | private int DeviceNumber = 0;
|
| | | /// <summary>
|
| | | /// 是否是游客体验
|
| | | /// </summary>
|
| | | public bool IsExperience
|
| | | {
|
| | | get { return Config.Instance.Guid == "chushiGuid"; }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | /// </summary> |
| | | /// <param name="zbGateway">网关</param> |
| | | /// <param name="mode">是否显示错误</param> |
| | | public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode) |
| | | /// <param name="logMode">是否写Log</param> |
| | | public bool AddNewGateway(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO) |
| | | {
|
| | | //设置网关的经纬度
|
| | | bool falge = this.SetGatewaySite(zbGateway, Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude, ShowErrorMode.NO); |
| | | if (falge == false)
|
| | | {
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 设置经纬度失败");
|
| | | }
|
| | | return falge;
|
| | | } |
| | | //执行添加网关到内存 |
| | | var result = this.DoAddGatewayToMemory(zbGateway, mode); |
| | | var result = this.DoAddGatewayToMemory(zbGateway, mode, logMode); |
| | | //前的网关绑定在了当前账号下的不同住宅里面
|
| | | if (result == 0)
|
| | | {
|
| | |
| | | msg = string.Format(msg, "\r\n");
|
| | | }
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 网关绑定在了当前账号下的不同住宅里面,云端不给绑定");
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <param name="mode">是否显示错误</param>
|
| | | /// <param name="logMode">是否写Log</param>
|
| | | /// <returns></returns>
|
| | | private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode)
|
| | | private int DoAddGatewayToMemory(ZbGateway zbGateway, ShowErrorMode mode, WriteLogMode logMode = WriteLogMode.NO)
|
| | | {
|
| | | if (zbGateway == null)
|
| | | {
|
| | |
| | | string msg = Language.StringByID(R.MyInternationalizationString.uGetGatewayInfoFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 获取网关信息失败");
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
|
| | |
| | | //向网关设置住宅ID失败
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uSetHomeIdToGatewayFail);
|
| | | this.ShowTipMsg(msg);
|
| | | }
|
| | | if (logMode == WriteLogMode.YES)
|
| | | {
|
| | | HdlLogLogic.Current.WriteLog(-1, zbGateway.GwIP + " 向网关设置住宅ID失败");
|
| | | }
|
| | | return -1;
|
| | | }
|
| | |
| | | //断开mqtt连接 |
| | | if (realWay != null)
|
| | | {
|
| | | realWay.DisConnectLocalMqttClient("GD");
|
| | | realWay.CloseLocalConnectionOnForce();
|
| | | } |
| | | |
| | | return true; |
| | |
| | | {
|
| | | foreach (var zbway in listGateway)
|
| | | {
|
| | | //是否存在网关存在于WIFI下
|
| | | if (this.CheckGatewayOnlineByFlage(zbway) == true)
|
| | | //如果广播得到网关,则会刷新OnlineTime,如果与当前时间相差少于指定秒数,则判断为存在网关存在于WIFI下
|
| | | if ((DateTime.Now - zbway.OnlineTime).TotalSeconds <= ZigBee.Common.Application.SendTime * 2)
|
| | | {
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | return this.CheckGatewayOnlineByFlage(zbGateway);
|
| | | }
|
| | |
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 刷新网关的在线时间点
|
| | | /// </summary>
|
| | | /// <param name="i_gatewayId">网关ID</param> |
| | | public void RefreshGatewayOnlineTime(string i_gatewayId)
|
| | | {
|
| | | try
|
| | | {
|
| | | if (this.dicGateway.ContainsKey(i_gatewayId) == true)
|
| | | {
|
| | | this.dicGateway[i_gatewayId].OnlineTime = DateTime.Now;
|
| | | }
|
| | | }
|
| | | catch { }
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 根据指定标识,判断网关是否在线
|
| | | /// </summary>
|
| | | /// <param name="zbGateway"></param>
|
| | | /// <returns></returns>
|
| | | /// <returns></returns> |
| | | private bool CheckGatewayOnlineByFlage(ZbGateway zbGateway)
|
| | | {
|
| | | if (this.nowGwConnectMode == GatewayConnectMode.Remote)
|
| | |
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 网关房间相关_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | return this.GetRoomByGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="gatewayId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(string gatewayId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(gatewayId);
|
| | | if (localGateway == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关Id</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(string gwId, string roomId)
|
| | | {
|
| | | var localGateway = this.GetLocalGateway(gwId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | | localGateway.ReSave();
|
| | | //添加备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 清空真实网关链接___________________
|
| | |
|
| | | /// <summary>
|
| | |
| | | //断开mqtt连接(即使保存在内存当中也没问题,因为如果广播不到,则它不会建立链接)
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | | {
|
| | | ZbGateway.GateWayList[i].DisConnectLocalMqttClient("G");
|
| | | ZbGateway.GateWayList[i].CloseLocalConnectionOnForce();
|
| | | }
|
| | | //加载本地网关对象
|
| | | if (roadGateway == true)
|
| | |
| | | /// <summary>
|
| | | /// 重新发送命令去绑定断网情况下备份的网关
|
| | | /// </summary>
|
| | | public void ResetComandToBindBackupGateway()
|
| | | public bool ResetComandToBindBackupGateway()
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData == null)
|
| | | {
|
| | | var fileData = HdlFileLogic.Current.ReadFileByteContent(DirNameResourse.BackupGatewayIdFile);
|
| | | if (fileData == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | var listTempId = new List<string>();
|
| | | listTempId.AddRange(this.listBackupGwId);
|
| | | return true;
|
| | | }
|
| | | this.listBackupGwId = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(System.Text.Encoding.UTF8.GetString(fileData));
|
| | | var listTempId = new List<string>();
|
| | | listTempId.AddRange(this.listBackupGwId);
|
| | |
|
| | | //调用接口,绑定网关
|
| | | var bindGateway = new BindGatewayPra();
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | | //调用接口,绑定网关
|
| | | var bindGateway = new BindGatewayPra();
|
| | | //获取控制主人账号的Token
|
| | | bindGateway.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
|
| | |
|
| | | foreach (var gwId in listTempId)
|
| | | foreach (var gwId in listTempId)
|
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
|
| | | if (result == "Success")
|
| | | {
|
| | | bindGateway.BindGateways.Clear();
|
| | | bindGateway.BindGateways.Add(gwId);
|
| | | var result = UserCenterLogic.GetResultCodeByRequestHttps("App/BindGatewayToHome", true, bindGateway, new List<string> { "NotCheck" }, false);
|
| | | if (result == "Success")
|
| | | {
|
| | | this.listBackupGwId.Remove(gwId);
|
| | | }
|
| | | if (result == "Error")
|
| | | {
|
| | | break;
|
| | | }
|
| | | this.listBackupGwId.Remove(gwId);
|
| | | }
|
| | | if (result == "Error")
|
| | | {
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | if (this.listBackupGwId.Count == 0)
|
| | | if (this.listBackupGwId.Count == 0)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | //如果没有了内容,则删除文件
|
| | | string file = DirNameResourse.BackupGatewayIdFile;
|
| | | if (System.IO.File.Exists(file) == true)
|
| | | {
|
| | | System.IO.File.Delete(file);
|
| | | }
|
| | | System.IO.File.Delete(file);
|
| | | }
|
| | | else
|
| | | {
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | }
|
| | | });
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //备份
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.BackupGatewayIdFile, listBackupGwId);
|
| | | return false;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | if (realWay == null)
|
| | | {
|
| | | //如果网关对象丢失了,则创建个新的
|
| | | realWay = new ZbGateway { IsVirtual = true, };
|
| | | realWay.GwId = i_gatewayId;
|
| | | realWay.HomeId = Config.Instance.HomeId;
|
| | | realWay = new ZbGateway { IsVirtual = true, }; |
| | | realWay.GwId = i_gatewayId; |
| | | realWay.HomeId = Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(realWay);
|
| | | }
|
| | | if (useLocalConnect == false)
|
| | |
| | | private void CheckGatewayStatuByWIFI(Dictionary<string, bool> dicOldOnline)
|
| | | {
|
| | | //从网关获取全部的网关
|
| | | List<ZbGateway> list = this.GetAllGatewayFromGateway();
|
| | | List<ZbGateway> list = this.GetAllLocalGateway();
|
| | |
|
| | | //2020.05.25追加:此住宅是否拥有网关在线
|
| | | var hadGwOnline = false;
|
| | |
| | | /// <param name="msgData">接收的数据</param>
|
| | | public void GatewayOverallMsgReceive(string gatewayId, string topic, string reportTopic, string msgData)
|
| | | {
|
| | | //如果它在登陆界面,则不做任何处理
|
| | | if (Common.Config.Instance.HomeId == string.Empty)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (topic == "AppNoLogin")
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | |
| | | {
|
| | | if (HdlGatewayLogic.Current.IsGatewayExist(gatewayId) == false)
|
| | | {
|
| | | //不是自己绑定的网关,则不处理
|
| | | //不是自己绑定的网关,则不处理,但是下面这个东西有点特殊
|
| | | if (gatewayId == this.GatewayReceiveId)
|
| | | {
|
| | | this.GatewayReceiveEvent?.Invoke(topic, msgData);
|
| | | }
|
| | | return;
|
| | | }
|
| | | //设备属性上报
|
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// GPS的坐标转换逻辑 |
| | | /// </summary> |
| | | public class HdlGpsLocationConvertLogic |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// GPS的坐标转换逻辑 |
| | | /// </summary> |
| | | private static HdlGpsLocationConvertLogic m_Current = null; |
| | | /// <summary> |
| | | /// GPS的坐标转换逻辑 |
| | | /// </summary> |
| | | public static HdlGpsLocationConvertLogic Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new HdlGpsLocationConvertLogic(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | // 保留的小数位数 |
| | | private const string decimals = "f6"; |
| | | |
| | | // 椭球参数-圆周率 |
| | | private const double pi = 3.14159265358979324; |
| | | |
| | | private const double x_pi = pi * 3000.0 / 180.0; |
| | | |
| | | // (北京54)椭球长半轴,卫星椭球坐标投影到平面地图坐标系的投影因子 |
| | | private const double a = 6378245.0; |
| | | /* |
| | | * Krasovsky 1940 (北京54)椭球长半轴第一偏心率平方 |
| | | * 计算方式: |
| | | * 长半轴: |
| | | * a = 6378245.0 |
| | | * 扁率: |
| | | * 1/f = 298.3(变量相关计算为:(a-b)/a) |
| | | * 短半轴: |
| | | * b = 6356863.0188 (变量相关计算方法为:b = a * (1 - f)) |
| | | * 第一偏心率平方: |
| | | * e2 = (a^2 - b^2) / a^2; |
| | | */ |
| | | private const double ee = 0.00669342162296594323; |
| | | // 地球半径 |
| | | private const double earthR = 6371000.0; |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 计算偏差 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="dLng"></param> |
| | | /// <param name="dLat"></param> |
| | | private void CalculateDev(double in_lng, double in_lat, out double dLng, out double dLat) |
| | | { |
| | | dLat = TransformLat(in_lng - 105.0, in_lat - 35.0); |
| | | dLng = TransformLng(in_lng - 105.0, in_lat - 35.0); |
| | | |
| | | double radLat = in_lat / 180.0 * pi; |
| | | double magic = Math.Sin(radLat); |
| | | magic = 1 - ee * magic * magic; |
| | | double sqrtMagic = Math.Sqrt(magic); |
| | | dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); |
| | | dLng = (dLng * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * pi); |
| | | } |
| | | |
| | | #region 高德坐标转WGS84坐标 |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void GCJ02_to_WGS84(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | if (OutOfChina(in_lat, in_lng)) |
| | | { |
| | | out_lng = in_lng; |
| | | out_lat = in_lat; |
| | | return; |
| | | } |
| | | |
| | | CalculateDev(in_lng, in_lat, out out_lng, out out_lat); |
| | | out_lng = in_lng - out_lng; |
| | | out_lat = in_lat - out_lat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] GCJ02_to_WGS84(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | GCJ02_to_WGS84(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] GCJ02_to_WGS84(double[] lnglat) |
| | | { |
| | | return GCJ02_to_WGS84(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] GCJ02_to_WGS84(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | GCJ02_to_WGS84(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] GCJ02_to_WGS84(string[] _lnglat) |
| | | { |
| | | return GCJ02_to_WGS84(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void GCJ02_to_WGS84(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | GCJ02_to_WGS84(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转WGS84坐标 精确(二分极限法) |
| | | /// 默认设置的是精确到小数点后9位,这个值越小,越精确 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | /// <param name="threshold"></param> |
| | | public void GCJ02_to_WGS84_Exact(double in_lng, double in_lat, out double out_lng, out double out_lat, double threshold = 0.000000001) |
| | | { |
| | | double dLng = 0.01, dLat = 0.01; |
| | | double mLng = in_lng - dLng, mLat = in_lat - dLat; |
| | | double pLng = in_lng + dLng, pLat = in_lat + dLat; |
| | | double wgsLng, wgsLat; |
| | | int i = 0; |
| | | |
| | | while (true) |
| | | { |
| | | wgsLng = (mLng + pLng) / 2; |
| | | wgsLat = (mLat + pLat) / 2; |
| | | |
| | | GCJ02_to_WGS84(wgsLat, wgsLng, out out_lng, out out_lat); |
| | | dLng = out_lng - in_lng; |
| | | dLat = out_lat - in_lat; |
| | | |
| | | if ((Math.Abs(dLat) < threshold) && (Math.Abs(dLng) < threshold)) |
| | | break; |
| | | |
| | | if (dLat > 0) |
| | | pLat = wgsLat; |
| | | else |
| | | mLat = wgsLat; |
| | | |
| | | if (dLng > 0) |
| | | pLng = wgsLng; |
| | | else |
| | | mLng = wgsLng; |
| | | |
| | | if (++i > 10000) |
| | | break; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | #region 高德坐标转百度坐标 |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void GCJ02_to_BD09(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | double x = in_lng, y = in_lat; |
| | | double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * x_pi); |
| | | double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * x_pi); |
| | | out_lng = z * Math.Cos(theta) + 0.0065; |
| | | out_lat = z * Math.Sin(theta) + 0.006; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] GCJ02_to_BD09(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | GCJ02_to_BD09(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] GCJ02_to_BD09(double[] lnglat) |
| | | { |
| | | return GCJ02_to_BD09(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] GCJ02_to_BD09(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | GCJ02_to_BD09(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] GCJ02_to_BD09(string[] _lnglat) |
| | | { |
| | | return GCJ02_to_BD09(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 高德坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void GCJ02_to_BD09(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | GCJ02_to_BD09(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 百度坐标转高德坐标 |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void BD09_to_GCJ02(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | double x = in_lng - 0.0065, y = in_lat - 0.006; |
| | | double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * x_pi); |
| | | double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * x_pi); |
| | | out_lng = z * Math.Cos(theta); |
| | | out_lat = z * Math.Sin(theta); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] BD09_to_GCJ02(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | BD09_to_GCJ02(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] BD09_to_GCJ02(double[] lnglat) |
| | | { |
| | | return BD09_to_GCJ02(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] BD09_to_GCJ02(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | BD09_to_GCJ02(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] BD09_to_GCJ02(string[] _lnglat) |
| | | { |
| | | return BD09_to_GCJ02(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 百度坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void BD09_to_GCJ02(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | BD09_to_GCJ02(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | #endregion |
| | | |
| | | #region 百度坐标转WGS84坐标 |
| | | /// <summary> |
| | | /// 百度坐标转WGS84坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void BD09_to_WGS84(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | BD09_to_GCJ02(in_lng, in_lat, out out_lng, out out_lat); |
| | | GCJ02_to_WGS84(out_lng, out_lat, out out_lng, out out_lat); |
| | | } |
| | | #endregion |
| | | |
| | | #region WGS-84 to Web mercator |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_Mercator(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | out_lng = in_lng * 20037508.34 / 180.0; |
| | | double y = Math.Log(Math.Tan((90.0 + in_lat) * pi / 360.0)) / (pi / 180.0); |
| | | out_lat = y * 20037508.34 / 180.0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] WGS84_to_Mercator(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | WGS84_to_Mercator(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] WGS84_to_Mercator(double[] lnglat) |
| | | { |
| | | return WGS84_to_Mercator(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] WGS84_to_Mercator(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | WGS84_to_Mercator(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] WGS84_to_Mercator(string[] _lnglat) |
| | | { |
| | | return WGS84_to_Mercator(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS-84 to Web mercator |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_Mercator(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | WGS84_to_Mercator(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | #endregion |
| | | |
| | | #region Web mercator to WGS-84 |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void Mercator_to_WGS84(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | out_lng = in_lng / 20037508.34 * 180.0; |
| | | double y = in_lat / 20037508.34 * 180.0; |
| | | out_lat = 180.0 / pi * (2 * Math.Atan(Math.Exp(y * pi / 180.0)) - pi / 2); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] Mercator_to_WGS84(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | Mercator_to_WGS84(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] Mercator_to_WGS84(double[] lnglat) |
| | | { |
| | | return Mercator_to_WGS84(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] Mercator_to_WGS84(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | Mercator_to_WGS84(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] Mercator_to_WGS84(string[] _lnglat) |
| | | { |
| | | return Mercator_to_WGS84(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// Web mercator to WGS-84 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void Mercator_to_WGS84(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | Mercator_to_WGS84(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | #endregion |
| | | |
| | | #region WGS84坐标转高德坐标 |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_GCJ02(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | if (OutOfChina(in_lat, in_lng)) |
| | | { |
| | | out_lng = in_lng; |
| | | out_lat = in_lat; |
| | | return; |
| | | } |
| | | |
| | | CalculateDev(in_lng, in_lat, out out_lng, out out_lat); |
| | | out_lng = in_lng + out_lng; |
| | | out_lat = in_lat + out_lat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | public double[] WGS84_to_GCJ02(double lng, double lat) |
| | | { |
| | | double[] lnglat = new double[2]; |
| | | WGS84_to_GCJ02(lng, lat, out lnglat[0], out lnglat[1]); |
| | | return lnglat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lnglat"></param> |
| | | /// <returns></returns> |
| | | public double[] WGS84_to_GCJ02(double[] lnglat) |
| | | { |
| | | return WGS84_to_GCJ02(lnglat[0], lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="lng"></param> |
| | | /// <param name="lat"></param> |
| | | /// <returns></returns> |
| | | public string[] WGS84_to_GCJ02(string lng, string lat) |
| | | { |
| | | double _lng, _lat; |
| | | WGS84_to_GCJ02(ToDouble(lng), ToDouble(lat), out _lng, out _lat); |
| | | return new string[] { _lng.ToString(decimals), _lat.ToString(decimals) }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="_lnglat"></param> |
| | | /// <returns></returns> |
| | | public string[] WGS84_to_GCJ02(string[] _lnglat) |
| | | { |
| | | return WGS84_to_GCJ02(_lnglat[0], _lnglat[1]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// WGS84坐标转高德坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_GCJ02(string in_lng, string in_lat, out string out_lng, out string out_lat) |
| | | { |
| | | double _lng, _lat; |
| | | WGS84_to_GCJ02(ToDouble(in_lng), ToDouble(in_lat), out _lng, out _lat); |
| | | out_lng = _lng.ToString(decimals); |
| | | out_lat = _lat.ToString(decimals); |
| | | } |
| | | #endregion |
| | | |
| | | #region WGS84坐标转百度坐标 |
| | | /// <summary> |
| | | /// WGS84坐标转百度坐标 |
| | | /// </summary> |
| | | /// <param name="in_lng"></param> |
| | | /// <param name="in_lat"></param> |
| | | /// <param name="out_lng"></param> |
| | | /// <param name="out_lat"></param> |
| | | public void WGS84_to_BD09(double in_lng, double in_lat, out double out_lng, out double out_lat) |
| | | { |
| | | WGS84_to_GCJ02(in_lng, in_lat, out out_lng, out out_lat); |
| | | GCJ02_to_BD09(out_lng, out_lat, out out_lng, out out_lat); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 两点直接的距离 |
| | | /// </summary> |
| | | public double GetDistance(double latA, double lonA, double latB, double lonB) |
| | | { |
| | | double x = Math.Cos(latA * pi / 180.0) * Math.Cos(latB * pi / 180.0) * Math.Cos((lonA - lonB) * pi / 180.0); |
| | | double y = Math.Sin(latA * pi / 180.0) * Math.Sin(latB * pi / 180.0); |
| | | double s = x + y; |
| | | if (s > 1) s = 1; |
| | | if (s < -1) s = -1; |
| | | double alpha = Math.Acos(s); |
| | | double distance = alpha * earthR; |
| | | return distance; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 坐标是否在中国境内 |
| | | /// </summary> |
| | | /// <param name="lat"></param> |
| | | /// <param name="lng"></param> |
| | | /// <returns></returns> |
| | | public bool OutOfChina(double lat, double lng) |
| | | { |
| | | if (lng < 72.004 || lng > 137.8347) |
| | | return true; |
| | | if (lat < 0.8293 || lat > 55.8271) |
| | | return true; |
| | | return false; |
| | | } |
| | | |
| | | private double TransformLat(double x, double y) |
| | | { |
| | | double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x)); |
| | | ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.Sin(y * pi) + 40.0 * Math.Sin(y / 3.0 * pi)) * 2.0 / 3.0; |
| | | ret += (160.0 * Math.Sin(y / 12.0 * pi) + 320 * Math.Sin(y * pi / 30.0)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | |
| | | private double TransformLng(double x, double y) |
| | | { |
| | | double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x)); |
| | | ret += (20.0 * Math.Sin(6.0 * x * pi) + 20.0 * Math.Sin(2.0 * x * pi)) * 2.0 / 3.0; |
| | | ret += (20.0 * Math.Sin(x * pi) + 40.0 * Math.Sin(x / 3.0 * pi)) * 2.0 / 3.0; |
| | | ret += (150.0 * Math.Sin(x / 12.0 * pi) + 300.0 * Math.Sin(x / 30.0 * pi)) * 2.0 / 3.0; |
| | | return ret; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将string转换为十进制双精度数,如果格式错误将转换失败并返回默认值 |
| | | /// </summary> |
| | | /// <param name="str"></param> |
| | | /// <returns></returns> |
| | | private double ToDouble(string str, double defaultValue = default) |
| | | { |
| | | if (double.TryParse(str, out double result)) |
| | | { |
| | | return result; |
| | | } |
| | | |
| | | return defaultValue; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Net; |
| | | using System.Text; |
| | | |
| | | namespace Shared.Phone.UserCenter |
| | | { |
| | | /// <summary> |
| | | /// Http访问逻辑 |
| | | /// </summary> |
| | | public class HdlHttpLogic |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// Http访问逻辑 |
| | | /// </summary> |
| | | private static HdlHttpLogic m_Current = null; |
| | | /// <summary> |
| | | /// Http访问逻辑 |
| | | /// </summary> |
| | | public static HdlHttpLogic Current |
| | | { |
| | | get |
| | | { |
| | | if (m_Current == null) |
| | | { |
| | | m_Current = new HdlHttpLogic(); |
| | | } |
| | | return m_Current; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 第三方接口访问_____________________ |
| | | |
| | | /// <summary> |
| | | /// 第三方接口访问 |
| | | /// </summary> |
| | | /// <param name="requestFullUrl">请求Url的完成路径</param> |
| | | /// <param name="contentType">text/html 或者 application/json</param> |
| | | /// <param name="requestMethod">POST 或者 GET 等等</param> |
| | | /// <param name="timeout">超时,默认5秒</param> |
| | | /// <returns>得到响应的数据</returns> |
| | | public byte[] RequestThridPartyHttps(string requestFullUrl, string contentType = "text/html", string requestMethod = "GET", int timeout = 5) |
| | | { |
| | | try |
| | | { |
| | | //初始化新的webRequst |
| | | //1. 创建httpWebRequest对象 |
| | | var webRequest = (HttpWebRequest)WebRequest.Create(new Uri(requestFullUrl)); |
| | | |
| | | //2. 初始化HttpWebRequest对象 |
| | | webRequest.Method = requestMethod; |
| | | webRequest.Timeout = timeout * 1000; |
| | | //取消使用代理访问 |
| | | webRequest.Proxy = null; |
| | | webRequest.UseDefaultCredentials = false; |
| | | webRequest.ContentType = contentType; |
| | | |
| | | //4. 读取服务器的返回信息 |
| | | var response = (HttpWebResponse)webRequest.GetResponse(); |
| | | using (var stream = response.GetResponseStream()) |
| | | { |
| | | if (stream == null) |
| | | { |
| | | return null; |
| | | } |
| | | var ms = new System.IO.MemoryStream(); |
| | | var bytes = new byte[1024]; |
| | | var len = int.MaxValue; |
| | | while (stream.CanRead && 0 < len) |
| | | { |
| | | len = stream.Read(bytes, 0, bytes.Length); |
| | | ms.Write(bytes, 0, len); |
| | | } |
| | | return ms.ToArray(); |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | |
| | | /// 所有的房间信息
|
| | | /// </summary>
|
| | | private Dictionary<string, Room> dicRooms = new Dictionary<string, Room>();
|
| | | /// <summary>
|
| | | /// 物理设备属于哪个房间的记录
|
| | | /// </summary>
|
| | | private Dictionary<string, string> dicDeviceRoomId = null;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | | HdlAutoBackupLogic.DeleteFile(roomFilePath);
|
| | |
|
| | | //根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | Common.LocalDevice.Current.DeleteRealDeviceByRoomId(roomId);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceByRoomId(roomId);
|
| | | if (refreshLeftView == true)
|
| | | {
|
| | | //刷新房间视图列表
|
| | |
| | | return listRoom;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="zbGateway">网关对象</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(ZbGateway zbGateway)
|
| | | {
|
| | | return this.GetRoomByGateway(zbGateway.GwId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取网关所在的房间
|
| | | /// </summary>
|
| | | /// <param name="gatewayId">网关ID</param>
|
| | | /// <returns></returns>
|
| | | public Room GetRoomByGateway(string gatewayId)
|
| | | {
|
| | | var localGateway = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
|
| | | if (localGateway == null)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(localGateway.RoomId);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 变更网关房间
|
| | | /// </summary>
|
| | | /// <param name="gwId">网关Id</param>
|
| | | /// <param name="roomId">房间ID</param>
|
| | | public void ChangedGatewayRoom(string gwId, string roomId)
|
| | | {
|
| | | var localGateway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
|
| | | if (localGateway != null)
|
| | | {
|
| | | localGateway.RoomId = roomId;
|
| | | localGateway.ReSave();
|
| | | //添加备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(localGateway.FilePath);
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | |
|
| | | #region ■ 物理设备所属房间___________________
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化物理设备所属房间的记录
|
| | | /// </summary>
|
| | | public void InitRealDeviceRoomId()
|
| | | {
|
| | | this.dicDeviceRoomId = new Dictionary<string, string>();
|
| | | string fullName = DirNameResourse.DeviceRoomIdFile;
|
| | | var strData = HdlFileLogic.Current.ReadFileTextContent(fullName);
|
| | | if (strData != null)
|
| | | {
|
| | | this.dicDeviceRoomId = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取全部物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | public Dictionary<string, string> GetAllRealDeviceRoomData()
|
| | | {
|
| | | return this.dicDeviceRoomId;
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 保存物理设备所属房间的记录
|
| | | /// </summary>
|
| | | /// <param name="listDevice">需要保存的设备对象</param>
|
| | | /// <param name="roomId">需要保存的哪个设备的房间ID</param>
|
| | | /// <param name="saveRoadDevice">如果只有一个回路,是否把回路的房间一起修改</param>
|
| | | public void SaveRealDeviceRoomId(List<CommonDevice> listDevice, string roomId, bool saveRoadDevice = true)
|
| | | {
|
| | | if (listDevice == null || listDevice.Count == 0)
|
| | | {
|
| | | return;
|
| | | }
|
| | | //如果设备只有一个回路,如果改变了真实设备区域,则它的回路的区域也一起改了
|
| | | if (saveRoadDevice == true && listDevice.Count == 1)
|
| | | {
|
| | | if ((listDevice[0] is OTADevice) == false)
|
| | | {
|
| | | //ota设备不需要处理
|
| | | HdlRoomLogic.Current.ChangedRoom(listDevice[0], roomId, false);
|
| | | }
|
| | | }
|
| | | bool save = false;
|
| | | if (roomId == string.Empty)
|
| | | {
|
| | | //选择的是未分配
|
| | | this.dicDeviceRoomId.Remove(listDevice[0].DeviceAddr);
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(listDevice[0].DeviceAddr) == false)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | //2020.05.18追加:如果记录的房间ID是不存在的话,则重新覆盖
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[listDevice[0].DeviceAddr]);
|
| | | if (room == null || this.dicDeviceRoomId[listDevice[0].DeviceAddr] != roomId)
|
| | | {
|
| | | this.dicDeviceRoomId[listDevice[0].DeviceAddr] = roomId;
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (save == true)
|
| | | {
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备的房间名字
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public string GeteRealDeviceRoomName(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | //未分配区域
|
| | | return Language.StringByID(R.MyInternationalizationString.uDeviceNotAssignedRoom);
|
| | | }
|
| | | var room = HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | return HdlRoomLogic.Current.GetRoomName(room);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 获取真实物理设备属于哪个房间
|
| | | /// </summary>
|
| | | /// <param name="device">设备的某一个回路</param>
|
| | | /// <returns></returns>
|
| | | public Room GeteRealDeviceRoom(CommonDevice device)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(device.DeviceAddr) == false)
|
| | | {
|
| | | return null;
|
| | | }
|
| | | return HdlRoomLogic.Current.GetRoomById(this.dicDeviceRoomId[device.DeviceAddr]);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="device">随便一个回路</param>
|
| | | public void DeleteRealDeviceFromRoom(CommonDevice device)
|
| | | {
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(new List<string>() { device.DeviceAddr });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 将真实物理设备从房间中移除
|
| | | /// </summary>
|
| | | /// <param name="listMac">设备Mac地址</param>
|
| | | public void DeleteRealDeviceFromRoom(List<string> listMac)
|
| | | {
|
| | | bool save = false;
|
| | | foreach (var deviceMacAddr in listMac)
|
| | | {
|
| | | if (this.dicDeviceRoomId.ContainsKey(deviceMacAddr) == true)
|
| | | {
|
| | | this.dicDeviceRoomId.Remove(deviceMacAddr);
|
| | | save = true;
|
| | | }
|
| | | }
|
| | | if (save == false)
|
| | | {
|
| | | //没有改变,不需要保存
|
| | | return;
|
| | | }
|
| | | //保存记录
|
| | | HdlFileLogic.Current.SaveFileContent(DirNameResourse.DeviceRoomIdFile, this.dicDeviceRoomId);
|
| | |
|
| | | //添加自动备份
|
| | | HdlAutoBackupLogic.AddOrEditorFile(DirNameResourse.DeviceRoomIdFile);
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 根据房间ID,移除指定的真实物理设备的所属房间记录
|
| | | /// </summary>
|
| | | /// <param name="i_RoomId"></param>
|
| | | public void DeleteRealDeviceByRoomId(string i_RoomId)
|
| | | {
|
| | | var listDeleteKey = new List<string>();
|
| | | foreach (var deviceAddr in this.dicDeviceRoomId.Keys)
|
| | | {
|
| | | if (this.dicDeviceRoomId[deviceAddr] == i_RoomId
|
| | | && listDeleteKey.Contains(deviceAddr) == false)
|
| | | {
|
| | | listDeleteKey.Add(deviceAddr);
|
| | | }
|
| | | }
|
| | | //将真实物理设备从房间中移除
|
| | | this.DeleteRealDeviceFromRoom(listDeleteKey);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region ■ 房间方法___________________________
|
| | |
| | | if (i_room.IsLove == false && saveRealRoom == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //如果只有一个回路,则修改真实物理设备的房间
|
| | | LocalDevice.Current.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, i_room.Id, false);
|
| | | this.SaveRealDeviceRoomId(new List<CommonDevice>() { device }, i_room.Id, false);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | if (deleteReal == true && LocalDevice.Current.GetDevicesCountByMac(device.DeviceAddr) == 1)
|
| | | {
|
| | | //删除掉它的真实物理设备的所在位置
|
| | | LocalDevice.Current.DeleteRealDeviceFromRoom(device);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(device);
|
| | | }
|
| | |
|
| | | //根据设备,获取所在的房间
|
| | |
| | | var houseInfo = new AreaSpaceInfo();
|
| | | houseInfo.name = Common.Config.Instance.Home.Name;
|
| | | houseInfo.uid = Common.Config.Instance.Home.Id;
|
| | | houseInfo.parentId = "null";
|
| | | houseInfo.parentId = null;
|
| | | listAreaSpaceInfo.Add(houseInfo);
|
| | | //然后添加楼层
|
| | | foreach (var floorId in Common.Config.Instance.Home.FloorDics.Keys)
|
| | |
| | | gatewayInfo.uid = "000101" + gwMac.Substring(2) + "07";
|
| | | gatewayInfo.name = HdlGatewayLogic.Current.GetGatewayName(loaclGateway);
|
| | |
|
| | | var roomGateway = HdlGatewayLogic.Current.GetRoomByGateway(loaclGateway);
|
| | | var roomGateway = HdlRoomLogic.Current.GetRoomByGateway(loaclGateway);
|
| | | if (roomGateway != null)
|
| | | {
|
| | | gatewayInfo.parentId = roomGateway.Id;
|
| | |
| | | {
|
| | | //创建文件对象
|
| | | var result0 = await realMain.CreateFileAsync("DeviceRoomInfo.json");
|
| | | if (result0 == null || result0.Result != 0)
|
| | | if (result0 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result0.Result != 0 && result0.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | | //发送数据流
|
| | |
| | |
|
| | | //创建文件对象
|
| | | var result3 = await realMain.CreateFileAsync("space.json");
|
| | | if (result3 == null || result3.Result != 0)
|
| | | if (result3 == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (result3.Result != 0 && result3.Result != 2)
|
| | | {
|
| | | //如果是2,允许上传
|
| | | return;
|
| | | }
|
| | |
|
| | | //发送区域信息
|
| | | var byteData2 = ASCIIEncoding.UTF8.GetBytes(strSendRoomInfo);
|
| | |
| | | //断掉本地连接
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
|
| | | //断掉远程
|
| | | ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | |
|
| | | //如果是wifi
|
| | | if (value == 2)
|
| | |
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | | }
|
| | |
|
| | |
| | | //断开远程Mqtt连接
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | |
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | HdlGatewayLogic.Current.ClearAllRealGatewayConection(true);
|
| | | await ZigBee.Device.ZbGateway.DisConnectRemoteMqttClient();
|
| | | await ZigBee.Device.ZbGateway.CloseRemoteConnectionOnForce();
|
| | | }, ShowErrorMode.NO);
|
| | |
|
| | | //刷新APP前一次选择的网关ID(可以反复调用,需要在网关初始化完了之后才能调用)
|
| | |
| | | }
|
| | | }
|
| | | //保存设备房间索引
|
| | | Common.LocalDevice.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys);
|
| | | HdlRoomLogic.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys);
|
| | | };
|
| | |
|
| | | //更多配置
|
| | |
| | | HdlRoomLogic.Current.DeleteDevice(device);
|
| | | HdlRoomLogic.Current.DeleteLoveDevice(device);
|
| | | }
|
| | | Common.LocalDevice.Current.DeleteRealDeviceFromRoom(this.listNewDevice[0]);
|
| | | HdlRoomLogic.Current.DeleteRealDeviceFromRoom(this.listNewDevice[0]);
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | var rowSerial = new FrameRowControl(listView.rowSpace / 2);
|
| | | rowSerial.UseClickStatu = false; |
| | | listView.AddChidren(rowSerial); |
| | | rowSerial.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSerialNumber), 400); |
| | | rowSerial.AddMostRightView(listDevice[0].SerialNumber != string.Empty ? listDevice[0].SerialNumber : listDevice[0].DeviceAddr, 600); |
| | | rowSerial.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uSerialNumber), 400);
|
| | | if (Common.LocalDevice.Current.IsHdlDevice(listDevice[0]) == false)
|
| | | {
|
| | | //第三方设备固定使用Mac
|
| | | rowSerial.AddMostRightView(listDevice[0].DeviceAddr, 600);
|
| | | } |
| | | else
|
| | | {
|
| | | rowSerial.AddMostRightView(listDevice[0].SerialNumber != string.Empty ? listDevice[0].SerialNumber : listDevice[0].DeviceAddr, 600);
|
| | | } |
| | | rowSerial.AddBottomLine();
|
| | |
|
| | | //MAC
|
| | |
| | | /// </summary>
|
| | | private NormalViewControl btnName = null;
|
| | | /// <summary>
|
| | | /// 在线状态
|
| | | /// 在线状态(初始状态为在线)
|
| | | /// </summary>
|
| | | public bool isOnline = false;
|
| | | public bool isOnline = true;
|
| | |
|
| | | /// <summary>
|
| | | /// 自定义网关控件
|
| | |
| | | {
|
| | | btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
|
| | | //在线状态
|
| | | this.isOnline = HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(zbway);
|
| | | if (this.isOnline == false)
|
| | | {
|
| | | btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | }
|
| | | //this.isOnline = HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(zbway);
|
| | | //if (this.isOnline == false)
|
| | | //{
|
| | | // btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | //}
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | }
|
| | | }
|
| | | //保存设备房间索引
|
| | | Common.LocalDevice.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys);
|
| | | HdlRoomLogic.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys);
|
| | | };
|
| | |
|
| | | //添加全部菜单
|
| | |
| | |
|
| | | //初始化中部控件
|
| | | this.InitMiddleFrame();
|
| | | |
| | |
|
| | | this.zbGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId); |
| | | } |
| | | |
| | |
| | | rowThrid.ButtonClickEvent += (sender, e) => |
| | | {
|
| | | rowThrid.CanClick = false;
|
| | | HdlThreadLogic.Current.RunThread(() => |
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //检测网关
|
| | | var errorMsg = this.CheckGateway();
|
| | | HdlThreadLogic.Current.RunMain(() => |
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | rowThrid.CanClick = true; |
| | | if (errorMsg != null) |
| | | { |
| | | this.ShowMassage(ShowMsgType.Tip, errorMsg); |
| | | } |
| | | else |
| | | { |
| | | var form = new Device.DeviceSearchForm(); |
| | | form.AddForm(string.Empty); |
| | | } |
| | | }); |
| | | rowThrid.CanClick = true;
|
| | | if (errorMsg != null)
|
| | | {
|
| | | this.ShowMassage(ShowMsgType.Tip, errorMsg);
|
| | | }
|
| | | else
|
| | | {
|
| | | var form = new Device.DeviceSearchForm();
|
| | | form.AddForm(string.Empty);
|
| | | }
|
| | | });
|
| | | }); |
| | | }; |
| | | |
| | |
| | | /// </summary> |
| | | private string CheckGateway()
|
| | | {
|
| | | if (zbGateway != null && zbGateway.LinuxImageType == 11) |
| | | { |
| | | if (zbGateway != null && zbGateway.LinuxImageType == 11)
|
| | | {
|
| | | //mini夜灯只能限制加入16和设备
|
| | | this.ShowProgressBar();
|
| | |
|
| | |
| | | var listDevice = Common.LocalDevice.Current.GetDeviceListFromGateway(zbGateway.GwId, ref statu, true, ShowErrorMode.NO);
|
| | | if (statu != 1)
|
| | | {
|
| | | //如果 |
| | | //如果
|
| | | listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGateway.GwId);
|
| | | }
|
| | | //检测mini网关的设备数
|
| | |
| | | listMac.Add(device.DeviceAddr);
|
| | | }
|
| | | }
|
| | | this.CloseProgressBar(); |
| | | |
| | | this.CloseProgressBar();
|
| | |
|
| | | bool canAdd = listMac.Count < 16;
|
| | | if (canAdd == false) |
| | | { |
| | | //Mini网关最大只能添加16个设备 |
| | | return Language.StringByID(R.MyInternationalizationString.uMiniGatewayMaxDeviceCountMsg); |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | if (canAdd == false)
|
| | | {
|
| | | //Mini网关最大只能添加16个设备
|
| | | return Language.StringByID(R.MyInternationalizationString.uMiniGatewayMaxDeviceCountMsg);
|
| | | }
|
| | | }
|
| | |
|
| | | return null;
|
| | | } |
| | | |
| | | #endregion |
| | |
| | | if (formName != string.Empty) |
| | | { |
| | | rowLayout.ButtonClickEvent += (sender, e) => |
| | | { |
| | | {
|
| | | rowLayout.CanClick = false;
|
| | | HdlThreadLogic.Current.RunThread(() => |
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //检测网关
|
| | | var errorMsg = this.CheckGateway();
|
| | | HdlThreadLogic.Current.RunMain(() => |
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | | {
|
| | | rowLayout.CanClick = true; |
| | | if (errorMsg != null) |
| | | { |
| | | this.ShowMassage(ShowMsgType.Tip, errorMsg); |
| | | } |
| | | else |
| | | { |
| | | //反射目标界面 |
| | | this.LoadFormByFullName("Shared.Phone.UserCenter.DeviceDirection." + formName); |
| | | } |
| | | }); |
| | | rowLayout.CanClick = true;
|
| | | if (errorMsg != null)
|
| | | {
|
| | | this.ShowMassage(ShowMsgType.Tip, errorMsg);
|
| | | }
|
| | | else
|
| | | {
|
| | | //反射目标界面
|
| | | this.LoadFormByFullName("Shared.Phone.UserCenter.DeviceDirection." + formName);
|
| | | }
|
| | | });
|
| | | }); |
| | | }; |
| | | } |
| | |
| | | //设备备注 |
| | | string caption = Language.StringByID(R.MyInternationalizationString.DeviceRemarkXm); |
| | | string deviceName = Common.LocalDevice.Current.GetDeviceMacName(doorLock); |
| | | var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2); |
| | | var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
|
| | | btnNote.txtInput.MaxByte = 48;//限制只能输入48个字节 |
| | | listview.AddChidren(btnNote); |
| | | btnNote.InitControl(); |
| | |
| | | } |
| | | } |
| | | //保存设备房间索引 |
| | | Common.LocalDevice.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys); |
| | | HdlRoomLogic.Current.SaveRealDeviceRoomId(this.listNewDevice, roomKeys); |
| | | }; |
| | | |
| | | //设备模块 |
| | |
| | | {
|
| | | var way = ZbGateway.GateWayList[i];
|
| | | var wayId = way.GwId;
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true || way.localIsConnected == false)
|
| | |
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true)
|
| | | {
|
| | | //已经处理了
|
| | | continue;
|
| | | }
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (way.localIsConnected == false)
|
| | | {
|
| | | string strMsg = "搜索到了网关,但是本地链接不上 ID:" + way.GwId + " IP:" + way.GwIP + " 名称:" + way.GwName;
|
| | | HdlLogLogic.Current.WriteLog(-1, strMsg);
|
| | | continue;
|
| | | }
|
| | |
|
| | |
| | | if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
|
| | | {
|
| | | //添加搜索到的网关到缓存(执行网关保存操作)
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO, WriteLogMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | continue;
|
| | |
| | | for (int i = 0; i < listId.Count; i++)
|
| | | {
|
| | | ZbGateway way = ZbGateway.GateWayList.Find((obj) => obj.GwId == listId[i]);
|
| | | if (way == null || way.localIsConnected == false)
|
| | | if (way == null)
|
| | | {
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | continue;
|
| | | }
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (way.localIsConnected == false)
|
| | | {
|
| | | string strMsg = "搜索到了网关,但是本地链接不上 ID:" + way.GwId + " IP:" + way.GwIP + " 名称:" + way.GwName;
|
| | | HdlLogLogic.Current.WriteLog(-1, strMsg);
|
| | | continue;
|
| | | }
|
| | |
|
| | |
| | | if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
|
| | | {
|
| | | //添加搜索到的网关到缓存(执行网关保存操作)
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO, WriteLogMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | continue;
|
| | |
| | | {
|
| | | var way = ZbGateway.GateWayList[i];
|
| | | var wayId = way.GwId;
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true || way.localIsConnected == false)
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true)
|
| | | {
|
| | | //已经处理了
|
| | | continue;
|
| | | }
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (way.localIsConnected == false)
|
| | | {
|
| | | string strMsg = "搜索到了网关,但是本地链接不上 ID:" + way.GwId + " IP:" + way.GwIP + " 名称:" + way.GwName;
|
| | | HdlLogLogic.Current.WriteLog(-1, strMsg);
|
| | | continue;
|
| | | }
|
| | |
|
| | |
| | | if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
|
| | | {
|
| | | //添加搜索到的网关到缓存(执行网关保存操作)
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO, WriteLogMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | continue;
|
| | |
| | | {
|
| | | var way = ZbGateway.GateWayList[i];
|
| | | var wayId = way.GwId;
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true || way.localIsConnected == false)
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true)
|
| | | {
|
| | | //已经处理了
|
| | | continue;
|
| | | }
|
| | | //2020.09.18 本地连接没有连接上,则不处理
|
| | | if (way.localIsConnected == false)
|
| | | {
|
| | | string strMsg = "搜索到了网关,但是本地链接不上 ID:" + way.GwId + " IP:" + way.GwIP + " 名称:" + way.GwName;
|
| | | HdlLogLogic.Current.WriteLog(-1, strMsg);
|
| | | continue;
|
| | | }
|
| | |
|
| | |
| | | if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
|
| | | {
|
| | | //添加搜索到的网关到缓存(执行网关保存操作)
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
|
| | | var result = HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO, WriteLogMode.YES);
|
| | | if (result == false)
|
| | | {
|
| | | continue;
|
| | |
| | | string caption = Language.StringByID(R.MyInternationalizationString.uDeviceNote);
|
| | | string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
|
| | | var btnNote = new FrameCaptionInputControl(caption, nameValue, listview.rowSpace / 2);
|
| | | btnNote.txtInput.MaxByte = 48;//限制只能输入48个字节
|
| | | btnNote.txtInput.MaxByte = 32;//限制只能输入32个字节
|
| | | listview.AddChidren(btnNote);
|
| | | btnNote.InitControl();
|
| | | //划线
|
| | |
| | | rowBeloneArea.SelectRoomEvent += (roomKeys) =>
|
| | | {
|
| | | //变更网关房间
|
| | | HdlGatewayLogic.Current.ChangedGatewayRoom(this.zbGateway.GwId, roomKeys);
|
| | | HdlRoomLogic.Current.ChangedGatewayRoom(this.zbGateway.GwId, roomKeys);
|
| | | };
|
| | | //如果是展示模板的话,不能编辑
|
| | | if (Common.Config.Instance.Home.IsShowTemplate == true)
|
| | |
| | | /// </summary>
|
| | | private void ShowTopRightMenu()
|
| | | {
|
| | | bool flage = UserCenterResourse.DicActionForm.ContainsKey("NewGateWayMenuSelectForm");
|
| | | var frame = new TopRightMenuControl(flage == true ? 1 : 3, 1);
|
| | | //搜索网关的时候,不能删除,不给他切换,只有定位功能
|
| | | bool isSearchGw = UserCenterResourse.DicActionForm.ContainsKey("NewGateWayMenuSelectForm");
|
| | | int menuCount = isSearchGw == true ? 1 : 3;
|
| | |
|
| | | bool canAddReplaceMenu = false;
|
| | | //获取本地网关
|
| | | var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
|
| | | foreach (var gw in listGateway)
|
| | | {
|
| | | if (gw.GwId != this.zbGateway.GwId && gw.LinuxImageType == this.zbGateway.LinuxImageType)
|
| | | {
|
| | | //如果是同一种类型的网关,允许出现替换菜单
|
| | | canAddReplaceMenu = true;
|
| | | break;
|
| | | }
|
| | | }
|
| | | if (canAddReplaceMenu == true
|
| | | && Common.Config.Instance.Home.IsShowTemplate == false
|
| | | && Common.Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | //menuCount++;
|
| | | }
|
| | | var frame = new TopRightMenuControl(menuCount, 1);
|
| | | //定位
|
| | | string MenuName = Language.StringByID(R.MyInternationalizationString.uFixedPosition);
|
| | | frame.AddRowMenu(MenuName, "Item/FixedPosition.png", "Item/FixedPositionSelected.png", () =>
|
| | |
| | | //发送定位功能
|
| | | HdlGatewayLogic.Current.SetFixedPositionCommand(zbGateway);
|
| | | });
|
| | | if (flage == true)
|
| | | {
|
| | | //搜索网关的时候,不能删除,不给他切换
|
| | | return;
|
| | | }
|
| | |
|
| | | //切换
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uSwitch1);
|
| | | string strWayId = this.zbGateway.GwId;
|
| | | if (strWayId == GatewayResourse.AppOldSelectGatewayId)
|
| | | //搜索网关的时候,不能删除,不给他切换
|
| | | if (isSearchGw == false)
|
| | | {
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uRefresh);
|
| | | }
|
| | | frame.AddRowMenu(MenuName, "Item/GwSwitchIcon.png", "Item/GwSwitchIconSelected.png", () =>
|
| | | {
|
| | | string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
|
| | | //是否切换到{0}网关?
|
| | | string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + nameValue + "]");
|
| | | //切换
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uSwitch1);
|
| | | string strWayId = this.zbGateway.GwId;
|
| | | if (strWayId == GatewayResourse.AppOldSelectGatewayId)
|
| | | {
|
| | | //是否重新刷新{0}网关?
|
| | | msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + nameValue + "]");
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uRefresh);
|
| | | }
|
| | | this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
| | | frame.AddRowMenu(MenuName, "Item/GwSwitchIcon.png", "Item/GwSwitchIconSelected.png", () =>
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
|
| | | //是否切换到{0}网关?
|
| | | string msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToSwitchTheGateway), "[" + nameValue + "]");
|
| | | if (strWayId == GatewayResourse.AppOldSelectGatewayId)
|
| | | {
|
| | | //执行切换网关操作
|
| | | this.DoSwitchGateway();
|
| | | //是否重新刷新{0}网关?
|
| | | msg = string.Format(Language.StringByID(R.MyInternationalizationString.uConfirmWantToRefreshTheGateway), "[" + nameValue + "]");
|
| | | }
|
| | | this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //执行切换网关操作
|
| | | this.DoSwitchGateway();
|
| | | });
|
| | | });
|
| | | });
|
| | | });
|
| | | //删除
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uDelete);
|
| | | frame.AddRowMenu(MenuName, "Item/DeleteIcon2.png", "Item/DeleteIcon2Selected.png", () =>
|
| | | {
|
| | | //如移除网关,该网关绑定的设备列表{0}将清空,确认继续执行该操作?
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uUnBindedMsg);
|
| | | if (msg.Contains("{0}") == true)
|
| | | //删除
|
| | | MenuName = Language.StringByID(R.MyInternationalizationString.uDelete);
|
| | | frame.AddRowMenu(MenuName, "Item/DeleteIcon2.png", "Item/DeleteIcon2Selected.png", () =>
|
| | | {
|
| | | msg = string.Format(msg, "\r\n");
|
| | | }
|
| | | this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
| | | {
|
| | | this.DeleteGateway(strWayId);
|
| | | //如移除网关,该网关绑定的设备列表{0}将清空,确认继续执行该操作?
|
| | | string msg = Language.StringByID(R.MyInternationalizationString.uUnBindedMsg);
|
| | | if (msg.Contains("{0}") == true)
|
| | | {
|
| | | msg = string.Format(msg, "\r\n");
|
| | | }
|
| | | this.ShowMassage(ShowMsgType.Confirm, msg, () =>
|
| | | {
|
| | | this.DeleteGateway(strWayId);
|
| | | });
|
| | | });
|
| | | });
|
| | | }
|
| | | //if (canAddReplaceMenu == true)
|
| | | //{
|
| | | // //替换
|
| | | // MenuName = Language.StringByID(R.MyInternationalizationString.uReplace);
|
| | | // frame.AddRowMenu(MenuName, null, "Item/ReplaceIconSelected.png", () =>
|
| | | // {
|
| | | // });
|
| | | //}
|
| | | }
|
| | | #endregion
|
| | |
|
| | |
| | | if (gateWayExist == true)
|
| | | {
|
| | | btnGateName = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
|
| | | btnGateName.txtInput.MaxByte = 48;//限制只能输入48个字节
|
| | | btnGateName.txtInput.MaxByte = 32;//限制只能输入32个字节
|
| | | listview.AddChidren(btnGateName);
|
| | | btnGateName.InitControl();
|
| | | //划线
|
| | |
| | | rowBeloneArea.SelectRoomEvent += (roomKeys) =>
|
| | | {
|
| | | //变更网关房间
|
| | | HdlGatewayLogic.Current.ChangedGatewayRoom(this.zbGateway.GwId, roomKeys);
|
| | | HdlRoomLogic.Current.ChangedGatewayRoom(this.zbGateway.GwId, roomKeys);
|
| | | };
|
| | |
|
| | | //完成初始化桌布
|
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using ZigBee.Device; |
| | | |
| | | namespace Shared.Phone.UserCenter.Gateway |
| | | { |
| | | /// <summary> |
| | | /// 网关替换界面 |
| | | /// </summary> |
| | | public class GatewayReplaceForm : EditorCommonForm |
| | | { |
| | | #region ■ 变量声明___________________________ |
| | | |
| | | /// <summary> |
| | | /// 当前网关对象 |
| | | /// </summary> |
| | | private ZbGateway nowZbGateway = null; |
| | | /// <summary> |
| | | /// 列表控件 |
| | | /// </summary> |
| | | private VerticalListControl listView = null; |
| | | /// <summary> |
| | | /// 确认按钮 |
| | | /// </summary> |
| | | private BottomClickButton btnConfirm = null; |
| | | /// <summary> |
| | | /// 当前选择的状态控件 MainKey是网关ID |
| | | /// </summary> |
| | | private MostRightIconControl btnSelectIcon = null; |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 初始化_____________________________ |
| | | |
| | | /// <summary> |
| | | /// 画面显示(底层会固定调用此方法,借以完成画面创建) |
| | | /// </summary> |
| | | /// <param name="i_zbGateway">当前网关对象</param> |
| | | public void ShowForm(ZbGateway i_zbGateway) |
| | | { |
| | | this.nowZbGateway = i_zbGateway; |
| | | |
| | | //设置标题信息 |
| | | base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uReplaceGateway)); |
| | | |
| | | //初始化中部控件 |
| | | this.InitMiddleFrame(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化中部控件 |
| | | /// </summary> |
| | | private void InitMiddleFrame() |
| | | { |
| | | //清空bodyFrame |
| | | this.ClearBodyFrame(); |
| | | |
| | | //确定按钮 |
| | | this.btnConfirm = new BottomClickButton(); |
| | | btnConfirm.TextID = R.MyInternationalizationString.uConfirm1; |
| | | btnConfirm.oldBackgroundColor = UserCenterColor.Current.ClickButtonDefultColor; |
| | | bodyFrameLayout.AddChidren(btnConfirm); |
| | | btnConfirm.CanClick = false; |
| | | btnConfirm.ButtonClickEvent += (sender, e) => |
| | | { |
| | | //执行网关替换操作 |
| | | this.DoReplaceGateway(); |
| | | }; |
| | | |
| | | //请选择被替换的网关 |
| | | var btnMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false); |
| | | btnMsg.Y = btnConfirm.Yaxis - Application.GetRealHeight(50 + 35); |
| | | btnMsg.TextSize = 12; |
| | | btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1; |
| | | btnMsg.TextAlignment = TextAlignment.Center; |
| | | btnMsg.TextID = R.MyInternationalizationString.uPleaseSelectGatewayToBeReplaced; |
| | | bodyFrameLayout.AddChidren(btnMsg); |
| | | |
| | | this.listView = new VerticalListControl(29); |
| | | listView.Height = btnMsg.Y - Application.GetRealHeight(23); |
| | | listView.BackgroundColor = UserCenterColor.Current.White; |
| | | bodyFrameLayout.AddChidren(listView); |
| | | |
| | | HdlThreadLogic.Current.RunMainInThread(() => |
| | | { |
| | | //设定中部信息 |
| | | this.SetMiddleFrameInfo(); |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设定中部信息 |
| | | /// </summary> |
| | | private void SetMiddleFrameInfo() |
| | | { |
| | | //获取本地全部网关对象 |
| | | List<ZbGateway> listway = HdlGatewayLogic.Current.GetAllLocalGateway(); |
| | | var listShowWay = new List<ZbGateway>(); |
| | | for (int i = 0; i < listway.Count; i++) |
| | | { |
| | | //只有类型相同的网关,才能显示 |
| | | if (listway[i].GwId != this.nowZbGateway.GwId && listway[i].LinuxImageType == this.nowZbGateway.LinuxImageType) |
| | | { |
| | | listShowWay.Add(listway[i]); |
| | | } |
| | | } |
| | | for (int i = 0; i < listShowWay.Count; i++) |
| | | { |
| | | //添加行 |
| | | this.AddRowLayout( listShowWay[i], i != listShowWay.Count - 1); |
| | | } |
| | | |
| | | //调整列表控件的高度 |
| | | this.listView.AdjustRealHeight(Application.GetRealHeight(23)); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 添加网关行_________________________ |
| | | |
| | | /// <summary> |
| | | /// 添加行 |
| | | /// </summary> |
| | | /// <param name="localWay">本地网关</param> |
| | | /// <param name="addLine">是否添加底线</param> |
| | | private void AddRowLayout(ZbGateway localWay, bool addLine) |
| | | { |
| | | var frameRow = new FrameRowControl(this.listView.rowSpace / 2); |
| | | this.listView.AddChidren(frameRow); |
| | | |
| | | //图标 |
| | | var btnIcon = frameRow.AddLeftIcon(); |
| | | HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, localWay); |
| | | |
| | | //显示文本 |
| | | var wayName = HdlGatewayLogic.Current.GetGatewayName(localWay); |
| | | if (wayName == string.Empty) |
| | | { |
| | | //无法识别的网关设备 |
| | | wayName = Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice); |
| | | } |
| | | frameRow.AddTopView(wayName, 700); |
| | | |
| | | //房间 |
| | | var room = HdlRoomLogic.Current.GetRoomByGateway(localWay.GwId); |
| | | var roomName = HdlRoomLogic.Current.GetRoomName(room); |
| | | frameRow.AddBottomView(roomName, 700); |
| | | |
| | | //选择状态 |
| | | var btnSelect = frameRow.AddMostRightEmptyIcon(58, 58); |
| | | btnSelect.MainKey = localWay.GwId; |
| | | btnSelect.Visible = false; |
| | | btnSelect.UnSelectedImagePath = "Item/ItemSelected.png"; |
| | | |
| | | if (addLine == true) |
| | | { |
| | | //底线 |
| | | frameRow.AddBottomLine(); |
| | | } |
| | | btnSelect.ButtonClickEvent += (sender, e) => |
| | | { |
| | | if (this.btnSelectIcon != null) { this.btnSelectIcon.IsSelected = false; } |
| | | |
| | | btnSelect.IsSelected = true; |
| | | this.btnSelectIcon = btnSelect; |
| | | this.btnConfirm.CanClick = true; |
| | | }; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region ■ 执行网关替换操作___________________ |
| | | |
| | | /// <summary> |
| | | /// 执行网关替换操作 |
| | | /// </summary> |
| | | private void DoReplaceGateway() |
| | | { |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | |
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //绑定还没有成功的网关
|
| | | var result2 = HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | if (result2 == false)
|
| | | {
|
| | | //临时这么写,新云端就会写到R文件了
|
| | | this.ShowMassage(ShowMsgType.Tip, "绑定网关失败,请重新上传");
|
| | | return;
|
| | | }
|
| | | //创建一个备份名字
|
| | | string backupClassId = HdlBackupLogic.Current.CreatNewBackupNameToDB(backName);
|
| | | if (backupClassId == null)
|
| | |
| | | {
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //绑定还没有成功的网关
|
| | | var result2 = HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | if (result2 == false)
|
| | | {
|
| | | //临时这么写,新云端就会写到R文件了
|
| | | this.ShowMassage(ShowMsgType.Tip, "绑定网关失败,请重新上传");
|
| | | return;
|
| | | }
|
| | | int result = HdlAutoBackupLogic.DoUpLoadAutoBackupDataByHand();
|
| | | if (result == -1)
|
| | | {
|
| | |
| | | };
|
| | | }
|
| | |
|
| | | #if Android
|
| | | row1 = new FrameRowControl(listView.rowSpace / 2);
|
| | | row1.UseClickStatu = false;
|
| | | listView.AddChidren(row1);
|
| | | row1.AddLeftCaption("上报GBS定位功能", 500);
|
| | | row1.AddLeftCaption("记录定位", 500);
|
| | | row1.AddBottomLine();
|
| | | var btnGbsSwitch = row1.AddMostRightSwitchIcon();
|
| | | if (System.IO.File.Exists(DirNameResourse.OpenGbsFile) == true)
|
| | | {
|
| | | btnGbsSwitch.IsSelected = true;
|
| | | }
|
| | | btnGbsSwitch.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | this.ShowMassage(ShowMsgType.Confirm, "注意:开启或者关闭此功能会重启App", () =>
|
| | | if (btnGbsSwitch.IsSelected == true)
|
| | | {
|
| | | btnGbsSwitch.IsSelected = !btnGbsSwitch.IsSelected;
|
| | | if (btnGbsSwitch.IsSelected == true)
|
| | | {
|
| | | HdlFileLogic.Current.SaveTextToFile(DirNameResourse.OpenGbsFile, "nmsl");
|
| | | }
|
| | | else
|
| | | {
|
| | | HdlFileLogic.Current.DeleteFile(DirNameResourse.OpenGbsFile);
|
| | | }
|
| | | HDLUtils.RestartApp();
|
| | | });
|
| | | btnGbsSwitch.IsSelected = false;
|
| | | UserCenterResourse.HideOption.WriteGpsPoint = 0;
|
| | | return;
|
| | | }
|
| | | this.ShowDialogInputForm("????", string.Empty, "请输入识别码", (contr, value) =>
|
| | | {
|
| | | if (value == "542397")
|
| | | {
|
| | | UserCenterResourse.HideOption.WriteGpsPoint = 1;
|
| | | btnGbsSwitch.IsSelected = true;
|
| | | }
|
| | | contr.CloseDialog();
|
| | | });
|
| | | };
|
| | | #endif
|
| | |
|
| | | row1 = new FrameRowControl(listView.rowSpace / 2);
|
| | | listView.AddChidren(row1);
|
| | |
| | | this.ShowProgressBar();
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //绑定还没有成功的网关
|
| | | var result2 = HdlGatewayLogic.Current.ResetComandToBindBackupGateway();
|
| | | if (result2 == false)
|
| | | {
|
| | | //临时这么写,新云端就会写到R文件了
|
| | | this.ShowMassage(ShowMsgType.Tip, "绑定网关失败,请重新操作");
|
| | | this.CloseProgressBar();
|
| | | return;
|
| | | }
|
| | | //检测它有没有备份
|
| | | var listBack = HdlBackupLogic.Current.GetBackupListNameFromDB();
|
| | | this.CloseProgressBar();
|
| | |
| | | private void CheckAuthorityAndShowMap(NormalViewControl btnLocation)
|
| | | {
|
| | | #if Android
|
| | | //显示地图
|
| | | this.ShowMap(btnLocation);
|
| | | ////申请定位权限
|
| | | //((BaseActivity)Application.Activity).SetGPSLocationPermission((result1) =>
|
| | | //{
|
| | | // if (result1 == false) { return; }
|
| | | // //申请读权限
|
| | | // ((BaseActivity)Application.Activity).ReadWriteContact((result2) =>
|
| | | // {
|
| | | // if (result2 == false) { return; }
|
| | | // //申请读取手机号权限
|
| | | // ((BaseActivity)Application.Activity).SetPermission((result3) =>
|
| | | // {
|
| | | // if (result3 == false) { return; }
|
| | | // //显示地图
|
| | | // this.ShowMap(btnLocation);
|
| | | // }, "android.permission.READ_PHONE_STATE");
|
| | | // });
|
| | | //});
|
| | | //申请定位权限
|
| | | ((BaseActivity)Application.Activity).SetGPSLocationPermission((result1) =>
|
| | | {
|
| | | if (result1 == false) { return; }
|
| | |
|
| | | //申请允许程序写入外部存储,如SD卡上写文件
|
| | | ((BaseActivity)Application.Activity).SetPermission((result2) =>
|
| | | {
|
| | | if (result2 == false) { return; }
|
| | | //读取电话状态权限
|
| | | ((BaseActivity)Application.Activity).SetPermission((result3) =>
|
| | | {
|
| | | if (result3 == false) { return; }
|
| | | //显示地图
|
| | | this.ShowMap(btnLocation);
|
| | | }, "android.permission.READ_PHONE_STATE");
|
| | |
|
| | | }, "android.permission.WRITE_EXTERNAL_STORAGE");
|
| | | });
|
| | | #endif
|
| | | #if iOS
|
| | | //显示地图
|
| | |
| | | btnAbountView.X -= ControlCommonResourse.XXLeft / 2;
|
| | | rowAbount.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | if (Common.Config.Instance.Home.IsVirtually == true)
|
| | | {
|
| | | //如果住宅为虚拟住宅,则此功能无效
|
| | | return;
|
| | | }
|
| | | var form = new Abount.AbountForm();
|
| | | form.AddForm();
|
| | | };
|
| | |
| | | BackgroundColor = Shared.Common.ZigbeeColor.Current.MainColor; |
| | | Shared.Application.LocationAction += (lon, lat) => |
| | | { |
| | | //GPS坐标转成高德坐标
|
| | | double out_lng, out_lat;
|
| | | HdlGpsLocationConvertLogic.Current.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat); |
| | | //上报经纬度 |
| | | Login.AccountLogic.Instance.ReceiveAppLatAndLon(lon.ToString(), lat.ToString()); |
| | | Login.AccountLogic.Instance.ReceiveAppLatAndLon(out_lng.ToString(), out_lat.ToString()); |
| | | }; |
| | | }
|
| | |
|
| | |
| | | /// 是否正在搜索网关 |
| | | /// </summary> |
| | | public static bool IsSearchingGateway = false; |
| | | /// <summary>
|
| | | /// 发送的时间间隔(单位:秒)
|
| | | /// </summary> |
| | | public static int SendTime = 3; |
| | | /// <summary> |
| | | /// 上一次的住宅ID
|
| | | /// </summary> |
| | |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var broadBytes = new byte[44];// byteHomeId[0] ,//H |
| | | broadBytes[0] = 0xfe; |
| | | broadBytes[1] = 0x29; |
| | | broadBytes[2] = 0x00; |
| | | broadBytes[3] = 0x00; |
| | | broadBytes[4] = 0x00; |
| | | broadBytes[5] = 0x00; |
| | | broadBytes[6] = 0x00; |
| | | broadBytes[43] = 0x02; |
| | | var broadBytes = new byte[44]; |
| | | |
| | | while (true) |
| | | { |
| | | try |
| | | { |
| | | //检测能否发送广播 |
| | | if (CheckCanSendBroadcast(broadBytes) == false) |
| | | { |
| | | continue; |
| | | {
|
| | | //检测能否发送广播 0:不能发送广播 1:可以发送广播 2:住宅ID变更
|
| | | int result = CheckCanSendBroadcast(); |
| | | if (result == 0)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (result == 2)
|
| | | {
|
| | | //重新初始化广播数据
|
| | | broadBytes = new byte[44];
|
| | | broadBytes[0] = 0xfe;
|
| | | broadBytes[1] = 0x29;
|
| | | broadBytes[2] = 0x00;
|
| | | broadBytes[3] = 0x00;
|
| | | broadBytes[4] = 0x00;
|
| | | broadBytes[5] = 0x00;
|
| | | broadBytes[6] = 0x00;
|
| | | broadBytes[43] = 0x02;
|
| | | var tempBytes = System.Text.Encoding.UTF8.GetBytes(oldHomeID);
|
| | | System.Array.Copy(tempBytes, 0, broadBytes, 7, 36 < tempBytes.Length ? 36 : tempBytes.Length);
|
| | | } |
| | | |
| | | var broadcastIpAddress = new Shared.Net.NetWiFi().BroadcastIpAddress;
|
| | | |
| | | |
| | | //清空接收到的IP |
| | | listReceiveIP.Clear(); |
| | | if (broadcastIpAddress.ToString() != "0.0.0.0") |
| | | listReceiveIP.Clear();
|
| | | if (broadcastIpAddress.ToString() != "0.0.0.0")
|
| | | {
|
| | | //广播出去 |
| | | FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes); |
| | | } |
| | | //等待3秒,下面的接收方法会去接收广播 |
| | | System.Threading.Thread.Sleep(3000); |
| | | //广播出去
|
| | | FindGateWaySocket.BeginSend(new System.Net.IPEndPoint(broadcastIpAddress, 7624), broadBytes);
|
| | | }
|
| | | //等待3秒,下面的接收方法会去接收广播
|
| | | System.Threading.Thread.Sleep(SendTime * 1000); |
| | | |
| | | if (listReceiveIP.Count > 0)
|
| | | {
|
| | |
| | | }
|
| | | else
|
| | | {
|
| | | //局域网广播不到网关 |
| | | //局域网广播不到网关
|
| | | ZbGateway.IsRemote = true;
|
| | | //当网关的连接方式改变时,记录当前的连接方式
|
| | | Shared.Phone.UserCenter.HdlGatewayLogic.Current.CheckGatewayByConnectChanged(Shared.Phone.UserCenter.GatewayConnectMode.Remote);
|
| | |
| | | System.Threading.Thread.Sleep(500); |
| | | continue; |
| | | }
|
| | | var ipEndPoint = new System.Net.IPEndPoint(0, 0); |
| | | var ipEndPoint = new System.Net.IPEndPoint(IPAddress.Any, 0); |
| | | var bytes = FindGateWaySocket.udpClient.Receive(ref ipEndPoint); |
| | | if (bytes[43] == 0xA2) |
| | | { |
| | |
| | | var gateWay = ZbGateway.GateWayList.Find(obj => obj.GwId == zbGateWay.GwId); |
| | | if (gateWay == null) |
| | | {
|
| | | zbGateWay.OnlineTime = DateTime.Now; |
| | | //刷新网关的在线时间点
|
| | | Shared.Phone.UserCenter.HdlGatewayLogic.Current.RefreshGatewayOnlineTime(zbGateWay.GwId);
|
| | |
|
| | | ZbGateway.GateWayList.Add(zbGateWay); |
| | | await zbGateWay.StartLocalMqtt(ipAddress); |
| | | } |
| | | else |
| | | { |
| | | {
|
| | | //刷新网关的在线时间点
|
| | | Shared.Phone.UserCenter.HdlGatewayLogic.Current.RefreshGatewayOnlineTime(gateWay.GwId); |
| | | |
| | | gateWay.IsVirtual = false; |
| | | //将该网关标识为【可搜索到,即:在线】 |
| | | gateWay.OnlineTime = DateTime.Now; |
| | | if (gateWay.GwIP != ipAddress) |
| | | { |
| | | await gateWay.DisConnectLocalMqttClient("2"); |
| | |
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, data33);
|
| | | } |
| | | } |
| | | await System.Threading.Tasks.Task.Delay(20); |
| | | } |
| | | catch (Exception ex) |
| | | {
|
| | |
| | | {
|
| | | //为了那么多少万分之一的几率,这里设置成别的另一类的值
|
| | | oldHomeID = "**";
|
| | | } |
| | | |
| | | /// <summary> |
| | | /// 检测能否发送广播 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private static bool CheckCanSendBroadcast(byte[] broadBytes) |
| | | { |
| | | if (string.IsNullOrEmpty(Config.Instance.HomeId)) |
| | | { |
| | | //住宅ID为空只有一种可能就是退出了登录,这里的上一次住宅ID要清空 |
| | | oldHomeID = "?"; |
| | | System.Threading.Thread.Sleep(1000); |
| | | return false; |
| | | } |
| | | //首次进入网关,和切换住宅会清除网关列表,重新搜索存储 |
| | | if (Config.Instance.HomeId != oldHomeID) |
| | | { |
| | | //因为那一瞬间,有可能mqtt会加回来,所以先加缓存 |
| | | var list = new List<ZbGateway>(); |
| | | list.AddRange(ZbGateway.GateWayList); |
| | | //然后清空掉 |
| | | ZbGateway.GateWayList.Clear(); |
| | | //最后再断开mqtt连接 |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | list[i]?.DisConnectLocalMqttClient("1"); |
| | | } |
| | | list.Clear(); |
| | | oldHomeID = Shared.Common.Config.Instance.HomeId; |
| | | |
| | | var tempBytes = System.Text.Encoding.UTF8.GetBytes(Shared.Common.Config.Instance.HomeId); |
| | | System.Array.Copy(tempBytes, 0, broadBytes, 7, 36 < tempBytes.Length ? 36 : tempBytes.Length); |
| | | |
| | | //住宅中已经存在的网关如果局域网不存在,需要在当前住宅中虚拟一个网关ID相同的网关 |
| | | var gateWayFileList = Global.FileListByHomeId().FindAll(obj => obj.StartsWith("Gateway_")); |
| | | foreach (var filePath in gateWayFileList) |
| | | { |
| | | var paths = filePath.Split('_'); |
| | | if (paths.Length < 3) |
| | | continue; |
| | | |
| | | var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == paths[2])); |
| | | if (gateWay == null) |
| | | { |
| | | gateWay = new ZbGateway { IsVirtual = true }; |
| | | gateWay.GwId = paths[2]; |
| | | gateWay.HomeId = Config.Instance.HomeId; |
| | | ZbGateway.GateWayList.Add(gateWay); |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测能否发送广播(0:不能发送广播 1:可以发送广播 2:住宅ID变更)
|
| | | /// </summary>
|
| | | /// <returns></returns>
|
| | | private static int CheckCanSendBroadcast()
|
| | | {
|
| | | if (string.IsNullOrEmpty(Config.Instance.HomeId))
|
| | | {
|
| | | //住宅ID为空只有一种可能就是退出了登录,这里的上一次住宅ID要清空
|
| | | oldHomeID = "?";
|
| | | System.Threading.Thread.Sleep(1000);
|
| | | return 0;
|
| | | }
|
| | | //首次进入网关,和切换住宅会清除网关列表,重新搜索存储
|
| | | if (Config.Instance.HomeId == oldHomeID)
|
| | | {
|
| | | return 1;
|
| | | }
|
| | |
|
| | | //因为那一瞬间,有可能mqtt会加回来,所以先加缓存
|
| | | var list = new List<ZbGateway>();
|
| | | list.AddRange(ZbGateway.GateWayList);
|
| | | //然后清空掉
|
| | | ZbGateway.GateWayList.Clear();
|
| | | //最后再断开mqtt连接
|
| | | for (int i = 0; i < list.Count; i++)
|
| | | {
|
| | | list[i]?.DisConnectLocalMqttClient("1");
|
| | | }
|
| | | list.Clear();
|
| | |
|
| | | //住宅中已经存在的网关如果局域网不存在,需要在当前住宅中虚拟一个网关ID相同的网关
|
| | | var gateWayFileList = Global.FileListByHomeId().FindAll(obj => obj.StartsWith("Gateway_"));
|
| | | foreach (var filePath in gateWayFileList)
|
| | | {
|
| | | var paths = filePath.Split('_');
|
| | | if (paths.Length < 3)
|
| | | continue;
|
| | |
|
| | | var gateWay = ZbGateway.GateWayList.Find(obj => (obj != null) && (obj.GwId == paths[2]));
|
| | | if (gateWay == null)
|
| | | {
|
| | | gateWay = new ZbGateway { IsVirtual = true };
|
| | | gateWay.GwId = paths[2];
|
| | | gateWay.HomeId = Config.Instance.HomeId;
|
| | | ZbGateway.GateWayList.Add(gateWay);
|
| | | }
|
| | | }
|
| | | //住宅ID变更
|
| | | oldHomeID = Config.Instance.HomeId;
|
| | |
|
| | | return 2;
|
| | | } |
| | | |
| | | #endregion |
| | |
| | | return;
|
| | | }
|
| | | int value = udpClient.Send(bytes, bytes.Length, iPEndPoint);
|
| | | //调试用 |
| | | if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1) |
| | | { |
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "发送长度(BeginSendTo):" + value + " 发送内容:" + System.Text.Encoding.UTF8.GetString(bytes)); |
| | | } |
| | | //调试用
|
| | | if (Shared.Phone.UserCenter.UserCenterResourse.HideOption.WriteSocketReceiveDataToFile == 1)
|
| | | {
|
| | | Shared.Phone.UserCenter.HdlLogLogic.Current.WriteLog(3, "发送长度(BeginSendTo):" + value + " 发送内容:" + System.Text.Encoding.UTF8.GetString(bytes));
|
| | | }
|
| | | } |
| | | catch (Exception ex) |
| | | {
|
| | |
| | | { |
| | | get |
| | | { |
| | | if (Shared.Phone.UserCenter.HdlExperienceAccountLogic.Current.IsExperience == true)
|
| | | {
|
| | | //体验账号的Token
|
| | | return this.TokenExperience;
|
| | | } |
| | | string md5Password; |
| | | if (string.IsNullOrEmpty(Password)) |
| | | { |
| | |
| | | return Convert.ToBase64String(tokenBytes).Replace("=", "%3D"); |
| | | } |
| | | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 体验账号的Token
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | private string m_TokenExperience = null;
|
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string TokenExperience
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_TokenExperience != null) { return m_TokenExperience; }
|
| | |
|
| | | var result = System.Text.Encoding.UTF8.GetBytes("123456");
|
| | | var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
| | | var output = md5.ComputeHash(result);
|
| | | var md5Password = BitConverter.ToString(output).Replace("-", "");
|
| | | var account_md5Pssword = "ceyir277@163.com:" + md5Password; |
| | | var tokenBytes = System.Text.Encoding.UTF8.GetBytes(account_md5Pssword); |
| | | m_TokenExperience = Convert.ToBase64String(tokenBytes).Replace("=", "%3D");
|
| | | return m_TokenExperience;
|
| | | }
|
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | //订阅一个挤下线的主题
|
| | | await RemoteMqttClient.SubscribeAsync("/ZigbeeGateWayToClient/" + Config.Instance.ConnEmqClientId + "/Push/NotifySqueeze");
|
| | |
|
| | | await initGateWayBaseInfomation(); |
| | |
|
| | | //没有主网关时主动读取,获取主网关信息
|
| | | var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
|
| | | if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null)
|
| | | //如果这个函数卡久了的话,会接收到云端推送的挤下线主题,不知道为什么
|
| | | new Thread(async () =>
|
| | | {
|
| | | if (gateWayList.Count == 1)
|
| | | await initGateWayBaseInfomation();
|
| | |
|
| | | //没有主网关时主动读取,获取主网关信息
|
| | | var gateWayList = GateWayList.FindAll(obj => obj.HomeId == Shared.Common.Config.Instance.HomeId);
|
| | | if (gateWayList.Find(obj => obj.IsMainGateWay == true) == null)
|
| | | {
|
| | | gateWayList[0].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < gateWayList.Count; i++)
|
| | | if (gateWayList.Count == 1)
|
| | | {
|
| | | var gateWay = gateWayList[i];
|
| | | var info = await gateWay.GetZbGwInfoAsync();
|
| | | if (info == null || info.getGwData == null)
|
| | | gateWayList[0].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | for (int i = 0; i < gateWayList.Count; i++)
|
| | | {
|
| | | continue;
|
| | | }
|
| | | if (info.getGwData.IsDominant == 1)
|
| | | {
|
| | | for (int j = 0; j < gateWayList.Count; j++)
|
| | | var gateWay = gateWayList[i];
|
| | | var info = await gateWay.GetZbGwInfoAsync();
|
| | | if (info == null || info.getGwData == null)
|
| | | {
|
| | | if (gateWayList[i].GwId == info.getGwData.GwId)
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = false;
|
| | | }
|
| | | continue;
|
| | | }
|
| | | break;
|
| | | if (info.getGwData.IsDominant == 1)
|
| | | {
|
| | | for (int j = 0; j < gateWayList.Count; j++)
|
| | | {
|
| | | if (gateWayList[i].GwId == info.getGwData.GwId)
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = true;
|
| | | }
|
| | | else
|
| | | {
|
| | | gateWayList[i].IsMainGateWay = false;
|
| | | }
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | |
| | | }); |
| | | } |
| | | #endregion |
| | |
| | | { |
| | | DebugPrintLog($"Local断开通讯连接出异常:{ex.Message}"); |
| | | } |
| | | }
|
| | |
|
| | | /// <summary> |
| | | /// 强制断开本地的网关连接 |
| | | /// </summary> |
| | | public async Task CloseLocalConnectionOnForce() |
| | | { |
| | | try |
| | | {
|
| | | await localMqttClient.DisconnectAsync();
|
| | | } |
| | | catch { } |
| | | finally |
| | | {
|
| | | localIsConnected = false;
|
| | | //这个东西也要弄
|
| | | localMqttIsConnecting = false;
|
| | | } |
| | | } |
| | | |
| | | /// <summary>
|
| | |
| | | catch (Exception e)
|
| | | { |
| | | DebugPrintLog($"Remote断开通讯连接出异常:{e.Message}");
|
| | | }
|
| | | } |
| | | |
| | | /// <summary>
|
| | | /// 强制断开远程Mqtt的链接
|
| | | /// </summary>
|
| | | /// <returns></returns> |
| | | public static async Task CloseRemoteConnectionOnForce()
|
| | | {
|
| | | try
|
| | | {
|
| | | await RemoteMqttClient.DisconnectAsync();
|
| | | }
|
| | | catch { }
|
| | | finally
|
| | | {
|
| | | remoteIsConnected = false;
|
| | | //这个东西也要弄
|
| | | remoteMqttIsConnecting = false;
|
| | | }
|
| | | } |
| | | |
| | |
| | | #if DEBUG |
| | | if (flage == true) |
| | | { |
| | | //if (msg.Contains("DeviceStatusReport") == false) |
| | | //if (msg.Contains("DeviceInfoRespon") == true) |
| | | { |
| | | System.Console.WriteLine(msg + " " + System.DateTime.Now.ToLongTimeString() + " " + System.DateTime.Now.Millisecond); |
| | | } |
| | |
| | | public class ZbGatewayData |
| | | { |
| | | #region 一堆变量 |
| | | /// <summary> |
| | | /// 网关在线的时间点 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime OnlineTime = DateTime.Now; |
| | | |
| | | /// <summary>
|
| | | /// 住宅ID |
| | | /// </summary> |
| | |
| | | ///<summary> |
| | | ///网关序列号,该网关唯一标识 |
| | | /// </summary> |
| | | public string GwId = string.Empty; |
| | | public string GwId = string.Empty;
|
| | | /// <summary> |
| | | ///网关绑定网卡的mac地址 |
| | | /// </summary> |
| | |
| | | /// 最后的更新时间 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime LastDateTime = DateTime.MinValue; |
| | | public DateTime LastDateTime = DateTime.MinValue;
|
| | | /// <summary>
|
| | | /// 网关在线的时间点(这个东西有点用处,当第一次获取时,需要返回当前时间回去,然后才开始计时)
|
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | private DateTime m_OnlineTime = new DateTime(1970, 1, 1); |
| | | /// <summary> |
| | | /// 网关在线的时间点 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DateTime OnlineTime
|
| | | {
|
| | | get
|
| | | {
|
| | | if (m_OnlineTime.Year == 1970)
|
| | | {
|
| | | //当第一次获取时,需要返回当前时间回去,然后才开始计时
|
| | | m_OnlineTime = DateTime.Now;
|
| | | }
|
| | | return m_OnlineTime;
|
| | | }
|
| | | set { m_OnlineTime = value; }
|
| | | } |
| | | |
| | | #endregion |
| | | |
| | |
| | | /// 检测到还没有备份,请先备份
|
| | | /// </summary>
|
| | | public const int uIsNotHadBackupByCheckPleaseBackup = 16167;
|
| | | /// <summary>
|
| | | /// 替换
|
| | | /// </summary>
|
| | | public const int uReplace = 16168;
|
| | | /// <summary>
|
| | | /// 替换网关
|
| | | /// </summary>
|
| | | public const int uReplaceGateway = 16169;
|
| | | /// <summary>
|
| | | /// 请选择被替换的网关
|
| | | /// </summary>
|
| | | public const int uPleaseSelectGatewayToBeReplaced = 16170;
|
| | |
|
| | |
|
| | | //★★★★下面这些是接口的返回信息翻译,从18000开始★★★★
|
| | |
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlFileLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlGatewayBackupLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlGatewayUpdateLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlGpsLocationConvertLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlHttpLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlLogLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlMessageLogic.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\CommonBase\Logic\HdlResidenceLogic.cs" />
|
| | |
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewayAddSuccessForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewayBackUpListForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewayProductInfoForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewayReplaceForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewaySearchListForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Manage\GatewayRebindForm.cs" />
|
| | | <Compile Include="$(MSBuildThisFileDirectory)Phone\UserCenter\Gateway\Add\WirelessUdpDirectionForm.cs" />
|