From 7bd515ff8ebdb2e8a92222b4c9234e3327092fe0 Mon Sep 17 00:00:00 2001 From: MysticBoy Date: Mon, 27 Jun 2022 00:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Data/ApplicationDbContext.cs | 4 + Data/Enmus.cs | 37 ++ ...626135705_CreateIdentitySchema.Designer.cs | 0 .../20220626135705_CreateIdentitySchema.cs | 0 ...220626162542_ModBusDataMapping.Designer.cs | 351 ++++++++++++++++++ .../20220626162542_ModBusDataMapping.cs | 67 ++++ .../ApplicationDbContextModelSnapshot.cs | 80 ++++ Data/ModbusSlave.cs | 39 ++ Data/PointMapping.cs | 47 +++ IoTSharp.Gateway.Modbus.csproj | 12 +- Jobs/ModbusPoll.cs | 6 + Pages/PointMapAdmin/Create.cshtml | 69 ++++ Pages/PointMapAdmin/Create.cshtml.cs | 44 +++ Pages/PointMapAdmin/Delete.cshtml | 70 ++++ Pages/PointMapAdmin/Delete.cshtml.cs | 62 ++++ Pages/PointMapAdmin/Details.cshtml | 67 ++++ Pages/PointMapAdmin/Details.cshtml.cs | 42 +++ Pages/PointMapAdmin/Edit.cshtml | 70 ++++ Pages/PointMapAdmin/Edit.cshtml.cs | 76 ++++ Pages/PointMapAdmin/Index.cshtml | 78 ++++ Pages/PointMapAdmin/Index.cshtml.cs | 31 ++ Pages/SlaveAdmin/Create.cshtml | 49 +++ Pages/SlaveAdmin/Create.cshtml.cs | 44 +++ Pages/SlaveAdmin/Delete.cshtml | 46 +++ Pages/SlaveAdmin/Delete.cshtml.cs | 62 ++++ Pages/SlaveAdmin/Details.cshtml | 43 +++ Pages/SlaveAdmin/Details.cshtml.cs | 42 +++ Pages/SlaveAdmin/Edit.cshtml | 50 +++ Pages/SlaveAdmin/Edit.cshtml.cs | 76 ++++ Pages/SlaveAdmin/Index.cshtml | 54 +++ Pages/SlaveAdmin/Index.cshtml.cs | 31 ++ Program.cs | 16 +- 33 files changed, 1759 insertions(+), 7 deletions(-) create mode 100644 Data/Enmus.cs rename {Migrations => Data/Migrations}/20220626135705_CreateIdentitySchema.Designer.cs (100%) rename {Migrations => Data/Migrations}/20220626135705_CreateIdentitySchema.cs (100%) create mode 100644 Data/Migrations/20220626162542_ModBusDataMapping.Designer.cs create mode 100644 Data/Migrations/20220626162542_ModBusDataMapping.cs rename {Migrations => Data/Migrations}/ApplicationDbContextModelSnapshot.cs (76%) create mode 100644 Data/ModbusSlave.cs create mode 100644 Data/PointMapping.cs create mode 100644 Jobs/ModbusPoll.cs create mode 100644 Pages/PointMapAdmin/Create.cshtml create mode 100644 Pages/PointMapAdmin/Create.cshtml.cs create mode 100644 Pages/PointMapAdmin/Delete.cshtml create mode 100644 Pages/PointMapAdmin/Delete.cshtml.cs create mode 100644 Pages/PointMapAdmin/Details.cshtml create mode 100644 Pages/PointMapAdmin/Details.cshtml.cs create mode 100644 Pages/PointMapAdmin/Edit.cshtml create mode 100644 Pages/PointMapAdmin/Edit.cshtml.cs create mode 100644 Pages/PointMapAdmin/Index.cshtml create mode 100644 Pages/PointMapAdmin/Index.cshtml.cs create mode 100644 Pages/SlaveAdmin/Create.cshtml create mode 100644 Pages/SlaveAdmin/Create.cshtml.cs create mode 100644 Pages/SlaveAdmin/Delete.cshtml create mode 100644 Pages/SlaveAdmin/Delete.cshtml.cs create mode 100644 Pages/SlaveAdmin/Details.cshtml create mode 100644 Pages/SlaveAdmin/Details.cshtml.cs create mode 100644 Pages/SlaveAdmin/Edit.cshtml create mode 100644 Pages/SlaveAdmin/Edit.cshtml.cs create mode 100644 Pages/SlaveAdmin/Index.cshtml create mode 100644 Pages/SlaveAdmin/Index.cshtml.cs diff --git a/.gitignore b/.gitignore index 51cb241..ddad7db 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /obj /SQlLiteDatabase.db /IoTSharp.Gateway.Modbus.csproj.user +/.vs/ProjectEvaluation diff --git a/Data/ApplicationDbContext.cs b/Data/ApplicationDbContext.cs index a031aa5..ef993f1 100644 --- a/Data/ApplicationDbContext.cs +++ b/Data/ApplicationDbContext.cs @@ -9,5 +9,9 @@ namespace IoTSharp.Gateway.Modbus.Data : base(options) { } + + public DbSet ModbusSlaves { get; set; } + + public DbSet PointMappings { get; set; } } } \ No newline at end of file diff --git a/Data/Enmus.cs b/Data/Enmus.cs new file mode 100644 index 0000000..8227ba9 --- /dev/null +++ b/Data/Enmus.cs @@ -0,0 +1,37 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace IoTSharp.Gateway.Modbus.Data +{ + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] + [JsonConverter(typeof(StringEnumConverter))] + public enum FunCode + { + ReadCoils =1, + ReadDiscreteInputs=2, + ReadMultipleHoldingRegisters = 3, + ReadInputRegisters=4, + WriteSingleCoil=5, + WriteSingleHoldingRegister=6, + WriteMultipleCoils=15, + WriteMultipleHoldingRegisters=16 + + } + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] + [JsonConverter(typeof(StringEnumConverter))] + public enum DataType + { + Boolean, + String, + Long, + Double, + DateTime + } + [System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.JsonStringEnumConverter))] + [JsonConverter(typeof(StringEnumConverter))] + public enum DataCatalog + { + AttributeData, + TelemetryData, + } +} diff --git a/Migrations/20220626135705_CreateIdentitySchema.Designer.cs b/Data/Migrations/20220626135705_CreateIdentitySchema.Designer.cs similarity index 100% rename from Migrations/20220626135705_CreateIdentitySchema.Designer.cs rename to Data/Migrations/20220626135705_CreateIdentitySchema.Designer.cs diff --git a/Migrations/20220626135705_CreateIdentitySchema.cs b/Data/Migrations/20220626135705_CreateIdentitySchema.cs similarity index 100% rename from Migrations/20220626135705_CreateIdentitySchema.cs rename to Data/Migrations/20220626135705_CreateIdentitySchema.cs diff --git a/Data/Migrations/20220626162542_ModBusDataMapping.Designer.cs b/Data/Migrations/20220626162542_ModBusDataMapping.Designer.cs new file mode 100644 index 0000000..1644a49 --- /dev/null +++ b/Data/Migrations/20220626162542_ModBusDataMapping.Designer.cs @@ -0,0 +1,351 @@ +// +using System; +using IoTSharp.Gateway.Modbus.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IoTSharp.Gateway.Modbus.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20220626162542_ModBusDataMapping")] + partial class ModBusDataMapping + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.6"); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.ModbusSlave", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DeviceName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DeviceNameFormat") + .HasColumnType("TEXT"); + + b.Property("Slave") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TimeOut") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("ModbusSlaves"); + }); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.PointMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Address") + .HasColumnType("INTEGER"); + + b.Property("CodePage") + .HasColumnType("INTEGER"); + + b.Property("DataCatalog") + .HasColumnType("INTEGER"); + + b.Property("DataName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DataType") + .HasColumnType("INTEGER"); + + b.Property("DateTimeFormat") + .HasColumnType("TEXT"); + + b.Property("FunCode") + .HasColumnType("INTEGER"); + + b.Property("Length") + .HasColumnType("INTEGER"); + + b.Property("OwnerId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("PointMappings"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("AccessFailedCount") + .HasColumnType("INTEGER"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("TEXT"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("EmailConfirmed") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnabled") + .HasColumnType("INTEGER"); + + b.Property("LockoutEnd") + .HasColumnType("TEXT"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.Property("PasswordHash") + .HasColumnType("TEXT"); + + b.Property("PhoneNumber") + .HasColumnType("TEXT"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("INTEGER"); + + b.Property("SecurityStamp") + .HasColumnType("TEXT"); + + b.Property("TwoFactorEnabled") + .HasColumnType("INTEGER"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("ClaimType") + .HasColumnType("TEXT"); + + b.Property("ClaimValue") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("ProviderKey") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("ProviderDisplayName") + .HasColumnType("TEXT"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("RoleId") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("TEXT"); + + b.Property("LoginProvider") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Name") + .HasMaxLength(128) + .HasColumnType("TEXT"); + + b.Property("Value") + .HasColumnType("TEXT"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.PointMapping", b => + { + b.HasOne("IoTSharp.Gateway.Modbus.Data.ModbusSlave", "Owner") + .WithMany("PointMappings") + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.ModbusSlave", b => + { + b.Navigation("PointMappings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Data/Migrations/20220626162542_ModBusDataMapping.cs b/Data/Migrations/20220626162542_ModBusDataMapping.cs new file mode 100644 index 0000000..e461c5d --- /dev/null +++ b/Data/Migrations/20220626162542_ModBusDataMapping.cs @@ -0,0 +1,67 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IoTSharp.Gateway.Modbus.Migrations +{ + public partial class ModBusDataMapping : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ModbusSlaves", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Slave = table.Column(type: "TEXT", nullable: false), + TimeOut = table.Column(type: "INTEGER", nullable: false), + DeviceName = table.Column(type: "TEXT", nullable: false), + DeviceNameFormat = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ModbusSlaves", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PointMappings", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + DataName = table.Column(type: "TEXT", nullable: false), + DataType = table.Column(type: "INTEGER", nullable: false), + DataCatalog = table.Column(type: "INTEGER", nullable: false), + FunCode = table.Column(type: "INTEGER", nullable: false), + Address = table.Column(type: "INTEGER", nullable: false), + Length = table.Column(type: "INTEGER", nullable: false), + DateTimeFormat = table.Column(type: "TEXT", nullable: true), + CodePage = table.Column(type: "INTEGER", nullable: false), + OwnerId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PointMappings", x => x.Id); + table.ForeignKey( + name: "FK_PointMappings_ModbusSlaves_OwnerId", + column: x => x.OwnerId, + principalTable: "ModbusSlaves", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_PointMappings_OwnerId", + table: "PointMappings", + column: "OwnerId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "PointMappings"); + + migrationBuilder.DropTable( + name: "ModbusSlaves"); + } + } +} diff --git a/Migrations/ApplicationDbContextModelSnapshot.cs b/Data/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 76% rename from Migrations/ApplicationDbContextModelSnapshot.cs rename to Data/Migrations/ApplicationDbContextModelSnapshot.cs index e7e247a..a90b25a 100644 --- a/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Data/Migrations/ApplicationDbContextModelSnapshot.cs @@ -17,6 +17,72 @@ namespace IoTSharp.Gateway.Modbus.Migrations #pragma warning disable 612, 618 modelBuilder.HasAnnotation("ProductVersion", "6.0.6"); + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.ModbusSlave", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DeviceName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DeviceNameFormat") + .HasColumnType("TEXT"); + + b.Property("Slave") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TimeOut") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("ModbusSlaves"); + }); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.PointMapping", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Address") + .HasColumnType("INTEGER"); + + b.Property("CodePage") + .HasColumnType("INTEGER"); + + b.Property("DataCatalog") + .HasColumnType("INTEGER"); + + b.Property("DataName") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("DataType") + .HasColumnType("INTEGER"); + + b.Property("DateTimeFormat") + .HasColumnType("TEXT"); + + b.Property("FunCode") + .HasColumnType("INTEGER"); + + b.Property("Length") + .HasColumnType("INTEGER"); + + b.Property("OwnerId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("PointMappings"); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") @@ -213,6 +279,15 @@ namespace IoTSharp.Gateway.Modbus.Migrations b.ToTable("AspNetUserTokens", (string)null); }); + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.PointMapping", b => + { + b.HasOne("IoTSharp.Gateway.Modbus.Data.ModbusSlave", "Owner") + .WithMany("PointMappings") + .HasForeignKey("OwnerId"); + + b.Navigation("Owner"); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) @@ -263,6 +338,11 @@ namespace IoTSharp.Gateway.Modbus.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + + modelBuilder.Entity("IoTSharp.Gateway.Modbus.Data.ModbusSlave", b => + { + b.Navigation("PointMappings"); + }); #pragma warning restore 612, 618 } } diff --git a/Data/ModbusSlave.cs b/Data/ModbusSlave.cs new file mode 100644 index 0000000..20f5665 --- /dev/null +++ b/Data/ModbusSlave.cs @@ -0,0 +1,39 @@ +using System.ComponentModel.DataAnnotations; + +namespace IoTSharp.Gateway.Modbus.Data +{ + public class ModbusSlave + { + + [Key] + public Guid Id { get; set; } + + /// + /// + /// + /// + /// DTU: dtu://dev.ttyS0:115200 + /// DTU: dtu://COM1:115200 + /// TCP: tcp://www.host.com:602 + // DTU over TCP: DTUoverTCP://www.host.com:602 + /// + [Required] + public Uri Slave { get; set; } + + /// + /// 连接超时和读取写入超时 按秒 + /// + public int TimeOut { get; set; } + + [Required] + public string DeviceName { get; set; } + + /// + /// 如果为空, 则直接使用 DeviceName , + /// 否则, 使用 PointMapping 里面的 映射ID作为设备名称。 {Name}-{ID} , 前提是PointMappings中要有, 如果没有, 则为空。 + /// + public string? DeviceNameFormat { get; set; } + + public List? PointMappings { get; set; } + } +} diff --git a/Data/PointMapping.cs b/Data/PointMapping.cs new file mode 100644 index 0000000..cce15db --- /dev/null +++ b/Data/PointMapping.cs @@ -0,0 +1,47 @@ +using System.ComponentModel.DataAnnotations; + +namespace IoTSharp.Gateway.Modbus.Data +{ + public class PointMapping + { + + [Key] + public Guid Id { get; set; } + + [Required] + public string DataName { get; set; } + + /// + /// 如果是DataType为 Long , 如果是Length一个寄存器那么就是int16 , 如果是2个寄存器 就是 in32, 如果是4个寄存器 int64 , 4字节就是int64 + /// 如果是DataType为DateTime 如果Lenght为 4 , 就是 秒时间戳, 如果超过4 字节, 则需指定时间格式 yyyyMMddHHmmss + /// 如果是DataType为String, 则需指定编码格式CodePage, + /// 如果是DataType为Double, 如果Length是2个寄存器就是4个字节, 则是float, 如果是4个寄存器那就是8个字节, 就是double, + /// + public DataType DataType { get; set; } + /// + /// 数据分类 + /// + public DataCatalog DataCatalog { get; set; } + + public FunCode FunCode { get; set; } + + public int Address { get; set; } + + /// + /// 如果是读取寄存器, 那么一个寄存器就是2字节, 如果是线圈, 那就是 1位。 一个字节为 8位。 + /// + public int Length { get; set; } + + /// + /// 默认不转换 + /// + public string? DateTimeFormat { get; set; } + /// + /// 默认 65001 , 简体中文 936 繁体 950 + /// + public int CodePage { get; set; } = 65001; + + public ModbusSlave? Owner { get; set; } + + } +} diff --git a/IoTSharp.Gateway.Modbus.csproj b/IoTSharp.Gateway.Modbus.csproj index f2662f8..9a7bc73 100644 --- a/IoTSharp.Gateway.Modbus.csproj +++ b/IoTSharp.Gateway.Modbus.csproj @@ -14,17 +14,19 @@ + + + + + - - - - - + + diff --git a/Jobs/ModbusPoll.cs b/Jobs/ModbusPoll.cs new file mode 100644 index 0000000..9cedb7c --- /dev/null +++ b/Jobs/ModbusPoll.cs @@ -0,0 +1,6 @@ +namespace IoTSharp.Gateway.Modbus.Jobs +{ + public class ModbusPoll + { + } +} diff --git a/Pages/PointMapAdmin/Create.cshtml b/Pages/PointMapAdmin/Create.cshtml new file mode 100644 index 0000000..90dd519 --- /dev/null +++ b/Pages/PointMapAdmin/Create.cshtml @@ -0,0 +1,69 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.PointMapAdmin.CreateModel + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

