From 66e4045bc60dcf34aa9d1631e7c9a7c814625278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Thu, 29 Jun 2023 16:56:28 +0200 Subject: [PATCH 1/9] Added Range() method in Stats (#117) --- PeyrSharp.Core/Maths/Stats.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/PeyrSharp.Core/Maths/Stats.cs b/PeyrSharp.Core/Maths/Stats.cs index decd566..8a9c723 100644 --- a/PeyrSharp.Core/Maths/Stats.cs +++ b/PeyrSharp.Core/Maths/Stats.cs @@ -111,5 +111,36 @@ public static double Mode(List values) return frequencyGroups.First().Key; } + /// + /// Calculates the range of a list of double numbers. + /// + /// The list of double numbers. + /// The range of the list of double numbers. + /// Thrown when the list is null or empty. + public static double Range(this List numbers) + { + if (numbers == null || numbers.Count == 0) + { + throw new ArgumentException("The list cannot be null or empty."); + } + + double min = numbers[0]; + double max = numbers[0]; + + for (int i = 1; i < numbers.Count; i++) + { + if (numbers[i] < min) + { + min = numbers[i]; + } + + if (numbers[i] > max) + { + max = numbers[i]; + } + } + + return max - min; + } } } From 6b6c0c85e2edbbc61c3b1becef4ddfa2b9bf056d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Thu, 29 Jun 2023 17:02:28 +0200 Subject: [PATCH 2/9] Added Variance() method in Stats (#118) --- PeyrSharp.Core/Maths/Stats.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PeyrSharp.Core/Maths/Stats.cs b/PeyrSharp.Core/Maths/Stats.cs index 8a9c723..de49992 100644 --- a/PeyrSharp.Core/Maths/Stats.cs +++ b/PeyrSharp.Core/Maths/Stats.cs @@ -142,5 +142,22 @@ public static double Range(this List numbers) return max - min; } + + /// + /// Calculates the sample variance of a list of double values. + /// + /// The list of double values. + /// The sample variance of the list of double values. + public static double Variance(List values) + { + double mean = values.Average(); + double variance = 0; + for (int i = 0; i < values.Count; i++) + { + variance += Math.Pow((values[i] - mean), 2); + } + int n = values.Count; + return variance / (n - 1); + } } } From 6eae22c3f7efd6d5e107958a4bdf52b93d2d4c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Thu, 29 Jun 2023 17:05:21 +0200 Subject: [PATCH 3/9] Improved exceptions --- PeyrSharp.Core/Maths/Stats.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/PeyrSharp.Core/Maths/Stats.cs b/PeyrSharp.Core/Maths/Stats.cs index de49992..a6701bf 100644 --- a/PeyrSharp.Core/Maths/Stats.cs +++ b/PeyrSharp.Core/Maths/Stats.cs @@ -44,7 +44,7 @@ public static double Mean(List values) // Check for empty input if (values.Count == 0) { - throw new ArgumentException("Cannot calculate mean of empty dataset", "values"); + throw new ArgumentException("Cannot calculate mean of empty dataset", nameof(values)); } // Calculate sum of values @@ -67,7 +67,7 @@ public static double Median(List values) // Check for empty input if (values.Count == 0) { - throw new ArgumentException("Cannot calculate median of empty dataset", "values"); + throw new ArgumentException("Cannot calculate median of empty dataset", nameof(values)); } // Sort values @@ -101,7 +101,7 @@ public static double Mode(List values) // Check for empty input if (values.Count == 0) { - throw new ArgumentException("Cannot calculate mode of empty dataset", "values"); + throw new ArgumentException("Cannot calculate mode of empty dataset", nameof(values)); } // Group values by frequency @@ -121,7 +121,7 @@ public static double Range(this List numbers) { if (numbers == null || numbers.Count == 0) { - throw new ArgumentException("The list cannot be null or empty."); + throw new ArgumentException("The list cannot be null or empty.", nameof(numbers)); } double min = numbers[0]; @@ -148,8 +148,14 @@ public static double Range(this List numbers) /// /// The list of double values. /// The sample variance of the list of double values. + /// Thrown when the list is null or empty. public static double Variance(List values) { + if (values == null || values.Count == 0) + { + throw new ArgumentException("The list cannot be null or empty.", nameof(values)); + } + double mean = values.Average(); double variance = 0; for (int i = 0; i < values.Count; i++) From 38264e3039b6257e55d05c7085d3642c8133d404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Thu, 29 Jun 2023 17:12:42 +0200 Subject: [PATCH 4/9] Version 1.7.0.2307-pre1 --- PeyrSharp.Core/PeyrSharp.Core.csproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/PeyrSharp.Core/PeyrSharp.Core.csproj b/PeyrSharp.Core/PeyrSharp.Core.csproj index 73e3ef9..1cf1741 100644 --- a/PeyrSharp.Core/PeyrSharp.Core.csproj +++ b/PeyrSharp.Core/PeyrSharp.Core.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Core - 1.6.1.2305 + 1.7.0.2307-pre1 Devyus Core methods and features of PeyrSharp. © 2023 @@ -16,7 +16,10 @@ NUGET_README.md MIT True - - Fixed IsAvailableAsync() crashes when no internet connection is available (#112) + - Added Range() method in Stats (#117) +- Added Variance() method in Stats (#118) +- Improved exceptions + From bee237a4de7eac9b3ad4cf2781038ea3c9d0098a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 30 Jun 2023 11:18:29 +0200 Subject: [PATCH 5/9] Added StandardDeviation() method in Stats (#119) --- PeyrSharp.Core/Maths/Stats.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/PeyrSharp.Core/Maths/Stats.cs b/PeyrSharp.Core/Maths/Stats.cs index a6701bf..394affe 100644 --- a/PeyrSharp.Core/Maths/Stats.cs +++ b/PeyrSharp.Core/Maths/Stats.cs @@ -165,5 +165,20 @@ public static double Variance(List values) int n = values.Count; return variance / (n - 1); } + + /// + /// Calculates the standard deviation of a list of double numbers. + /// + /// The list of double numbers. + /// The standard deviation of the list of double numbers. + /// Thrown when the list is null or empty. + public static double StandardDeviation(List values) + { + if (values == null || values.Count == 0) + { + throw new ArgumentException("The list cannot be null or empty.", nameof(values)); + } + return Math.Sqrt(Variance(values)); + } } } From 74e50250228e48d5ffeb8e456013495bbc6e1424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 30 Jun 2023 11:37:24 +0200 Subject: [PATCH 6/9] Added UwpApp record (#120) --- PeyrSharp.Env/UwpApp.cs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 PeyrSharp.Env/UwpApp.cs diff --git a/PeyrSharp.Env/UwpApp.cs b/PeyrSharp.Env/UwpApp.cs new file mode 100644 index 0000000..c0d1463 --- /dev/null +++ b/PeyrSharp.Env/UwpApp.cs @@ -0,0 +1,33 @@ +/* +MIT License + +Copyright (c) Devyus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +namespace PeyrSharp.Env +{ + /// + /// Represents a smplified version of an UWP app object. + /// + /// The name of the UWP app. + /// The App ID in the Package Family Name property. + public record UwpApp(string Name, string AppID); +} From 6ff45aec212821cc84c7c41f8060cdc04158908a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 30 Jun 2023 11:37:53 +0200 Subject: [PATCH 7/9] Added the possibility to get UWP apps asynchronously (#120) --- PeyrSharp.Env/Sys.cs | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/PeyrSharp.Env/Sys.cs b/PeyrSharp.Env/Sys.cs index 7c3988d..dc49080 100644 --- a/PeyrSharp.Env/Sys.cs +++ b/PeyrSharp.Env/Sys.cs @@ -30,6 +30,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE using System.Linq; using System.Runtime.InteropServices; using System.Runtime.Versioning; +using System.Text.Json; +using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; namespace PeyrSharp.Env { @@ -248,5 +251,52 @@ public static bool TerminateProcess(int processId) return false; } } + + /// + /// Retrieves a list of UWP (Universal Windows Platform) apps asynchronously. + /// + /// Only works on Windows 10 and higher. + /// A task that represents the asynchronous operation. The task result contains a list of UwpApp objects representing the UWP apps. + /// + /// + [SupportedOSPlatform("windows")] + public static async Task> GetUwpAppsAsync() + { + ProcessStartInfo pInfo = new() + { + FileName = "powershell.exe", + Arguments = @"& Get-StartApps | ConvertTo-Json > $env:appdata\UwpApps.json", + UseShellExecute = true, + CreateNoWindow = true + }; + + Process process = new() { StartInfo = pInfo }; + process.Start(); + await process.WaitForExitAsync(); + + string appsFile = await File.ReadAllTextAsync($@"{FileSys.AppDataPath}\UWPapps.json"); + List apps = JsonSerializer.Deserialize>(appsFile); // Get apps + List sortedApps = new(); // Create final list + Dictionary uwpApps = new(); // Create a dictionnary + + // Sort apps to only have UWP apps (they have a "!" in the AppID property) + for (int i = 0; i < apps.Count; i++) + { + if (apps[i].AppID.Contains('!')) + { + uwpApps.Add(apps[i], apps[i].Name); + } + } + + // Sort alphabetically + var sorted = from pair in uwpApps orderby pair.Value ascending select pair; // Sort + + foreach (KeyValuePair pair1 in sorted) + { + sortedApps.Add(pair1.Key); + } + + return sortedApps; // Return + } } } From f1e904c1b706a3e56dc2d8a265cb6b0767807aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 30 Jun 2023 11:42:18 +0200 Subject: [PATCH 8/9] Version 1.7.0.2307-rc1 --- PeyrSharp.Core/PeyrSharp.Core.csproj | 3 ++- PeyrSharp.Env/PeyrSharp.Env.csproj | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/PeyrSharp.Core/PeyrSharp.Core.csproj b/PeyrSharp.Core/PeyrSharp.Core.csproj index 1cf1741..e59954f 100644 --- a/PeyrSharp.Core/PeyrSharp.Core.csproj +++ b/PeyrSharp.Core/PeyrSharp.Core.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Core - 1.7.0.2307-pre1 + 1.7.0.2307-rc1 Devyus Core methods and features of PeyrSharp. © 2023 @@ -18,6 +18,7 @@ True - Added Range() method in Stats (#117) - Added Variance() method in Stats (#118) +- Added StandardDeviation() method in Stats (#119) - Improved exceptions diff --git a/PeyrSharp.Env/PeyrSharp.Env.csproj b/PeyrSharp.Env/PeyrSharp.Env.csproj index 5d1d1d6..0f54706 100644 --- a/PeyrSharp.Env/PeyrSharp.Env.csproj +++ b/PeyrSharp.Env/PeyrSharp.Env.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Env - 1.6.1.2305 + 1.7.0.2307-rc1 Devyus Environment-related methods of PeyrSharp. © 2023 @@ -16,7 +16,8 @@ NUGET_README.md MIT True - + - Added UwpApp record (#120) +- Added the possibility to get UWP apps asynchronously (#120) From 46488350c1f4d52895de84744d899c8391e31593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Fri, 30 Jun 2023 13:41:04 +0200 Subject: [PATCH 9/9] Version 1.7.0.2307 --- PeyrSharp.Core/PeyrSharp.Core.csproj | 12 ++++++------ PeyrSharp.Enums/PeyrSharp.Enums.csproj | 2 +- PeyrSharp.Env/PeyrSharp.Env.csproj | 4 ++-- PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj | 2 +- PeyrSharp.Extensions/PeyrSharp.Extensions.csproj | 4 ++-- PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj | 4 ++-- PeyrSharp/PeyrSharp.cs | 2 +- PeyrSharp/PeyrSharp.csproj | 14 +++++++------- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/PeyrSharp.Core/PeyrSharp.Core.csproj b/PeyrSharp.Core/PeyrSharp.Core.csproj index e0bbab3..ec3f160 100644 --- a/PeyrSharp.Core/PeyrSharp.Core.csproj +++ b/PeyrSharp.Core/PeyrSharp.Core.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Core - 1.7.0.2307-rc1 + 1.7.0.2307 Devyus Core methods and features of PeyrSharp. © 2023 @@ -17,9 +17,9 @@ MIT True - Added Range() method in Stats (#117) - - Added Variance() method in Stats (#118) - - Added StandardDeviation() method in Stats (#119) - - Improved exceptions +- Added Variance() method in Stats (#118) +- Added StandardDeviation() method in Stats (#119) +- Improved exceptions @@ -35,8 +35,8 @@ - - + + \ No newline at end of file diff --git a/PeyrSharp.Enums/PeyrSharp.Enums.csproj b/PeyrSharp.Enums/PeyrSharp.Enums.csproj index 47bc682..fb98be1 100644 --- a/PeyrSharp.Enums/PeyrSharp.Enums.csproj +++ b/PeyrSharp.Enums/PeyrSharp.Enums.csproj @@ -11,7 +11,7 @@ https://peyrsharp.leocorporation.dev/ https://github.com/DevyusCode/PeyrSharp enums;c-sharp;dotnet;vb;peyrsharp;leo corp - 1.6.1.2305 + 1.7.0.2307 True logo.png NUGET_README.md diff --git a/PeyrSharp.Env/PeyrSharp.Env.csproj b/PeyrSharp.Env/PeyrSharp.Env.csproj index 0f54706..d80c86e 100644 --- a/PeyrSharp.Env/PeyrSharp.Env.csproj +++ b/PeyrSharp.Env/PeyrSharp.Env.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Env - 1.7.0.2307-rc1 + 1.7.0.2307 Devyus Environment-related methods of PeyrSharp. © 2023 @@ -32,6 +32,6 @@ - + \ No newline at end of file diff --git a/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj b/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj index 9e4a711..ca6bf08 100644 --- a/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj +++ b/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj @@ -6,7 +6,7 @@ enable True PeyrSharp.Exceptions - 1.6.1.2305 + 1.7.0.2307 Devyus Exceptions of PeyrSharp. © 2023 diff --git a/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj b/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj index 594310c..31bca90 100644 --- a/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj +++ b/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net7.0 True PeyrSharp.Extensions - 1.6.1.2305 + 1.7.0.2307 Devyus Extensions methods of PeyrSharp. © 2023 @@ -31,7 +31,7 @@ - + \ No newline at end of file diff --git a/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj b/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj index d7785b8..1dc4315 100644 --- a/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj +++ b/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj @@ -8,7 +8,7 @@ true True PeyrSharp.UiHelpers - 1.6.1.2305 + 1.7.0.2307 Devyus Useful helpers for Windows Forms and Windows Presentation Framework. © 2023 @@ -35,7 +35,7 @@ - + \ No newline at end of file diff --git a/PeyrSharp/PeyrSharp.cs b/PeyrSharp/PeyrSharp.cs index 65b20ad..669bca9 100644 --- a/PeyrSharp/PeyrSharp.cs +++ b/PeyrSharp/PeyrSharp.cs @@ -32,6 +32,6 @@ public static class PeyrSharp /// /// The current version of PeyrSharp. /// - public static string Version => "1.6.1.2305"; + public static string Version => "1.7.0.2307"; } } diff --git a/PeyrSharp/PeyrSharp.csproj b/PeyrSharp/PeyrSharp.csproj index 83615ec..05ab5dc 100644 --- a/PeyrSharp/PeyrSharp.csproj +++ b/PeyrSharp/PeyrSharp.csproj @@ -4,7 +4,7 @@ net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows True PeyrSharp - 1.6.1.2305 + 1.7.0.2307 Devyus © 2023 A C# library designed to make developers' job easier. @@ -32,12 +32,12 @@ - - - - - - + + + + + + \ No newline at end of file