Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
IoTSharp
提交
46b2d006
I
IoTSharp
项目概览
jobily
/
IoTSharp
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
IoTSharp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
46b2d006
编写于
1月 18, 2019
作者:
麦壳饼
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add AddDeviceIdentity
Add ApiResult
上级
1e6d8f69
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
728 addition
and
39 deletion
+728
-39
IoTSharp.Hub/Controllers/CustomersController.cs
IoTSharp.Hub/Controllers/CustomersController.cs
+21
-11
IoTSharp.Hub/Controllers/DevicesController.cs
IoTSharp.Hub/Controllers/DevicesController.cs
+30
-8
IoTSharp.Hub/Controllers/TenantsController.cs
IoTSharp.Hub/Controllers/TenantsController.cs
+0
-1
IoTSharp.Hub/Data/ApplicationDbContext.cs
IoTSharp.Hub/Data/ApplicationDbContext.cs
+2
-6
IoTSharp.Hub/Data/Device.cs
IoTSharp.Hub/Data/Device.cs
+5
-6
IoTSharp.Hub/Data/DeviceIdentity.cs
IoTSharp.Hub/Data/DeviceIdentity.cs
+36
-0
IoTSharp.Hub/Data/Enums.cs
IoTSharp.Hub/Data/Enums.cs
+18
-7
IoTSharp.Hub/Data/Migrations/20190118115805_AddDeviceIdentity.Designer.cs
...a/Migrations/20190118115805_AddDeviceIdentity.Designer.cs
+510
-0
IoTSharp.Hub/Data/Migrations/20190118115805_AddDeviceIdentity.cs
...p.Hub/Data/Migrations/20190118115805_AddDeviceIdentity.cs
+43
-0
IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs
....Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs
+29
-0
IoTSharp.Hub/Dtos/ApiResult.cs
IoTSharp.Hub/Dtos/ApiResult.cs
+34
-0
未找到文件。
IoTSharp.Hub/Controllers/CustomersController.cs
浏览文件 @
46b2d006
...
...
@@ -6,10 +6,12 @@ using Microsoft.AspNetCore.Http;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Hub.Data
;
using
Microsoft.AspNetCore.Authorization
;
namespace
IoTSharp.Hub.Controllers
{
[
Route
(
"api/[controller]"
)]
[
Authorize
]
[
ApiController
]
public
class
CustomersController
:
ControllerBase
{
...
...
@@ -22,12 +24,22 @@ namespace IoTSharp.Hub.Controllers
// GET: api/Tenants
[
HttpGet
(
"Tenant/{tenantId}"
)]
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
public
async
Task
<
ActionResult
<
IEnumerable
<
Customer
>>>
GetCustomers
(
Guid
tenantId
)
{
return
(
await
_context
.
Tenant
.
FindAsync
(
tenantId
)).
Customers
?.
ToList
();
var
f
=
from
c
in
_context
.
Customer
where
c
.
Tenant
.
Id
==
tenantId
select
c
;
if
(!
f
.
Any
())
{
return
NotFound
();
}
else
{
return
await
f
.
ToArrayAsync
();
}
}
// GET: api/Customers/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Customer
>>
GetCustomer
(
Guid
id
)
{
...
...
@@ -42,6 +54,7 @@ namespace IoTSharp.Hub.Controllers
}
// PUT: api/Customers/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
CustomerAdmin
))]
[
HttpPut
(
"{id}"
)]
public
async
Task
<
IActionResult
>
PutCustomer
(
Guid
id
,
Customer
customer
)
{
...
...
@@ -49,12 +62,7 @@ namespace IoTSharp.Hub.Controllers
{
return
BadRequest
();
}
var
tent
=
await
_context
.
Tenant
.
FindAsync
(
customer
.
Id
);
if
(
tent
==
null
)
{
return
NotFound
();
}
customer
.
Tenant
=
tent
;
customer
.
Tenant
=
_context
.
Tenant
.
Find
(
customer
.
Tenant
.
Id
);
_context
.
Entry
(
customer
).
State
=
EntityState
.
Modified
;
try
{
...
...
@@ -76,16 +84,18 @@ namespace IoTSharp.Hub.Controllers
}
// POST: api/Customers
[
Authorize
(
Roles
=
nameof
(
UserRole
.
CustomerAdmin
))]
[
HttpPost
]
public
async
Task
<
ActionResult
<
Customer
>>
PostCustomer
(
Customer
customer
)
{
customer
.
Tenant
=
_context
.
Tenant
.
Find
(
customer
.
Tenant
.
Id
);
customer
.
Tenant
=
_context
.
Tenant
.
Find
(
customer
.
Tenant
.
Id
);
_context
.
Customer
.
Add
(
customer
);
await
_context
.
SaveChangesAsync
();
return
CreatedAtAction
(
"GetCustomer"
,
customer
.
Id
);
return
await
GetCustomer
(
customer
.
Id
);
}
// DELETE: api/Customers/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
TenantAdmin
))]
[
HttpDelete
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Customer
>>
DeleteCustomer
(
Guid
id
)
{
...
...
@@ -108,7 +118,7 @@ namespace IoTSharp.Hub.Controllers
public
class
TenantDto
{
public
Guid
Id
{
get
;
set
;
}
public
Guid
Id
{
get
;
set
;
}
}
}
}
}
\ No newline at end of file
IoTSharp.Hub/Controllers/DevicesController.cs
浏览文件 @
46b2d006
...
...
@@ -6,10 +6,13 @@ using Microsoft.AspNetCore.Http;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.EntityFrameworkCore
;
using
IoTSharp.Hub.Data
;
using
Microsoft.AspNetCore.Authorization
;
using
IoTSharp.Hub.Dtos
;
namespace
IoTSharp.Hub.Controllers
{
[
Route
(
"api/[controller]"
)]
[
Authorize
]
[
ApiController
]
public
class
DevicesController
:
ControllerBase
{
...
...
@@ -21,13 +24,24 @@ namespace IoTSharp.Hub.Controllers
}
// GET: api/Devices
[
HttpGet
(
"Customers/{customerId}"
)]
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
]
public
async
Task
<
ActionResult
<
IEnumerable
<
Device
>>>
GetDevice
(
)
public
async
Task
<
ActionResult
<
IEnumerable
<
Device
>>>
GetDevice
s
(
Guid
customerId
)
{
return
await
_context
.
Device
.
ToListAsync
();
var
f
=
from
c
in
_context
.
Device
where
c
.
Customer
.
Id
==
customerId
select
c
;
if
(!
f
.
Any
())
{
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundCustomer
,
$"Customer
{
customerId
}
not found "
,
customerId
));
}
else
{
return
await
f
.
ToArrayAsync
();
}
}
// GET: api/Devices/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
NormalUser
))]
[
HttpGet
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Device
>>
GetDevice
(
Guid
id
)
{
...
...
@@ -35,13 +49,14 @@ namespace IoTSharp.Hub.Controllers
if
(
device
==
null
)
{
return
NotFound
();
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundDevice
,
$"Device
{
id
}
not found "
,
id
)
);
}
return
device
;
}
// PUT: api/Devices/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
CustomerAdmin
))]
[
HttpPut
(
"{id}"
)]
public
async
Task
<
IActionResult
>
PutDevice
(
Guid
id
,
Device
device
)
{
...
...
@@ -60,7 +75,7 @@ namespace IoTSharp.Hub.Controllers
{
if
(!
DeviceExists
(
id
))
{
return
NotFound
();
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundDevice
,
$"Device
{
id
}
not found "
,
id
)
);
}
else
{
...
...
@@ -72,23 +87,30 @@ namespace IoTSharp.Hub.Controllers
}
// POST: api/Devices
[
Authorize
(
Roles
=
nameof
(
UserRole
.
CustomerAdmin
))]
[
HttpPost
]
public
async
Task
<
ActionResult
<
Device
>>
PostDevice
(
Device
device
)
{
device
.
Tenant
=
_context
.
Tenant
.
Find
(
device
.
Tenant
.
Id
);
device
.
Customer
=
_context
.
Customer
.
Find
(
device
.
Customer
.
Id
);
if
(
device
.
Tenant
==
null
||
device
.
Customer
==
null
)
{
return
NotFound
(
new
ApiResult
<
Device
>(
ApiCode
.
NotFoundTenantOrCustomer
,
$"Not found Tenant or Customer "
,
device
));
}
_context
.
Device
.
Add
(
device
);
await
_context
.
SaveChangesAsync
();
return
CreatedAtAction
(
"GetDevice"
,
new
{
id
=
device
.
Id
},
device
);
return
await
GetDevice
(
device
.
Id
);
}
// DELETE: api/Devices/5
[
Authorize
(
Roles
=
nameof
(
UserRole
.
CustomerAdmin
))]
[
HttpDelete
(
"{id}"
)]
public
async
Task
<
ActionResult
<
Device
>>
DeleteDevice
(
Guid
id
)
{
var
device
=
await
_context
.
Device
.
FindAsync
(
id
);
if
(
device
==
null
)
{
return
NotFound
();
return
NotFound
(
new
ApiResult
<
Guid
>(
ApiCode
.
NotFoundDevice
,
$"Device
{
id
}
not found "
,
id
)
);
}
_context
.
Device
.
Remove
(
device
);
...
...
@@ -102,4 +124,4 @@ namespace IoTSharp.Hub.Controllers
return
_context
.
Device
.
Any
(
e
=>
e
.
Id
==
id
);
}
}
}
}
\ No newline at end of file
IoTSharp.Hub/Controllers/TenantsController.cs
浏览文件 @
46b2d006
...
...
@@ -22,7 +22,6 @@ namespace IoTSharp.Hub.Controllers
private
ApplicationDbContext
_context
;
private
ILogger
_logger
;
private
readonly
UserManager
<
IdentityUser
>
_userManager
;
private
readonly
IConfiguration
_configuration
;
private
readonly
SignInManager
<
IdentityUser
>
_signInManager
;
public
TenantsController
(
...
...
IoTSharp.Hub/Data/ApplicationDbContext.cs
浏览文件 @
46b2d006
...
...
@@ -24,7 +24,6 @@ namespace IoTSharp.Hub.Data
{
Database
.
Migrate
();
}
}
public
DatabaseType
DatabaseType
{
get
;
private
set
;
}
...
...
@@ -32,7 +31,7 @@ namespace IoTSharp.Hub.Data
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
base
.
OnModelCreating
(
modelBuilder
);
modelBuilder
.
Entity
<
DataStorage
>()
.
HasDiscriminator
<
DataCatalog
>(
nameof
(
Data
.
DataStorage
.
Catalog
))
.
HasValue
<
DataStorage
>(
DataCatalog
.
None
)
...
...
@@ -45,9 +44,6 @@ namespace IoTSharp.Hub.Data
modelBuilder
.
Entity
<
AttributeLatest
>().
HasDiscriminator
<
DataCatalog
>(
nameof
(
Data
.
DataStorage
.
Catalog
));
modelBuilder
.
Entity
<
TelemetryData
>().
HasDiscriminator
<
DataCatalog
>(
nameof
(
Data
.
DataStorage
.
Catalog
));
modelBuilder
.
Entity
<
TelemetryLatest
>().
HasDiscriminator
<
DataCatalog
>(
nameof
(
Data
.
DataStorage
.
Catalog
));
switch
(
DatabaseType
)
{
...
...
@@ -67,7 +63,6 @@ namespace IoTSharp.Hub.Data
}
}
private
void
ForNpgsql
(
ModelBuilder
modelBuilder
)
{
modelBuilder
.
Entity
<
TelemetryData
>()
...
...
@@ -131,5 +126,6 @@ namespace IoTSharp.Hub.Data
public
DbSet
<
DataStorage
>
DataStorage
{
get
;
set
;
}
public
DbSet
<
AttributeData
>
AttributeData
{
get
;
set
;
}
public
DbSet
<
TelemetryLatest
>
TelemetryLatest
{
get
;
set
;
}
public
DbSet
<
DeviceIdentity
>
DeviceIdentities
{
get
;
set
;
}
}
}
\ No newline at end of file
IoTSharp.Hub/Data/Device
s
.cs
→
IoTSharp.Hub/Data/Device.cs
浏览文件 @
46b2d006
...
...
@@ -7,20 +7,19 @@ namespace IoTSharp.Hub.Data
{
public
class
Device
{
public
Guid
Id
{
get
;
set
;
}
=
Guid
.
NewGuid
();
public
string
Name
{
get
;
set
;
}
public
string
Type
{
get
;
set
;
}
public
Tenant
Tenant
{
get
;
set
;
}
public
Tenant
Tenant
{
get
;
set
;
}
public
Customer
Customer
{
get
;
set
;
}
public
Customer
Customer
{
get
;
set
;
}
public
virtual
List
<
AttributeData
>
AttributeData
{
get
;
set
;
}
public
virtual
List
<
AttributeLatest
>
AttributeLatest
{
get
;
set
;
}
public
virtual
List
<
TelemetryData
>
TelemetryData
{
get
;
set
;
}
public
virtual
List
<
TelemetryData
>
TelemetryData
{
get
;
set
;
}
public
virtual
List
<
TelemetryLatest
>
TelemetryLatest
{
get
;
set
;
}
}
}
}
\ No newline at end of file
IoTSharp.Hub/Data/DeviceIdentity.cs
0 → 100644
浏览文件 @
46b2d006
using
System
;
using
System.Collections.Generic
;
using
System.ComponentModel.DataAnnotations
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Hub.Data
{
public
class
DeviceIdentity
{
[
Key
]
public
Guid
Id
{
get
;
set
;
}
[
Required
]
[
EnumDataType
(
typeof
(
IdentityType
))]
public
IdentityType
IdentityType
{
get
;
set
;
}
/// <summary>
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.AccessToken"/> ,this is a Token.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.DevicePassword"/> ,this is a device name.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.X509Certificate"/> ,this is X509 Certificate' Fingerprint.
/// </summary>
[
Required
]
public
string
IdentityId
{
get
;
set
;
}
/// <summary>
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.AccessToken"/> ,this is null.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.DevicePassword"/> ,this is a password.
/// When <see cref="IdentityType"/> Is <see cref="IdentityType.X509Certificate"/> ,this is X509 Certificate' PEM.
/// </summary>
public
string
IdentityValue
{
get
;
set
;
}
[
Required
]
public
Device
Device
{
get
;
set
;
}
}
}
\ No newline at end of file
IoTSharp.Hub/Data/Enums.cs
浏览文件 @
46b2d006
...
...
@@ -9,17 +9,21 @@ namespace IoTSharp.Hub.Data
{
public
static
class
IoTSharpClaimTypes
{
public
const
string
Customer
=
"http://schemas.iotsharp.net/ws/2019/01/identity/claims/customer"
;
public
const
string
Tenant
=
"http://schemas.iotsharp.net/ws/2019/01/identity/claims/tenant"
;
}
public
enum
ApiCode
:
int
public
enum
ApiCode
:
int
{
Success
=
10000
,
LoginError
=
10001
,
Success
=
10000
,
LoginError
=
10001
,
Exception
=
10002
,
AlreadyExists
=
10003
,
NotFoundTenantOrCustomer
=
10004
,
NotFoundDevice
=
10005
,
NotFoundCustomer
=
10006
,
}
public
enum
DataCatalog
{
None
,
...
...
@@ -27,8 +31,8 @@ namespace IoTSharp.Hub.Data
AttributeLatest
,
TelemetryData
,
TelemetryLatest
,
}
public
enum
UserRole
{
Anonymous
,
...
...
@@ -36,7 +40,6 @@ namespace IoTSharp.Hub.Data
CustomerAdmin
,
TenantAdmin
,
SystemAdmin
,
}
public
enum
DataType
...
...
@@ -49,10 +52,18 @@ namespace IoTSharp.Hub.Data
XML
,
Binary
}
public
enum
DatabaseType
{
mssql
,
npgsql
,
sqlite
}
}
public
enum
IdentityType
{
AccessToken
,
DevicePassword
,
X509Certificate
}
}
\ No newline at end of file
IoTSharp.Hub/Data/Migrations/20190118115805_AddDeviceIdentity.Designer.cs
0 → 100644
浏览文件 @
46b2d006
// <auto-generated />
using
System
;
using
IoTSharp.Hub.Data
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
namespace
IoTSharp.Hub.Migrations
{
[
DbContext
(
typeof
(
ApplicationDbContext
))]
[
Migration
(
"20190118115805_AddDeviceIdentity"
)]
partial
class
AddDeviceIdentity
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
SerialColumn
)
.
HasAnnotation
(
"ProductVersion"
,
"2.2.0-rtm-35687"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
modelBuilder
.
Entity
(
"IoTSharp.Hub.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.Hub.Data.DataStorage"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
int
>(
"Catalog"
);
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
<
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.Hub.Data.Device"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
.
ValueGeneratedOnAdd
();
b
.
Property
<
Guid
?>(
"CustomerId"
);
b
.
Property
<
string
>(
"Name"
);
b
.
Property
<
Guid
?>(
"TenantId"
);
b
.
Property
<
string
>(
"Type"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"CustomerId"
);
b
.
HasIndex
(
"TenantId"
);
b
.
ToTable
(
"Device"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.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.Hub.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.Hub.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.Hub.Data.AttributeData"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Hub.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
1
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.AttributeLatest"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Hub.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"AttributeLatest_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
2
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.TelemetryData"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Hub.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"TelemetryData_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
3
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.TelemetryLatest"
,
b
=>
{
b
.
HasBaseType
(
"IoTSharp.Hub.Data.DataStorage"
);
b
.
Property
<
Guid
>(
"DeviceId"
)
.
HasColumnName
(
"TelemetryLatest_DeviceId"
);
b
.
HasIndex
(
"DeviceId"
);
b
.
HasDiscriminator
().
HasValue
(
4
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.Customer"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Tenant"
,
"Tenant"
)
.
WithMany
(
"Customers"
)
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.Device"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Customer"
,
"Customer"
)
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"IoTSharp.Hub.Data.Tenant"
,
"Tenant"
)
.
WithMany
(
"Devices"
)
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.DeviceIdentity"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
()
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.Relationship"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Customer"
,
"Customer"
)
.
WithMany
()
.
HasForeignKey
(
"CustomerId"
);
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityUser"
,
"IdentityUser"
)
.
WithMany
()
.
HasForeignKey
(
"IdentityUserId"
);
b
.
HasOne
(
"IoTSharp.Hub.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.Hub.Data.AttributeData"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
(
"AttributeData"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.AttributeLatest"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
(
"AttributeLatest"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.TelemetryData"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
(
"TelemetryData"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.TelemetryLatest"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
(
"TelemetryLatest"
)
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
#pragma warning restore 612, 618
}
}
}
IoTSharp.Hub/Data/Migrations/20190118115805_AddDeviceIdentity.cs
0 → 100644
浏览文件 @
46b2d006
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
namespace
IoTSharp.Hub.Migrations
{
public
partial
class
AddDeviceIdentity
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"DeviceIdentities"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
Guid
>(
nullable
:
false
),
IdentityType
=
table
.
Column
<
int
>(
nullable
:
false
),
IdentityId
=
table
.
Column
<
string
>(
nullable
:
false
),
IdentityValue
=
table
.
Column
<
string
>(
nullable
:
true
),
DeviceId
=
table
.
Column
<
Guid
>(
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_DeviceIdentities"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_DeviceIdentities_Device_DeviceId"
,
column
:
x
=>
x
.
DeviceId
,
principalTable
:
"Device"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateIndex
(
name
:
"IX_DeviceIdentities_DeviceId"
,
table
:
"DeviceIdentities"
,
column
:
"DeviceId"
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"DeviceIdentities"
);
}
}
}
IoTSharp.Hub/Data/Migrations/ApplicationDbContextModelSnapshot.cs
浏览文件 @
46b2d006
...
...
@@ -110,6 +110,27 @@ namespace IoTSharp.Hub.Migrations
b
.
ToTable
(
"Device"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.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.Hub.Data.Relationship"
,
b
=>
{
b
.
Property
<
Guid
>(
"Id"
)
...
...
@@ -382,6 +403,14 @@ namespace IoTSharp.Hub.Migrations
.
HasForeignKey
(
"TenantId"
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.DeviceIdentity"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Device"
,
"Device"
)
.
WithMany
()
.
HasForeignKey
(
"DeviceId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
);
});
modelBuilder
.
Entity
(
"IoTSharp.Hub.Data.Relationship"
,
b
=>
{
b
.
HasOne
(
"IoTSharp.Hub.Data.Customer"
,
"Customer"
)
...
...
IoTSharp.Hub/Dtos/ApiResult.cs
0 → 100644
浏览文件 @
46b2d006
using
IoTSharp.Hub.Data
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Threading.Tasks
;
namespace
IoTSharp.Hub.Dtos
{
public
class
ApiResult
{
public
ApiResult
()
{
}
public
ApiResult
(
ApiCode
_code
,
string
_msg
)
{
Code
=
(
int
)
_code
;
Msg
=
_msg
;
}
public
int
Code
{
get
;
set
;
}
=
(
int
)
ApiCode
.
Success
;
public
string
Msg
{
get
;
set
;
}
=
"OK"
;
}
public
class
ApiResult
<
T
>
:
ApiResult
{
public
ApiResult
(
ApiCode
_code
,
string
_msg
,
T
data
)
:
base
(
_code
,
_msg
)
{
Data
=
data
;
}
public
T
Data
{
set
;
get
;
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录