PointMapping

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Pages/PointMapAdmin/Create.cshtml.cs b/Pages/PointMapAdmin/Create.cshtml.cs new file mode 100644 index 0000000..ffe15b8 --- /dev/null +++ b/Pages/PointMapAdmin/Create.cshtml.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin +{ + public class CreateModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public CreateModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + return Page(); + } + + [BindProperty] + public PointMapping PointMapping { get; set; } = default!; + + + // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD + public async Task OnPostAsync() + { + if (!ModelState.IsValid || _context.PointMappings == null || PointMapping == null) + { + return Page(); + } + + _context.PointMappings.Add(PointMapping); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } + } +} diff --git a/Pages/PointMapAdmin/Delete.cshtml b/Pages/PointMapAdmin/Delete.cshtml new file mode 100644 index 0000000..80a1bdf --- /dev/null +++ b/Pages/PointMapAdmin/Delete.cshtml @@ -0,0 +1,70 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.PointMapAdmin.DeleteModel + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

PointMapping

+
+
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataName) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataName) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataType) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataType) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataCatalog) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataCatalog) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.FunCode) +
+
+ @Html.DisplayFor(model => model.PointMapping.FunCode) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.Address) +
+
+ @Html.DisplayFor(model => model.PointMapping.Address) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.Length) +
+
+ @Html.DisplayFor(model => model.PointMapping.Length) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DateTimeFormat) +
+
+ @Html.DisplayFor(model => model.PointMapping.DateTimeFormat) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.CodePage) +
+
+ @Html.DisplayFor(model => model.PointMapping.CodePage) +
+
+ +
+ + | + Back to List +
+
diff --git a/Pages/PointMapAdmin/Delete.cshtml.cs b/Pages/PointMapAdmin/Delete.cshtml.cs new file mode 100644 index 0000000..a78b2a6 --- /dev/null +++ b/Pages/PointMapAdmin/Delete.cshtml.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin +{ + public class DeleteModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public DeleteModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public PointMapping PointMapping { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.PointMappings == null) + { + return NotFound(); + } + + var pointmapping = await _context.PointMappings.FirstOrDefaultAsync(m => m.Id == id); + + if (pointmapping == null) + { + return NotFound(); + } + else + { + PointMapping = pointmapping; + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null || _context.PointMappings == null) + { + return NotFound(); + } + var pointmapping = await _context.PointMappings.FindAsync(id); + + if (pointmapping != null) + { + PointMapping = pointmapping; + _context.PointMappings.Remove(PointMapping); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } + } +} diff --git a/Pages/PointMapAdmin/Details.cshtml b/Pages/PointMapAdmin/Details.cshtml new file mode 100644 index 0000000..bf3b0af --- /dev/null +++ b/Pages/PointMapAdmin/Details.cshtml @@ -0,0 +1,67 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.PointMapAdmin.DetailsModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

