Skip to content

Commit

Permalink
逐步使用Remoting架构替代应用层代码
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed May 10, 2024
1 parent 0cbc4d8 commit e8a7f30
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
8 changes: 5 additions & 3 deletions NewLife.Remoting.Extensions/Common/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NewLife.Remoting.Extensions.Services;
using NewLife.Serialization;
using NewLife.Web;
using static NewLife.Remoting.ApiHttpClient;
using IWebFilter = Microsoft.AspNetCore.Mvc.Filters.IActionFilter;

namespace NewLife.Remoting.Extensions;
Expand Down Expand Up @@ -57,10 +58,11 @@ void IWebFilter.OnActionExecuting(ActionExecutingContext context)

try
{
if (context.ActionDescriptor is ControllerActionDescriptor act && !act.MethodInfo.IsDefined(typeof(AllowAnonymousAttribute)))
var rs = !token.IsNullOrEmpty() && OnAuthorize(token);

if (!rs && context.ActionDescriptor is ControllerActionDescriptor act && !act.MethodInfo.IsDefined(typeof(AllowAnonymousAttribute)))
{
var rs = !token.IsNullOrEmpty() && OnAuthorize(token);
if (!rs) throw new ApiException(ApiCode.Forbidden, "认证失败");
throw new ApiException(ApiCode.Forbidden, "认证失败");
}
}
catch (Exception ex)
Expand Down
33 changes: 33 additions & 0 deletions Samples/IoTZero/Clients/ClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using IoTEdge;
using NewLife.Log;

namespace IoTZero.Clients;

/// <summary>客户端测试入口。主程序通过反射调用</summary>
public static class ClientTest
{
private static ITracer _tracer;
private static HttpDevice _device;

public static async Task Main(IServiceProvider serviceProvider)
{
await Task.Delay(3_000);

XTrace.WriteLine("开始IoT客户端测试");

_tracer = serviceProvider.GetService<ITracer>();

var set = ClientSetting.Current;

// 产品编码、产品密钥从IoT管理平台获取,设备编码支持自动注册
var device = new HttpDevice(set)
{
Tracer = _tracer,
Log = XTrace.Log,
};

await device.LoginAsync();

_device = device;
}
}
9 changes: 5 additions & 4 deletions Samples/IoTZero/IoTZero.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<Compile Include="..\ZeroIoT\IoTCore\Models\PingResponse.cs" Link="Models\PingResponse.cs" />
<Compile Include="..\ZeroIoT\IoTCore\Models\ThingSpecModel.cs" Link="Models\ThingSpecModel.cs" />
<Compile Include="..\ZeroIoT\IoTCore\Models\UpgradeInfo.cs" Link="Models\UpgradeInfo.cs" />
<Compile Include="..\ZeroIoT\IoTEdge\ClientSetting.cs" Link="Clients\ClientSetting.cs" />
<Compile Include="..\ZeroIoT\IoTEdge\HttpDevice.cs" Link="Clients\HttpDevice.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\Controllers\DeviceController.cs" Link="Areas\IoT\Controllers\DeviceController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\Controllers\DeviceDataController.cs" Link="Areas\IoT\Controllers\DeviceDataController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\Controllers\DeviceGroupController.cs" Link="Areas\IoT\Controllers\DeviceGroupController.cs" />
Expand All @@ -48,9 +50,7 @@
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\Controllers\DevicePropertyController.cs" Link="Areas\IoT\Controllers\DevicePropertyController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\Controllers\ProductController.cs" Link="Areas\IoT\Controllers\ProductController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Areas\IoT\IoTArea.cs" Link="Areas\IoT\IoTArea.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Common\ApiFilterAttribute.cs" Link="Common\ApiFilterAttribute.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Controllers\AppController.cs" Link="Controllers\AppController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Controllers\BaseController.cs" Link="Controllers\BaseController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Controllers\DeviceController.cs" Link="Controllers\DeviceController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\Controllers\ThingController.cs" Link="Controllers\ThingController.cs" />
<Compile Include="..\ZeroIoT\IoTZero\IoTSetting.cs" Link="IoTSetting.cs" />
Expand All @@ -66,8 +66,9 @@
<ItemGroup>
<Content Include="..\ZeroIoT\IoT.Data\Entity\IoT.htm" Link="Entity\IoT.htm" />
<Content Include="..\ZeroIoT\IoT.Data\Entity\Model.xml" Link="Entity\Model.xml" />
<Content Include="..\ZeroIoT\IoTZero\appsettings.Development.json" Link="appsettings.Development.json" />
<Content Include="..\ZeroIoT\IoTZero\appsettings.json" Link="appsettings.json" />
<Content Include="..\ZeroIoT\IoTZero\appsettings.json" Link="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit e8a7f30

Please sign in to comment.