Move device statistics to database.

This commit is contained in:
2018-12-21 03:55:56 +00:00
parent c6684c43cc
commit f376286e8a
8 changed files with 1441 additions and 32 deletions

View File

@@ -307,11 +307,14 @@
<e p="20181221015906_NameValueStatistics.cs" t="Include" /> <e p="20181221015906_NameValueStatistics.cs" t="Include" />
<e p="20181221032605_MediaStatistics.Designer.cs" t="Include" /> <e p="20181221032605_MediaStatistics.Designer.cs" t="Include" />
<e p="20181221032605_MediaStatistics.cs" t="Include" /> <e p="20181221032605_MediaStatistics.cs" t="Include" />
<e p="20181221034941_SeenDevicesStatistics.Designer.cs" t="Include" />
<e p="20181221034941_SeenDevicesStatistics.cs" t="Include" />
<e p="DicContextModelSnapshot.cs" t="Include" /> <e p="DicContextModelSnapshot.cs" t="Include" />
</e> </e>
<e p="Models" t="Include"> <e p="Models" t="Include">
<e p="Command.cs" t="Include" /> <e p="Command.cs" t="Include" />
<e p="Device.cs" t="Include" /> <e p="Device.cs" t="Include" />
<e p="DeviceStat.cs" t="Include" />
<e p="Filesystem.cs" t="Include" /> <e p="Filesystem.cs" t="Include" />
<e p="Filter.cs" t="Include" /> <e p="Filter.cs" t="Include" />
<e p="Media.cs" t="Include" /> <e p="Media.cs" t="Include" />

View File

@@ -393,39 +393,14 @@ namespace DiscImageChef.Core
else if(dev.IsFireWire) deviceBus = "FireWire"; else if(dev.IsFireWire) deviceBus = "FireWire";
else deviceBus = dev.Type.ToString(); else deviceBus = dev.Type.ToString();
DeviceStats old = AllStats.Devices.FirstOrDefault(ds => ds.Manufacturer == dev.Manufacturer && ctx.SeenDevices.Add(new DeviceStat
ds.Model == dev.Model &&
ds.Revision == dev.Revision &&
ds.Bus == deviceBus);
if(old != null) AllStats.Devices.Remove(old);
DeviceStats nw = new DeviceStats
{ {
Model = dev.Model,
Manufacturer = dev.Manufacturer,
Revision = dev.Revision,
Bus = deviceBus, Bus = deviceBus,
ManufacturerSpecified = true
};
AllStats.Devices.Add(nw);
old = CurrentStats.Devices.FirstOrDefault(ds => ds.Manufacturer == dev.Manufacturer &&
ds.Model == dev.Model &&
ds.Revision == dev.Revision &&
ds.Bus == deviceBus);
if(old != null) CurrentStats.Devices.Remove(old);
nw = new DeviceStats
{
Model = dev.Model,
Manufacturer = dev.Manufacturer, Manufacturer = dev.Manufacturer,
Model = dev.Model,
Revision = dev.Revision, Revision = dev.Revision,
Bus = deviceBus, Synchronized = false
ManufacturerSpecified = true });
};
CurrentStats.Devices.Add(nw);
} }
/// <summary> /// <summary>

View File

@@ -51,6 +51,7 @@ namespace DiscImageChef.Database
public DbSet<MediaFormat> MediaFormats { get; set; } public DbSet<MediaFormat> MediaFormats { get; set; }
public DbSet<Partition> Partitions { get; set; } public DbSet<Partition> Partitions { get; set; }
public DbSet<Media> Medias { get; set; } public DbSet<Media> Medias { get; set; }
public DbSet<DeviceStat> SeenDevices { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {

View File

@@ -68,9 +68,12 @@
<Compile Include="Migrations\20181221015906_NameValueStatistics.Designer.cs" /> <Compile Include="Migrations\20181221015906_NameValueStatistics.Designer.cs" />
<Compile Include="Migrations\20181221032605_MediaStatistics.cs" /> <Compile Include="Migrations\20181221032605_MediaStatistics.cs" />
<Compile Include="Migrations\20181221032605_MediaStatistics.Designer.cs" /> <Compile Include="Migrations\20181221032605_MediaStatistics.Designer.cs" />
<Compile Include="Migrations\20181221034941_SeenDevicesStatistics.cs" />
<Compile Include="Migrations\20181221034941_SeenDevicesStatistics.Designer.cs" />
<Compile Include="Migrations\DicContextModelSnapshot.cs" /> <Compile Include="Migrations\DicContextModelSnapshot.cs" />
<Compile Include="Models\Command.cs" /> <Compile Include="Models\Command.cs" />
<Compile Include="Models\Device.cs" /> <Compile Include="Models\Device.cs" />
<Compile Include="Models\DeviceStat.cs" />
<Compile Include="Models\Filesystem.cs" /> <Compile Include="Models\Filesystem.cs" />
<Compile Include="Models\Filter.cs" /> <Compile Include="Models\Filter.cs" />
<Compile Include="Models\Media.cs" /> <Compile Include="Models\Media.cs" />

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace DiscImageChef.Database.Migrations
{
public partial class SeenDevicesStatistics : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable("SeenDevices",
table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Manufacturer = table.Column<string>(nullable: true),
Model = table.Column<string>(nullable: true),
Revision = table.Column<string>(nullable: true),
Bus = table.Column<string>(nullable: true),
Synchronized = table.Column<bool>(nullable: false)
},
constraints: table => { table.PrimaryKey("PK_SeenDevices", x => x.Id); });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable("SeenDevices");
}
}
}

View File

@@ -890,6 +890,25 @@ namespace DiscImageChef.Database.Migrations
b.ToTable("Devices"); b.ToTable("Devices");
}); });
modelBuilder.Entity("DiscImageChef.Database.Models.DeviceStat", b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd();
b.Property<string>("Bus");
b.Property<string>("Manufacturer");
b.Property<string>("Model");
b.Property<string>("Revision");
b.Property<bool>("Synchronized");
b.HasKey("Id");
b.ToTable("SeenDevices");
});
modelBuilder.Entity("DiscImageChef.Database.Models.Filesystem", b => modelBuilder.Entity("DiscImageChef.Database.Models.Filesystem", b =>
{ {
b.Property<int>("Id").ValueGeneratedOnAdd(); b.Property<int>("Id").ValueGeneratedOnAdd();

View File

@@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
namespace DiscImageChef.Database.Models
{
public class DeviceStat
{
[Key]
public int Id { get; set; }
public string Manufacturer { get; set; }
public string Model { get; set; }
public string Revision { get; set; }
public string Bus { get; set; }
public bool Synchronized { get; set; }
}
}