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)); + } } } diff --git a/PeyrSharp.Core/PeyrSharp.Core.csproj b/PeyrSharp.Core/PeyrSharp.Core.csproj index 1bcb3a9..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.6.1.2305 + 1.7.0.2307 Devyus Core methods and features of PeyrSharp. © 2023 @@ -16,8 +16,11 @@ 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) +- Added StandardDeviation() method in Stats (#119) +- Improved exceptions + @@ -32,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 5d1d1d6..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.6.1.2305 + 1.7.0.2307 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) @@ -31,6 +32,6 @@ - + \ No newline at end of file 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 + } } } 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); +} 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