Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IoTSharp
IoTSharp
提交
10517109
IoTSharp
项目概览
IoTSharp
/
IoTSharp
9 个月 前同步成功
通知
15
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
10517109
编写于
5月 18, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add device owner and auto create device
上级
f3f171da
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
657 addition
and
11 deletion
+657
-11
IoTSharp/Data/Migrations/20190518041926_DeviceOwner.Designer.cs
...rp/Data/Migrations/20190518041926_DeviceOwner.Designer.cs
+580
-0
IoTSharp/Data/Migrations/20190518041926_DeviceOwner.cs
IoTSharp/Data/Migrations/20190518041926_DeviceOwner.cs
+57
-0
IoTSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs
...harp/Data/Migrations/ApplicationDbContextModelSnapshot.cs
+5
-5
IoTSharp/Handlers/MqttEventsHandler.cs
IoTSharp/Handlers/MqttEventsHandler.cs
+15
-6
未找到文件。
IoTSharp/Data/Migrations/20190518041926_DeviceOwner.Designer.cs
0 → 100644
浏览文件 @
10517109
// <auto-generated />
using
System
;
using
IoTSharp.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
namespace
IoTSharp.Migrations
{
[
DbContext
(
typeof
(
ApplicationDbContext
))]
[
Migration
(
"20190518041926_DeviceOwner"
)]
partial
class
DeviceOwner
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
SerialColumn
)
.
HasAnnotation
(
"ProductVersion"
,
"2.2.4-servicing-10062"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
modelBuilder
.
Entity
(
"IoTSharp.Data.AuditLog"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"ActionData"
)
.
HasColumnType
(
"jsonb"
);
b
.
Property
<
string
>(
"ActionName"
);
b
.
Property
<
string
>(
"ActionResult"
)
.
HasColumnType
(
"jsonb"
);
b
.
Property
<
DateTime
>(
"ActiveDateTime"
);
b
.
Property
<
Guid
?>(
"CustomerId"
);
b
.
Property
<
Guid
>(
"ObjectID"
);
b
.
Property
<
string
>(
"ObjectName"
);
b
.
Property
<
int
>(
"ObjectType"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
Property
<
string
>(
"UserId"
);
b
.
Property
<
string
>(
"UserName"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"TenantId"
);
b
.
ToTable
(
"AuditLog"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Customer"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Address"
);
b
.
Property
<
string
>(
"City"
);
b
.
Property
<
string
>(
"Country"
);
b
.
Property
<
string
>(
"Email"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
string
>(
"Phone"
);
b
.
Property
<
string
>(
"Province"
);
b
.
Property
<
string
>(
"Street"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
Property
<
int
>(
"ZipCode"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"TenantId"
);
b
.
ToTable
(
"Customer"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DataStorage"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
int
>(
"Catalog"
);
b
.
Property
<
int
>(
"DataSide"
);
b
.
Property
<
DateTime
>(
"DateTime"
);
b
.
Property
<
string
>(
"KeyName"
)
.
IsRequired
();
b
.
Property
<
int
>(
"Type"
);
b
.
Property
<
byte
[
]>
(
"Value_Binary"
);
b
.
Property
<
bool
>(
"Value_Boolean"
);
b
.
Property
<
DateTime
>(
"Value_DateTime"
);
b
.
Property
<
double
>(
"Value_Double"
);
b
.
Property
<
string
>(
"Value_Json"
)
.
HasColumnType
(
"jsonb"
);
b
.
Property
<
long
>(
"Value_Long"
);
b
.
Property
<
string
>(
"Value_String"
);
b
.
Property
<
string
>(
"Value_XML"
)
.
HasColumnType
(
"xml"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"DataStorage"
);
b
.
HasDiscriminator
<
int
>(
"Catalog"
).
HasValue
(
0
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Device"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
Guid
?>(
"CustomerId"
);
b
.
Property
<
int
>(
"DeviceType"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
Guid
?>(
"OwnerId"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"OwnerId"
);
b
.
HasIndex
(
"TenantId"
);
b
.
ToTable
(
"Device"
);
b
.
HasDiscriminator
<
int
>(
"DeviceType"
).
HasValue
(
0
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceIdentity"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
Guid
>(
"DeviceId"
);
b
.
Property
<
string
>(
"IdentityId"
)
.
IsRequired
();
b
.
Property
<
int
>(
"IdentityType"
);
b
.
Property
<
string
>(
"IdentityValue"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
ToTable
(
"DeviceIdentities"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Relationship"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
Guid
?>(
"CustomerId"
);
b
.
Property
<
string
>(
"IdentityUserId"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"IdentityUserId"
);
b
.
HasIndex
(
"TenantId"
);
b
.
ToTable
(
"Relationship"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Tenant"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"Address"
);
b
.
Property
<
string
>(
"City"
);
b
.
Property
<
string
>(
"Country"
);
b
.
Property
<
string
>(
"EMail"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
string
>(
"Phone"
);
b
.
Property
<
string
>(
"Province"
);
b
.
Property
<
string
>(
"Street"
);
b
.
Property
<
int
>(
"ZipCode"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Tenant"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
();
b
.
Property
<
string
>(
"Name"
)
.
HasMaxLength
(
256
);
b
.
Property
<
string
>(
"NormalizedName"
)
.
HasMaxLength
(
256
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"NormalizedName"
)
.
IsUnique
()
.
HasName
(
"RoleNameIndex"
);
b
.
ToTable
(
"AspNetRoles"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"ClaimType"
);
b
.
Property
<
string
>(
"ClaimValue"
);
b
.
Property
<
string
>(
"RoleId"
)
.
IsRequired
();
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"AspNetRoleClaims"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUser"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
int
>(
"AccessFailedCount"
);
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
();
b
.
Property
<
string
>(
"Email"
)
.
HasMaxLength
(
256
);
b
.
Property
<
bool
>(
"EmailConfirmed"
);
b
.
Property
<
bool
>(
"LockoutEnabled"
);
b
.
Property
<
DateTimeOffset
?>(
"LockoutEnd"
);
b
.
Property
<
string
>(
"NormalizedEmail"
)
.
HasMaxLength
(
256
);
b
.
Property
<
string
>(
"NormalizedUserName"
)
.
HasMaxLength
(
256
);
b
.
Property
<
string
>(
"PasswordHash"
);
b
.
Property
<
string
>(
"PhoneNumber"
);
b
.
Property
<
bool
>(
"PhoneNumberConfirmed"
);
b
.
Property
<
string
>(
"SecurityStamp"
);
b
.
Property
<
bool
>(
"TwoFactorEnabled"
);
b
.
Property
<
string
>(
"UserName"
)
.
HasMaxLength
(
256
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"NormalizedEmail"
)
.
HasName
(
"EmailIndex"
);
b
.
HasIndex
(
"NormalizedUserName"
)
.
IsUnique
()
.
HasName
(
"UserNameIndex"
);
b
.
ToTable
(
"AspNetUsers"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserClaim<string>"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
string
>(
"ClaimType"
);
b
.
Property
<
string
>(
"ClaimValue"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
();
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserClaims"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
Property
<
string
>(
"LoginProvider"
);
b
.
Property
<
string
>(
"ProviderKey"
);
b
.
Property
<
string
>(
"ProviderDisplayName"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
();
b
.
HasKey
(
"LoginProvider"
,
"ProviderKey"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserLogins"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserRole<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
);
b
.
Property
<
string
>(
"RoleId"
);
b
.
HasKey
(
"UserId"
,
"RoleId"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"AspNetUserRoles"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserToken<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
);
b
.
Property
<
string
>(
"LoginProvider"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
string
>(
"Value"
);
b
.
HasKey
(
"UserId"
,
"LoginProvider"
,
"Name"
);
b
.
ToTable
(
"AspNetUserTokens"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.AttributeData"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
1
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.AttributeLatest"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"AttributeLatest_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
2
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.TelemetryData"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"TelemetryData_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
3
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.TelemetryLatest"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"TelemetryLatest_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
4
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Gateway"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Data.Device"
);
b
.
HasDiscriminator
().
HasValue
(
1
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.AuditLog"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Customer"
,
"Customer"
)
.
WithMany
()
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"IoTSharp.Data.Tenant"
,
"Tenant"
)
.
WithMany
()
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Customer"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Tenant"
,
"Tenant"
)
.
WithMany
(
"Customers"
)
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Device"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Customer"
,
"Customer"
)
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"IoTSharp.Data.Gateway"
,
"Owner"
)
.
WithMany
(
"Children"
)
.
HasForeignKey
(
"OwnerId"
);
b
.
HasOne
(
"IoTSharp.Data.Tenant"
,
"Tenant"
)
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.DeviceIdentity"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
.
WithMany
()
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.Relationship"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Customer"
,
"Customer"
)
.
WithMany
()
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
,
"IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"IdentityUserId"
);
b
.
HasOne
(
"IoTSharp.Data.Tenant"
,
"Tenant"
)
.
WithMany
()
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserClaim<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserRole<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserToken<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.AttributeData"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
.
WithMany
(
"AttributeData"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.AttributeLatest"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
.
WithMany
(
"AttributeLatest"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.TelemetryData"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
.
WithMany
(
"TelemetryData"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Data.TelemetryLatest"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Data.Device"
,
"Device"
)
.
WithMany
(
"TelemetryLatest"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
#pragma warning restore 612, 618
}
}
}
IoTSharp/Data/Migrations/20190518041926_DeviceOwner.cs
0 → 100644
浏览文件 @
10517109
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
IoTSharp.Migrations
{
public
partial
class
DeviceOwner
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_Device_Device_GatewayId"
,
table
:
"Device"
);
migrationBuilder
.
RenameColumn
(
name
:
"GatewayId"
,
table
:
"Device"
,
newName
:
"OwnerId"
);
migrationBuilder
.
RenameIndex
(
name
:
"IX_Device_GatewayId"
,
table
:
"Device"
,
newName
:
"IX_Device_OwnerId"
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_Device_Device_OwnerId"
,
table
:
"Device"
,
column
:
"OwnerId"
,
principalTable
:
"Device"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Restrict
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropForeignKey
(
name
:
"FK_Device_Device_OwnerId"
,
table
:
"Device"
);
migrationBuilder
.
RenameColumn
(
name
:
"OwnerId"
,
table
:
"Device"
,
newName
:
"GatewayId"
);
migrationBuilder
.
RenameIndex
(
name
:
"IX_Device_OwnerId"
,
table
:
"Device"
,
newName
:
"IX_Device_GatewayId"
);
migrationBuilder
.
AddForeignKey
(
name
:
"FK_Device_Device_GatewayId"
,
table
:
"Device"
,
column
:
"GatewayId"
,
principalTable
:
"Device"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Restrict
);
}
}
}
IoTSharp/Data/Migrations/ApplicationDbContextModelSnapshot.cs
浏览文件 @
10517109
...
...
@@ -139,17 +139,17 @@ namespace IoTSharp.Migrations
b
.
Property
<
int
>(
"DeviceType"
);
b
.
Property
<
Guid
?>(
"GatewayId"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
Guid
?>(
"OwnerId"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"
Gateway
Id"
);
b
.
HasIndex
(
"
Owner
Id"
);
b
.
HasIndex
(
"TenantId"
);
...
...
@@ -464,9 +464,9 @@ namespace IoTSharp.Migrations
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"IoTSharp.Data.Gateway"
)
b
.
HasOne
(
"IoTSharp.Data.Gateway"
,
"Owner"
)
.
WithMany
(
"Children"
)
.
HasForeignKey
(
"
Gateway
Id"
);
.
HasForeignKey
(
"
Owner
Id"
);
b
.
HasOne
(
"IoTSharp.Data.Tenant"
,
"Tenant"
)
.
WithMany
(
"Devices"
)
...
...
IoTSharp/Handlers/MqttEventsHandler.cs
浏览文件 @
10517109
...
...
@@ -69,7 +69,7 @@ namespace IoTSharp.Handlers
var
tpary
=
topic
.
Split
(
'/'
);
if
(
tpary
.
Length
>=
3
&&
tpary
[
0
]
==
"devices"
&&
Devices
.
ContainsKey
(
e
.
ClientId
))
{
Device
device
=
JudgeDevice
(
tpary
,
Devices
[
e
.
ClientId
]);
Device
device
=
Judge
OrCreateNew
Device
(
tpary
,
Devices
[
e
.
ClientId
]);
if
(
device
!=
null
)
{
if
(
tpary
[
2
]
==
"telemetry"
)
...
...
@@ -111,15 +111,24 @@ namespace IoTSharp.Handlers
}
private
Device
JudgeDevice
(
string
[]
tpary
,
Device
device
)
private
Device
Judge
OrCreateNew
Device
(
string
[]
tpary
,
Device
device
)
{
Device
devicedatato
=
device
;
if
(
tpary
[
1
]
!=
"me"
&&
device
.
DeviceType
==
DeviceType
.
Gateway
)
{
//var ch = from g in _dbContext.Gateway.Include(c => c.Children) where g.Id == device.Id select g.Children;
//if (ch.Any)
//var subdev = from cd in ().FirstOrDefault() where cd.Name == tpary[1] select cd ;
//devicedatato = subdev.FirstOrDefault();
var
ch
=
from
g
in
_dbContext
.
Gateway
.
Include
(
c
=>
c
.
Children
)
where
g
.
Id
==
device
.
Id
select
g
;
var
gw
=
ch
.
FirstOrDefault
();
var
subdev
=
from
cd
in
gw
.
Children
where
cd
.
Name
==
tpary
[
1
]
select
cd
;
if
(!
subdev
.
Any
())
{
devicedatato
=
new
Device
()
{
Id
=
Guid
.
NewGuid
(),
Name
=
tpary
[
1
],
DeviceType
=
DeviceType
.
Device
,
Tenant
=
device
.
Tenant
,
Customer
=
device
.
Customer
};
gw
.
Children
.
Add
(
devicedatato
);
_dbContext
.
SaveChangesAsync
();
}
else
{
devicedatato
=
subdev
.
FirstOrDefault
();
}
}
return
devicedatato
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录