mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Fix statistics uploading.
This commit is contained in:
@@ -458,152 +458,163 @@ namespace DiscImageChef.Core
|
|||||||
Thread submitThread = new Thread(() =>
|
Thread submitThread = new Thread(() =>
|
||||||
{
|
{
|
||||||
DicContext ctx = DicContext.Create(Settings.Settings.LocalDbPath);
|
DicContext ctx = DicContext.Create(Settings.Settings.LocalDbPath);
|
||||||
|
try
|
||||||
if(ctx.Commands.Any(c => !c.Synchronized) || ctx.Filesystems.Any(c => !c.Synchronized) ||
|
|
||||||
ctx.Filters.Any(c => !c.Synchronized) || ctx.MediaFormats.Any(c => !c.Synchronized) ||
|
|
||||||
ctx.Partitions.Any(c => !c.Synchronized) || ctx.Medias.Any(c => !c.Synchronized) ||
|
|
||||||
ctx.SeenDevices.Any(c => !c.Synchronized) || ctx.OperatingSystems.Any(c => !c.Synchronized) ||
|
|
||||||
ctx.Versions.Any(c => !c.Synchronized))
|
|
||||||
{
|
{
|
||||||
StatsDto dto = new StatsDto();
|
if(submitStatsLock) return;
|
||||||
|
|
||||||
if(ctx.Commands.Any(c => !c.Synchronized))
|
submitStatsLock = true;
|
||||||
{
|
|
||||||
dto.Commands = new List<NameValueStats>();
|
|
||||||
foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
|
||||||
dto.Commands.Add(new NameValueStats
|
|
||||||
{
|
|
||||||
name = nvs,
|
|
||||||
Value = ctx.Commands.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Name == nvs)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.Filesystems.Any(c => !c.Synchronized))
|
if(ctx.Commands.Any(c => !c.Synchronized) || ctx.Filesystems.Any(c => !c.Synchronized) ||
|
||||||
|
ctx.Filters.Any(c => !c.Synchronized) || ctx.MediaFormats.Any(c => !c.Synchronized) ||
|
||||||
|
ctx.Partitions.Any(c => !c.Synchronized) || ctx.Medias.Any(c => !c.Synchronized) ||
|
||||||
|
ctx.SeenDevices.Any(c => !c.Synchronized) || ctx.OperatingSystems.Any(c => !c.Synchronized) ||
|
||||||
|
ctx.Versions.Any(c => !c.Synchronized))
|
||||||
{
|
{
|
||||||
dto.Filesystems = new List<NameValueStats>();
|
StatsDto dto = new StatsDto();
|
||||||
foreach(string nvs in ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name).Distinct()
|
|
||||||
)
|
|
||||||
dto.Filesystems.Add(new NameValueStats
|
|
||||||
{
|
|
||||||
name = nvs,
|
|
||||||
Value = ctx.Filesystems.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Name == nvs)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.Filters.Any(c => !c.Synchronized))
|
if(ctx.Commands.Any(c => !c.Synchronized))
|
||||||
{
|
{
|
||||||
dto.Filters = new List<NameValueStats>();
|
dto.Commands = new List<NameValueStats>();
|
||||||
foreach(string nvs in ctx.Filters.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
foreach(string nvs in
|
||||||
dto.Filters.Add(new NameValueStats
|
ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
||||||
{
|
dto.Commands.Add(new NameValueStats
|
||||||
name = nvs,
|
{
|
||||||
Value = ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs)
|
name = nvs,
|
||||||
});
|
Value = ctx.Commands.LongCount(c => !c.Synchronized &&
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.MediaFormats.Any(c => !c.Synchronized))
|
|
||||||
{
|
|
||||||
dto.MediaFormats = new List<NameValueStats>();
|
|
||||||
foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
|
||||||
dto.MediaFormats.Add(new NameValueStats
|
|
||||||
{
|
|
||||||
name = nvs,
|
|
||||||
Value = ctx.MediaFormats.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Name == nvs)
|
c.Name == nvs)
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.Partitions.Any(c => !c.Synchronized))
|
|
||||||
{
|
|
||||||
dto.Partitions = new List<NameValueStats>();
|
|
||||||
foreach(string nvs in ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
|
||||||
dto.Partitions.Add(new NameValueStats
|
|
||||||
{
|
|
||||||
name = nvs,
|
|
||||||
Value = ctx.Partitions.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Name == nvs)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.Versions.Any(c => !c.Synchronized))
|
|
||||||
{
|
|
||||||
dto.Versions = new List<NameValueStats>();
|
|
||||||
foreach(string nvs in ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value).Distinct())
|
|
||||||
dto.Versions.Add(new NameValueStats
|
|
||||||
{
|
|
||||||
name = nvs,
|
|
||||||
Value = ctx.Versions.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Value == nvs)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.Medias.Any(c => !c.Synchronized))
|
|
||||||
{
|
|
||||||
dto.Medias = new List<MediaStats>();
|
|
||||||
foreach(string media in ctx.Medias.Where(c => !c.Synchronized).Select(c => c.Type).Distinct())
|
|
||||||
{
|
|
||||||
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real))
|
|
||||||
dto.Medias.Add(new MediaStats
|
|
||||||
{
|
|
||||||
real = true,
|
|
||||||
type = media,
|
|
||||||
Value = ctx.Medias.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Type == media && c.Real)
|
|
||||||
});
|
|
||||||
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real))
|
|
||||||
dto.Medias.Add(new MediaStats
|
|
||||||
{
|
|
||||||
real = false,
|
|
||||||
type = media,
|
|
||||||
Value = ctx.Medias.LongCount(c => !c.Synchronized &&
|
|
||||||
c.Type == media && !c.Real)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.SeenDevices.Any(c => !c.Synchronized))
|
if(ctx.Filesystems.Any(c => !c.Synchronized))
|
||||||
{
|
|
||||||
dto.Devices = new List<DeviceStats>();
|
|
||||||
foreach(DeviceStat device in ctx.SeenDevices.Where(c => !c.Synchronized))
|
|
||||||
dto.Devices.Add(new DeviceStats
|
|
||||||
{
|
|
||||||
Bus = device.Bus,
|
|
||||||
Manufacturer = device.Manufacturer,
|
|
||||||
ManufacturerSpecified = !(device.Manufacturer is null),
|
|
||||||
Model = device.Model,
|
|
||||||
Revision = device.Revision
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ctx.OperatingSystems.Any(c => !c.Synchronized))
|
|
||||||
{
|
|
||||||
dto.OperatingSystems = new List<OsStats>();
|
|
||||||
foreach(string osName in ctx.OperatingSystems.Where(c => !c.Synchronized).Select(c => c.Name)
|
|
||||||
.Distinct())
|
|
||||||
{
|
{
|
||||||
foreach(string osVersion in
|
dto.Filesystems = new List<NameValueStats>();
|
||||||
ctx.OperatingSystems.Where(c => !c.Synchronized && c.Name == osName)
|
foreach(string nvs in
|
||||||
.Select(c => c.Version).Distinct())
|
ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
||||||
dto.OperatingSystems.Add(new OsStats
|
dto.Filesystems.Add(new NameValueStats
|
||||||
{
|
{
|
||||||
name = osName,
|
name = nvs,
|
||||||
version = osVersion,
|
Value = ctx.Filesystems.LongCount(c => !c.Synchronized &&
|
||||||
Value =
|
c.Name == nvs)
|
||||||
ctx.OperatingSystems.LongCount(c =>
|
|
||||||
!c
|
|
||||||
.Synchronized &&
|
|
||||||
c.Name ==
|
|
||||||
osName &&
|
|
||||||
c.Version ==
|
|
||||||
osVersion)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
try
|
if(ctx.Filters.Any(c => !c.Synchronized))
|
||||||
{
|
{
|
||||||
|
dto.Filters = new List<NameValueStats>();
|
||||||
|
foreach(string nvs in ctx.Filters.Where(c => !c.Synchronized).Select(c => c.Name).Distinct()
|
||||||
|
)
|
||||||
|
dto.Filters.Add(new NameValueStats
|
||||||
|
{
|
||||||
|
name = nvs,
|
||||||
|
Value = ctx.Filters.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Name == nvs)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.MediaFormats.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.MediaFormats = new List<NameValueStats>();
|
||||||
|
foreach(string nvs in
|
||||||
|
ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
||||||
|
dto.MediaFormats.Add(new NameValueStats
|
||||||
|
{
|
||||||
|
name = nvs,
|
||||||
|
Value = ctx.MediaFormats.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Name == nvs)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.Partitions.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.Partitions = new List<NameValueStats>();
|
||||||
|
foreach(string nvs in
|
||||||
|
ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name).Distinct())
|
||||||
|
dto.Partitions.Add(new NameValueStats
|
||||||
|
{
|
||||||
|
name = nvs,
|
||||||
|
Value = ctx.Partitions.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Name == nvs)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.Versions.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.Versions = new List<NameValueStats>();
|
||||||
|
foreach(string nvs in
|
||||||
|
ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value).Distinct())
|
||||||
|
dto.Versions.Add(new NameValueStats
|
||||||
|
{
|
||||||
|
name = nvs,
|
||||||
|
Value = ctx.Versions.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Value == nvs)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.Medias.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.Medias = new List<MediaStats>();
|
||||||
|
foreach(string media in ctx.Medias.Where(c => !c.Synchronized).Select(c => c.Type)
|
||||||
|
.Distinct())
|
||||||
|
{
|
||||||
|
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && c.Real))
|
||||||
|
dto.Medias.Add(new MediaStats
|
||||||
|
{
|
||||||
|
real = true,
|
||||||
|
type = media,
|
||||||
|
Value = ctx.Medias.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Type == media && c.Real)
|
||||||
|
});
|
||||||
|
if(ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real))
|
||||||
|
dto.Medias.Add(new MediaStats
|
||||||
|
{
|
||||||
|
real = false,
|
||||||
|
type = media,
|
||||||
|
Value = ctx.Medias.LongCount(c => !c.Synchronized &&
|
||||||
|
c.Type == media && !c.Real)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.SeenDevices.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.Devices = new List<DeviceStats>();
|
||||||
|
foreach(DeviceStat device in ctx.SeenDevices.Where(c => !c.Synchronized))
|
||||||
|
dto.Devices.Add(new DeviceStats
|
||||||
|
{
|
||||||
|
Bus = device.Bus,
|
||||||
|
Manufacturer = device.Manufacturer,
|
||||||
|
ManufacturerSpecified = !(device.Manufacturer is null),
|
||||||
|
Model = device.Model,
|
||||||
|
Revision = device.Revision
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ctx.OperatingSystems.Any(c => !c.Synchronized))
|
||||||
|
{
|
||||||
|
dto.OperatingSystems = new List<OsStats>();
|
||||||
|
foreach(string osName in ctx.OperatingSystems.Where(c => !c.Synchronized)
|
||||||
|
.Select(c => c.Name).Distinct())
|
||||||
|
{
|
||||||
|
foreach(string osVersion in ctx
|
||||||
|
.OperatingSystems
|
||||||
|
.Where(c => !c.Synchronized && c.Name == osName)
|
||||||
|
.Select(c => c.Version).Distinct())
|
||||||
|
dto.OperatingSystems.Add(new OsStats
|
||||||
|
{
|
||||||
|
name = osName,
|
||||||
|
version = osVersion,
|
||||||
|
Value =
|
||||||
|
ctx.OperatingSystems.LongCount(c =>
|
||||||
|
!c
|
||||||
|
.Synchronized &&
|
||||||
|
c.Name ==
|
||||||
|
osName &&
|
||||||
|
c.Version ==
|
||||||
|
osVersion)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
System.Console.WriteLine("Uploading statistics");
|
System.Console.WriteLine("Uploading statistics");
|
||||||
#else
|
#else
|
||||||
@@ -784,23 +795,23 @@ namespace DiscImageChef.Core
|
|||||||
osVersion));
|
osVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch(WebException)
|
ctx.SaveChanges();
|
||||||
{
|
|
||||||
// Can't connect to the server, do nothing
|
|
||||||
}
|
|
||||||
// ReSharper disable once RedundantCatchClause
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
if(Debugger.IsAttached) throw;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch(WebException)
|
||||||
|
{
|
||||||
|
// Can't connect to the server, do nothing
|
||||||
|
}
|
||||||
|
// ReSharper disable once RedundantCatchClause
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
submitStatsLock = false;
|
||||||
|
if(Debugger.IsAttached) throw;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if(submitStatsLock) return;
|
|
||||||
|
|
||||||
submitStatsLock = true;
|
|
||||||
|
|
||||||
IEnumerable<string> statsFiles =
|
IEnumerable<string> statsFiles =
|
||||||
Directory.EnumerateFiles(Settings.Settings.StatsPath, "PartialStats_*.xml",
|
Directory.EnumerateFiles(Settings.Settings.StatsPath, "PartialStats_*.xml",
|
||||||
|
|||||||
Reference in New Issue
Block a user