更新了iOS扫码sdk,兼容最新手机系统(17.5.1);增加了阿里云日志服务
3个文件已添加
7个文件已修改
398 ■■■■■ 已修改文件
DLL/Aliyun.Api.LogService.dll 补丁 | 查看 | 原始文档 | blame | 历史
DLL/IOS/HDL.Shared.IOS.ScanQRCode.dll 补丁 | 查看 | 原始文档 | blame | 历史
HDL-ON_Android/HDL-ON_Android.csproj 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL-ON_iOS/HDL-ON_iOS.csproj 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/Common/AliyunLog/AliyunLogClient.cs 152 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/Common/AliyunLog/AliyunLogInvokeAsync.cs 173 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/HDL_ON.projitems 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/UI/MainPage.cs 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/UI/UI0-Stan/Logic/HdlMessageLogic.cs 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/UI/UI2/1-HomePage/HomePage.cs 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
DLL/Aliyun.Api.LogService.dll
Binary files differ
DLL/IOS/HDL.Shared.IOS.ScanQRCode.dll
Binary files differ
HDL-ON_Android/HDL-ON_Android.csproj
@@ -198,6 +198,9 @@
    <Reference Include="HdlEzvizDroid">
      <HintPath>..\DLL\Android\HdlEzvizDroid.dll</HintPath>
    </Reference>
    <Reference Include="Aliyun.Api.LogService">
      <HintPath>..\DLL\Aliyun.Api.LogService.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MainActivity.cs" />
@@ -973,6 +976,18 @@
    <PackageReference Include="Square.OkHttp3">
      <Version>3.14.4</Version>
    </PackageReference>
    <PackageReference Include="Google.Protobuf">
      <Version>3.5.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client">
      <Version>5.2.4</Version>
    </PackageReference>
    <PackageReference Include="Iconic.Zlib.Netstandard">
      <Version>1.0.0</Version>
    </PackageReference>
    <PackageReference Include="lz4net">
      <Version>1.0.15.93</Version>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <AndroidAsset Include="Assets\Language.ini" />
HDL-ON_iOS/HDL-ON_iOS.csproj
@@ -30,6 +30,7 @@
        <CodesignProvision>OnPro2307291-Dev</CodesignProvision>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <MtouchI18n>cjk</MtouchI18n>
        <MtouchSdkVersion>17.5</MtouchSdkVersion>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
        <DebugType>none</DebugType>
@@ -55,12 +56,13 @@
        <CodesignKey>Apple Development: xuebiao huang (4P32GXQWWK)</CodesignKey>
        <MtouchDebug>true</MtouchDebug>
        <MtouchI18n>cjk</MtouchI18n>
        <MtouchLink>None</MtouchLink>
        <MtouchLink>SdkOnly</MtouchLink>
        <MtouchExtraArgs>-gcc_flags="-dead_strip -ObjC"</MtouchExtraArgs>
        <MtouchEnableSGenConc>false</MtouchEnableSGenConc>
<CodesignEntitlements>Entitlements.plist</CodesignEntitlements>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodesignProvision>OnPro2307291-Dev</CodesignProvision>
<MtouchSdkVersion>17.5</MtouchSdkVersion>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
        <DebugType>none</DebugType>
@@ -76,6 +78,7 @@
        <MtouchI18n>cjk</MtouchI18n>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <CodesignProvision>OnPro240130-1-Hoc</CodesignProvision>
        <MtouchSdkVersion>17.5</MtouchSdkVersion>
    </PropertyGroup>
    <ItemGroup>
        <Reference Include="System" />
@@ -119,6 +122,9 @@
        <Reference Include="Shared.IOS">
          <HintPath>..\DLL\Shared.IOS.dll</HintPath>
        </Reference>
        <Reference Include="Aliyun.Api.LogService">
          <HintPath>..\DLL\Aliyun.Api.LogService.dll</HintPath>
        </Reference>
    </ItemGroup>
    <ItemGroup>
      <PackageReference Include="Newtonsoft.Json">
@@ -142,6 +148,18 @@
      <PackageReference Include="Xamarin.iOS.SwiftRuntimeSupport">
        <Version>0.2.1</Version>
      </PackageReference>
      <PackageReference Include="Google.Protobuf">
        <Version>3.5.1</Version>
      </PackageReference>
      <PackageReference Include="Microsoft.AspNet.WebApi.Client">
        <Version>5.2.4</Version>
      </PackageReference>
      <PackageReference Include="Iconic.Zlib.Netstandard">
        <Version>1.0.0</Version>
      </PackageReference>
      <PackageReference Include="lz4net">
        <Version>1.0.15.93</Version>
      </PackageReference>
    </ItemGroup>
    <ItemGroup>
        <ImageAsset Include="Assets.xcassets\add_server1.imageset\add_server1.png" />