PointMapping

+
+
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataName) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataName) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataType) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataType) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DataCatalog) +
+
+ @Html.DisplayFor(model => model.PointMapping.DataCatalog) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.FunCode) +
+
+ @Html.DisplayFor(model => model.PointMapping.FunCode) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.Address) +
+
+ @Html.DisplayFor(model => model.PointMapping.Address) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.Length) +
+
+ @Html.DisplayFor(model => model.PointMapping.Length) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.DateTimeFormat) +
+
+ @Html.DisplayFor(model => model.PointMapping.DateTimeFormat) +
+
+ @Html.DisplayNameFor(model => model.PointMapping.CodePage) +
+
+ @Html.DisplayFor(model => model.PointMapping.CodePage) +
+
+
+ diff --git a/Pages/PointMapAdmin/Details.cshtml.cs b/Pages/PointMapAdmin/Details.cshtml.cs new file mode 100644 index 0000000..ac235fa --- /dev/null +++ b/Pages/PointMapAdmin/Details.cshtml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin +{ + public class DetailsModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public DetailsModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public PointMapping PointMapping { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.PointMappings == null) + { + return NotFound(); + } + + var pointmapping = await _context.PointMappings.FirstOrDefaultAsync(m => m.Id == id); + if (pointmapping == null) + { + return NotFound(); + } + else + { + PointMapping = pointmapping; + } + return Page(); + } + } +} diff --git a/Pages/PointMapAdmin/Edit.cshtml b/Pages/PointMapAdmin/Edit.cshtml new file mode 100644 index 0000000..e153564 --- /dev/null +++ b/Pages/PointMapAdmin/Edit.cshtml @@ -0,0 +1,70 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.PointMapAdmin.EditModel + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

