提交 baaff3dc 编写于 作者: 麦壳饼's avatar 麦壳饼

Split database-related code to support multiple databases

上级 f3eb811c
......@@ -7,12 +7,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AntDesign" Version="0.5.0-nightly-2012261732" />
<PackageReference Include="AntDesign" Version="0.6.0" />
<PackageReference Include="AntDesign.Charts" Version="0.2.0-*" />
<PackageReference Include="AntDesign.Pro.Layout" Version="0.1.0-nightly-201127071242" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.3" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="5.0.0" />
</ItemGroup>
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace IoTSharp.Migrations
{
public partial class RemoveRetainedMessage : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
table: "DeviceIdentities");
migrationBuilder.DropTable(
name: "RetainedMessage");
migrationBuilder.AlterColumn<Guid>(
name: "DeviceId",
table: "DeviceIdentities",
type: "uuid",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uuid");
migrationBuilder.AddForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
table: "DeviceIdentities",
column: "DeviceId",
principalTable: "Device",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
table: "DeviceIdentities");
migrationBuilder.AlterColumn<Guid>(
name: "DeviceId",
table: "DeviceIdentities",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
oldClrType: typeof(Guid),
oldType: "uuid",
oldNullable: true);
migrationBuilder.CreateTable(
name: "RetainedMessage",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Payload = table.Column<byte[]>(type: "bytea", nullable: true),
QualityOfServiceLevel = table.Column<int>(type: "integer", nullable: false),
Retain = table.Column<bool>(type: "boolean", nullable: false),
Topic = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_RetainedMessage", x => x.Id);
});
migrationBuilder.AddForeignKey(
name: "FK_DeviceIdentities_Device_DeviceId",
table: "DeviceIdentities",
column: "DeviceId",
principalTable: "Device",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}
......@@ -15,9 +15,9 @@ namespace IoTSharp.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn)
.HasAnnotation("ProductVersion", "3.1.9")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
.UseIdentityByDefaultColumns()
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.1");
modelBuilder.Entity("IoTSharp.Data.AuditLog", b =>
{
......@@ -246,7 +246,7 @@ namespace IoTSharp.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("DeviceId")
b.Property<Guid?>("DeviceId")
.HasColumnType("uuid");
b.Property<string>("IdentityId")
......@@ -292,28 +292,6 @@ namespace IoTSharp.Migrations
b.ToTable("Relationship");
});
modelBuilder.Entity("IoTSharp.Data.RetainedMessage", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<byte[]>("Payload")
.HasColumnType("bytea");
b.Property<int>("QualityOfServiceLevel")
.HasColumnType("integer");
b.Property<bool>("Retain")
.HasColumnType("boolean");
b.Property<string>("Topic")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("RetainedMessage");
});
modelBuilder.Entity("IoTSharp.Data.TelemetryData", b =>
{
b.Property<Guid>("DeviceId")
......@@ -416,18 +394,18 @@ namespace IoTSharp.Migrations
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasName("RoleNameIndex");
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles");
});
......@@ -437,7 +415,7 @@ namespace IoTSharp.Migrations
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
.UseIdentityByDefaultColumn();
b.Property<string>("ClaimType")
.HasColumnType("text");
......@@ -469,8 +447,8 @@ namespace IoTSharp.Migrations
.HasColumnType("text");
b.Property<string>("Email")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
......@@ -482,12 +460,12 @@ namespace IoTSharp.Migrations
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
......@@ -505,17 +483,17 @@ namespace IoTSharp.Migrations
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasColumnType("character varying(256)")
.HasMaxLength(256);
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasName("EmailIndex");
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasName("UserNameIndex");
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers");
});
......@@ -525,7 +503,7 @@ namespace IoTSharp.Migrations
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
.UseIdentityByDefaultColumn();
b.Property<string>("ClaimType")
.HasColumnType("text");
......@@ -630,6 +608,10 @@ namespace IoTSharp.Migrations
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
......@@ -641,6 +623,10 @@ namespace IoTSharp.Migrations
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
......@@ -648,6 +634,8 @@ namespace IoTSharp.Migrations
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Customers")
.HasForeignKey("TenantId");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.Device", b =>
......@@ -667,15 +655,21 @@ namespace IoTSharp.Migrations
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany("Devices")
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("Owner");
b.Navigation("Tenant");
});
modelBuilder.Entity("IoTSharp.Data.DeviceIdentity", b =>
{
b.HasOne("IoTSharp.Data.Device", "Device")
.WithMany()
.HasForeignKey("DeviceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("DeviceId");
b.Navigation("Device");
});
modelBuilder.Entity("IoTSharp.Data.Relationship", b =>
......@@ -691,6 +685,12 @@ namespace IoTSharp.Migrations
b.HasOne("IoTSharp.Data.Tenant", "Tenant")
.WithMany()
.HasForeignKey("TenantId");
b.Navigation("Customer");
b.Navigation("IdentityUser");
b.Navigation("Tenant");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
......@@ -743,6 +743,28 @@ namespace IoTSharp.Migrations
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("IoTSharp.Data.AuthorizedKey", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Customer", b =>
{
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Tenant", b =>
{
b.Navigation("Customers");
b.Navigation("Devices");
});
modelBuilder.Entity("IoTSharp.Data.Gateway", b =>
{
b.Navigation("Children");
});
#pragma warning restore 612, 618
}
}
......
......@@ -92,7 +92,6 @@ namespace IoTSharp.Data
public DbSet<DeviceIdentity> DeviceIdentities { get; set; }
public DbSet<AuditLog> AuditLog { get; set; }
public DbSet<RetainedMessage> RetainedMessage { get; set; }
public DbSet<AuthorizedKey> AuthorizedKeys { get; set; }
......
using NpgsqlTypes;
using System;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
......
......@@ -70,12 +70,14 @@ namespace IoTSharp.Data
Binary,
DateTime
}
public enum DatabaseType
[JsonConverter(typeof(StringEnumConverter))]
public enum DataBaseType
{
mssql,
npgsql,
sqlite
PostgreSql,
SqlServer,
MySql ,
Oracle ,
SQLite
}
[JsonConverter(typeof(StringEnumConverter))]
public enum IdentityType
......
using CoAP;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
......
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
</Project>
......@@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MQTTnet" Version="3.0.14-rc5" />
<PackageReference Include="MQTTnet" Version="3.0.14" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
......
......@@ -43,6 +43,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Sdk.Http", "IoTSha
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTSharp.Sdk.MQTT", "IoTSharp.SDKs\IoTSharp.Sdk.MQTT\IoTSharp.Sdk.MQTT.csproj", "{A2A1191C-32ED-482B-AACE-4091EE518CEC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data.PostgreSQL", "IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj", "{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IoTSharp.Data", "IoTSharp.Data\IoTSharp.Data.csproj", "{522B2676-EB0E-4191-ACBC-EDC86DD2351D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -232,6 +236,46 @@ Global
{A2A1191C-32ED-482B-AACE-4091EE518CEC}.Release|x64.Build.0 = Release|Any CPU
{A2A1191C-32ED-482B-AACE-4091EE518CEC}.Release|x86.ActiveCfg = Release|Any CPU
{A2A1191C-32ED-482B-AACE-4091EE518CEC}.Release|x86.Build.0 = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|ARM.ActiveCfg = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|ARM.Build.0 = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|ARM64.Build.0 = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|x64.ActiveCfg = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|x64.Build.0 = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|x86.ActiveCfg = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Debug|x86.Build.0 = Debug|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|Any CPU.Build.0 = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|ARM.ActiveCfg = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|ARM.Build.0 = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|ARM64.ActiveCfg = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|ARM64.Build.0 = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|x64.ActiveCfg = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|x64.Build.0 = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|x86.ActiveCfg = Release|Any CPU
{0A6EAEEC-79A3-406B-9897-C3DA17F06BB9}.Release|x86.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|ARM.Build.0 = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|ARM64.Build.0 = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|x64.ActiveCfg = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|x64.Build.0 = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|x86.ActiveCfg = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Debug|x86.Build.0 = Debug|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|Any CPU.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|ARM.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|ARM.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|ARM64.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|ARM64.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x64.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x64.Build.0 = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x86.ActiveCfg = Release|Any CPU
{522B2676-EB0E-4191-ACBC-EDC86DD2351D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "3.1.9",
"commands": [
"dotnet-ef"
]
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
using CoAP.Server;
using DotNetCore.CAP.Dashboard.NodeDiscovery;
using EFCore.Sharding;
using IoTSharp.Data;
using MaiKeBing.CAP;
using MaiKeBing.HostedService.ZeroMQ;
using Newtonsoft.Json;
......@@ -78,6 +79,7 @@ namespace IoTSharp
public DiscoveryOptions Discovery { get; set; } = null;
public ZMQOption ZMQOption { get; set; } = null;
public int SucceedMessageExpiredAfter { get; set; } = 3600 * 6;
public DataBaseType DataBase { get; set; } = DataBaseType.PostgreSql;
}
public class ShardingSetting
......
......@@ -9,7 +9,6 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.IO.Compression;
using System.Linq;
......@@ -27,7 +26,7 @@ namespace IoTSharp.Controllers
/// </summary>
[ApiController]
[Route("api/[controller]/[action]")]
public class InstallerController : ControllerBase
public partial class InstallerController : ControllerBase
{
private ApplicationDbContext _context;
private ILogger _logger;
......@@ -99,58 +98,5 @@ namespace IoTSharp.Controllers
}
return actionResult;
}
public class InstanceDto
{
/// <summary>
/// 系统版本
/// </summary>
public string Version { get; internal set; }
/// <summary>
/// 是否被安装
/// </summary>
public bool Installed { get; internal set; }
}
public class InstallDto
{
/// <summary>
/// 系统管理员用户名
/// </summary>
[Required]
[EmailAddress]
public string Email { get; set; }
/// <summary>
/// 客户名称
/// </summary>
[Required]
public string CustomerName { get; set; }
/// <summary>
/// 系统管理员密码
/// </summary>
[Required]
[StringLength(100, ErrorMessage = "PASSWORD_MIN_LENGTH", MinimumLength = 6)]
public string Password { get; set; }
/// <summary>
/// 租户姓名
/// </summary>
public string TenantName { get; set; }
/// <summary>
/// 租户邮箱
/// </summary>
[EmailAddress]
public string TenantEMail { get; set; }
/// <summary>
/// 客户邮箱
/// </summary>
[EmailAddress]
public string CustomerEMail { get; set; }
/// <summary>
/// 电话号码
/// </summary>
[Phone]
public string PhoneNumber { get; set; }
}
}
}
\ No newline at end of file
using MQTTnet;
using MQTTnet.Protocol;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Cryptography;
using System.Threading.Tasks;
namespace IoTSharp.Data
{
public class RetainedMessage
{
public RetainedMessage()
{
}
[Key]
public string Id { get; set; }
public static implicit operator MqttApplicationMessage(RetainedMessage f)
{
return new MqttApplicationMessage() { Payload = f.Payload, Retain = true, Topic = f.Topic, QualityOfServiceLevel = f.QualityOfServiceLevel };
}
public static implicit operator RetainedMessage(MqttApplicationMessage f)
{
return new RetainedMessage(f);
}
public byte[] Payload { get; set; }
public MqttQualityOfServiceLevel QualityOfServiceLevel { get; set; }
public string Topic { get; set; }
public bool Retain { get; set; }
static MD5 MD5 = MD5.Create();
public RetainedMessage(MqttApplicationMessage retained)
{
Topic = retained.Topic;
QualityOfServiceLevel = retained.QualityOfServiceLevel;
Payload = retained.Payload;
Retain = retained.Retain;
List<byte> lst = new List<byte>(Payload);
lst.AddRange(System.Text.Encoding.UTF8.GetBytes(Topic));
Id = BitConverter.ToString(MD5.ComputeHash(lst.ToArray())).Replace("-", "");
}
}
}
......@@ -38,7 +38,9 @@ RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib n
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
WORKDIR /src
COPY ["IoTSharp/IoTSharp.csproj", "IoTSharp/"]
RUN dotnet restore "IoTSharp/IoTSharp.csproj" /clp:PerformanceSummary
COPY ["IoTSharp.Data/IoTSharp.Data.csproj", "IoTSharp.Data/"]
COPY ["IoTSharp.Data.PostgreSQL/IoTSharp.Data.PostgreSQL.csproj", "IoTSharp.Data.PostgreSQL/"]
RUN dotnet restore "IoTSharp/IoTSharp.csproj"
COPY . .
WORKDIR "/src/IoTSharp"
RUN dotnet build "IoTSharp.csproj" -c Release -o /app/build
......@@ -49,4 +51,4 @@ RUN dotnet publish "IoTSharp.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "IoTSharp.dll"]
ENTRYPOINT ["dotnet", "IoTSharp.dll"]
\ No newline at end of file
using System.ComponentModel.DataAnnotations;
namespace IoTSharp.Dtos
{
public class InstallDto
{
/// <summary>
/// 系统管理员用户名
/// </summary>
[Required]
[EmailAddress]
public string Email { get; set; }
/// <summary>
/// 客户名称
/// </summary>
[Required]
public string CustomerName { get; set; }
/// <summary>
/// 系统管理员密码
/// </summary>
[Required]
[StringLength(100, ErrorMessage = "PASSWORD_MIN_LENGTH", MinimumLength = 6)]
public string Password { get; set; }
/// <summary>
/// 租户姓名
/// </summary>
public string TenantName { get; set; }
/// <summary>
/// 租户邮箱
/// </summary>
[EmailAddress]
public string TenantEMail { get; set; }
/// <summary>
/// 客户邮箱
/// </summary>
[EmailAddress]
public string CustomerEMail { get; set; }
/// <summary>
/// 电话号码
/// </summary>
[Phone]
public string PhoneNumber { get; set; }
}
}
\ No newline at end of file
namespace IoTSharp.Dtos
{
public class InstanceDto
{
/// <summary>
/// 系统版本
/// </summary>
public string Version { get; internal set; }
/// <summary>
/// 是否被安装
/// </summary>
public bool Installed { get; internal set; }
}
}
\ No newline at end of file
using Microsoft.AspNetCore.Identity;
using IoTSharp.Dtos;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
......@@ -7,7 +8,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using static IoTSharp.Controllers.InstallerController;
namespace IoTSharp.Data
{
......
......@@ -27,47 +27,48 @@ namespace IoTSharp.Handlers
public async Task<IList<MqttApplicationMessage>> LoadRetainedMessagesAsync()
{
await Task.CompletedTask;
try
{
var lst = from m in _context.RetainedMessage select (MqttApplicationMessage)m;
//try
//{
// var lst = from m in _context.RetainedMessage select (MqttApplicationMessage)m;
return await lst.ToListAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, $"load RetainedMessage error {ex.Message} ");
return new List<MqttApplicationMessage>();
}
// return await lst.ToListAsync();
//}
//catch (Exception ex)
//{
// _logger.LogError(ex, $"load RetainedMessage error {ex.Message} ");
// return new List<MqttApplicationMessage>();
//}
return await Task.FromResult( new List<MqttApplicationMessage>());
}
public Task SaveRetainedMessagesAsync(IList<MqttApplicationMessage> messages)
{
Task.Factory.StartNew(() =>
{
_context.Database.BeginTransaction();
try
{
DateTime dateTime = DateTime.Now;
var needsave = from mam in messages select new RetainedMessage(mam);
var ids = needsave.Select(x => x.Id).ToList();
var dbids = _context.RetainedMessage.Select(x => x.Id).ToArray();
var needdelete = dbids.Except(ids);//.Except(dbids);
var del = from f in _context.RetainedMessage where needdelete.Contains(f.Id) select f;
var needadd = ids.Except(dbids);
var add = from f in needsave where needadd.Contains(f.Id) select f;
if (del.Any()) _context.RetainedMessage.RemoveRange(del);
if (add.Any()) _context.RetainedMessage.AddRange(add);
int ret = _context.SaveChanges();
_context.Database.CommitTransaction();
_logger.LogInformation($"{ret} pieces of data were saved and took {DateTime.Now.Subtract(dateTime).TotalSeconds} seconds.");
}
catch (Exception ex)
{
_context.Database.RollbackTransaction();
_logger.LogError(ex, $" An exception was encountered,{ex.Message}");
}
}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
// Task.Factory.StartNew(() =>
//{
// _context.Database.BeginTransaction();
// try
// {
// DateTime dateTime = DateTime.Now;
// var needsave = from mam in messages select new RetainedMessage(mam);
// var ids = needsave.Select(x => x.Id).ToList();
// var dbids = _context.RetainedMessage.Select(x => x.Id).ToArray();
// var needdelete = dbids.Except(ids);//.Except(dbids);
// var del = from f in _context.RetainedMessage where needdelete.Contains(f.Id) select f;
// var needadd = ids.Except(dbids);
// var add = from f in needsave where needadd.Contains(f.Id) select f;
// if (del.Any()) _context.RetainedMessage.RemoveRange(del);
// if (add.Any()) _context.RetainedMessage.AddRange(add);
// int ret = _context.SaveChanges();
// _context.Database.CommitTransaction();
// _logger.LogInformation($"{ret} pieces of data were saved and took {DateTime.Now.Subtract(dateTime).TotalSeconds} seconds.");
// }
// catch (Exception ex)
// {
// _context.Database.RollbackTransaction();
// _logger.LogError(ex, $" An exception was encountered,{ex.Message}");
// }
//}, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default);
return Task.CompletedTask;
}
}
......
......@@ -33,6 +33,7 @@
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<DocumentationFile>IoTSharp.xml</DocumentationFile>
<NoWarn>1701;1702;1591</NoWarn>
<OutputPath></OutputPath>
</PropertyGroup>
<ItemGroup>
......@@ -59,18 +60,18 @@
<PackageReference Include="DotNetCore.CAP.MongoDB" Version="3.1.2" />
<PackageReference Include="DotNetCore.CAP.PostgreSql" Version="3.1.2" />
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="3.1.2" />
<PackageReference Include="EasyCaching.Core" Version="1.2.0-alpha20201214003208" />
<PackageReference Include="EasyCaching.InMemory" Version="1.2.0-alpha20201214003208" />
<PackageReference Include="EasyCaching.LiteDB" Version="1.2.0-alpha20201214003208" />
<PackageReference Include="EasyCaching.Redis" Version="1.2.0-alpha20201214003208" />
<PackageReference Include="EFCore.Sharding" Version="5.0.0.5" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="5.0.0.5" />
<PackageReference Include="EasyCaching.Core" Version="1.2.0" />
<PackageReference Include="EasyCaching.InMemory" Version="1.2.0" />
<PackageReference Include="EasyCaching.LiteDB" Version="1.2.0" />
<PackageReference Include="EasyCaching.Redis" Version="1.2.1" />
<PackageReference Include="EFCore.Sharding" Version="5.0.0.6" />
<PackageReference Include="EFCore.Sharding.PostgreSql" Version="5.0.0.6" />
<PackageReference Include="GitVersionTask" Version="5.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="hyjiacan.py4n" Version="4.0.0" />
<PackageReference Include="InfluxDB.Client" Version="1.15.0-dev.1705" />
<PackageReference Include="InfluxDB.Client" Version="1.15.0" />
<PackageReference Include="IoTSharp.CoAP.NET" Version="2.0.8" />
<PackageReference Include="IoTSharp.X509Extensions" Version="1.4.27" />
<PackageReference Include="kimbus" Version="2.0.1" />
......@@ -80,41 +81,41 @@
<PackageReference Include="Maikebing.Data.Taos" Version="2.0.209" />
<PackageReference Include="Maikebing.HealthChecks.Taos" Version="2.0.209" />
<PackageReference Include="MaiKeBing.HostedService.ZeroMQ" Version="1.0.31" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.1" />
<PackageReference Include="MQTTnet" Version="3.0.14-rc5" />
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.14-rc5" />
<PackageReference Include="MQTTnet.Extensions.Rpc" Version="3.0.14-rc5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
<PackageReference Include="MQTTnet" Version="3.0.14" />
<PackageReference Include="MQTTnet.AspNetCore" Version="3.0.14" />
<PackageReference Include="MQTTnet.Extensions.Rpc" Version="3.0.14" />
<PackageReference Include="NetMQ" Version="4.0.1.6" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.1" />
<PackageReference Include="NSwag.AspNetCore" Version="13.9.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="NSwag.AspNetCore" Version="13.10.2" />
<PackageReference Include="ProxyKit" Version="2.3.4" />
<PackageReference Include="Quartz.Serialization.Json" Version="3.2.3" />
<PackageReference Include="Quartz.Serialization.Json" Version="3.2.4" />
<PackageReference Include="Savorboard.CAP.InMemoryMessageQueue" Version="3.1.1" />
<PackageReference Include="Silkier" Version="1.0.274" />
<PackageReference Include="Silkier.AspNetCore" Version="1.0.274" />
<PackageReference Include="Silkier.EFCore" Version="1.0.274" />
<PackageReference Include="SilkierQuartz" Version="5.0.196" />
<PackageReference Include="SilkierQuartz.Plugins.RecentHistory" Version="5.0.196" />
<PackageReference Include="Silkier" Version="1.0.312" />
<PackageReference Include="Silkier.AspNetCore" Version="1.0.312" />
<PackageReference Include="Silkier.EFCore" Version="1.0.312" />
<PackageReference Include="SilkierQuartz" Version="5.0.213" />
<PackageReference Include="SilkierQuartz.Plugins.RecentHistory" Version="5.0.213" />
<PackageReference Include="System.Collections" Version="4.3.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.1" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
<PackageReference Include="MQTTnet.AspNetCoreEx" Version="3.0.13" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.0.14-rc5" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="3.0.14" />
</ItemGroup>
<ItemGroup>
<Compile Remove="Migrations\**" />
......@@ -137,4 +138,8 @@
<PackagePath></PackagePath>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\IoTSharp.Data.PostgreSQL\IoTSharp.Data.PostgreSQL.csproj" />
<ProjectReference Include="..\IoTSharp.Data\IoTSharp.Data.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -307,51 +307,6 @@
</summary>
<returns></returns>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstanceDto.Version">
<summary>
系统版本
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstanceDto.Installed">
<summary>
是否被安装
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.Email">
<summary>
系统管理员用户名
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.CustomerName">
<summary>
客户名称
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.Password">
<summary>
系统管理员密码
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.TenantName">
<summary>
租户姓名
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.TenantEMail">
<summary>
租户邮箱
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.CustomerEMail">
<summary>
客户邮箱
</summary>
</member>
<member name="P:IoTSharp.Controllers.InstallerController.InstallDto.PhoneNumber">
<summary>
电话号码
</summary>
</member>
<member name="T:IoTSharp.Controllers.TenantsController">
<summary>
租户管理
......@@ -392,85 +347,6 @@
<param name="id"></param>
<returns></returns>
</member>
<member name="T:IoTSharp.Data.Device">
<summary>
设备
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Id">
<summary>
设备ID
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Name">
<summary>
设备名称
</summary>
</member>
<member name="P:IoTSharp.Data.Device.DeviceType">
<summary>
设备类型
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Online">
<summary>
在线
</summary>
</member>
<member name="P:IoTSharp.Data.Device.LastActive">
<summary>
最后一次活跃时间
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Timeout">
<summary>
超时时间 秒数
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Owner">
<summary>
所有者
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Tenant">
<summary>
租户
</summary>
</member>
<member name="P:IoTSharp.Data.Device.Customer">
<summary>
客户
</summary>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.Id">
<summary>
认证方式ID
</summary>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.IdentityType">
<summary>
认证方式类型
</summary>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.IdentityId">
<summary>
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.AccessToken"/> ,this is a Token.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.DevicePassword"/> ,this is a device name.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.X509Certificate"/> ,this is X509 Certificate' Fingerprint.
</summary>
</member>
<member name="P:IoTSharp.Data.DeviceIdentity.IdentityValue">
<summary>
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.AccessToken"/> ,this is null.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.DevicePassword"/> ,this is a password.
When <see cref="P:IoTSharp.Data.DeviceIdentity.IdentityType"/> Is <see cref="F:IoTSharp.Data.IdentityType.X509Certificate"/> ,this is X509 Certificate' PEM.
</summary>
</member>
<member name="T:IoTSharp.Data.TelemetryDataConfiguration">
<summary>
https://github.com/Coldairarrow/EFCore.Sharding/issues/60
</summary>
</member>
<member name="P:IoTSharp.Dtos.TokenEntity.access_token">
<summary>
token
......@@ -541,6 +417,51 @@
用户名密码
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.Email">
<summary>
系统管理员用户名
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.CustomerName">
<summary>
客户名称
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.Password">
<summary>
系统管理员密码
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.TenantName">
<summary>
租户姓名
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.TenantEMail">
<summary>
租户邮箱
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.CustomerEMail">
<summary>
客户邮箱
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstallDto.PhoneNumber">
<summary>
电话号码
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstanceDto.Version">
<summary>
系统版本
</summary>
</member>
<member name="P:IoTSharp.Dtos.InstanceDto.Installed">
<summary>
是否被安装
</summary>
</member>
<member name="M:IoTSharp.IoTSharpExtension.CheckOrUpdateDevStatus(IoTSharp.Data.Device)">
<summary>
//如果上次活动时间距离当前时间超过10秒 或者 设备离线状态, 则更新状态。
......
......@@ -72,7 +72,18 @@ namespace IoTSharp
{
Configuration.Bind(setting);
}));
services.AddDbContextPool<ApplicationDbContext>(options => options.UseNpgsql(Configuration.GetConnectionString("IoTSharp")), poolSize: settings.DbContextPoolSize);
services.AddDbContextPool<ApplicationDbContext>(options =>
{
switch (settings.DataBase)
{
case DataBaseType.PostgreSql:
default:
options.UseNpgsql(Configuration.GetConnectionString("IoTSharp"), s => s.MigrationsAssembly("IoTSharp.Data.PostgreSQL"));
break;
}
}
, poolSize: settings.DbContextPoolSize);
services.AddIdentity<IdentityUser, IdentityRole>()
.AddRoles<IdentityRole>()
.AddRoleManager<RoleManager<IdentityRole>>()
......
......@@ -7,7 +7,7 @@
}
},
"ConnectionStrings": {
"IoTSharp": "Server=10.165.83.194;Database=IoTSharp;Username=postgres;Password=future;",
"IoTSharp": "Server=localhost;Database=IoTSharp;Username=postgres;Password=future;",
"EventBusStore": "mongodb://root:kissme@mongodb:27017",
"TelemetryStorage": "DataSource=taos;DataBase=IoTSharp;Username=root;Password=taosdata;Port=6030",
"EventBusMQ": "amqp://root:kissme@rabbitmq:5672"
......
dotnet ef migrations add %1 --context IoTSharp.Data.ApplicationDbContext
\ No newline at end of file
cd IoTSharp.Data.PostgreSQL
dotnet ef migrations add %1 --context IoTSharp.Data.ApplicationDbContext --startup-project ..\IoTSharp\IoTSharp.csproj
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册