From d4add54b53890e62c5a8079444133f7c2061f83b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 11 Sep 2017 02:05:07 +0100 Subject: [PATCH] Added statistics to underlying operating system version. --- DiscImageChef.Core/Statistics.cs | 16 ++++++------ DiscImageChef.Metadata/Statistics.cs | 12 ++++++++- .../Controllers/UploadStatsController.cs | 26 +++++++++---------- DiscImageChef.Server/Default.aspx.cs | 6 +++-- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/DiscImageChef.Core/Statistics.cs b/DiscImageChef.Core/Statistics.cs index 03c7ca81..a22898e2 100644 --- a/DiscImageChef.Core/Statistics.cs +++ b/DiscImageChef.Core/Statistics.cs @@ -55,9 +55,9 @@ namespace DiscImageChef.Core AllStats = new Stats(); CurrentStats = new Stats() { - OperatingSystems = new List + OperatingSystems = new List { - new NameValueStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = 1 } + new OsStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = 1, version = Environment.OSVersion.Version.ToString() } }, Versions = new List { @@ -74,9 +74,9 @@ namespace DiscImageChef.Core AllStats = new Stats(); CurrentStats = new Stats() { - OperatingSystems = new List + OperatingSystems = new List { - new NameValueStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = 1 } + new OsStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = 1, version = Environment.OSVersion.Version.ToString() } }, Versions = new List { @@ -99,10 +99,10 @@ namespace DiscImageChef.Core { long count = 0; - NameValueStats old = null; - foreach(NameValueStats nvs in AllStats.OperatingSystems) + OsStats old = null; + foreach(OsStats nvs in AllStats.OperatingSystems) { - if(nvs.name == Interop.DetectOS.GetRealPlatformID().ToString()) + if(nvs.name == Interop.DetectOS.GetRealPlatformID().ToString() && nvs.version == Environment.OSVersion.Version.ToString()) { count = nvs.Value + 1; old = nvs; @@ -114,7 +114,7 @@ namespace DiscImageChef.Core AllStats.OperatingSystems.Remove(old); count++; - AllStats.OperatingSystems.Add(new NameValueStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = count }); + AllStats.OperatingSystems.Add(new OsStats { name = Interop.DetectOS.GetRealPlatformID().ToString(), Value = count, version = Environment.OSVersion.Version.ToString() }); } else if(CurrentStats != null) AllStats.OperatingSystems = CurrentStats.OperatingSystems; diff --git a/DiscImageChef.Metadata/Statistics.cs b/DiscImageChef.Metadata/Statistics.cs index c2a6096a..95cc154a 100644 --- a/DiscImageChef.Metadata/Statistics.cs +++ b/DiscImageChef.Metadata/Statistics.cs @@ -39,7 +39,7 @@ namespace DiscImageChef.Metadata public class Stats { [XmlArrayItem("OperatingSystem")] - public List OperatingSystems { get; set; } + public List OperatingSystems { get; set; } [XmlArrayItem("Version")] public List Versions { get; set; } public CommandsStats Commands; @@ -165,4 +165,14 @@ namespace DiscImageChef.Metadata [XmlText] public long Value { get; set; } } + + public class OsStats + { + [XmlAttribute] + public string name { get; set; } + [XmlAttribute] + public string version { get; set; } + [XmlText] + public long Value { get; set; } + } } diff --git a/DiscImageChef.Server/Controllers/UploadStatsController.cs b/DiscImageChef.Server/Controllers/UploadStatsController.cs index 393f037b..36eb35cb 100644 --- a/DiscImageChef.Server/Controllers/UploadStatsController.cs +++ b/DiscImageChef.Server/Controllers/UploadStatsController.cs @@ -120,16 +120,16 @@ namespace DiscImageChef.Server.Controllers oldStats.OperatingSystems = newStats.OperatingSystems; else { - foreach(NameValueStats newNvs in newStats.OperatingSystems) + foreach(OsStats newNvs in newStats.OperatingSystems) { - NameValueStats removeNvs = null; - NameValueStats addNvs = null; + OsStats removeNvs = null; + OsStats addNvs = null; - foreach(NameValueStats oldNvs in oldStats.OperatingSystems) + foreach(OsStats oldNvs in oldStats.OperatingSystems) { - if(oldNvs.name == newNvs.name) + if(oldNvs.name == newNvs.name && oldNvs.version == newNvs.version) { - addNvs = new NameValueStats { name = oldNvs.name, Value = oldNvs.Value + newNvs.Value }; + addNvs = new OsStats { name = oldNvs.name, Value = oldNvs.Value + newNvs.Value, version = oldNvs.version }; removeNvs = oldNvs; break; } @@ -148,20 +148,20 @@ namespace DiscImageChef.Server.Controllers else { if(oldStats.OperatingSystems == null) - oldStats.OperatingSystems = new System.Collections.Generic.List + oldStats.OperatingSystems = new System.Collections.Generic.List { - new NameValueStats { name = "Linux", Value = 1 } + new OsStats { name = "Linux", Value = 1 } }; else { - NameValueStats removeNvs = null; - NameValueStats addNvs = null; + OsStats removeNvs = null; + OsStats addNvs = null; - foreach(NameValueStats oldNvs in oldStats.OperatingSystems) + foreach(OsStats oldNvs in oldStats.OperatingSystems) { if(oldNvs.name == "Linux") { - addNvs = new NameValueStats { name = oldNvs.name, Value = oldNvs.Value + 1 }; + addNvs = new OsStats { name = oldNvs.name, Value = oldNvs.Value + 1, version = oldNvs.version }; removeNvs = oldNvs; break; } @@ -173,7 +173,7 @@ namespace DiscImageChef.Server.Controllers oldStats.OperatingSystems.Add(addNvs); } else - oldStats.OperatingSystems.Add(new NameValueStats { name = "Linux", Value = 1 }); + oldStats.OperatingSystems.Add(new OsStats { name = "Linux", Value = 1 }); } } diff --git a/DiscImageChef.Server/Default.aspx.cs b/DiscImageChef.Server/Default.aspx.cs index 7bb11dcc..f46750cd 100644 --- a/DiscImageChef.Server/Default.aspx.cs +++ b/DiscImageChef.Server/Default.aspx.cs @@ -62,8 +62,10 @@ namespace DiscImageChef.Server if(statistics.OperatingSystems != null) { operatingSystems = new List(); - foreach(NameValueStats nvs in statistics.OperatingSystems) - operatingSystems.Add(new NameValueStats { name = Interop.DetectOS.GetPlatformName((Interop.PlatformID)Enum.Parse(typeof(Interop.PlatformID), nvs.name)), Value = nvs.Value }); + foreach(OsStats nvs in statistics.OperatingSystems) + operatingSystems.Add(new NameValueStats { name = string.Format("{0}{1}{2}", Interop.DetectOS.GetPlatformName((Interop.PlatformID)Enum.Parse(typeof(Interop.PlatformID), nvs.name), nvs.version), + string.IsNullOrEmpty(nvs.version) ? "" : " ", nvs.version), Value = nvs.Value }); + //operatingSystems.Add(new OsStats { name = Interop.DetectOS.GetPlatformName((Interop.PlatformID)Enum.Parse(typeof(Interop.PlatformID), nvs.name), nvs.version), Value = nvs.Value, version = nvs.version }); repOperatingSystems.DataSource = operatingSystems.OrderBy(os => os.name).ToList(); repOperatingSystems.DataBind(); }