PointMapping

+
+
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Pages/PointMapAdmin/Edit.cshtml.cs b/Pages/PointMapAdmin/Edit.cshtml.cs new file mode 100644 index 0000000..4c2c725 --- /dev/null +++ b/Pages/PointMapAdmin/Edit.cshtml.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin +{ + public class EditModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public EditModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public PointMapping PointMapping { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.PointMappings == null) + { + return NotFound(); + } + + var pointmapping = await _context.PointMappings.FirstOrDefaultAsync(m => m.Id == id); + if (pointmapping == null) + { + return NotFound(); + } + PointMapping = pointmapping; + return Page(); + } + + // To protect from overposting attacks, enable the specific properties you want to bind to. + // For more details, see https://aka.ms/RazorPagesCRUD. + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(PointMapping).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!PointMappingExists(PointMapping.Id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return RedirectToPage("./Index"); + } + + private bool PointMappingExists(Guid id) + { + return (_context.PointMappings?.Any(e => e.Id == id)).GetValueOrDefault(); + } + } +} diff --git a/Pages/PointMapAdmin/Index.cshtml b/Pages/PointMapAdmin/Index.cshtml new file mode 100644 index 0000000..48576d5 --- /dev/null +++ b/Pages/PointMapAdmin/Index.cshtml @@ -0,0 +1,78 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.PointMapAdmin.IndexModel + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + + + + + + +@foreach (var item in Model.PointMapping) { + + + + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.PointMapping[0].DataName) + + @Html.DisplayNameFor(model => model.PointMapping[0].DataType) + + @Html.DisplayNameFor(model => model.PointMapping[0].DataCatalog) + + @Html.DisplayNameFor(model => model.PointMapping[0].FunCode) + + @Html.DisplayNameFor(model => model.PointMapping[0].Address) + + @Html.DisplayNameFor(model => model.PointMapping[0].Length) + + @Html.DisplayNameFor(model => model.PointMapping[0].DateTimeFormat) + + @Html.DisplayNameFor(model => model.PointMapping[0].CodePage) +
+ @Html.DisplayFor(modelItem => item.DataName) + + @Html.DisplayFor(modelItem => item.DataType) + + @Html.DisplayFor(modelItem => item.DataCatalog) + + @Html.DisplayFor(modelItem => item.FunCode) + + @Html.DisplayFor(modelItem => item.Address) + + @Html.DisplayFor(modelItem => item.Length) + + @Html.DisplayFor(modelItem => item.DateTimeFormat) + + @Html.DisplayFor(modelItem => item.CodePage) + + Edit | + Details | + Delete +
diff --git a/Pages/PointMapAdmin/Index.cshtml.cs b/Pages/PointMapAdmin/Index.cshtml.cs new file mode 100644 index 0000000..0b0570b --- /dev/null +++ b/Pages/PointMapAdmin/Index.cshtml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.PointMapAdmin +{ + public class IndexModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public IndexModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public IList PointMapping { get;set; } = default!; + + public async Task OnGetAsync() + { + if (_context.PointMappings != null) + { + PointMapping = await _context.PointMappings.ToListAsync(); + } + } + } +} diff --git a/Pages/SlaveAdmin/Create.cshtml b/Pages/SlaveAdmin/Create.cshtml new file mode 100644 index 0000000..2ad5444 --- /dev/null +++ b/Pages/SlaveAdmin/Create.cshtml @@ -0,0 +1,49 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.SlaveAdmin.CreateModel + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

