Sicherung
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using FSI.BT.IR.Plc.Settings.Log.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FSI.BT.IR.Plc.Settings.Log.Data
|
||||
{
|
||||
@@ -10,6 +11,8 @@ namespace FSI.BT.IR.Plc.Settings.Log.Data
|
||||
|
||||
}
|
||||
|
||||
public DbSet<Models.Organization> Organizations { get; set; }
|
||||
|
||||
public DbSet<Models.Plc> Plcs { get; set; }
|
||||
|
||||
public DbSet<Models.Parameter> Parameters { get; set; }
|
||||
|
||||
208
worker/FSI.BT.IR.Plc.Settings.Log/Migrations/20241018054354_OrganizationAdded.Designer.cs
generated
Normal file
208
worker/FSI.BT.IR.Plc.Settings.Log/Migrations/20241018054354_OrganizationAdded.Designer.cs
generated
Normal file
@@ -0,0 +1,208 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FSI.BT.IR.Plc.Settings.Log.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FSI.BT.IR.Plc.Settings.Log.Migrations
|
||||
{
|
||||
[DbContext(typeof(ApplicationDbContext))]
|
||||
[Migration("20241018054354_OrganizationAdded")]
|
||||
partial class OrganizationAdded
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.10");
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Logging", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ParameterId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Timestamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ParameterId");
|
||||
|
||||
b.ToTable("Logging");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreationTimeStamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("FullShortName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("ModificationTimeStamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ShortName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ParentId");
|
||||
|
||||
b.ToTable("Organizations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Parameter", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("DataType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("DbNo")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("DbSize")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("DbStart")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("DefaultValue")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("PlcId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Updated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("PlcId");
|
||||
|
||||
b.ToTable("Parameters");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Plc", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("IpAdress")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Rack")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("Slot")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("Updated")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Plcs");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Logging", b =>
|
||||
{
|
||||
b.HasOne("FSI.BT.IR.Plc.Settings.Log.Models.Parameter", "Parameter")
|
||||
.WithMany()
|
||||
.HasForeignKey("ParameterId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Parameter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.HasOne("FSI.BT.IR.Plc.Settings.Log.Models.Organization", "Parent")
|
||||
.WithMany("Parents")
|
||||
.HasForeignKey("ParentId");
|
||||
|
||||
b.Navigation("Parent");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Parameter", b =>
|
||||
{
|
||||
b.HasOne("FSI.BT.IR.Plc.Settings.Log.Models.Plc", "Plc")
|
||||
.WithMany()
|
||||
.HasForeignKey("PlcId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Plc");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.Navigation("Parents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FSI.BT.IR.Plc.Settings.Log.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class OrganizationAdded : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Organizations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 30, nullable: false),
|
||||
ShortName = table.Column<string>(type: "TEXT", maxLength: 10, nullable: false),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
||||
ParentId = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Type = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
CreationTimeStamp = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
ModificationTimeStamp = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
FullShortName = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Organizations", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Organizations_Organizations_ParentId",
|
||||
column: x => x.ParentId,
|
||||
principalTable: "Organizations",
|
||||
principalColumn: "Id");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Organizations_ParentId",
|
||||
table: "Organizations",
|
||||
column: "ParentId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Organizations");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,49 @@ namespace FSI.BT.IR.Plc.Settings.Log.Migrations
|
||||
b.ToTable("Logging");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("CreationTimeStamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("FullShortName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<DateTime>("ModificationTimeStamp")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(30)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int?>("ParentId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("ShortName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Type")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ParentId");
|
||||
|
||||
b.ToTable("Organizations");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Parameter", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -132,6 +175,15 @@ namespace FSI.BT.IR.Plc.Settings.Log.Migrations
|
||||
b.Navigation("Parameter");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.HasOne("FSI.BT.IR.Plc.Settings.Log.Models.Organization", "Parent")
|
||||
.WithMany("Parents")
|
||||
.HasForeignKey("ParentId");
|
||||
|
||||
b.Navigation("Parent");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Parameter", b =>
|
||||
{
|
||||
b.HasOne("FSI.BT.IR.Plc.Settings.Log.Models.Plc", "Plc")
|
||||
@@ -142,6 +194,11 @@ namespace FSI.BT.IR.Plc.Settings.Log.Migrations
|
||||
|
||||
b.Navigation("Plc");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FSI.BT.IR.Plc.Settings.Log.Models.Organization", b =>
|
||||
{
|
||||
b.Navigation("Parents");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
||||
58
worker/FSI.BT.IR.Plc.Settings.Log/Models/Organization.cs
Normal file
58
worker/FSI.BT.IR.Plc.Settings.Log/Models/Organization.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace FSI.BT.IR.Plc.Settings.Log.Models
|
||||
{
|
||||
|
||||
public class Organization
|
||||
{
|
||||
public Organization()
|
||||
{
|
||||
Parents = new HashSet<Organization>();
|
||||
}
|
||||
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
[StringLength(30)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[StringLength(10)]
|
||||
public string ShortName { get; set; }
|
||||
|
||||
[StringLength(255)]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[ForeignKey(nameof(Id))]
|
||||
public int? ParentId { get; set; }
|
||||
|
||||
public virtual Organization? Parent { get; set; }
|
||||
public virtual ICollection<Organization> Parents { get; set; }
|
||||
|
||||
[DisplayName("Type")]
|
||||
public OrganizationType Type { get; set; }
|
||||
|
||||
public DateTime CreationTimeStamp { get; set; }
|
||||
|
||||
public DateTime ModificationTimeStamp { get; set; }
|
||||
|
||||
public string FullShortName { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum OrganizationType
|
||||
{
|
||||
[Display(Name = "Firma")]
|
||||
company,
|
||||
[Display(Name = "Werk")]
|
||||
factory,
|
||||
[Display(Name = "Bereich")]
|
||||
area,
|
||||
[Display(Name = "Anlage")]
|
||||
plant,
|
||||
[Display(Name = "Teilanlage")]
|
||||
subPlant,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -128,12 +128,12 @@ namespace FSI.BT.IR.Plc.Settings.Log.Settings
|
||||
/// <summary>
|
||||
/// Update Intevall in ms
|
||||
/// </summary>
|
||||
public int UpdateIntervall { get; set; }
|
||||
public int UpdateInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Clean intevall in days
|
||||
/// </summary>
|
||||
public int CleanIntevall { get; set; }
|
||||
public int CleanInterval { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ namespace FSI.BT.IR.Plc.Settings.Log
|
||||
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (oldDate.Date != DateTime.Now)
|
||||
if (oldDate.Date != DateTime.Now.Date && _settings.Cfg.CleanInterval > 0 )
|
||||
{
|
||||
_log.Debug("Neuer Tag.");
|
||||
_log.Debug("Neuer Tag.");
|
||||
CleanLoggTable();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace FSI.BT.IR.Plc.Settings.Log
|
||||
_log.Debug(parameter.Plc.Name + " Start Task-Wartezeit");
|
||||
try
|
||||
{
|
||||
await Task.Delay(_settings.Cfg.UpdateIntervall, stoppingToken); // Warten bis zum n<>chsten Verbindungsversuch (Zeiten aus config.json)
|
||||
await Task.Delay(_settings.Cfg.UpdateInterval, stoppingToken); // Warten bis zum n<>chsten Verbindungsversuch (Zeiten aus config.json)
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace FSI.BT.IR.Plc.Settings.Log
|
||||
for (int i = 1; i < loggs.Count; i++)
|
||||
{
|
||||
span = Math.Abs(loggs[i].Timestamp.Subtract(DateTime.Now).Days);
|
||||
if (span > _settings.Cfg.CleanIntevall)
|
||||
if (span > _settings.Cfg.CleanInterval)
|
||||
{
|
||||
_context.Logging.Remove(loggs[i]);
|
||||
cntDel++;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"UpdateIntervall": "1000",
|
||||
"CleanIntervall" : "2"
|
||||
"UpdateInterval": "1000",
|
||||
"CleanInterval" : "2"
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user