Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions PeyrSharp.Core/Maths/Proba.cs
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Provides methods for working with probabilities.
/// </summary>
public static class Proba
{
/// <summary>
/// Gets a random value based on the specified probabilities.
/// </summary>
/// <typeparam name="T">The type of the values to select from.</typeparam>
/// <param name="probabilities">A dictionary containing the probability of getting each value.</param>
/// <returns>
/// A randomly selected value.
/// </returns>
/// <exception cref="ArgumentException">
/// Thrown if the sum of probabilities is not equal to 1.
/// </exception>
/// <exception cref="Exception">
/// Thrown if an unexpected error occurs while selecting a random value.
/// </exception>
public static T GetRandomValue<T>(Dictionary<T, double> 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.");
}
}
}
13 changes: 5 additions & 8 deletions PeyrSharp.Core/PeyrSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,19 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Core</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Authors>Léo Corporation</Authors>
<Description>Core methods and features of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>math;password;guid;generators;core;geometry</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Created Stats class (#52)
- Added the Mean() method (#53)
- Added the Median() method (#54)
- Added the Mode() method (#55)</PackageReleaseNotes>
<PackageReleaseNotes>- Added the possibility to generate a random value based on probabilities (#71)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -34,8 +31,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Enums" Version="1.3.0.2302" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.3.0.2302" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions PeyrSharp.Enums/PeyrSharp.Enums.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<Authors>Léo Corporation</Authors>
<Description>Enumerations of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<PackageTags>enums;c-sharp;dotnet;vb;peyrsharp;leo corp</PackageTags>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
8 changes: 8 additions & 0 deletions PeyrSharp.Env/FileSys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,13 @@ public static StorageUnits GetDriveStorageUnit(DriveInfo driveInfo)
return StorageUnits.Byte;
}
}

/// <summary>
/// Gets the current directory of the application.
/// </summary>
/// <returns>
/// A string representing the full path of the current directory.
/// </returns>
public static string CurrentDirectory => Directory.GetCurrentDirectory();
}
}
11 changes: 7 additions & 4 deletions PeyrSharp.Env/PeyrSharp.Env.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Env</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Authors>Léo Corporation</Authors>
<Description>Environment-related methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>logger;file;env;file-system;update-system;windows;system</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageReleaseNotes>- 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)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,6 +34,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Enums" Version="1.3.0.2302" />
</ItemGroup>
</Project>
49 changes: 49 additions & 0 deletions PeyrSharp.Env/Sys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +123,25 @@ static IEnumerable<string> GetProcs()
}
}

/// <summary>
/// Gets if a specified process name is currently running.
/// </summary>
/// <param name="processName">The process name to find.</param>
/// <returns>A <see cref="bool"/> value.</returns>
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
}
}

/// <summary>
/// Launches an UWP application.
/// </summary>
Expand Down Expand Up @@ -199,5 +219,34 @@ public static void ExecuteAsAdmin(string filename)
/// </summary>
/// <returns>The current unix time.</returns>
public static int UnixTime => (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; // Get Unix Time

/// <summary>
/// Gets the name of the current computer.
/// </summary>
/// <returns>The name of the current computer.</returns>
public static string ComputerName => Environment.MachineName;

/// <summary>
/// Terminates a process with the specified process ID.
/// </summary>
/// <param name="processId">The ID of the process to terminate.</param>
/// <returns>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.</returns>
public static bool TerminateProcess(int processId)
{
try
{
Process process = Process.GetProcessById(processId);
process.Kill();
return true;
}
catch (ArgumentException)
{
return false;
}
catch (Win32Exception)
{
return false;
}
}
}
}
4 changes: 2 additions & 2 deletions PeyrSharp.Exceptions/PeyrSharp.Exceptions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>PeyrSharp.Exceptions</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Company>Léo Corporation</Company>
<Description>Exceptions of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
Expand Down
9 changes: 4 additions & 5 deletions PeyrSharp.Extensions/PeyrSharp.Extensions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.Extensions</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Authors>Léo Corporation</Authors>
<Description>Extensions methods of PeyrSharp.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>extension;extends;string;double;int;peyrsharp;crypt;converters;array</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added the UnSplit() extension method (#56)
- Added the ToUpperAt() method (#57)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -32,7 +31,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Enums" Version="1.3.0.2302" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions PeyrSharp.UiHelpers/PeyrSharp.UiHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp.UiHelpers</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Authors>Léo Corporation</Authors>
<Description>Useful helpers for Windows Forms and Windows Presentation Framework.</Description>
<Copyright>© 2023</Copyright>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<PackageTags>ui-helpers;c-sharp;dotnet;vb;peyrsharp;leo corp;wpf;windows-forms;win-forms;ui;windows</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- Added the CenterWindow() method (#58)</PackageReleaseNotes>
<PackageReleaseNotes></PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -34,7 +34,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Enums" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Enums" Version="1.3.0.2302" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion PeyrSharp/PeyrSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public static class PeyrSharp
/// <summary>
/// The current version of PeyrSharp.
/// </summary>
public static string Version => "1.2.0.2301";
public static string Version => "1.3.0.2302";
}
}
28 changes: 13 additions & 15 deletions PeyrSharp/PeyrSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
<TargetFrameworks>net5.0;net6.0;net5.0-windows;net6.0-windows;net7.0;net7.0-windows</TargetFrameworks>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Title>PeyrSharp</Title>
<Version>1.2.0.2301</Version>
<Version>1.3.0.2302</Version>
<Authors>Léo Corporation</Authors>
<Copyright>© 2023</Copyright>
<Description>A C# library designed to make developers' job easier.</Description>
<PackageProjectUrl>https://github.com/Leo-Corporation/PeyrSharp</PackageProjectUrl>
<PackageProjectUrl>https://peyrsharp.leocorporation.dev/</PackageProjectUrl>
<RepositoryUrl>https://github.com/Leo-Corporation/PeyrSharp</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>math;password;guid;generators;core;geometry;environment;extensions;enumerations;exceptions;ui-helpers</PackageTags>
<PackageIcon>logo.png</PackageIcon>
<PackageReadmeFile>NUGET_README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageReleaseNotes>- 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)</PackageReleaseNotes>
<PackageReleaseNotes>- 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)</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,12 +35,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="PeyrSharp.Core" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Enums" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Env" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.2.0.2301" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.2.0.2301" />
<PackageReference Include="PeyrSharp.Core" Version="1.3.0.2302" />
<PackageReference Include="PeyrSharp.Enums" Version="1.3.0.2302" />
<PackageReference Include="PeyrSharp.Env" Version="1.3.0.2302" />
<PackageReference Include="PeyrSharp.Exceptions" Version="1.3.0.2302" />
<PackageReference Include="PeyrSharp.Extensions" Version="1.3.0.2302" />
<PackageReference Condition="'$(TargetPlatformIdentifier)' == 'Windows'" Include="PeyrSharp.UiHelpers" Version="1.3.0.2302" />
</ItemGroup>

</Project>