ModbusSlave

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Pages/SlaveAdmin/Create.cshtml.cs b/Pages/SlaveAdmin/Create.cshtml.cs new file mode 100644 index 0000000..44d2c3f --- /dev/null +++ b/Pages/SlaveAdmin/Create.cshtml.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.SlaveAdmin +{ + public class CreateModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public CreateModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public IActionResult OnGet() + { + return Page(); + } + + [BindProperty] + public ModbusSlave ModbusSlave { get; set; } = default!; + + + // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD + public async Task OnPostAsync() + { + if (!ModelState.IsValid || _context.ModbusSlaves == null || ModbusSlave == null) + { + return Page(); + } + + _context.ModbusSlaves.Add(ModbusSlave); + await _context.SaveChangesAsync(); + + return RedirectToPage("./Index"); + } + } +} diff --git a/Pages/SlaveAdmin/Delete.cshtml b/Pages/SlaveAdmin/Delete.cshtml new file mode 100644 index 0000000..b15f183 --- /dev/null +++ b/Pages/SlaveAdmin/Delete.cshtml @@ -0,0 +1,46 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.SlaveAdmin.DeleteModel + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

ModbusSlave

+
+
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.Slave) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.Slave) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.TimeOut) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.TimeOut) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.DeviceName) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.DeviceName) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.DeviceNameFormat) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.DeviceNameFormat) +
+
+ +
+ + | + Back to List +
+
diff --git a/Pages/SlaveAdmin/Delete.cshtml.cs b/Pages/SlaveAdmin/Delete.cshtml.cs new file mode 100644 index 0000000..e063f1c --- /dev/null +++ b/Pages/SlaveAdmin/Delete.cshtml.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.SlaveAdmin +{ + public class DeleteModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public DeleteModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public ModbusSlave ModbusSlave { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.ModbusSlaves == null) + { + return NotFound(); + } + + var modbusslave = await _context.ModbusSlaves.FirstOrDefaultAsync(m => m.Id == id); + + if (modbusslave == null) + { + return NotFound(); + } + else + { + ModbusSlave = modbusslave; + } + return Page(); + } + + public async Task OnPostAsync(Guid? id) + { + if (id == null || _context.ModbusSlaves == null) + { + return NotFound(); + } + var modbusslave = await _context.ModbusSlaves.FindAsync(id); + + if (modbusslave != null) + { + ModbusSlave = modbusslave; + _context.ModbusSlaves.Remove(ModbusSlave); + await _context.SaveChangesAsync(); + } + + return RedirectToPage("./Index"); + } + } +} diff --git a/Pages/SlaveAdmin/Details.cshtml b/Pages/SlaveAdmin/Details.cshtml new file mode 100644 index 0000000..5150180 --- /dev/null +++ b/Pages/SlaveAdmin/Details.cshtml @@ -0,0 +1,43 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.SlaveAdmin.DetailsModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

