Move media statistics to database.

This commit is contained in:
2018-12-21 03:34:54 +00:00
parent a7721f943a
commit c6684c43cc
8 changed files with 1406 additions and 40 deletions

View File

@@ -305,6 +305,8 @@
<e p="20181127013131_CorrectReportsDbSet.cs" t="Include" />
<e p="20181221015906_NameValueStatistics.Designer.cs" t="Include" />
<e p="20181221015906_NameValueStatistics.cs" t="Include" />
<e p="20181221032605_MediaStatistics.Designer.cs" t="Include" />
<e p="20181221032605_MediaStatistics.cs" t="Include" />
<e p="DicContextModelSnapshot.cs" t="Include" />
</e>
<e p="Models" t="Include">
@@ -312,6 +314,7 @@
<e p="Device.cs" t="Include" />
<e p="Filesystem.cs" t="Include" />
<e p="Filter.cs" t="Include" />
<e p="Media.cs" t="Include" />
<e p="MediaFormat.cs" t="Include" />
<e p="Partition.cs" t="Include" />
<e p="Report.cs" t="Include" />

View File

@@ -437,46 +437,7 @@ namespace DiscImageChef.Core
{
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaStats) return;
if(AllStats.Medias == null) AllStats.Medias = new List<MediaStats>();
if(CurrentStats.Medias == null) CurrentStats.Medias = new List<MediaStats>();
MediaStats old = AllStats.Medias.FirstOrDefault(ms => ms.real == real && ms.type == type.ToString());
MediaStats nw = new MediaStats();
if(old != null)
{
nw.type = old.type;
nw.real = old.real;
nw.Value = old.Value + 1;
AllStats.Medias.Remove(old);
}
else
{
nw.type = type.ToString();
nw.real = real;
nw.Value = 1;
}
AllStats.Medias.Add(nw);
old = CurrentStats.Medias.FirstOrDefault(ms => ms.real == real && ms.type == type.ToString());
nw = new MediaStats();
if(old != null)
{
nw.type = old.type;
nw.real = old.real;
nw.Value = old.Value + 1;
CurrentStats.Medias.Remove(old);
}
else
{
nw.type = type.ToString();
nw.real = real;
nw.Value = 1;
}
CurrentStats.Medias.Add(nw);
ctx.Medias.Add(new Database.Models.Media {Real = real, Synchronized = false, Type = type.ToString()});
}
/// <summary>

View File

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

View File

@@ -66,11 +66,14 @@
<Compile Include="Migrations\20181127013131_CorrectReportsDbSet.Designer.cs" />
<Compile Include="Migrations\20181221015906_NameValueStatistics.cs" />
<Compile Include="Migrations\20181221015906_NameValueStatistics.Designer.cs" />
<Compile Include="Migrations\20181221032605_MediaStatistics.cs" />
<Compile Include="Migrations\20181221032605_MediaStatistics.Designer.cs" />
<Compile Include="Migrations\DicContextModelSnapshot.cs" />
<Compile Include="Models\Command.cs" />
<Compile Include="Models\Device.cs" />
<Compile Include="Models\Filesystem.cs" />
<Compile Include="Models\Filter.cs" />
<Compile Include="Models\Media.cs" />
<Compile Include="Models\MediaFormat.cs" />
<Compile Include="Models\Partition.cs" />
<Compile Include="Models\Report.cs" />

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace DiscImageChef.Database.Migrations
{
public partial class MediaStatistics : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable("Medias",
table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Type = table.Column<string>(nullable: true),
Real = table.Column<bool>(nullable: false),
Synchronized = table.Column<bool>(nullable: false)
}, constraints: table => { table.PrimaryKey("PK_Medias", x => x.Id); });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable("Medias");
}
}
}

View File

@@ -916,6 +916,21 @@ namespace DiscImageChef.Database.Migrations
b.ToTable("Filters");
});
modelBuilder.Entity("DiscImageChef.Database.Models.Media", b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd();
b.Property<bool>("Real");
b.Property<bool>("Synchronized");
b.Property<string>("Type");
b.HasKey("Id");
b.ToTable("Medias");
});
modelBuilder.Entity("DiscImageChef.Database.Models.MediaFormat", b =>
{
b.Property<int>("Id").ValueGeneratedOnAdd();

View File

@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
namespace DiscImageChef.Database.Models
{
public class Media
{
[Key]
public int Id { get; set; }
public string Type { get; set; }
public bool Real { get; set; }
public bool Synchronized { get; set; }
}
}