diff --git a/.github/images/logo.png b/.github/images/logo.png
index 470de1e..de9b548 100644
Binary files a/.github/images/logo.png and b/.github/images/logo.png differ
diff --git a/PeyrSharp.Core/Maths/Proba.cs b/PeyrSharp.Core/Maths/Proba.cs
new file mode 100644
index 0000000..2a247fd
--- /dev/null
+++ b/PeyrSharp.Core/Maths/Proba.cs
@@ -0,0 +1,76 @@
+/*
+MIT License
+
+Copyright (c) Léo Corporation
+
+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.
+*/
+
+using System;
+using System.Collections.Generic;
+
+namespace PeyrSharp.Core.Maths
+{
+ ///
+ /// Provides methods for working with probabilities.
+ ///
+ public static class Proba
+ {
+ ///
+ /// Gets a random value based on the specified probabilities.
+ ///
+ /// The type of the values to select from.
+ /// A dictionary containing the probability of getting each value.
+ ///
+ /// A randomly selected value.
+ ///
+ ///
+ /// Thrown if the sum of probabilities is not equal to 1.
+ ///
+ ///
+ /// Thrown if an unexpected error occurs while selecting a random value.
+ ///
+ public static T GetRandomValue(Dictionary probabilities)
+ {
+ double totalProbability = 0.0;
+ foreach (double probability in probabilities.Values)
+ {
+ totalProbability += probability;
+ }
+
+ if (totalProbability != 1.0)
+ {
+ throw new ArgumentException("The sum of probabilities must be 1.");
+ }
+
+ double randomValue = new Random().NextDouble();
+ double cumulativeProbability = 0.0;
+ foreach (T value in probabilities.Keys)
+ {
+ cumulativeProbability += probabilities[value];
+ if (randomValue < cumulativeProbability)
+ {
+ return value;
+ }
+ }
+
+ throw new Exception("An unexpected error occurred while selecting a random value.");
+ }
+ }
+}
diff --git a/PeyrSharp.Core/PeyrSharp.Core.csproj b/PeyrSharp.Core/PeyrSharp.Core.csproj
index 235aeed..ab24d99 100644
--- a/PeyrSharp.Core/PeyrSharp.Core.csproj
+++ b/PeyrSharp.Core/PeyrSharp.Core.csproj
@@ -4,11 +4,11 @@
net5.0;net6.0;net7.0
True
PeyrSharp.Core
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
Core methods and features of PeyrSharp.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
git
math;password;guid;generators;core;geometry
@@ -16,10 +16,7 @@
NUGET_README.md
MIT
True
- - Created Stats class (#52)
-- Added the Mean() method (#53)
-- Added the Median() method (#54)
-- Added the Mode() method (#55)
+ - Added the possibility to generate a random value based on probabilities (#71)
@@ -34,8 +31,8 @@
-
-
+
+
diff --git a/PeyrSharp.Enums/PeyrSharp.Enums.csproj b/PeyrSharp.Enums/PeyrSharp.Enums.csproj
index f68ebb9..6234eec 100644
--- a/PeyrSharp.Enums/PeyrSharp.Enums.csproj
+++ b/PeyrSharp.Enums/PeyrSharp.Enums.csproj
@@ -8,10 +8,10 @@
Léo Corporation
Enumerations of PeyrSharp.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
enums;c-sharp;dotnet;vb;peyrsharp;leo corp
- 1.2.0.2301
+ 1.3.0.2302
True
logo.png
NUGET_README.md
diff --git a/PeyrSharp.Env/FileSys.cs b/PeyrSharp.Env/FileSys.cs
index da04cef..cb8c6d4 100644
--- a/PeyrSharp.Env/FileSys.cs
+++ b/PeyrSharp.Env/FileSys.cs
@@ -241,5 +241,13 @@ public static StorageUnits GetDriveStorageUnit(DriveInfo driveInfo)
return StorageUnits.Byte;
}
}
+
+ ///
+ /// Gets the current directory of the application.
+ ///
+ ///
+ /// A string representing the full path of the current directory.
+ ///
+ public static string CurrentDirectory => Directory.GetCurrentDirectory();
}
}
diff --git a/PeyrSharp.Env/PeyrSharp.Env.csproj b/PeyrSharp.Env/PeyrSharp.Env.csproj
index 1f9915c..c03c50d 100644
--- a/PeyrSharp.Env/PeyrSharp.Env.csproj
+++ b/PeyrSharp.Env/PeyrSharp.Env.csproj
@@ -4,11 +4,11 @@
net5.0;net6.0;net7.0
True
PeyrSharp.Env
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
Environment-related methods of PeyrSharp.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
git
logger;file;env;file-system;update-system;windows;system
@@ -16,7 +16,10 @@
NUGET_README.md
MIT
True
-
+ - Added the possibility to check if a process is running (#67)
+- Added the possibility to get the current directory (#68)
+- Added the possibility to get the name of the computer (#69)
+- Added the possibility to terminate a process (#70)
@@ -31,6 +34,6 @@
-
+
diff --git a/PeyrSharp.Env/Sys.cs b/PeyrSharp.Env/Sys.cs
index 8a15169..9e14495 100644
--- a/PeyrSharp.Env/Sys.cs
+++ b/PeyrSharp.Env/Sys.cs
@@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using PeyrSharp.Enums;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
@@ -122,6 +123,25 @@ static IEnumerable GetProcs()
}
}
+ ///
+ /// Gets if a specified process name is currently running.
+ ///
+ /// The process name to find.
+ /// A value.
+ public static bool IsProcessRunning(string processName)
+ {
+ Process[] processes = Process.GetProcessesByName(processName); // Get the process(es) that match the name
+
+ if (processes.Length == 0) // If the process is not running
+ {
+ return false; // Return false
+ }
+ else // If the process is running
+ {
+ return true; // Return true
+ }
+ }
+
///
/// Launches an UWP application.
///
@@ -199,5 +219,34 @@ public static void ExecuteAsAdmin(string filename)
///
/// The current unix time.
public static int UnixTime => (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; // Get Unix Time
+
+ ///
+ /// Gets the name of the current computer.
+ ///
+ /// The name of the current computer.
+ public static string ComputerName => Environment.MachineName;
+
+ ///
+ /// Terminates a process with the specified process ID.
+ ///
+ /// The ID of the process to terminate.
+ /// True if the process was successfully terminated, or false if no such process was found or if an error occurred while trying to terminate the process.
+ public static bool TerminateProcess(int processId)
+ {
+ try
+ {
+ Process process = Process.GetProcessById(processId);
+ process.Kill();
+ return true;
+ }
+ catch (ArgumentException)
+ {
+ return false;
+ }
+ catch (Win32Exception)
+ {
+ return false;
+ }
+ }
}
}
diff --git a/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj b/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
index c6b0c29..fb54d9f 100644
--- a/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
+++ b/PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
@@ -6,11 +6,11 @@
enable
True
PeyrSharp.Exceptions
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
Exceptions of PeyrSharp.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
logo.png
NUGET_README.md
diff --git a/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj b/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
index 3ec1094..0eda59b 100644
--- a/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
+++ b/PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
@@ -4,11 +4,11 @@
net5.0;net6.0;net7.0
True
PeyrSharp.Extensions
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
Extensions methods of PeyrSharp.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
git
extension;extends;string;double;int;peyrsharp;crypt;converters;array
@@ -16,8 +16,7 @@
NUGET_README.md
MIT
True
- - Added the UnSplit() extension method (#56)
-- Added the ToUpperAt() method (#57)
+
@@ -32,7 +31,7 @@
-
+
diff --git a/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj b/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
index 5cd4445..d37544b 100644
--- a/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
+++ b/PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
@@ -8,18 +8,18 @@
true
True
PeyrSharp.UiHelpers
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
Useful helpers for Windows Forms and Windows Presentation Framework.
© 2023
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
ui-helpers;c-sharp;dotnet;vb;peyrsharp;leo corp;wpf;windows-forms;win-forms;ui;windows
logo.png
NUGET_README.md
MIT
True
- - Added the CenterWindow() method (#58)
+
@@ -34,7 +34,7 @@
-
+
diff --git a/PeyrSharp/PeyrSharp.cs b/PeyrSharp/PeyrSharp.cs
index 73cdacf..2c00a06 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.2.0.2301";
+ public static string Version => "1.3.0.2302";
}
}
diff --git a/PeyrSharp/PeyrSharp.csproj b/PeyrSharp/PeyrSharp.csproj
index 79b6f78..ce790f0 100644
--- a/PeyrSharp/PeyrSharp.csproj
+++ b/PeyrSharp/PeyrSharp.csproj
@@ -4,11 +4,11 @@
net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows
True
PeyrSharp
- 1.2.0.2301
+ 1.3.0.2302
Léo Corporation
© 2023
A C# library designed to make developers' job easier.
- https://github.com/Leo-Corporation/PeyrSharp
+ https://peyrsharp.leocorporation.dev/
https://github.com/Leo-Corporation/PeyrSharp
git
math;password;guid;generators;core;geometry;environment;extensions;enumerations;exceptions;ui-helpers
@@ -16,13 +16,11 @@
NUGET_README.md
MIT
True
- - Created Stats class (#52)
-- Added the Mean() method (#53)
-- Added the Median() method (#54)
-- Added the Mode() method (#55)
-- Added the UnSplit() extension method (#56)
-- Added the ToUpperAt() method (#57)
-- Added the CenterWindow() method (#58)
+ - Added the possibility to check if a process is running (#67)
+- Added the possibility to get the current directory (#68)
+- Added the possibility to get the name of the computer (#69)
+- Added the possibility to terminate a process (#70)
+- Added the possibility to generate a random value based on probabilities (#71)
@@ -37,12 +35,12 @@
-
-
-
-
-
-
+
+
+
+
+
+