ModbusSlave

+
+
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.Slave) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.Slave) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.TimeOut) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.TimeOut) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.DeviceName) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.DeviceName) +
+
+ @Html.DisplayNameFor(model => model.ModbusSlave.DeviceNameFormat) +
+
+ @Html.DisplayFor(model => model.ModbusSlave.DeviceNameFormat) +
+
+
+ diff --git a/Pages/SlaveAdmin/Details.cshtml.cs b/Pages/SlaveAdmin/Details.cshtml.cs new file mode 100644 index 0000000..a9d7e90 --- /dev/null +++ b/Pages/SlaveAdmin/Details.cshtml.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.SlaveAdmin +{ + public class DetailsModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public DetailsModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public ModbusSlave ModbusSlave { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.ModbusSlaves == null) + { + return NotFound(); + } + + var modbusslave = await _context.ModbusSlaves.FirstOrDefaultAsync(m => m.Id == id); + if (modbusslave == null) + { + return NotFound(); + } + else + { + ModbusSlave = modbusslave; + } + return Page(); + } + } +} diff --git a/Pages/SlaveAdmin/Edit.cshtml b/Pages/SlaveAdmin/Edit.cshtml new file mode 100644 index 0000000..68251d3 --- /dev/null +++ b/Pages/SlaveAdmin/Edit.cshtml @@ -0,0 +1,50 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.SlaveAdmin.EditModel + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

