Crabtree/ON/Aliyu/AliyuLogProducerClient.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/Aliyu/AliyuLogUtil.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/Aliyu/Level.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/Aliyu/LogBean.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/ON.Droid.csproj | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/ON/Properties/AndroidManifest.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome.sln | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/HDL/Common/HttpUtil/HttpUtil.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/UI/SimpleControl/MainPage.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountLogin.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Crabtree/ON/Aliyu/AliyuLogProducerClient.cs
New file @@ -0,0 +1,133 @@ using System; using Android.Content; using Com.Aliyun.Sls.Android.Producer; using Java.IO; namespace HDL_ON_Android.Aliyu { public class AliyuLogProducerClient : Java.Lang.Object, ILogProducerCallback { private static string TAG = "ProducerClient"; LogProducerClient client = null; private Context context; protected string endpoint; protected string logProject; protected string logStore; protected string accessKeyId; protected string accessKeySecret; protected string accessKeyToken; protected string pluginAppId; public AliyuLogProducerClient(Context context, string endpoint, string logProject, string logStore, string accessKeyId, string accessKeySecret, string accessKeyToken, string pluginAppId) { this.context = context; this.endpoint = endpoint; this.logProject = logProject; this.logStore = logStore; this.accessKeyId = accessKeyId; this.accessKeySecret = accessKeySecret; this.accessKeyToken = accessKeyToken; this.pluginAppId = pluginAppId; } public void initProducer() { try { // endpoint 必须是以 https:// 或 http:// 开头的链接 string endpoint = this.endpoint; string project = this.logProject; string logstore = this.logStore; string accessKeyId = this.accessKeyId; string accessKeySecret = this.accessKeySecret; string accessKeyToken = this.accessKeyToken; LogProducerConfig config = new LogProducerConfig(context, endpoint, project, logstore, accessKeyId, accessKeySecret, accessKeyToken); // 设置主题 config.SetTopic("test_topic"); // 设置tag信息,此tag会附加在每条日志上 config.AddTag("test", "test_tag"); // 每个缓存的日志包的大小上限,取值为1~5242880,单位为字节。默认为1024 * 1024 config.SetPacketLogBytes(1024 * 1024); // 每个缓存的日志包中包含日志数量的最大值,取值为1~4096,默认为1024 config.SetPacketLogCount(1024); // 被缓存日志的发送超时时间,如果缓存超时,则会被立即发送,单位为毫秒,默认为3000 config.SetPacketTimeout(3000); // 单个Producer Client实例可以使用的内存的上限,超出缓存时add_log接口会立即返回失败 // 默认为64 * 1024 * 1024 config.SetMaxBufferLimit(64 * 1024 * 1024); // 发送线程数,默认为1 config.SetSendThreadCount(1); //网络连接超时时间,整数,单位秒,默认为10 config.SetConnectTimeoutSec(10); //日志发送超时时间,整数,单位秒,默认为15 config.SetSendTimeoutSec(10); //flusher线程销毁最大等待时间,整数,单位秒,默认为1 config.SetDestroyFlusherWaitSec(2); //sender线程池销毁最大等待时间,整数,单位秒,默认为1 config.SetDestroySenderWaitSec(2); //数据上传时的压缩类型,默认为LZ4压缩,0 不压缩,1 LZ4压缩,默认为1 config.SetCompressType(1); //设备时间与标准时间之差,值为标准时间-设备时间,一般此种情况用户客户端设备时间不同步的场景 //整数,单位秒,默认为0;比如当前设备时间为1607064208, 标准时间为1607064308,则值设置为 1607064308 - 1607064208 = 10 config.SetNtpTimeOffset(3); //日志时间与本机时间之差,超过该大小后会根据 `drop_delay_log` 选项进行处理。 //一般此种情况只会在设置persistent的情况下出现,即设备下线后,超过几天/数月启动,发送退出前未发出的日志 //整数,单位秒,默认为7*24*3600,即7天 config.SetMaxLogDelayTime(7 * 24 * 3600); //对于超过 `max_log_delay_time` 日志的处理策略 //0 不丢弃,把日志时间修改为当前时间; 1 丢弃,默认为 1 (丢弃) config.SetDropDelayLog(0); //是否丢弃鉴权失败的日志,0 不丢弃,1丢弃 //默认为 0,即不丢弃 config.SetDropUnauthorizedLog(0); // 是否使用主线程回调 // false: 使用主线程回调。回调会在主线程上执行,且每个 client 都有自己单独的回调。 // true: 使用 sender 线程回调。回调会在 sender 现呈上执行,每次执行回调时都会 attach 一个新的 java 线程,所有 client 共用一个回调。 // 注意:默认使用 sender 线程回调。 config.SetCallbackFromSenderThread(false); /** * 以下为开启断点续传的配置, 按照如下配置开启断点续传功能后, 日志会先缓存到本地 */ // 1 开启断点续传功能, 0 关闭 // 每次发送前会把日志保存到本地的binlog文件,只有发送成功才会删除,保证日志上传At Least Once config.SetPersistent(1); // 持久化的文件名,需要保证文件所在的文件夹已创建。 // !!!!!!!!!!!!!!!!!!!注意!!!!!!!!!!!!!!!!!!! // 配置多个客户端时,不应设置相同文件 config.SetPersistentFilePath(context.FilesDir + string.Format("%slog_data.dat", File.Separator)); // 是否每次AddLog强制刷新,高可靠性场景建议打开 config.SetPersistentForceFlush(0); // 持久化文件滚动个数,建议设置成10。 config.SetPersistentMaxFileCount(10); // 每个持久化文件的大小,建议设置成1-10M config.SetPersistentMaxFileSize(1024 * 1024); // 本地最多缓存的日志数,不建议超过1M,通常设置为65536即可 config.SetPersistentMaxLogCount(65536); client = new LogProducerClient(config, this); } catch (LogProducerException e) { } } public void sendLog(Log log) { LogProducerResult result = client.AddLog(log); } //callback为可选配置, 如果不需要关注日志的发送成功或失败状态, 可以不注册 callback public void OnCall(int resultCode, string reqId, string errorMessage, int logBytes, int compressedBytes) { // // resultCode: 状态码, 详见 LogProducerResult // // reqId: 请求Id, 已经废弃 // // errorMessage: 失败信息 // // logBytes: 日志原始字节数 // // compressedBytes: 日志压缩字节数 } } } Crabtree/ON/Aliyu/AliyuLogUtil.cs
New file @@ -0,0 +1,107 @@ using System; using Android.Content; using Com.Aliyun.Sls.Android.Producer; namespace HDL_ON_Android.Aliyu { public class AliyuLogUtil { private static AliyuLogProducerClient exceptionProducerClient; private static LogBean logBean; private static Object lockObj = new object (); private static AliyuLogProducerClient getExceptionProducerClient() { lock (lockObj) { if (exceptionProducerClient == null) { if (Shared.Application.Activity == null) { return null; } exceptionProducerClient = new AliyuLogProducerClient(Shared.Application.Activity, "https://cn-hangzhou.log.aliyuncs.com", "hdl-crabtree-log", "log","LTAI5tLzDxrtsFyi3xtK3YWt", "eX31JZrRAvC2wZWPiZU0SYhlfAUMoT", null, null); exceptionProducerClient.initProducer(); } return exceptionProducerClient; } } /** * 异常日志 * * @param title 标题 * @param content 附加数据内容 * @param level 报警等级 */ public static void log(string title, string content, Level level) { log(title, content, level, null); } /** * 异常日志 * * @param title 标题 * @param content 附加数据内容 * @param otherMsg 其他附加数据,没有可为空 * @param level 报警等级 * @param type 异常类型 */ public static void log(string title, string content, Level level, string type) { log(title, content, level, null, null); } /** * 异常日志 * * @param title 标题 * @param content 附加数据内容 * @param otherMsg 其他附加数据,没有可为空 * @param level 报警等级 * @param type 异常类型 * @param exceptionBlock 异常代码块 */ public static void log(string title, string content, Level level, string type, string exceptionBlock) { /** * 没有homeId和userId 不允许上传 只上传住宅里面的异常 减少云端压力 * 1.点击项目的时候设置 * 2.关闭住宅页面的时候去掉 */ if (string.IsNullOrEmpty(getLogBean.getUserId()) || string.IsNullOrEmpty(getLogBean.getHomeId())) { return; } Log log = new Log(); log.PutContent("title", title); log.PutContent("content", content); log.PutContent("level", level.ToString()); log.PutContent("userId", getLogBean.getUserId()); log.PutContent("homeId", getLogBean.getHomeId()); log.PutContent("time", System.DateTime.UtcNow + ""); log.PutContent("userAgent", getLogBean.getUserAgent()); log.PutContent("appVersion", getLogBean.getAppVersion()); log.PutContent("type", type); log.PutContent("exceptionBlock", exceptionBlock); var producerClient = getExceptionProducerClient(); if (producerClient == null) { return; } producerClient.sendLog(log); } public static LogBean getLogBean { get { if (logBean == null) { logBean = new LogBean(); } return logBean; } } } } Crabtree/ON/Aliyu/Level.cs
New file @@ -0,0 +1,10 @@ using System; namespace HDL_ON_Android.Aliyu { public enum Level { high,//高 middle,//中 low//低 } } Crabtree/ON/Aliyu/LogBean.cs
New file @@ -0,0 +1,77 @@ using System; namespace HDL_ON_Android.Aliyu { public class LogBean { /** * 用户id,非必填 */ private string userId; /** * 住宅id,非必填 */ private string homeId; /** * 网关mac,非必填 */ private string mac; /** * 系统:IOS、Android、Windows、网关 */ private string userAgent; /** * 软件版本 */ private string appVersion; public string getUserId() { return userId == null ? "" : userId; } public string getHomeId() { return homeId == null ? "" : homeId; } public void setUserId(string userId) { this.userId = userId; } public void setHomeId(string homeId) { this.homeId = homeId; } public string getMac() { return mac; } public void setMac(string mac) { this.mac = mac; } public string getUserAgent() { return userAgent; } public void setUserAgent(string userAgent) { this.userAgent = userAgent; } public string getAppVersion() { return appVersion; } public void setAppVersion(string appVersion) { this.appVersion = appVersion; } } } Crabtree/ON/ON.Droid.csproj
@@ -52,7 +52,7 @@ <NoWarn></NoWarn> <AndroidDexTool>d8</AndroidDexTool> <AndroidSupportedAbis>armeabi-v7a;arm64-v8a</AndroidSupportedAbis> <AndroidPackageFormat>aab</AndroidPackageFormat> <AndroidPackageFormat>apk</AndroidPackageFormat> </PropertyGroup> <ItemGroup> <Reference Include="System" /> @@ -176,6 +176,10 @@ <Compile Include="Scan.cs" /> <Compile Include="NetworkUtils.cs" /> <Compile Include="SplashActivity.cs" /> <Compile Include="Aliyu\AliyuLogUtil.cs" /> <Compile Include="Aliyu\AliyuLogProducerClient.cs" /> <Compile Include="Aliyu\LogBean.cs" /> <Compile Include="Aliyu\Level.cs" /> </ItemGroup> <ItemGroup> <None Include="Resources\AboutResources.txt" /> @@ -939,6 +943,11 @@ <AndroidAsset Include="Assets\Phone2\CrabtreeAdd\CloudOffline.png" /> <AndroidAsset Include="Assets\Phone2\CrabtreeAdd\Speaker.png" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\..\..\Downloads\AliyuLog\AliyuLog.csproj"> <Name>AliyuLog</Name> </ProjectReference> </ItemGroup> <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" /> <Import Project="..\packages\Xamarin.Android.Support.Annotations.28.0.0.3\build\monoandroid80\Xamarin.Android.Support.Annotations.targets" Condition="Exists('..\packages\Xamarin.Android.Support.Annotations.28.0.0.3\build\monoandroid80\Xamarin.Android.Support.Annotations.targets')" /> <Import Project="..\packages\Xamarin.Android.Arch.Core.Common.1.1.1.3\build\monoandroid80\Xamarin.Android.Arch.Core.Common.targets" Condition="Exists('..\packages\Xamarin.Android.Arch.Core.Common.1.1.1.3\build\monoandroid80\Xamarin.Android.Arch.Core.Common.targets')" /> Crabtree/ON/Properties/AndroidManifest.xml
@@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.806101" android:versionCode="202306101"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hdl.crabtreenew" android:versionName="2.807181" android:versionCode="202307181"> <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29" /> <!-- 在安卓P版本之后,必须要授予FOREGROUND_SERVICE权限,才能够使用前台服务 --> <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> Crabtree/SmartHome.sln
@@ -7,6 +7,8 @@ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ON.Ios", "ON.Ios\ON.Ios.csproj", "{1D83BF28-BA88-4152-BA41-D7EFE90A5437}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AliyuLog", "..\..\..\..\Downloads\AliyuLog\AliyuLog.csproj", "{3A0E9FF9-56B6-4323-9AE6-2B22975E399B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|iPhoneSimulator = Debug|iPhoneSimulator @@ -41,6 +43,18 @@ {1D83BF28-BA88-4152-BA41-D7EFE90A5437}.Debug|Any CPU.Build.0 = Debug|iPhoneSimulator {1D83BF28-BA88-4152-BA41-D7EFE90A5437}.Release|Any CPU.ActiveCfg = Release|iPhone {1D83BF28-BA88-4152-BA41-D7EFE90A5437}.Release|Any CPU.Build.0 = Release|iPhone {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|iPhone.ActiveCfg = Release|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|iPhone.Build.0 = Release|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|iPhone.ActiveCfg = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|iPhone.Build.0 = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|Any CPU.ActiveCfg = Release|Any CPU {3A0E9FF9-56B6-4323-9AE6-2B22975E399B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 Crabtree/SmartHome/HDL/Common/HttpUtil/HttpUtil.cs
@@ -251,12 +251,26 @@ } //*****一些判空处理***************** if (revertObj.Code != StateCode.SUCCESS) { if (revertObj.Code != "10001") { string upString = requestFullUrl + " Code : " + revertObj.Code; if (bodyParameterJson != null) { upString += " ;" + bodyParameterJson; } //记录日志 HDL_ON_Android.Aliyu.AliyuLogUtil.log ("接口告警", upString, HDL_ON_Android.Aliyu.Level.middle); } } return revertObj; } catch (Exception ex) { //记录日志 HDL_ON_Android.Aliyu.AliyuLogUtil.log ("接口异常", "Url : " + requestFullUrl + " Msg : " + ex.Message, HDL_ON_Android.Aliyu.Level.high); Utlis.WriteLine (ex.Message); return new ResponsePackNew () { Code = StateCode.DATA_EXCEPTION }; } } else { Utlis.WriteLine (response.Content); return new ResponsePackNew () { Code = StateCode.NETWORK_ERROR }; } Crabtree/SmartHome/UI/SimpleControl/EquipmentPublicClass.cs
@@ -117,6 +117,18 @@ }, SendCount.Three, true, true); var result = control.UsefulBytes; //优化一下,防止逻辑异常 if(result == null) { UserConfig.Instance.IsLocalEncrypt = true; control.Send (new Target () { IPEndPoint = new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000), Command = Command.ReadGateway, SubnetID = SmartHome.MqttCommon.GatewayCommon.SubnetID, DeviceID = SmartHome.MqttCommon.GatewayCommon.DeviceID, AddData = new byte [] { (byte)new Random ().Next (255), (byte)new Random ().Next (255) }, }, SendCount.Three, true, true); result = control.UsefulBytes; } #endregion if (result != null) { @@ -249,6 +261,12 @@ // }); //} //在确定用户及住宅信息后,初始化基本信息,如: var logBean = HDL_ON_Android.Aliyu.AliyuLogUtil.getLogBean; logBean.setHomeId (UserConfig.Instance.CurrentRegion.Id); logBean.setUserId (MainPage.LoginUser.ID); logBean.setAppVersion (MainPage.RequestVersion); #if DEBUG Shared.Utlis.WriteLine ($"CheckLinkRemote: 结束"); #endif Crabtree/SmartHome/UI/SimpleControl/MainPage.cs
@@ -38,7 +38,7 @@ //public static Button LogoButton = new Button (); public static string RequestVersion = "2.805291"; public static string RequestVersion = "2.807181"; public static UserInfo LoginUser; /// <summary> /// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token) Crabtree/SmartHome/UI/SimpleControl/Phone/Register/AccountLogin.cs
@@ -166,19 +166,19 @@ etPasswrod.SecureTextEntry = !btnShowPassword.IsSelected; }; //#if DEBUG // int NigelLoginPass = 0; // btnLogo.MouseUpEventHandler += (sender, e) => { // if (NigelLoginPass == 3) { // etAccount.Text = @"464027401@qq.com"; // etPasswrod.Text = "qqqqqq"; // } else if (NigelLoginPass == 5) { // etAccount.Text = @"Jai.singh@havells.com"; // etPasswrod.Text = "123456"; // } // NigelLoginPass++; // }; //#endif #if DEBUG int NigelLoginPass = 0; btnLogo.MouseUpEventHandler += (sender, e) => { if (NigelLoginPass == 3) { etAccount.Text = @"support6@hdlchina.com.cn"; etPasswrod.Text = "123456"; } else if (NigelLoginPass == 5) { etAccount.Text = @"Jai.singh@havells.com"; etPasswrod.Text = "123456"; } NigelLoginPass++; }; #endif //if (accountList.Count > 0) { // etAccount.Text = accountList [accountList.Count-1]; //}