mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Convert XML server statistics to database.
This commit is contained in:
5
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
5
.idea/.idea.DiscImageChef/.idea/contentModel.xml
generated
@@ -1772,6 +1772,7 @@
|
||||
<e p="ScsiMmcMode.cs" t="Include" />
|
||||
<e p="ScsiModeSense.cs" t="Include" />
|
||||
<e p="SscTestedMedia.cs" t="Include" />
|
||||
<e p="StatsConverter.cs" t="Include" />
|
||||
<e p="TestedMedia.cs" t="Include" />
|
||||
<e p="WebApiConfig.cs" t="Include" />
|
||||
</e>
|
||||
@@ -1813,10 +1814,6 @@
|
||||
<e p="Reports" t="Include">
|
||||
<e p=".htaccess" t="Include" />
|
||||
</e>
|
||||
<e p="Statistics" t="Include">
|
||||
<e p=".htaccess" t="Include" />
|
||||
<e p="Statistics.xml" t="Include" />
|
||||
</e>
|
||||
<e p="Statistics.aspx" t="Include" />
|
||||
<e p="Statistics.aspx.cs" t="Include" />
|
||||
<e p="Statistics.aspx.designer.cs" t="Include" />
|
||||
|
||||
332
DiscImageChef.Server/App_Start/StatsConverter.cs
Normal file
332
DiscImageChef.Server/App_Start/StatsConverter.cs
Normal file
@@ -0,0 +1,332 @@
|
||||
using System.Linq;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Server.Models;
|
||||
using Version = DiscImageChef.Server.Models.Version;
|
||||
|
||||
namespace DiscImageChef.Server
|
||||
{
|
||||
public static class StatsConverter
|
||||
{
|
||||
public static void Convert(Stats newStats)
|
||||
{
|
||||
DicServerContext ctx = new DicServerContext();
|
||||
|
||||
if(newStats.Commands != null)
|
||||
{
|
||||
if(newStats.Commands.Analyze > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "analyze");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Analyze, Name = "analyze"});
|
||||
else existing.Count += newStats.Commands.Analyze;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Benchmark > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "benchmark");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Benchmark, Name = "benchmark"});
|
||||
else existing.Count += newStats.Commands.Benchmark;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Checksum > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "checksum");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Checksum, Name = "checksum"});
|
||||
else existing.Count += newStats.Commands.Checksum;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Compare > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "compare");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Compare, Name = "compare"});
|
||||
else existing.Count += newStats.Commands.Compare;
|
||||
}
|
||||
|
||||
if(newStats.Commands.CreateSidecar > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.CreateSidecar, Name = "create-sidecar"
|
||||
});
|
||||
else existing.Count += newStats.Commands.CreateSidecar;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Decode > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "decode");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Decode, Name = "decode"});
|
||||
else existing.Count += newStats.Commands.Decode;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DeviceInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.DeviceInfo, Name = "device-info"});
|
||||
else existing.Count += newStats.Commands.DeviceInfo;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DeviceReport > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-report");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.DeviceReport, Name = "device-report"});
|
||||
else existing.Count += newStats.Commands.DeviceReport;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DumpMedia > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.DumpMedia, Name = "dump-media"});
|
||||
else existing.Count += newStats.Commands.DumpMedia;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Entropy > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "entropy");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Entropy, Name = "entropy"});
|
||||
else existing.Count += newStats.Commands.Entropy;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Formats > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "formats");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Formats, Name = "formats"});
|
||||
else existing.Count += newStats.Commands.Formats;
|
||||
}
|
||||
|
||||
if(newStats.Commands.MediaInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.MediaInfo, Name = "media-info"});
|
||||
else existing.Count += newStats.Commands.MediaInfo;
|
||||
}
|
||||
|
||||
if(newStats.Commands.MediaScan > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.MediaScan, Name = "media-scan"});
|
||||
else existing.Count += newStats.Commands.MediaScan;
|
||||
}
|
||||
|
||||
if(newStats.Commands.PrintHex > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "printhex");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.PrintHex, Name = "printhex"});
|
||||
else existing.Count += newStats.Commands.PrintHex;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Verify > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "verify");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Verify, Name = "verify"});
|
||||
else existing.Count += newStats.Commands.Verify;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Ls > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "ls");
|
||||
|
||||
if(existing == null) ctx.Commands.Add(new Command {Count = newStats.Commands.Ls, Name = "ls"});
|
||||
else existing.Count += newStats.Commands.Ls;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ExtractFiles > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "extract-files");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.ExtractFiles, Name = "extract-files"});
|
||||
else existing.Count += newStats.Commands.ExtractFiles;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ListDevices > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-devices");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.ListDevices, Name = "list-devices"});
|
||||
else existing.Count += newStats.Commands.ListDevices;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ListEncodings > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.ListEncodings, Name = "list-encodings"
|
||||
});
|
||||
else existing.Count += newStats.Commands.ListEncodings;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ConvertImage > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "convert-image");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.ConvertImage, Name = "convert-image"});
|
||||
else existing.Count += newStats.Commands.ConvertImage;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ImageInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "image-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.ImageInfo, Name = "image-info"});
|
||||
else existing.Count += newStats.Commands.ImageInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if(newStats.OperatingSystems != null)
|
||||
foreach(OsStats operatingSystem in newStats.OperatingSystems)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(operatingSystem.name) ||
|
||||
string.IsNullOrWhiteSpace(operatingSystem.version)) continue;
|
||||
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name &&
|
||||
c.Version == operatingSystem.version);
|
||||
|
||||
if(existing == null)
|
||||
ctx.OperatingSystems.Add(new OperatingSystem
|
||||
{
|
||||
Count = operatingSystem.Value,
|
||||
Name = operatingSystem.name,
|
||||
Version = operatingSystem.version
|
||||
});
|
||||
else existing.Count += operatingSystem.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Name == "Linux" && c.Version == null);
|
||||
|
||||
if(existing == null) ctx.OperatingSystems.Add(new OperatingSystem {Count = 1, Name = "Linux"});
|
||||
else existing.Count++;
|
||||
}
|
||||
|
||||
if(newStats.Versions != null)
|
||||
foreach(NameValueStats nvs in newStats.Versions)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Version existing = ctx.Versions.FirstOrDefault(c => c.Value == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Versions.Add(new Version {Count = nvs.Value, Value = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Version existing = ctx.Versions.FirstOrDefault(c => c.Value == "previous");
|
||||
|
||||
if(existing == null) ctx.Versions.Add(new Version {Count = 1, Value = "previous"});
|
||||
else existing.Count++;
|
||||
}
|
||||
|
||||
if(newStats.Filesystems != null)
|
||||
foreach(NameValueStats nvs in newStats.Filesystems)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Filesystem existing = ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Filesystems.Add(new Filesystem {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Partitions != null)
|
||||
foreach(NameValueStats nvs in newStats.Partitions)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Partition existing = ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Partitions.Add(new Partition {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.MediaImages != null)
|
||||
foreach(NameValueStats nvs in newStats.MediaImages)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
MediaFormat existing = ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.MediaFormats.Add(new MediaFormat {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Filters != null)
|
||||
foreach(NameValueStats nvs in newStats.Filters)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Filters.Add(new Filter {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Devices != null)
|
||||
foreach(DeviceStats device in newStats.Devices)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(device.Model)) continue;
|
||||
|
||||
if(!ctx.DeviceStats.Any(c => c.Bus == device.Bus && c.Manufacturer == device.Manufacturer &&
|
||||
c.Model == device.Model && c.Revision == device.Revision))
|
||||
ctx.DeviceStats.Add(new DeviceStat
|
||||
{
|
||||
Bus = device.Bus,
|
||||
Manufacturer = device.Manufacturer,
|
||||
Model = device.Model,
|
||||
Revision = device.Revision
|
||||
});
|
||||
}
|
||||
|
||||
if(newStats.Medias != null)
|
||||
foreach(MediaStats media in newStats.Medias)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(media.type)) continue;
|
||||
|
||||
Media existing = ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real);
|
||||
|
||||
if(existing == null)
|
||||
ctx.Medias.Add(new Media {Count = media.Value, Real = media.real, Type = media.type});
|
||||
else existing.Count += media.Value;
|
||||
}
|
||||
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,335 +75,7 @@ namespace DiscImageChef.Server.Controllers
|
||||
return response;
|
||||
}
|
||||
|
||||
DicServerContext ctx = new DicServerContext();
|
||||
if(newStats.Commands != null)
|
||||
{
|
||||
if(newStats.Commands.Analyze > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "analyze");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Analyze, Name = "analyze"});
|
||||
else existing.Count += newStats.Commands.Analyze;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Benchmark > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "benchmark");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Benchmark, Name = "benchmark"});
|
||||
else existing.Count += newStats.Commands.Benchmark;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Checksum > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "checksum");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Checksum, Name = "checksum"});
|
||||
else existing.Count += newStats.Commands.Checksum;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Compare > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "compare");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Compare, Name = "compare"});
|
||||
else existing.Count += newStats.Commands.Compare;
|
||||
}
|
||||
|
||||
if(newStats.Commands.CreateSidecar > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "create-sidecar");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.CreateSidecar, Name = "create-sidecar"
|
||||
});
|
||||
else existing.Count += newStats.Commands.CreateSidecar;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Decode > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "decode");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Decode, Name = "decode"});
|
||||
else existing.Count += newStats.Commands.Decode;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DeviceInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.DeviceInfo, Name = "device-info"});
|
||||
else existing.Count += newStats.Commands.DeviceInfo;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DeviceReport > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "device-report");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.DeviceReport, Name = "device-report"
|
||||
});
|
||||
else existing.Count += newStats.Commands.DeviceReport;
|
||||
}
|
||||
|
||||
if(newStats.Commands.DumpMedia > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "dump-media");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.DumpMedia, Name = "dump-media"});
|
||||
else existing.Count += newStats.Commands.DumpMedia;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Entropy > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "entropy");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Entropy, Name = "entropy"});
|
||||
else existing.Count += newStats.Commands.Entropy;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Formats > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "formats");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Formats, Name = "formats"});
|
||||
else existing.Count += newStats.Commands.Formats;
|
||||
}
|
||||
|
||||
if(newStats.Commands.MediaInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.MediaInfo, Name = "media-info"});
|
||||
else existing.Count += newStats.Commands.MediaInfo;
|
||||
}
|
||||
|
||||
if(newStats.Commands.MediaScan > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "media-scan");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.MediaScan, Name = "media-scan"});
|
||||
else existing.Count += newStats.Commands.MediaScan;
|
||||
}
|
||||
|
||||
if(newStats.Commands.PrintHex > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "printhex");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.PrintHex, Name = "printhex"});
|
||||
else existing.Count += newStats.Commands.PrintHex;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Verify > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "verify");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.Verify, Name = "verify"});
|
||||
else existing.Count += newStats.Commands.Verify;
|
||||
}
|
||||
|
||||
if(newStats.Commands.Ls > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "ls");
|
||||
|
||||
if(existing == null) ctx.Commands.Add(new Command {Count = newStats.Commands.Ls, Name = "ls"});
|
||||
else existing.Count += newStats.Commands.Ls;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ExtractFiles > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "extract-files");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.ExtractFiles, Name = "extract-files"
|
||||
});
|
||||
else existing.Count += newStats.Commands.ExtractFiles;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ListDevices > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-devices");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.ListDevices, Name = "list-devices"
|
||||
});
|
||||
else existing.Count += newStats.Commands.ListDevices;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ListEncodings > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "list-encodings");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.ListEncodings, Name = "list-encodings"
|
||||
});
|
||||
else existing.Count += newStats.Commands.ListEncodings;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ConvertImage > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "convert-image");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command
|
||||
{
|
||||
Count = newStats.Commands.ConvertImage, Name = "convert-image"
|
||||
});
|
||||
else existing.Count += newStats.Commands.ConvertImage;
|
||||
}
|
||||
|
||||
if(newStats.Commands.ImageInfo > 0)
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Name == "image-info");
|
||||
|
||||
if(existing == null)
|
||||
ctx.Commands.Add(new Command {Count = newStats.Commands.ImageInfo, Name = "image-info"});
|
||||
else existing.Count += newStats.Commands.ImageInfo;
|
||||
}
|
||||
}
|
||||
|
||||
if(newStats.OperatingSystems != null)
|
||||
foreach(OsStats operatingSystem in newStats.OperatingSystems)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(operatingSystem.name) ||
|
||||
string.IsNullOrWhiteSpace(operatingSystem.version)) continue;
|
||||
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Name == operatingSystem.name &&
|
||||
c.Version == operatingSystem.version);
|
||||
|
||||
if(existing == null)
|
||||
ctx.OperatingSystems.Add(new OperatingSystem
|
||||
{
|
||||
Count = operatingSystem.Value,
|
||||
Name = operatingSystem.name,
|
||||
Version = operatingSystem.version
|
||||
});
|
||||
else existing.Count += operatingSystem.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Name == "Linux" && c.Version == null);
|
||||
|
||||
if(existing == null) ctx.OperatingSystems.Add(new OperatingSystem {Count = 1, Name = "Linux"});
|
||||
else existing.Count++;
|
||||
}
|
||||
|
||||
if(newStats.Versions != null)
|
||||
foreach(NameValueStats nvs in newStats.Versions)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Version existing = ctx.Versions.FirstOrDefault(c => c.Value == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Versions.Add(new Version {Count = nvs.Value, Value = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Version existing = ctx.Versions.FirstOrDefault(c => c.Value == "previous");
|
||||
|
||||
if(existing == null) ctx.Versions.Add(new Version {Count = 1, Value = "previous"});
|
||||
else existing.Count++;
|
||||
}
|
||||
|
||||
if(newStats.Filesystems != null)
|
||||
foreach(NameValueStats nvs in newStats.Filesystems)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Filesystem existing = ctx.Filesystems.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Filesystems.Add(new Filesystem {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Partitions != null)
|
||||
foreach(NameValueStats nvs in newStats.Partitions)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Partition existing = ctx.Partitions.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Partitions.Add(new Partition {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.MediaImages != null)
|
||||
foreach(NameValueStats nvs in newStats.MediaImages)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
MediaFormat existing = ctx.MediaFormats.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.MediaFormats.Add(new MediaFormat {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Filters != null)
|
||||
foreach(NameValueStats nvs in newStats.Filters)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(nvs.name)) continue;
|
||||
|
||||
Filter existing = ctx.Filters.FirstOrDefault(c => c.Name == nvs.name);
|
||||
|
||||
if(existing == null) ctx.Filters.Add(new Filter {Count = nvs.Value, Name = nvs.name});
|
||||
else existing.Count += nvs.Value;
|
||||
}
|
||||
|
||||
if(newStats.Devices != null)
|
||||
foreach(DeviceStats device in newStats.Devices)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(device.Model)) continue;
|
||||
|
||||
if(!ctx.DeviceStats.Any(c => c.Bus == device.Bus && c.Manufacturer == device.Manufacturer &&
|
||||
c.Model == device.Model && c.Revision == device.Revision))
|
||||
ctx.DeviceStats.Add(new DeviceStat
|
||||
{
|
||||
Bus = device.Bus,
|
||||
Manufacturer = device.Manufacturer,
|
||||
Model = device.Model,
|
||||
Revision = device.Revision
|
||||
});
|
||||
}
|
||||
|
||||
if(newStats.Medias != null)
|
||||
foreach(MediaStats media in newStats.Medias)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(media.type)) continue;
|
||||
|
||||
Media existing = ctx.Medias.FirstOrDefault(c => c.Type == media.type && c.Real == media.real);
|
||||
|
||||
if(existing == null)
|
||||
ctx.Medias.Add(new Media {Count = media.Value, Real = media.real, Type = media.type});
|
||||
else existing.Count += media.Value;
|
||||
}
|
||||
|
||||
ctx.SaveChanges();
|
||||
StatsConverter.Convert(newStats);
|
||||
|
||||
response.Content = new StringContent("ok", Encoding.UTF8, "text/plain");
|
||||
return response;
|
||||
|
||||
@@ -182,6 +182,7 @@
|
||||
<Compile Include="App_Start\ScsiMmcMode.cs" />
|
||||
<Compile Include="App_Start\ScsiModeSense.cs" />
|
||||
<Compile Include="App_Start\SscTestedMedia.cs" />
|
||||
<Compile Include="App_Start\StatsConverter.cs" />
|
||||
<Compile Include="App_Start\TestedMedia.cs" />
|
||||
<Compile Include="App_Start\WebApiConfig.cs" />
|
||||
<Compile Include="Controllers\UploadReportController.cs" />
|
||||
@@ -268,8 +269,6 @@
|
||||
<None Include="int10h.org\.htaccess" />
|
||||
<None Include="int10h.org\vga_squarepx.woff2" />
|
||||
<None Include="Reports\.htaccess" />
|
||||
<None Include="Statistics\.htaccess" />
|
||||
<None Include="Statistics\Statistics.xml" />
|
||||
<None Include="usb.ids" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -39,6 +39,8 @@ using System.Threading;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.UI;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
using DiscImageChef.CommonTypes.Interop;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Server.Models;
|
||||
@@ -57,8 +59,6 @@ namespace DiscImageChef.Server
|
||||
List<DeviceItem> devices;
|
||||
List<NameValueStats> operatingSystems;
|
||||
List<MediaItem> realMedia;
|
||||
|
||||
//Stats statistics;
|
||||
List<NameValueStats> versions;
|
||||
List<MediaItem> virtualMedia;
|
||||
|
||||
@@ -68,27 +68,28 @@ namespace DiscImageChef.Server
|
||||
|
||||
try
|
||||
{
|
||||
/*
|
||||
if(!File.Exists(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
|
||||
"Statistics", "Statistics.xml")))
|
||||
{
|
||||
#if DEBUG
|
||||
content.InnerHtml =
|
||||
$"<b>Sorry, cannot load data file \"{Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(), "Statistics", "Statistics.xml")}\"</b>";
|
||||
#else
|
||||
content.InnerHtml = "<b>Sorry, cannot load data file</b>";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if(File.Exists(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
|
||||
"Statistics", "Statistics.xml")))
|
||||
try
|
||||
{
|
||||
Stats statistics = new Stats();
|
||||
|
||||
statistics = new Stats();
|
||||
XmlSerializer xs = new XmlSerializer(statistics.GetType());
|
||||
FileStream fs =
|
||||
WaitForFile(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(), "Statistics", "Statistics.xml"),
|
||||
FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
statistics = (Stats)xs.Deserialize(fs);
|
||||
fs.Close();
|
||||
|
||||
XmlSerializer xs = new XmlSerializer(statistics.GetType());
|
||||
FileStream fs =
|
||||
WaitForFile(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(), "Statistics", "Statistics.xml"),
|
||||
FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
statistics = (Stats)xs.Deserialize(fs);
|
||||
fs.Close();*/
|
||||
StatsConverter.Convert(statistics);
|
||||
|
||||
File.Delete(Path.Combine(HostingEnvironment.MapPath("~") ?? throw new InvalidOperationException(),
|
||||
"Statistics", "Statistics.xml"));
|
||||
}
|
||||
catch(XmlException)
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
if(ctx.OperatingSystems.Any())
|
||||
{
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
IndexIgnore *
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<DicStats xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
|
||||
Reference in New Issue
Block a user