ModbusSlave

+
+
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/Pages/SlaveAdmin/Edit.cshtml.cs b/Pages/SlaveAdmin/Edit.cshtml.cs new file mode 100644 index 0000000..0351793 --- /dev/null +++ b/Pages/SlaveAdmin/Edit.cshtml.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.SlaveAdmin +{ + public class EditModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public EditModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + [BindProperty] + public ModbusSlave ModbusSlave { get; set; } = default!; + + public async Task OnGetAsync(Guid? id) + { + if (id == null || _context.ModbusSlaves == null) + { + return NotFound(); + } + + var modbusslave = await _context.ModbusSlaves.FirstOrDefaultAsync(m => m.Id == id); + if (modbusslave == null) + { + return NotFound(); + } + ModbusSlave = modbusslave; + return Page(); + } + + // To protect from overposting attacks, enable the specific properties you want to bind to. + // For more details, see https://aka.ms/RazorPagesCRUD. + public async Task OnPostAsync() + { + if (!ModelState.IsValid) + { + return Page(); + } + + _context.Attach(ModbusSlave).State = EntityState.Modified; + + try + { + await _context.SaveChangesAsync(); + } + catch (DbUpdateConcurrencyException) + { + if (!ModbusSlaveExists(ModbusSlave.Id)) + { + return NotFound(); + } + else + { + throw; + } + } + + return RedirectToPage("./Index"); + } + + private bool ModbusSlaveExists(Guid id) + { + return (_context.ModbusSlaves?.Any(e => e.Id == id)).GetValueOrDefault(); + } + } +} diff --git a/Pages/SlaveAdmin/Index.cshtml b/Pages/SlaveAdmin/Index.cshtml new file mode 100644 index 0000000..770ef0c --- /dev/null +++ b/Pages/SlaveAdmin/Index.cshtml @@ -0,0 +1,54 @@ +@page +@model IoTSharp.Gateway.Modbus.Pages.SlaveAdmin.IndexModel + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + + +@foreach (var item in Model.ModbusSlave) { + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.ModbusSlave[0].Slave) + + @Html.DisplayNameFor(model => model.ModbusSlave[0].TimeOut) + + @Html.DisplayNameFor(model => model.ModbusSlave[0].DeviceName) + + @Html.DisplayNameFor(model => model.ModbusSlave[0].DeviceNameFormat) +
+ @Html.DisplayFor(modelItem => item.Slave) + + @Html.DisplayFor(modelItem => item.TimeOut) + + @Html.DisplayFor(modelItem => item.DeviceName) + + @Html.DisplayFor(modelItem => item.DeviceNameFormat) + + Edit | + Details | + Delete +
diff --git a/Pages/SlaveAdmin/Index.cshtml.cs b/Pages/SlaveAdmin/Index.cshtml.cs new file mode 100644 index 0000000..4d8ce25 --- /dev/null +++ b/Pages/SlaveAdmin/Index.cshtml.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.EntityFrameworkCore; +using IoTSharp.Gateway.Modbus.Data; + +namespace IoTSharp.Gateway.Modbus.Pages.SlaveAdmin +{ + public class IndexModel : PageModel + { + private readonly IoTSharp.Gateway.Modbus.Data.ApplicationDbContext _context; + + public IndexModel(IoTSharp.Gateway.Modbus.Data.ApplicationDbContext context) + { + _context = context; + } + + public IList ModbusSlave { get;set; } = default!; + + public async Task OnGetAsync() + { + if (_context.ModbusSlaves != null) + { + ModbusSlave = await _context.ModbusSlaves.ToListAsync(); + } + } + } +} diff --git a/Program.cs b/Program.cs index d91af72..c01ccec 100644 --- a/Program.cs +++ b/Program.cs @@ -1,6 +1,7 @@ using IoTSharp.Gateway.Modbus.Data; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; +using SilkierQuartz; namespace IoTSharp.Gateway.Modbus { @@ -9,7 +10,6 @@ namespace IoTSharp.Gateway.Modbus public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - // Add services to the container. var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); builder.Services.AddDbContext(options => @@ -19,6 +19,17 @@ namespace IoTSharp.Gateway.Modbus builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount=false) .AddEntityFrameworkStores(); builder.Services.AddRazorPages(); + builder.Services.AddSilkierQuartz(option => + { + option.VirtualPathRoot = "/SilkierQuartz"; + option.UseLocalTime = true; + option.DefaultDateFormat = "yyyy-MM-dd"; + option.DefaultTimeFormat = "HH:mm:ss"; + }, auth=> + { + auth.AccessRequirement = SilkierQuartzAuthenticationOptions.SimpleAccessRequirement.AllowAnonymous; + }); + var app = builder.Build(); @@ -41,7 +52,8 @@ namespace IoTSharp.Gateway.Modbus app.UseAuthentication(); app.UseAuthorization(); - + app.UseSilkierQuartz(); + app.MapRazorPages(); app.Run();