Use DateTimeOffset string converter.

This commit is contained in:
Jared Goodwin 2020-03-05 15:17:47 -08:00
parent bd5f967a97
commit 4fc612d427
7 changed files with 58 additions and 155 deletions

View File

@ -92,12 +92,11 @@ namespace Remotely.Server.Data
x => JsonSerializer.Serialize(x, null),
x => JsonSerializer.Deserialize<List<GenericCommandResult>>(x, null));
builder.Entity<GenericCommandResult>()
.HasNoKey();
builder.Entity<PSCoreCommandResult>()
.HasNoKey();
//builder.Entity<GenericCommandResult>()
// .HasNoKey();
//builder.Entity<PSCoreCommandResult>()
// .HasNoKey();
builder.Entity<RemotelyUser>()
.HasOne(x => x.Organization)
@ -137,6 +136,10 @@ namespace Remotely.Server.Data
// This only supports millisecond precision, but should be sufficient for most use cases.
foreach (var entityType in builder.Model.GetEntityTypes())
{
if (entityType.IsKeyless)
{
continue;
}
var properties = entityType.ClrType.GetProperties().Where(p => p.PropertyType == typeof(DateTimeOffset)
|| p.PropertyType == typeof(DateTimeOffset?));
foreach (var property in properties)
@ -144,7 +147,7 @@ namespace Remotely.Server.Data
builder
.Entity(entityType.Name)
.Property(property.Name)
.HasConversion(new DateTimeOffsetToBinaryConverter());
.HasConversion(new DateTimeOffsetToStringConverter());
}
}
}

View File

