提交 937a1c36 编写于 作者: S siaszhangjie

Merge branch 'master' of https://github.com/siaszhangjie/IoTSharp

......@@ -363,3 +363,5 @@ ASALocalRun/
/buildimageqhse.cmd
/IoTSharp/.data
/IoTSharp/ClientAppVue/package-lock.json
/package-lock.json
/yarn.lock
......@@ -17,58 +17,58 @@ services:
- iotsharp-network
#pgadmin:
# image: dpage/pgadmin4
# container_name: pgadmin
# restart: always
# volumes:
# - "./data/servers.json:/pgadmin4/servers.json"
# depends_on:
# - pgsql
# links:
# - pgsql
# ports:
# - 8090:80
# environment:
# TZ: "Asia/Shanghai"
# PGADMIN_DEFAULT_EMAIL: "root@iotsharp.io"
# PGADMIN_DEFAULT_PASSWORD: "1-q2-w3-e4-r5-t"
# networks:
# - iotsharp-network
pgadmin:
image: dpage/pgadmin4
container_name: pgadmin
restart: always
volumes:
- "./data/servers.json:/pgadmin4/servers.json"
depends_on:
- pgsql
links:
- pgsql
ports:
- 8090:80
environment:
TZ: "Asia/Shanghai"
PGADMIN_DEFAULT_EMAIL: "root@iotsharp.io"
PGADMIN_DEFAULT_PASSWORD: "1-q2-w3-e4-r5-t"
networks:
- iotsharp-network
#iotsharp:
# image: maikebing/iotsharp:latest
# restart: always
# container_name: iotsharp
# hostname: iotsharp
# environment:
# ASPNETCORE_ENVIRONMENT: Production
# TZ: Asia/Shanghai
# depends_on:
# - pgsql
# - mongodb1
# - mongodb2
# - mongodb3
# - rabbitmq
# - influx
# links:
# - pgsql
# - mongodb1
# - mongodb2
# - mongodb3
# - rabbitmq
# - influx
# volumes:
# - "./appsettings.Production.json:/app/appsettings.Production.json"
# ports:
# - 2927:80
# - 1883:1883
# - 8883:8883
# - 5683:5683
# - 5684:5684
# - 502:502
# networks:
# - iotsharp-network
iotsharp:
image: maikebing/iotsharp:latest
restart: always
container_name: iotsharp
hostname: iotsharp
environment:
ASPNETCORE_ENVIRONMENT: Production
TZ: Asia/Shanghai
depends_on:
- pgsql
- mongodb1
- mongodb2
- mongodb3
- rabbitmq
- influx
links:
- pgsql
- mongodb1
- mongodb2
- mongodb3
- rabbitmq
- influx
volumes:
- "./appsettings.Production.json:/app/appsettings.Production.json"
ports:
- 2927:80
- 1883:1883
- 8883:8883
- 5683:5683
- 5684:5684
- 502:502
networks:
- iotsharp-network
......@@ -159,14 +159,14 @@ services:
networks:
- iotsharp-network
#influxdb_cli:
# links:
# - influx
# image: quay.io/influxdb/influxdb:v2.0.4
# entrypoint: influx setup --bucket iotsharp-bucket -t iotsharp-token -o iotsharp --username=root --password=1-q2-w3-e4-r5-t --host=http://influx:8086 -f
# restart: on-failure:20
# depends_on:
# - influx
influxdb_cli:
links:
- influx
image: quay.io/influxdb/influxdb:v2.0.4
entrypoint: influx setup --bucket iotsharp-bucket -t iotsharp-token -o iotsharp --username=root --password=1-q2-w3-e4-r5-t --host=http://influx:8086 -f
restart: on-failure:20
depends_on:
- influx
......
......@@ -7,17 +7,17 @@ var config = {
"members": [
{
"_id": 1,
"host": "host.docker.internal:27017",
"host": "mongodb1:27017",
"priority": 3
},
{
"_id": 2,
"host": "host.docker.internal:27018",
"host": "mongodb2:27017",
"priority": 2
},
{
"_id": 3,
"host": "host.docker.internal:27019",
"host": "mongodb3:27017",
"priority": 1
}
]
......
docker-compose pull
docker-compose up -d
sleep 20
docker exec mongodb1 /bin/sh /scripts/mongodb-init.sh
......@@ -3,6 +3,12 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Migrations\**" />
<EmbeddedResource Remove="Migrations\**" />
<None Remove="Migrations\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Core" Version="7.0.0-rc2.7" />
<PackageReference Include="EFCore.Cassandra" Version="2.0.5" />
......@@ -11,8 +17,5 @@
<ItemGroup>
<ProjectReference Include="..\..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
......@@ -3,6 +3,12 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Migrations\**" />
<EmbeddedResource Remove="Migrations\**" />
<None Remove="Migrations\**" />
</ItemGroup>
<ItemGroup>
......@@ -14,8 +20,5 @@
<ItemGroup>
<ProjectReference Include="..\..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IoTSharp.Data.MySql.Migrations
{
/// <inheritdoc />
public partial class ProduceModify : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ProduceToken",
table: "Produces",
type: "longtext",
nullable: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ProduceToken",
table: "Produces");
}
}
}
......@@ -16,7 +16,7 @@ namespace IoTSharp.Data.MySql.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.10")
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("IoTSharp.Data.Alarm", b =>
......@@ -574,6 +574,8 @@ namespace IoTSharp.Data.MySql.Migrations
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
......@@ -627,6 +629,8 @@ namespace IoTSharp.Data.MySql.Migrations
b.ToTable("Device");
b.HasDiscriminator<int>("DeviceType").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.DeviceDiagram", b =>
......@@ -1491,6 +1495,9 @@ namespace IoTSharp.Data.MySql.Migrations
b.Property<string>("Name")
.HasColumnType("longtext");
b.Property<string>("ProduceToken")
.HasColumnType("longtext");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
......@@ -2086,13 +2093,6 @@ namespace IoTSharp.Data.MySql.Migrations
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.ProduceData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
......@@ -2112,6 +2112,13 @@ namespace IoTSharp.Data.MySql.Migrations
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.Alarm", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
......
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IoTSharp.Migrations
{
/// <inheritdoc />
public partial class ProduceModify : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ProduceToken",
table: "Produces",
type: "text",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ProduceToken",
table: "Produces");
}
}
}
......@@ -17,7 +17,7 @@ namespace IoTSharp.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.10")
.HasAnnotation("ProductVersion", "7.0.3")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
......@@ -583,6 +583,8 @@ namespace IoTSharp.Migrations
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
......@@ -636,6 +638,8 @@ namespace IoTSharp.Migrations
b.ToTable("Device");
b.HasDiscriminator<int>("DeviceType").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.DeviceDiagram", b =>
......@@ -1506,6 +1510,9 @@ namespace IoTSharp.Migrations
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("ProduceToken")
.HasColumnType("text");
b.Property<Guid?>("TenantId")
.HasColumnType("uuid");
......@@ -2105,13 +2112,6 @@ namespace IoTSharp.Migrations
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.ProduceData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
......@@ -2131,6 +2131,13 @@ namespace IoTSharp.Migrations
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.Alarm", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
......
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IoTSharp.Data.Sqlite.Migrations
{
/// <inheritdoc />
public partial class ProduceModify : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "ProduceToken",
table: "Produces",
type: "TEXT",
nullable: true,
collation: "NOCASE");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ProduceToken",
table: "Produces");
}
}
}
......@@ -17,7 +17,7 @@ namespace IoTSharp.Data.Sqlite.Migrations
#pragma warning disable 612, 618
modelBuilder
.UseCollation("NOCASE")
.HasAnnotation("ProductVersion", "6.0.10");
.HasAnnotation("ProductVersion", "7.0.3");
modelBuilder.Entity("IoTSharp.Data.Alarm", b =>
{
......@@ -652,6 +652,8 @@ namespace IoTSharp.Data.Sqlite.Migrations
b.ToTable("DataStorage");
b.HasDiscriminator<int>("Catalog").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
......@@ -706,6 +708,8 @@ namespace IoTSharp.Data.Sqlite.Migrations
b.ToTable("Device");
b.HasDiscriminator<int>("DeviceType").HasValue(0);
b.UseTphMappingStrategy();
});
modelBuilder.Entity("IoTSharp.Data.DeviceDiagram", b =>
......@@ -1664,6 +1668,10 @@ namespace IoTSharp.Data.Sqlite.Migrations
.HasColumnType("TEXT")
.UseCollation("NOCASE");
b.Property<string>("ProduceToken")
.HasColumnType("TEXT")
.UseCollation("NOCASE");
b.Property<Guid?>("TenantId")
.HasColumnType("TEXT");
......@@ -2336,13 +2344,6 @@ namespace IoTSharp.Data.Sqlite.Migrations
b.HasDiscriminator().HasValue(2);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.ProduceData", b =>
{
b.HasBaseType("IoTSharp.Data.DataStorage");
......@@ -2362,6 +2363,13 @@ namespace IoTSharp.Data.Sqlite.Migrations
b.HasDiscriminator().HasValue(4);
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.HasBaseType("IoTSharp.Data.Device");
b.HasDiscriminator().HasValue(1);
});
modelBuilder.Entity("IoTSharp.Data.Alarm", b =>
{
b.HasOne("IoTSharp.Data.Customer", "Customer")
......
......@@ -20,7 +20,6 @@ namespace IoTSharp.Data
public string Street { get; set; }
public string Address { get; set; }
public int ZipCode { get; set; }
public Guid? TenantId { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
[Newtonsoft.Json.JsonIgnore]
......
......@@ -109,6 +109,40 @@ namespace IoTSharp.Data
return exceptions;
}
public static Dic PreparingData<L>(this ApplicationDbContext _context, List<ProduceData> attributes, Guid deviceId)
where L : DataStorage, new()
{
Dic exceptions = new Dic();
attributes.ToList().ForEach(kp =>
{
try
{
var devdata = from tx in _context.Set<L>() where tx.DeviceId == deviceId select tx;
var tl = from tx in devdata where tx.KeyName == kp.KeyName select tx;
if (tl.Any())
{
var tx = tl.First();
tx.DateTime = DateTime.UtcNow;
_context.Set<L>().Update(tx).State = EntityState.Modified;
}
else
{
var t2 = new L() { DateTime = DateTime.UtcNow, DeviceId = deviceId, KeyName = kp.KeyName };
t2.Catalog = (typeof(L) == typeof(AttributeLatest) ? DataCatalog.AttributeLatest
: ((typeof(L) == typeof(TelemetryLatest) ? DataCatalog.TelemetryLatest
: 0)));
_context.Set<L>().Add(t2);
}
}
catch (Exception ex)
{
exceptions.Add(kp.KeyName, ex);
}
});
return exceptions;
}
public static object JPropertyToObject(this JProperty property)
{
object obj = null;
......
......@@ -50,9 +50,6 @@ namespace IoTSharp.Data
public DeviceIdentity DeviceIdentity { get; set; }
public bool Deleted { get; set; }
/// <summary>
/// 产品 Id
/// </summary>
public Guid? ProduceId { get; set; }
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ namespace IoTSharp.Data
[Newtonsoft.Json.JsonIgnore]
[Required]
public Device Device { get; set; }
public Guid DeviceId { get; set; }
}
}
\ No newline at end of file
......@@ -16,7 +16,8 @@ namespace IoTSharp.Data.Extensions
/// </summary>
/// <param name="_context"></param>
/// <param name="device"></param>
public static void AfterCreateDevice(this ApplicationDbContext _context, Device device)
/// <param name="prodId">归属于产品的设备都需要提前创建,因此这里只有前端API调用的时候传入值, 通过MQTT等创建的不传入值, 通过产品秘钥认证登录的 也会传入此值 。 </param>
public static void AfterCreateDevice(this ApplicationDbContext _context, Device device,Guid? prodId = null)
{
if (device.Customer == null || device.Tenant == null || string.IsNullOrEmpty(device.Name))
{
......@@ -24,14 +25,30 @@ namespace IoTSharp.Data.Extensions
}
else
{
_context.DeviceIdentities.Add(new DeviceIdentity()
var di = new DeviceIdentity()
{
Device = device,
IdentityType = IdentityType.AccessToken,
IdentityId = Guid.NewGuid().ToString().Replace("-", "")
});
Dictionary<string, object> pairs = new Dictionary<string, object>();
pairs.Add("CreateDateTime", DateTime.UtcNow);
};
Dictionary<string, object> pairs = new Dictionary<string, object>
{
{ "CreateDateTime", DateTime.UtcNow }
};
if (prodId != null && prodId != Guid.Empty )
{
var prod = _context.Produces.Include(p=>p.DefaultAttributes).FirstOrDefault( p=>p.Id==prodId);
if (prod != null)
{
prod.Devices.Add(device);
_context.PreparingData<AttributeLatest>(prod.DefaultAttributes, device.Id);
di.IdentityType = prod.DefaultIdentityType;
device.DeviceType = prod.DefaultDeviceType;
device.Timeout=prod.DefaultTimeout;
}
}
_context.DeviceIdentities.Add(di);
_context.PreparingData<AttributeLatest>(pairs, device.Id, DataSide.ServerSide);
}
}
......
......@@ -70,6 +70,7 @@ namespace IoTSharp.Data
/// 产品字典
/// </summary>
public List<ProduceDictionary> Dictionaries { get; set; }
public string ProduceToken { get; set; }
public bool Deleted { get; set; }
......
{
"name": "IoTSharp.SDKs",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
......@@ -59,8 +59,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Interpreter", "IoT
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.InMemory", "IoTSharp.Data.Storage\IoTSharp.Data.InMemory\IoTSharp.Data.InMemory.csproj", "{A57917E3-6F60-4D0E-8F13-36E5088DEFCE}"
EndProject
Project("{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}") = "IoTSharp.Docs", "docs\IoTSharp.Docs.njsproj", "{F5644BA6-2A0C-49A5-9C9B-3CECD6DB2D1F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Data.Cassandra", "IoTSharp.Data.Storage\IoTSharp.Data.Cassandra\IoTSharp.Data.Cassandra.csproj", "{9C6FA709-3334-4C39-922D-6FF5ADB8C683}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2.workflows", "2.workflows", "{59A51D63-F292-46F0-A4BF-975C98966DAA}"
......@@ -161,8 +159,6 @@ Global
{A57917E3-6F60-4D0E-8F13-36E5088DEFCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A57917E3-6F60-4D0E-8F13-36E5088DEFCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A57917E3-6F60-4D0E-8F13-36E5088DEFCE}.Release|Any CPU.Build.0 = Release|Any CPU
{F5644BA6-2A0C-49A5-9C9B-3CECD6DB2D1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F5644BA6-2A0C-49A5-9C9B-3CECD6DB2D1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9C6FA709-3334-4C39-922D-6FF5ADB8C683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9C6FA709-3334-4C39-922D-6FF5ADB8C683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9C6FA709-3334-4C39-922D-6FF5ADB8C683}.Release|Any CPU.ActiveCfg = Release|Any CPU
......
Subproject commit 28139a6066cab39930d964d145ed895d6bec1f77
Subproject commit 00d2cbeebf38a857d9f5986d3dfd661df177c9fe
......@@ -52,7 +52,7 @@ namespace IoTSharp.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("Tenant")]
[Authorize(Roles = nameof(UserRole.NormalUser))]
[Authorize(Roles = nameof(UserRole.TenantAdmin))]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ApiResult), StatusCodes.Status404NotFound)]
[ProducesDefaultResponseType]
......@@ -61,15 +61,14 @@ namespace IoTSharp.Controllers
var profile = this.GetUserProfile();
if (m.tenantId != Guid.Empty)
{
var querym = _context.Customer.Where(c => c.Deleted == false && c.TenantId == m.tenantId);
var querym = _context.Customer.Include(c=>c.Tenant).Where(c => !c.Deleted && c.Tenant.Id==m.tenantId);
var data = await m.Query(querym, c => c.Name);
return new ApiResult<PagedData<Customer>>(ApiCode.Success, "OK", data);
}
else
{
var querym = _context.Customer.Where(c => c.Deleted == false);
var data = await m.Query(querym, c => c.Name);
return new ApiResult<PagedData<Customer>>(ApiCode.Success, "OK", data);
return new ApiResult<PagedData<Customer>>(ApiCode.NotFoundCustomer, "没有指定客户ID",new PagedData<Customer> ());
}
}
......
using IoTSharp.EventBus;
using EasyCaching.Core;
using Esprima.Ast;
using IoTSharp.Contracts;
using IoTSharp.Controllers.Models;
using IoTSharp.Data;
......@@ -23,26 +22,18 @@ using MQTTnet.Client;
using MQTTnet.Exceptions;
using MQTTnet.Protocol;
using MQTTnet.Server;
using Org.BouncyCastle.Asn1.Cms;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Linq.Expressions;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using System.Xml;
using ShardingCore.Extensions;
using Dic = System.Collections.Generic.Dictionary<string, string>;
using DicKV = System.Collections.Generic.KeyValuePair<string, string>;
using Consul;
using LogLevel = Microsoft.Extensions.Logging.LogLevel;
using Shashlik.EventBus.Utils;
using static CoAP.Net.Exchange;
using System.Runtime.Intrinsics.X86;
using CoAP;
using IoTSharp.Extensions.X509;
namespace IoTSharp.Controllers
......@@ -785,7 +776,6 @@ namespace IoTSharp.Controllers
var tid = User.Claims.First(c => c.Type == IoTSharpClaimTypes.Tenant);
var devvalue = new Device()
{
ProduceId = device.ProductId,
Name = device.Name,
DeviceType = device.DeviceType,
Timeout = device.Timeout,
......@@ -800,7 +790,7 @@ namespace IoTSharp.Controllers
return new ApiResult<Device>(ApiCode.NotFoundTenantOrCustomer, "Not found Tenant or Customer", null);
}
_context.Device.Add(devvalue);
_context.AfterCreateDevice(devvalue);
_context.AfterCreateDevice(devvalue,device.ProductId);
await _context.SaveChangesAsync();
var identity = _context.DeviceIdentities.FirstOrDefault(c => c.Device.Id == devvalue.Id);
if (identity != null)
......@@ -846,7 +836,7 @@ namespace IoTSharp.Controllers
assets.Aggregate("", (x, y) => x + "," + y.Name), false);
}
var cert = _context.DeviceIdentities.FirstOrDefault(c => c.DeviceId == device.Id);
var cert = _context.DeviceIdentities.Include(d=>d.Device).FirstOrDefault(c => c.Device.Id == device.Id);
if (cert != null)
{
_context.DeviceIdentities.RemoveRange(cert);
......@@ -891,7 +881,7 @@ namespace IoTSharp.Controllers
assets.Aggregate("", (x, y) => x + "," + y.Name), false);
}
var cert = _context.DeviceIdentities.FirstOrDefault(c => c.DeviceId == device.Id);
var cert = _context.DeviceIdentities.Include(c=>c.Device).FirstOrDefault(c => c.Device.Id == device.Id);
if (cert != null)
{
_context.DeviceIdentities.RemoveRange(cert);
......@@ -1294,11 +1284,7 @@ namespace IoTSharp.Controllers
/// <summary>
/// 属性删除
/// </summary>
/// <param name="deviceId"></param>
/// <param name="keyName"></param>
/// <param name="dataSide"></param>
/// <returns></returns>
/// <param name="input">要删除的属性。</param>
[HttpDelete("[action]")]
public async Task<ApiResult<bool>> RemoveAttribute(RemoveDeviceAttributeInput input)
{
......
......@@ -135,6 +135,11 @@ namespace IoTSharp.Controllers
return result;
}
/// <summary>
/// 安装初始化IoTSharp
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[AllowAnonymous]
[HttpPost]
public async Task<ApiResult<InstanceDto>> Install([FromBody] InstallDto model)
......@@ -146,9 +151,6 @@ namespace IoTSharp.Controllers
await _dBInitializer.SeedRoleAsync();
await _dBInitializer.SeedUserAsync(model);
await _dBInitializer.SeedDictionary();
// await _dBInitializer.SeedI18N();
// actionResult = Ok(GetInstanceDto());
return new ApiResult<InstanceDto>(ApiCode.Success, "Ok", GetInstanceDto());
}
else
......
......@@ -528,10 +528,7 @@
<summary>
属性删除
</summary>
<param name="deviceId"></param>
<param name="keyName"></param>
<param name="dataSide"></param>
<returns></returns>
<param name="input">要删除的属性。</param>
</member>
<member name="M:IoTSharp.Controllers.DevicesController.GetSessionStatus">
<summary>
......
......@@ -13,6 +13,7 @@ using MQTTnet.Server;
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace IoTSharp.Services
{
......@@ -222,6 +223,34 @@ namespace IoTSharp.Services
_logger.LogInformation($"Bad username or password/AuthToken {obj.UserName},connection {obj.Endpoint} refused");
}
}
else if (_dbContextcv.Produces.Any(ak => obj.UserName.StartsWith( ak.Name+"_") && ak.ProduceToken == obj.Password && ak.Deleted == false))
{
var ak = _dbContextcv.Produces.Include(ak => ak.Customer).Include(ak => ak.Tenant).Include(ak => ak.Devices).FirstOrDefault(ak => ak.ProduceToken == obj.Password && ak.Deleted == false);
if (ak!=null && ak.Devices.Any(d => d.Name == obj.UserName && d.Deleted == false))
{
var devvalue = new Device() { Name = obj.UserName, DeviceType = ak.DefaultDeviceType, Timeout = ak.DefaultTimeout };
devvalue.Tenant = ak.Tenant;
devvalue.Customer = ak.Customer;
_dbContextcv.Device.Add(devvalue);
ak.Devices.Add(devvalue);
_dbContextcv.AfterCreateDevice(devvalue,ak.Id);
_dbContextcv.SaveChanges();
_queue.PublishConnect(devvalue.Id, ConnectStatus.Connected);
}
var mcp = ak.Devices.FirstOrDefault(d => d.Name == obj.UserName && d.Deleted == false);
if (mcp != null)
{
e.SessionItems.Add(nameof(Device), mcp);
e.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.Success;
_queue.PublishConnect(mcp.Id, ConnectStatus.Disconnected);
_logger.LogInformation($"Produce {ak.Name}'s device {mcp.Name}({mcp.Id}) is online ! Client name is {obj.UserName} and is endpoint{obj.Endpoint}");
}
else
{
e.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.BadUserNameOrPassword;
_logger.LogInformation($"Bad device name or ProduceToken {obj.UserName},connection {obj.Endpoint} refused");
}
}
else
{
e.ReasonCode = MQTTnet.Protocol.MqttConnectReasonCode.BadUserNameOrPassword;
......
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{f5644ba6-2a0c-49a5-9c9b-3cecd6db2d1f}</ProjectGuid>
<ProjectHome>.</ProjectHome>
<ProjectView>ShowAllFiles</ProjectView>
<StartupFile>docusaurus.config.js</StartupFile>
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<ProjectTypeGuids>{3AF33F2E-1136-4D97-BBB7-1795711AC8B8};{349c5851-65df-11da-9384-00065b846f21};{9092AA53-FB77-4645-B42D-1CCCA6BD08BD}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">17.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<StartWebBrowser>True</StartWebBrowser>
<SaveNodeJsSettingsInProjectFile>True</SaveNodeJsSettingsInProjectFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
<ItemGroup>
<Content Include="blog\authors.yml" />
<Content Include="docs\tutorial-basics\connectivity.md" />
<Content Include="docs\tutorial-basics\aggregate.md">
<SubType>Code</SubType>
</Content>
<Content Include="docs\tutorial-basics\appsettings.md" />
<Content Include="docs\tutorial-basics\deploy_by_docker.md" />
<Content Include="docs\tutorial-basics\deploy_linux.md" />
<Content Include="docs\tutorial-basics\deploy_win.md" />
<Content Include="docs\tutorial-basics\scriptuse.md" />
<Content Include="package.json" />
<Content Include="README.md" />
<Content Include="babel.config.js" />
<Content Include="docusaurus.config.js" />
<Content Include="sidebars.js" />
<Content Include="blog\2022-02-14-first-version-doc.md" />
<Content Include="docs\intro.md" />
<Content Include="docs\tutorial-basics\_category_.json" />
<Content Include="docs\tutorial-basics\debug.md" />
<Content Include="docs\tutorial-basics\gateway.md" />
<Content Include="docs\tutorial-basics\influxdb.md" />
<Content Include="docs\tutorial-basics\iotsharp.md" />
<Content Include="docs\tutorial-basics\sourcecode.md" />
<Content Include="docs\tutorial-basics\webapi.md" />
<Content Include="docs\tutorial-extras\_category_.json" />
<Content Include="docs\tutorial-extras\http.md" />
<Content Include="docs\tutorial-extras\mqtt.md" />
<Content Include="docs\tutorial-extras\raw_data_gateway.md" />
<Content Include="src\components\HomepageFeatures.module.css" />
<Content Include="src\components\HomepageFeatures.js" />
<Content Include="src\css\custom.css" />
<Content Include="src\pages\index.module.css" />
<Content Include="src\pages\markdown-page.md" />
<Content Include="src\pages\index.js" />
<Content Include="static\img\200x200.png" />
<Content Include="static\img\32x32.png" />
<Content Include="static\img\350x100.png" />
<Content Include="static\img\64x64.png" />
<Content Include="static\img\96x96.png" />
<Content Include="static\img\docusaurus.png" />
<Content Include="static\img\InfluxDB2.PNG" />
<Content Include="static\img\iotsharp.png" />
<Content Include="static\img\IoTSharpQQGruop.png" />
<Content Include="static\img\iotsharp\kep_iotgateway.png" />
<Content Include="static\img\iotsharp\kep_iotgateway2.png" />
<Content Include="static\img\iot_sharp_logo.png" />
<Content Include="static\img\screenshot.png" />
<Content Include="static\img\tn.png" />
<Content Include="static\img\20190615010003.jpg" />
<Content Include="static\img\20190615010115.jpg" />
<Content Include="static\img\qrcode.jpg" />
<Content Include="static\img\favicon.ico" />
<Content Include="static\img\logo.svg" />
<Content Include="static\img\undraw_docusaurus_mountain.svg" />
<Content Include="static\img\undraw_docusaurus_react.svg" />
<Content Include="static\img\undraw_docusaurus_tree.svg" />
<Content Include="static\img\iotsharp\add-gateway.png" />
<Content Include="static\img\iotsharp\bgweb.png" />
<Content Include="static\img\iotsharp\docker-run.png" />
<Content Include="static\img\iotsharp\font-login.png" />
<Content Include="static\img\iotsharp\gateway-config.png" />
<Content Include="static\img\iotsharp\gateway-online.png" />
<Content Include="static\img\iotsharp\gateway-token.png" />
<Content Include="static\img\iotsharp\influxdb-addtoken.png" />
<Content Include="static\img\iotsharp\influxdb-copytoken.png" />
<Content Include="static\img\iotsharp\influxdb-data.png" />
<Content Include="static\img\iotsharp\influxdb-ini.png" />
<Content Include="static\img\iotsharp\iotsharp-dashboard.png" />
<Content Include="static\img\iotsharp\iotsharp-regeist.png" />
<Content Include="static\img\iotsharp\project-appsettings.png" />
<Content Include="static\img\iotsharp\webapi-auth.png" />
<Content Include="static\img\iotsharp\webapi-deviceid.png" />
<Content Include="static\img\iotsharp\webapi-login.png" />
<Content Include="static\img\iotsharp\webapi-telemetry.png" />
<Content Include="static\img\tutorial\docsVersionDropdown.png" />
<Content Include="static\img\tutorial\localeDropdown.png" />
<Content Include="yarn.lock" />
</ItemGroup>
<ItemGroup>
<Folder Include="blog" />
<Folder Include="docs" />
<Folder Include="docs\tutorial-basics" />
<Folder Include="docs\tutorial-extras" />
<Folder Include="src" />
<Folder Include="src\components" />
<Folder Include="src\css" />
<Folder Include="src\pages" />
<Folder Include="static" />
<Folder Include="static\img" />
<Folder Include="static\img\iotsharp" />
<Folder Include="static\img\tutorial" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(VSToolsPath)\Node.js Tools\Microsoft.NodejsToolsV2.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>0</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:48022/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://localhost:1337</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}" User="">
<WebProjectProperties>
<StartPageUrl>
</StartPageUrl>
<StartAction>CurrentPage</StartAction>
<AspNetDebugging>True</AspNetDebugging>
<SilverlightDebugging>False</SilverlightDebugging>
<NativeDebugging>False</NativeDebugging>
<SQLDebugging>False</SQLDebugging>
<ExternalProgram>
</ExternalProgram>
<StartExternalURL>
</StartExternalURL>
<StartCmdLineArguments>
</StartCmdLineArguments>
<StartWorkingDirectory>
</StartWorkingDirectory>
<EnableENC>False</EnableENC>
<AlwaysStartWebServerOnDebug>False</AlwaysStartWebServerOnDebug>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
</Project>
\ No newline at end of file
---
slug: videos_1
title: IoTSharp培训教程第一集 开发环境安装配置、项目克隆、编译、调试、安装、登录
authors:
name: maikebing
title: IoTSharp Core Team
url: https://github.com/maikebing
image_url: https://github.com/maikebing.png
tags: [iotsharp]
---
<iframe src="//player.bilibili.com/player.html?aid=860913559&bvid=BV1QV4y1A78g&cid=914648074&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
IoTSharp 是一个 基于.Net Core 开源的物联网基础平台, 支持 HTTP、MQTT 、CoAp 协议, 属性数据和遥测数据协议简单类型丰富,简单设置即可将数据存储在PostgreSql、MySql、Oracle、SQLServer、Sqlite,是一个用于数据收集、处理、可视化与设备管理的 IoT 平台.
\ No newline at end of file
---
slug: videos_2
title: IoTSharp培训教程第二集 规则链使用
authors:
name: maikebing
title: IoTSharp Core Team
url: https://github.com/maikebing
image_url: https://github.com/maikebing.png
tags: [iotsharp]
---
<iframe src="//player.bilibili.com/player.html?aid=651347967&bvid=BV1be4y1N74s&cid=993314593&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
\ No newline at end of file
{
"name": "IoTSharp",
"lockfileVersion": 3,
"requires": true,
"packages": {}
}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册