HDL_ON/Common/AliyunLog/AliyunLogClient.cs
New file
@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Aliyun.Api.LogService;
using Aliyun.Api.LogService.Domain.Log;
using Aliyun.Api.LogService.Domain.LogStore.Index;
using Aliyun.Api.LogService.Infrastructure.Protocol;
namespace HDL_ON.Common.AliyunLog
{
    public class AliyunLogClient
    {
        // 日志服务的服务接入点。此处以杭州为例,其它地域请根据实际情况填写。
        private static string endpoint = "cn-hangzhou.log.aliyuncs.com";
        // 本示例从环境变量中获取AccessKey ID和AccessKey Secret。
        private static string accessKeyId = "LTAI5tLzDxrtsFyi3xtK3YWt";
        private static string accessKeySecret = "eX31JZrRAvC2wZWPiZU0SYhlfAUMoT";
        // Project名称。
        private static string project = "hdl-onpro-log";
        // Logstore名称。
        private static string logstore = "log";
        // 创建日志服务Client。
        private static ILogServiceClient client = BuildSimpleClient();
        public static ILogServiceClient BuildSimpleClient()
            => LogServiceClientBuilders.HttpBuilder
                .Endpoint(endpoint, project)
                .Credential(accessKeyId, accessKeySecret)
                .Build();
        public AliyunLogClient()
        {
        }
        //// 构建最简单的`ILogServiceClient`。
        //public static ILogServiceClient BuildSimpleClient()
        //    => LogServiceClientBuilders.HttpBuilder
        //        // 服务入口<endpoint>及项目名<projectName>
        //        .Endpoint(endpoint, project)
        //        // 访问密钥信息
        //        .Credential(accessKeyId, accessKeySecret)
        //        .Build();
        //static async Task Main(string[] args)
        //{
        //    // 创建Project。
        //    var proRes = await client.CreateProjectAsync(project, "des");
        //    check(proRes);
        //    Console.WriteLine("Create project success");
        //    Thread.Sleep(120 * 1000);
        //    // 创建Logstore。
        //    var storeRes = await client.CreateLogStoreAsync(logstore, 3, 2);
        //    check(storeRes);
        //    Console.WriteLine("Create logstore success");
        //    Thread.Sleep(10 * 1000);
        //    // 为Logstore创建索引。
        //    var indRes = await client.CreateIndexAsync(logstore, new IndexLineInfo(new[] { ' ', ',' }));
        //    check(indRes);
        //    Console.WriteLine("Create Index success");
        //    Thread.Sleep(60 * 1000);
        //    // 向Logstore写入数据。
        //    await PostLogs();
        //    Console.WriteLine("Post logs success");
        //    Thread.Sleep(3000);
        //    // 查询日志。
        //    await GetLogs();
        //}
        //public static async Task GetLogs()
        //{
        //    var logsRes = await client.GetLogsAsync(logstore, DateTimeOffset.UtcNow.AddMinutes(-1),
        //        DateTimeOffset.UtcNow,
        //        "test", "", 100, 0);
        //    check(logsRes);
        //    foreach (var log in logsRes.Result.Logs)
        //    {
        //        foreach (var key in log.Keys)
        //        {
        //            log.TryGetValue(key, out var value);
        //            Console.WriteLine(key + " : " + value);
        //        }
        //        Console.WriteLine("======");
        //    }
        //}
        public static async Task PostLogs(string topic, string msg)
        {
            if (client == null)
            {
                client = BuildSimpleClient();
            }
            try
            {
                var pushObj = new LogGroupInfo
                {
                    Topic = topic,
#if __ANDROID__
                    Source = "Android",
#else
                    Source = "IOS",
#endif
                    LogTags = new Dictionary<string, string>
                    {
                        {"tag1", DateTime.Now.ToLongTimeString()},
                    },
                    Logs = new List<LogInfo>
                    {
                        new LogInfo
                        {
                            Time = DateTimeOffset.Now,
                            Contents = new Dictionary<string, string>
                            {
                                {"id", DateTime.Now.Ticks.ToString()},
                                {"homeid", Entity.DB_ResidenceData.Instance.CurrentRegion.id},
                                {"userid", UserInfo.Current.ID},
                                {"userName", UserInfo.Current.userName},
                                {"message", msg},
                            }
                        }
                    }
                };
                var response = await client.PostLogStoreLogsAsync(logstore, pushObj);
                check(response);
            }
            catch (Exception ex)
            {
                MainPage.Log(ex.Message);
            }
        }
        public static void check(IResponse res)
        {
            if (!res.IsSuccess)
            {
                MainPage.Log("日志推送不成功.");
                //throw new ApplicationException(res.Error.ErrorMessage);
            }
        }
    }
}
HDL_ON/Common/AliyunLog/AliyunLogInvokeAsync.cs
New file
@@ -0,0 +1,173 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Aliyun.Api.LogService;
using Aliyun.Api.LogService.Domain;
using Aliyun.Api.LogService.Domain.Log;
using Aliyun.Api.LogService.Infrastructure.Protocol;
namespace HDL_ON.Common.AliyunLog
{
    public class AliyunLogInvokeAsync
    {
        public AliyunLogInvokeAsync()
        {
        }
        /// <summary>
        /// 执行请求方法。
        /// </summary>
        public static async Task<GetLogsResult> Invoke(ILogServiceClient client)
        {
            var response = await client.GetLogsAsync
            (
                // 「必填参数」会在 Request 构造器中列出,并且不可set;
                new GetLogsRequest("example-logstore", (Int32)DateTimeOffset.UtcNow.AddDays(-1).ToUnixTimeSeconds(), (Int32)DateTimeOffset.UtcNow.ToUnixTimeSeconds())
                {
                    // 「可选参数」不会在 Request 构造器中列出,可通过setter设置。
                    Offset = 1,
                    Line = 100,
                }
            );
            var result = response
                // 此方法会确保返回的响应失败时候抛出`LogServiceException`。
                .EnsureSuccess()
                // 此处获取Result是安全的。
                .Result;
            Console.WriteLine($"RequestId:{response.RequestId}");
            Console.WriteLine($"日志总数:{result.Count}");
            Console.WriteLine($"首条日志:{result.Logs.FirstOrDefault()}");
            return result;
        }
        /// <summary>
        /// 在调用时可使用扩展方法,扩展方法会将简单的请求对象的属性展开到方法入参中。
        /// 使用扩展方法 `using Aliyun.Api.Log;` 即可。
        /// </summary>
        public static async Task<GetLogsResult> InvokeUsingExtension(ILogServiceClient client)
        {
            var response = await client.GetLogsAsync
            (
                // 「必填参数」作为方法的普通必须参数
                "example-logstore",
                DateTimeOffset.UtcNow.AddDays(-1),
                DateTimeOffset.UtcNow,
                // 「可选参数」作为方法的可选参数,可通过命名参数方式指定
                offset: 1,
                line: 10
            );
            var result = response
                // 此方法会确保返回的响应失败时候抛出`LogServiceException`。
                .EnsureSuccess()
                // 此处获取Result是安全的。
                .Result;
            Console.WriteLine($"RequestId:{response.RequestId}");
            Console.WriteLine($"日志总数:{result.Count}");
            Console.WriteLine($"首条日志:{result.Logs.FirstOrDefault()}");
            return result;
        }
        /// <summary>
        /// 处理服务器返回(包含在Response中)的错误。
        /// </summary>
        public static async Task<GetLogsResult> InvokeWithErrorHandling(ILogServiceClient client)
        {
            var response = await client.GetLogsAsync
            (
                // 「必填参数」作为方法的普通必须参数
                "example-logstore",
                DateTimeOffset.UtcNow.AddDays(-1),
                DateTimeOffset.UtcNow,
                // 「可选参数」作为方法的可选参数,可通过命名参数方式指定
                offset: 1,
                line: 10
            );
            GetLogsResult result;
            // 尝试处理可处理的错误。
            if (!response.IsSuccess)
            {
                // 错误码
                var errorCode = response.Error.ErrorCode;
                // 错误消息
                var errorMessage = response.Error.ErrorMessage;
                Console.WriteLine($"RequestId:{response.RequestId}");
                Console.WriteLine($"错误码:{errorCode}");
                Console.WriteLine($"错误信息:{errorMessage}");
                // `ErrorCode`类可支持与自身实例或字符串进行对比。
                if (errorCode == ErrorCode.SignatureNotMatch /* SDK中预定义的错误码 */)
                {
                    // 在这里处理业务可处理的错误。。。。。。
                    Console.WriteLine("Signature not match, {0}.", errorMessage);
                }
                else if (errorCode == "ParameterInvalid" /* 业务相关特殊的SDK中未定义的错误码 */)
                {
                    // 在这里处理业务可处理的错误。。。。。。
                    Console.WriteLine("Parameter invalid, {0}.", errorMessage);
                }
                // 任何处理不到的错误请务必抛出异常中断原流程,避免外部获取到 null 的结果!
                throw new Exception("这里可以是系统的业务异常。" + response.Error /* 最好带上服务返回的错误信息以便调试 */);
            }
            else
            {
                // 此处获取Result是安全的。
                result = response.Result;
            }
            Console.WriteLine($"RequestId:{response.RequestId}");
            Console.WriteLine($"日志总数:{result.Count}");
            Console.WriteLine($"首条日志:{result.Logs.FirstOrDefault()}");
            return result;
        }
        /// <summary>
        /// 处理以异常形式抛出的错误。
        /// </summary>
        public static async Task<GetLogsResult> InvokeWithExceptionHandling(ILogServiceClient client)
        {
            try
            {
                return await Invoke(client);
            }
            catch (LogServiceException e)
            {
                // 错误码
                var errorCode = e.ErrorCode;
                // 错误消息
                var errorMessage = e.ErrorMessage;
                Console.WriteLine($"RequestId:{e.RequestId}");
                Console.WriteLine($"错误码:{errorCode}");
                Console.WriteLine($"错误信息:{errorMessage}");
                // `ErrorCode`类可支持与自身实例或字符串进行对比。
                if (errorCode == ErrorCode.SignatureNotMatch /* SDK中预定义的错误码 */)
                {
                    // 在这里处理业务可处理的错误。。。。。。
                    Console.WriteLine("Signature not match, {0}.", errorMessage);
                }
                else if (errorCode == "ParameterInvalid" /* 业务相关特殊的SDK中未定义的错误码 */)
                {
                    // 在这里处理业务可处理的错误。。。。。。
                    Console.WriteLine("Parameter invalid, {0}.", errorMessage);
                }
                // 任何处理不到的错误请务必抛出异常中断原流程,避免外部获取到 null 的结果!
                throw new Exception("这里可以是系统的业务异常。", e /* 在自定义的异常中最好带上服务返回的异常以便调试 */);
            }
        }
    }
}
HDL_ON/HDL_ON.projitems
@@ -594,6 +594,8 @@
    <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\3-Intelligence\Automation\Constant.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\3-Intelligence\Scene\SceneAutomationListChoosePage.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\3-Intelligence\Scene\SceneTargetTypeChoosePage.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)Common\AliyunLog\AliyunLogClient.cs" />
    <Compile Include="$(MSBuildThisFileDirectory)Common\AliyunLog\AliyunLogInvokeAsync.cs" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="$(MSBuildThisFileDirectory)Entity\Device\" />