@ -9,7 +9,7 @@ using Remotely.Server.Data;
namespace Remotely.Server.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20200305075755_Initial")]
[Migration("20200305230311_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -93,8 +93,8 @@ namespace Remotely.Server.Migrations
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<long?>("LockoutEnd")
.HasColumnType("INTEGER");
b.Property<string>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasColumnType("TEXT")
@ -225,8 +225,8 @@ namespace Remotely.Server.Migrations
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<long?>("LastUsed")
.HasColumnType("INTEGER");
b.Property<string>("LastUsed")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT")
@ -279,8 +279,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("TargetDeviceIDs")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.Property<string>("TimeStamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
@ -322,8 +323,9 @@ namespace Remotely.Server.Migrations
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<long>("LastOnline")
.HasColumnType("INTEGER");
b.Property<string>("LastOnline")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OSArchitecture")
.HasColumnType("INTEGER");
@ -409,8 +411,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("StackTrace")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.Property<string>("TimeStamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
@ -419,36 +422,14 @@ namespace Remotely.Server.Migrations
b.ToTable("EventLogs");
});
modelBuilder.Entity("Remotely.Shared.Models.GenericCommandResult", b =>
{
b.Property<string>("CommandResultID")
.HasColumnType("TEXT");
b.Property<string>("CommandType")
.HasColumnType("TEXT");
b.Property<string>("DeviceID")
.HasColumnType("TEXT");
b.Property<string>("ErrorOutput")
.HasColumnType("TEXT");
b.Property<string>("StandardOutput")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.ToTable("GenericCommandResult");
});
modelBuilder.Entity("Remotely.Shared.Models.InviteLink", b =>
{
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<long>("DateSent")
.HasColumnType("INTEGER");
b.Property<string>("DateSent")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("InvitedUser")
.HasColumnType("TEXT");
@ -483,20 +464,6 @@ namespace Remotely.Server.Migrations
b.ToTable("Organizations");
});
modelBuilder.Entity("Remotely.Shared.Models.PSCoreCommandResult", b =>
{
b.Property<string>("CommandResultID")
.HasColumnType("TEXT");
b.Property<string>("DeviceID")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.ToTable("PSCoreCommandResult");
});
modelBuilder.Entity("Remotely.Shared.Models.SharedFile", b =>
{
b.Property<string>("ID")
@ -514,8 +481,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("OrganizationID")
.HasColumnType("TEXT");
b.Property<long>("Timestamp")
.HasColumnType("INTEGER");
b.Property<string>("Timestamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");

View File

@ -21,21 +21,6 @@ namespace Remotely.Server.Migrations
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "GenericCommandResult",
columns: table => new
{
DeviceID = table.Column<string>(nullable: true),
CommandResultID = table.Column<string>(nullable: true),
CommandType = table.Column<string>(nullable: true),
StandardOutput = table.Column<string>(nullable: true),
ErrorOutput = table.Column<string>(nullable: true),
TimeStamp = table.Column<long>(nullable: false)
},
constraints: table =>
{
});
migrationBuilder.CreateTable(
name: "Organizations",
columns: table => new
@ -48,18 +33,6 @@ namespace Remotely.Server.Migrations
table.PrimaryKey("PK_Organizations", x => x.ID);
});
migrationBuilder.CreateTable(
name: "PSCoreCommandResult",
columns: table => new
{
CommandResultID = table.Column<string>(nullable: true),
DeviceID = table.Column<string>(nullable: true),
TimeStamp = table.Column<long>(nullable: false)
},
constraints: table =>
{
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
@ -86,7 +59,7 @@ namespace Remotely.Server.Migrations
columns: table => new
{
ID = table.Column<string>(nullable: false),
LastUsed = table.Column<long>(nullable: true),
LastUsed = table.Column<string>(nullable: true),
Name = table.Column<string>(maxLength: 200, nullable: true),
OrganizationID = table.Column<string>(nullable: true),
Secret = table.Column<string>(nullable: true),
@ -115,7 +88,7 @@ namespace Remotely.Server.Migrations
TargetDeviceIDs = table.Column<string>(nullable: true),
PSCoreResults = table.Column<string>(nullable: true),
CommandResults = table.Column<string>(nullable: true),
TimeStamp = table.Column<long>(nullable: false),
TimeStamp = table.Column<string>(nullable: false),
OrganizationID = table.Column<string>(nullable: true)
},
constraints: table =>
@ -158,7 +131,7 @@ namespace Remotely.Server.Migrations
Source = table.Column<string>(nullable: true),
StackTrace = table.Column<string>(nullable: true),
OrganizationID = table.Column<string>(nullable: true),
TimeStamp = table.Column<long>(nullable: false)
TimeStamp = table.Column<string>(nullable: false)
},
constraints: table =>
{
@ -178,7 +151,7 @@ namespace Remotely.Server.Migrations
ID = table.Column<string>(nullable: false),
InvitedUser = table.Column<string>(nullable: true),
IsAdmin = table.Column<bool>(nullable: false),
DateSent = table.Column<long>(nullable: false),
DateSent = table.Column<string>(nullable: false),
OrganizationID = table.Column<string>(nullable: true),
ResetUrl = table.Column<string>(nullable: true)
},
@ -209,7 +182,7 @@ namespace Remotely.Server.Migrations
PhoneNumber = table.Column<string>(nullable: true),
PhoneNumberConfirmed = table.Column<bool>(nullable: false),
TwoFactorEnabled = table.Column<bool>(nullable: false),
LockoutEnd = table.Column<long>(nullable: true),
LockoutEnd = table.Column<string>(nullable: true),
LockoutEnabled = table.Column<bool>(nullable: false),
AccessFailedCount = table.Column<int>(nullable: false),
Discriminator = table.Column<string>(nullable: false),
@ -236,7 +209,7 @@ namespace Remotely.Server.Migrations
FileName = table.Column<string>(nullable: true),
ContentType = table.Column<string>(nullable: true),
FileContents = table.Column<byte[]>(nullable: true),
Timestamp = table.Column<long>(nullable: false),
Timestamp = table.Column<string>(nullable: false),
OrganizationID = table.Column<string>(nullable: true)
},
constraints: table =>
@ -266,7 +239,7 @@ namespace Remotely.Server.Migrations
UsedStorage = table.Column<double>(nullable: false),
Is64Bit = table.Column<bool>(nullable: false),
IsOnline = table.Column<bool>(nullable: false),
LastOnline = table.Column<long>(nullable: false),
LastOnline = table.Column<string>(nullable: false),
OrganizationID = table.Column<string>(nullable: true),
OSArchitecture = table.Column<int>(nullable: false),
OSDescription = table.Column<string>(nullable: true),
@ -541,18 +514,12 @@ namespace Remotely.Server.Migrations
migrationBuilder.DropTable(
name: "EventLogs");
migrationBuilder.DropTable(
name: "GenericCommandResult");
migrationBuilder.DropTable(
name: "InviteLinks");
migrationBuilder.DropTable(
name: "PermissionLinks");
migrationBuilder.DropTable(
name: "PSCoreCommandResult");
migrationBuilder.DropTable(
name: "SharedFiles");

View File

@ -91,8 +91,8 @@ namespace Remotely.Server.Migrations
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<long?>("LockoutEnd")
.HasColumnType("INTEGER");
b.Property<string>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasColumnType("TEXT")
@ -223,8 +223,8 @@ namespace Remotely.Server.Migrations
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<long?>("LastUsed")
.HasColumnType("INTEGER");
b.Property<string>("LastUsed")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT")
@ -277,8 +277,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("TargetDeviceIDs")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.Property<string>("TimeStamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
@ -320,8 +321,9 @@ namespace Remotely.Server.Migrations
b.Property<bool>("IsOnline")
.HasColumnType("INTEGER");
b.Property<long>("LastOnline")
.HasColumnType("INTEGER");
b.Property<string>("LastOnline")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("OSArchitecture")
.HasColumnType("INTEGER");
@ -407,8 +409,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("StackTrace")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.Property<string>("TimeStamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");
@ -417,36 +420,14 @@ namespace Remotely.Server.Migrations
b.ToTable("EventLogs");
});
modelBuilder.Entity("Remotely.Shared.Models.GenericCommandResult", b =>
{
b.Property<string>("CommandResultID")
.HasColumnType("TEXT");
b.Property<string>("CommandType")
.HasColumnType("TEXT");
b.Property<string>("DeviceID")
.HasColumnType("TEXT");
b.Property<string>("ErrorOutput")
.HasColumnType("TEXT");
b.Property<string>("StandardOutput")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.ToTable("GenericCommandResult");
});
modelBuilder.Entity("Remotely.Shared.Models.InviteLink", b =>
{
b.Property<string>("ID")
.HasColumnType("TEXT");
b.Property<long>("DateSent")
.HasColumnType("INTEGER");
b.Property<string>("DateSent")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("InvitedUser")
.HasColumnType("TEXT");
@ -481,20 +462,6 @@ namespace Remotely.Server.Migrations
b.ToTable("Organizations");
});
modelBuilder.Entity("Remotely.Shared.Models.PSCoreCommandResult", b =>
{
b.Property<string>("CommandResultID")
.HasColumnType("TEXT");
b.Property<string>("DeviceID")
.HasColumnType("TEXT");
b.Property<long>("TimeStamp")
.HasColumnType("INTEGER");
b.ToTable("PSCoreCommandResult");
});
modelBuilder.Entity("Remotely.Shared.Models.SharedFile", b =>
{
b.Property<string>("ID")
@ -512,8 +479,9 @@ namespace Remotely.Server.Migrations
b.Property<string>("OrganizationID")
.HasColumnType("TEXT");
b.Property<long>("Timestamp")
.HasColumnType("INTEGER");
b.Property<string>("Timestamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("ID");

View File

@ -16,7 +16,9 @@ namespace Remotely.Shared.Models
public string SenderUserID { get; set; }
public string SenderConnectionID { get; set; }
public string[] TargetDeviceIDs { get; set; }
[NotMapped]
public ICollection<PSCoreCommandResult> PSCoreResults { get; set; } = new List<PSCoreCommandResult>();
[NotMapped]
public ICollection<GenericCommandResult> CommandResults { get; set; } = new List<GenericCommandResult>();
public DateTimeOffset TimeStamp { get; set; } = DateTimeOffset.Now;
[JsonIgnore]

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
namespace Remotely.Shared.Models

View File

@ -9,17 +9,11 @@ namespace Remotely.Shared.Models
{
public string CommandResultID { get; set; }
public string DeviceID { get; set; }
[NotMapped]
public List<string> VerboseOutput { get; set; }
[NotMapped]
public List<string> DebugOutput { get; set; }
[NotMapped]
public List<string> ErrorOutput { get; set; }
[NotMapped]
public string HostOutput { get; set; }
[NotMapped]
public List<string> InformationOutput { get; set; }
[NotMapped]
public List<string> WarningOutput { get; set; }
public DateTimeOffset TimeStamp { get; set; } = DateTimeOffset.Now;
}