mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Use correct path for database.
This commit is contained in:
@@ -60,13 +60,13 @@ namespace DiscImageChef.Core
|
||||
/// </summary>
|
||||
static bool submitStatsLock;
|
||||
|
||||
static DicContext ctx = new DicContext();
|
||||
|
||||
/// <summary>
|
||||
/// Loads saved statistics from disk
|
||||
/// </summary>
|
||||
public static void LoadStats()
|
||||
{
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
|
||||
if(File.Exists(Path.Combine(Settings.Settings.StatsPath, "Statistics.xml")))
|
||||
try
|
||||
{
|
||||
@@ -431,10 +431,12 @@ namespace DiscImageChef.Core
|
||||
Version = DetectOS.GetVersion(),
|
||||
Count = 1
|
||||
});
|
||||
|
||||
ctx.Versions.Add(new Version
|
||||
{
|
||||
Value = CommonTypes.Interop.Version.GetVersion(), Synchronized = false, Count = 1
|
||||
});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -442,6 +444,7 @@ namespace DiscImageChef.Core
|
||||
/// </summary>
|
||||
public static void SaveStats()
|
||||
{
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.SaveChanges();
|
||||
if(Settings.Settings.Current.Stats != null && Settings.Settings.Current.Stats.ShareStats) SubmitStats();
|
||||
}
|
||||
@@ -453,384 +456,348 @@ namespace DiscImageChef.Core
|
||||
{
|
||||
Thread submitThread = new Thread(() =>
|
||||
{
|
||||
lock(ctx)
|
||||
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))
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
|
||||
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(ctx.Commands.Any(c => !c.Synchronized))
|
||||
{
|
||||
StatsDto dto = new StatsDto();
|
||||
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))
|
||||
{
|
||||
dto.Filesystems = new List<NameValueStats>();
|
||||
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))
|
||||
{
|
||||
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)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Uploading statistics");
|
||||
#else
|
||||
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading statistics");
|
||||
#endif
|
||||
|
||||
MemoryStream jsonStream = new MemoryStream();
|
||||
StreamWriter jsonSw = new StreamWriter(jsonStream);
|
||||
|
||||
jsonSw.Write(JsonConvert.SerializeObject(dto, Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
}));
|
||||
jsonStream.Seek(0, SeekOrigin.Begin);
|
||||
WebRequest request = WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
|
||||
((HttpWebRequest)request).UserAgent =
|
||||
$"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
||||
request.Method = "POST";
|
||||
request.ContentLength = jsonStream.Length;
|
||||
request.ContentType = "application/json";
|
||||
Stream reqStream = request.GetRequestStream();
|
||||
jsonStream.CopyTo(reqStream);
|
||||
reqStream.Close();
|
||||
WebResponse response = request.GetResponse();
|
||||
|
||||
if(((HttpWebResponse)response).StatusCode != HttpStatusCode.OK) return;
|
||||
|
||||
Stream data = response.GetResponseStream();
|
||||
StreamReader reader = new StreamReader(data ?? throw new InvalidOperationException());
|
||||
|
||||
reader.ReadToEnd();
|
||||
data.Close();
|
||||
response.Close();
|
||||
jsonSw.Close();
|
||||
jsonStream.Close();
|
||||
|
||||
if(ctx.Commands.Any(c => !c.Synchronized))
|
||||
{
|
||||
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)
|
||||
});
|
||||
}
|
||||
foreach(string nvs in ctx.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Command existing = ctx.Commands.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Command {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count += (ulong)ctx.Commands.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Commands.Update(existing);
|
||||
ctx.Commands.RemoveRange(ctx.Commands.Where(c => !c.Synchronized && c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Filesystems.Any(c => !c.Synchronized))
|
||||
{
|
||||
dto.Filesystems = new List<NameValueStats>();
|
||||
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)
|
||||
});
|
||||
}
|
||||
foreach(string nvs in ctx.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Filesystem existing =
|
||||
ctx.Filesystems.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Filesystem {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Filesystems.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Filesystems.Update(existing);
|
||||
ctx.Filesystems.RemoveRange(ctx.Filesystems.Where(c => !c.Synchronized &&
|
||||
c.Name == nvs));
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
}
|
||||
{
|
||||
Filter existing = ctx.Filters.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Filter {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count += (ulong)ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Filters.Update(existing);
|
||||
ctx.Filters.RemoveRange(ctx.Filters.Where(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)
|
||||
});
|
||||
}
|
||||
foreach(string nvs in ctx.MediaFormats.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
MediaFormat existing =
|
||||
ctx.MediaFormats.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new MediaFormat {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.MediaFormats.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.MediaFormats.Update(existing);
|
||||
ctx.MediaFormats.RemoveRange(ctx.MediaFormats.Where(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)
|
||||
});
|
||||
}
|
||||
foreach(string nvs in ctx.Partitions.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Partition existing =
|
||||
ctx.Partitions.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Partition {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Partitions.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Partitions.Update(existing);
|
||||
ctx.Partitions.RemoveRange(ctx.Partitions.Where(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)
|
||||
});
|
||||
}
|
||||
foreach(string nvs in ctx.Versions.Where(c => !c.Synchronized).Select(c => c.Value)
|
||||
.Distinct())
|
||||
{
|
||||
Version existing = ctx.Versions.FirstOrDefault(c => c.Synchronized && c.Value == nvs) ??
|
||||
new Version {Value = nvs, Synchronized = true};
|
||||
|
||||
existing.Count += (ulong)ctx.Versions.LongCount(c => !c.Synchronized && c.Value == nvs);
|
||||
ctx.Versions.Update(existing);
|
||||
ctx.Versions.RemoveRange(ctx.Versions.Where(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)
|
||||
});
|
||||
{
|
||||
Database.Models.Media existing =
|
||||
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && c.Real) ??
|
||||
new Database.Models.Media {Synchronized = true, Type = media, Real = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && c.Real);
|
||||
ctx.Medias.Update(existing);
|
||||
ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized && c.Type == media &&
|
||||
c.Real));
|
||||
}
|
||||
|
||||
if(!ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real)) continue;
|
||||
|
||||
{
|
||||
Database.Models.Media existing =
|
||||
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media && !c.Real) ??
|
||||
new Database.Models.Media {Synchronized = true, Type = media, Real = false};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media && !c.Real);
|
||||
ctx.Medias.Update(existing);
|
||||
ctx.Medias.RemoveRange(ctx.Medias.Where(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
|
||||
});
|
||||
}
|
||||
{
|
||||
device.Synchronized = true;
|
||||
ctx.Update(device);
|
||||
}
|
||||
|
||||
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)
|
||||
});
|
||||
foreach(string osVersion in ctx
|
||||
.OperatingSystems
|
||||
.Where(c => !c.Synchronized && c.Name == osName)
|
||||
.Select(c => c.Version).Distinct())
|
||||
{
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Synchronized && c.Name == osName &&
|
||||
c.Version ==
|
||||
osVersion) ??
|
||||
new OperatingSystem {Synchronized = true, Version = osVersion, Name = osName};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.OperatingSystems.LongCount(c => !c.Synchronized &&
|
||||
c.Name == osName &&
|
||||
c.Version == osVersion);
|
||||
ctx.OperatingSystems.Update(existing);
|
||||
ctx.OperatingSystems.RemoveRange(ctx.OperatingSystems.Where(c => !c.Synchronized &&
|
||||
c.Name == osName &&
|
||||
c.Version ==
|
||||
osVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
#if DEBUG
|
||||
System.Console.WriteLine("Uploading statistics");
|
||||
#else
|
||||
DiscImageChef.Console.DicConsole.DebugWriteLine("Submit stats", "Uploading statistics");
|
||||
#endif
|
||||
|
||||
MemoryStream jsonStream = new MemoryStream();
|
||||
StreamWriter jsonSw = new StreamWriter(jsonStream);
|
||||
|
||||
jsonSw.Write(JsonConvert.SerializeObject(dto, Formatting.Indented,
|
||||
new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling =
|
||||
NullValueHandling.Ignore
|
||||
}));
|
||||
jsonStream.Seek(0, SeekOrigin.Begin);
|
||||
WebRequest request =
|
||||
WebRequest.Create("http://discimagechef.claunia.com/api/uploadstatsv2");
|
||||
((HttpWebRequest)request).UserAgent =
|
||||
$"DiscImageChef {typeof(Version).Assembly.GetName().Version}";
|
||||
request.Method = "POST";
|
||||
request.ContentLength = jsonStream.Length;
|
||||
request.ContentType = "application/json";
|
||||
Stream reqStream = request.GetRequestStream();
|
||||
jsonStream.CopyTo(reqStream);
|
||||
reqStream.Close();
|
||||
WebResponse response = request.GetResponse();
|
||||
|
||||
if(((HttpWebResponse)response).StatusCode != HttpStatusCode.OK) return;
|
||||
|
||||
Stream data = response.GetResponseStream();
|
||||
StreamReader reader = new StreamReader(data ?? throw new InvalidOperationException());
|
||||
|
||||
reader.ReadToEnd();
|
||||
data.Close();
|
||||
response.Close();
|
||||
jsonSw.Close();
|
||||
jsonStream.Close();
|
||||
|
||||
if(ctx.Commands.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.Commands.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Command existing =
|
||||
ctx.Commands.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Command {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Commands.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Commands.Update(existing);
|
||||
ctx.Commands.RemoveRange(ctx.Commands.Where(c => !c.Synchronized && c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Filesystems.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.Filesystems.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Filesystem existing =
|
||||
ctx.Filesystems.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Filesystem {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Filesystems.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Filesystems.Update(existing);
|
||||
ctx.Filesystems.RemoveRange(ctx.Filesystems.Where(c => !c.Synchronized &&
|
||||
c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Filters.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.Filters.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Filter existing =
|
||||
ctx.Filters.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Filter {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Filters.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Filters.Update(existing);
|
||||
ctx.Filters.RemoveRange(ctx.Filters.Where(c => !c.Synchronized && c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.MediaFormats.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.MediaFormats.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
MediaFormat existing =
|
||||
ctx.MediaFormats.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new MediaFormat {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.MediaFormats.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.MediaFormats.Update(existing);
|
||||
ctx.MediaFormats.RemoveRange(ctx.MediaFormats.Where(c => !c.Synchronized &&
|
||||
c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Partitions.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.Partitions.Where(c => !c.Synchronized).Select(c => c.Name)
|
||||
.Distinct())
|
||||
{
|
||||
Partition existing =
|
||||
ctx.Partitions.FirstOrDefault(c => c.Synchronized && c.Name == nvs) ??
|
||||
new Partition {Name = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Partitions.LongCount(c => !c.Synchronized && c.Name == nvs);
|
||||
ctx.Partitions.Update(existing);
|
||||
ctx.Partitions.RemoveRange(ctx.Partitions.Where(c => !c.Synchronized &&
|
||||
c.Name == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Versions.Any(c => !c.Synchronized))
|
||||
foreach(string nvs in ctx
|
||||
.Versions.Where(c => !c.Synchronized).Select(c => c.Value)
|
||||
.Distinct())
|
||||
{
|
||||
Version existing =
|
||||
ctx.Versions.FirstOrDefault(c => c.Synchronized && c.Value == nvs) ??
|
||||
new Version {Value = nvs, Synchronized = true};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Versions.LongCount(c => !c.Synchronized && c.Value == nvs);
|
||||
ctx.Versions.Update(existing);
|
||||
ctx.Versions.RemoveRange(ctx.Versions.Where(c => !c.Synchronized &&
|
||||
c.Value == nvs));
|
||||
}
|
||||
|
||||
if(ctx.Medias.Any(c => !c.Synchronized))
|
||||
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))
|
||||
{
|
||||
Database.Models.Media existing =
|
||||
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media &&
|
||||
c.Real) ?? new Database.Models.Media
|
||||
{
|
||||
Synchronized = true, Type = media, Real = true
|
||||
};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media &&
|
||||
c.Real);
|
||||
ctx.Medias.Update(existing);
|
||||
ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized &&
|
||||
c.Type == media && c.Real));
|
||||
}
|
||||
|
||||
if(!ctx.Medias.Any(c => !c.Synchronized && c.Type == media && !c.Real)) continue;
|
||||
|
||||
{
|
||||
Database.Models.Media existing =
|
||||
ctx.Medias.FirstOrDefault(c => c.Synchronized && c.Type == media &&
|
||||
!c.Real) ?? new Database.Models.Media
|
||||
{
|
||||
Synchronized = true, Type = media, Real = false
|
||||
};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.Medias.LongCount(c => !c.Synchronized && c.Type == media &&
|
||||
!c.Real);
|
||||
ctx.Medias.Update(existing);
|
||||
ctx.Medias.RemoveRange(ctx.Medias.Where(c => !c.Synchronized &&
|
||||
c.Type == media && !c.Real));
|
||||
}
|
||||
}
|
||||
|
||||
if(ctx.SeenDevices.Any(c => !c.Synchronized))
|
||||
foreach(DeviceStat device in ctx.SeenDevices.Where(c => !c.Synchronized))
|
||||
{
|
||||
device.Synchronized = true;
|
||||
ctx.Update(device);
|
||||
}
|
||||
|
||||
if(ctx.OperatingSystems.Any(c => !c.Synchronized))
|
||||
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())
|
||||
{
|
||||
OperatingSystem existing =
|
||||
ctx.OperatingSystems.FirstOrDefault(c => c.Synchronized &&
|
||||
c.Name == osName &&
|
||||
c.Version == osVersion) ??
|
||||
new OperatingSystem
|
||||
{
|
||||
Synchronized = true, Version = osVersion, Name = osName
|
||||
};
|
||||
|
||||
existing.Count +=
|
||||
(ulong)ctx.OperatingSystems.LongCount(c => !c.Synchronized &&
|
||||
c.Name == osName &&
|
||||
c.Version == osVersion);
|
||||
ctx.OperatingSystems.Update(existing);
|
||||
ctx.OperatingSystems.RemoveRange(ctx.OperatingSystems.Where(c =>
|
||||
!c
|
||||
.Synchronized &&
|
||||
c.Name ==
|
||||
osName &&
|
||||
c.Version ==
|
||||
osVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(WebException)
|
||||
{
|
||||
// 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
|
||||
if(Debugger.IsAttached) throw;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if(submitStatsLock) return;
|
||||
|
||||
@@ -911,7 +878,9 @@ namespace DiscImageChef.Core
|
||||
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.DeviceStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.Commands.Add(new Command {Name = command, Synchronized = false, Count = 1});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -924,7 +893,9 @@ namespace DiscImageChef.Core
|
||||
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilesystemStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.Filesystems.Add(new Filesystem {Name = filesystem, Synchronized = false, Count = 1});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -937,7 +908,9 @@ namespace DiscImageChef.Core
|
||||
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.PartitionStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.Partitions.Add(new Partition {Name = partition, Synchronized = false, Count = 1});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -950,7 +923,9 @@ namespace DiscImageChef.Core
|
||||
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.FilterStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.Filters.Add(new Filter {Name = filter, Synchronized = false, Count = 1});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -963,7 +938,9 @@ namespace DiscImageChef.Core
|
||||
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaImageStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.MediaFormats.Add(new MediaFormat {Name = format, Synchronized = false, Count = 1});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -979,6 +956,7 @@ namespace DiscImageChef.Core
|
||||
else if(dev.IsFireWire) deviceBus = "FireWire";
|
||||
else deviceBus = dev.Type.ToString();
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.SeenDevices.Add(new DeviceStat
|
||||
{
|
||||
Bus = deviceBus,
|
||||
@@ -987,6 +965,7 @@ namespace DiscImageChef.Core
|
||||
Revision = dev.Revision,
|
||||
Synchronized = false
|
||||
});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -998,10 +977,12 @@ namespace DiscImageChef.Core
|
||||
{
|
||||
if(Settings.Settings.Current.Stats == null || !Settings.Settings.Current.Stats.MediaStats) return;
|
||||
|
||||
DicContext ctx = DicContext.Create(Settings.Settings.DbPath);
|
||||
ctx.Medias.Add(new Database.Models.Media
|
||||
{
|
||||
Real = real, Synchronized = false, Type = type.ToString(), Count = 1
|
||||
});
|
||||
ctx.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user