HDL_ON/UI/MainPage.cs
@@ -649,6 +649,14 @@
        {
#if DEBUG
            Console.WriteLine($"{tag}-->{msg}");
            if (tag == "error")
            {
                new System.Threading.Thread(async () =>
                {
                    await Common.AliyunLog.AliyunLogClient.PostLogs("自定义Error日志", msg);
                })
                { IsBackground = true }.Start();
            }
#endif
        }
HDL_ON/UI/UI0-Stan/Logic/HdlMessageLogic.cs
@@ -89,7 +89,14 @@
                form.AddForm(string.Empty);
                form.SetTextContent(msg);
            }, "ok");
            }, "ok");
            //上报日志服务器
            new System.Threading.Thread(async () =>
            {
                await Common.AliyunLog.AliyunLogClient.PostLogs("App程序错误", ex.Message);
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
@@ -104,7 +111,13 @@
                form.AddForm(string.Empty);
                form.SetTextContent(msg);
            }, "ok");
            }, "ok");
            //上报日志服务器
            new System.Threading.Thread(async () =>
            {
                await Common.AliyunLog.AliyunLogClient.PostLogs("App程序错误", msg);
            })
            { IsBackground = true }.Start();
        }
HDL_ON/UI/UI2/1-HomePage/HomePage.cs
@@ -553,6 +553,17 @@
                LoadContentView();
                #endregion
#if DEBUG
                btnResidenceName.MouseUpEventHandler = (envent, ee) => {
                    MainPage.Log("sss");
                    new System.Threading.Thread(async() =>
                    {
                        await Common.AliyunLog.AliyunLogClient.PostLogs("告警测试", "测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息测试信息");
                    })
                    { IsBackground = true }.Start();
                };
#endif
            }
            catch (Exception ex)
            {