Bugfixes
This commit is contained in:
50
AsusFanControl.Domain/AsusFanControl.Domain.csproj
Normal file
50
AsusFanControl.Domain/AsusFanControl.Domain.csproj
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{27DE14F4-82B0-4D2B-B694-D2F563810BD9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>AsusFanControl.Domain</RootNamespace>
|
||||
<AssemblyName>AsusFanControl.Domain</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="services\FanCurve.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
36
AsusFanControl.Domain/Properties/AssemblyInfo.cs
Normal file
36
AsusFanControl.Domain/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("AsusFanControl.Domain")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("AsusFanControl.Domain")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("27de14f4-82b0-4d2b-b694-d2f563810bd9")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
78
AsusFanControl.Domain/services/FanCurve.cs
Normal file
78
AsusFanControl.Domain/services/FanCurve.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsusFanControl.Domain.services
|
||||
{
|
||||
public class FanCurve
|
||||
{
|
||||
// private readonly Dictionary<int, Point> _fanCurvePoints = new Dictionary<int, Point>();
|
||||
|
||||
public Dictionary<int, Point>? convertStringToPointsDictionary(
|
||||
string fanCurvePointsString, int temperatureLowerBound, int temperatureUpperBound, int fanSpeedLowerBound, int fanSpeedUpperBound
|
||||
)
|
||||
{
|
||||
if (fanCurvePointsString == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Define the allowed characters
|
||||
var allowedChars = new HashSet<char>("0123456789-,");
|
||||
// Check if the string contains any invalid characters
|
||||
if (fanCurvePointsString.Any(c => !allowedChars.Contains(c)))
|
||||
{
|
||||
throw new ArgumentException($"The fan curve points string contains invalid characters. Allowed characters: {string.Join("", allowedChars)}");
|
||||
}
|
||||
|
||||
|
||||
// Parse the string
|
||||
int pointCount = 1;
|
||||
var pointsDictionary = new Dictionary<int, Point>();
|
||||
try
|
||||
{
|
||||
var pointStrings = fanCurvePointsString.Split('-');
|
||||
|
||||
foreach (var pointString in pointStrings)
|
||||
{
|
||||
// Split the point string into temperature and fan speed parts
|
||||
string[] parts = pointString.Split(',');
|
||||
|
||||
// Ensure there are exactly two parts (temperature and fan speed)
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
throw new ArgumentException($"Invalid point format: '{pointString}'. Expected format: 'temperature,fanSpeed'.");
|
||||
}
|
||||
|
||||
// Parse the temperature and fan speed values
|
||||
int temperature = int.Parse(parts[0]);
|
||||
int fanSpeed = int.Parse(parts[1]);
|
||||
|
||||
// Validate temperature and fan speed ranges
|
||||
if (temperature < temperatureLowerBound || temperature > temperatureUpperBound)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(temperature), $"Temperature value {temperature} is out of range. Valid range: {temperatureLowerBound}-{temperatureUpperBound}.");
|
||||
}
|
||||
|
||||
if (fanSpeed < fanSpeedLowerBound || fanSpeed > fanSpeedUpperBound)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(fanSpeed), $"Fan speed value {fanSpeed} is out of range. Valid range: {fanSpeedLowerBound}-{fanSpeedUpperBound}.");
|
||||
}
|
||||
|
||||
// Create a new KeyValuePair with an incremented ID and the parsed Point
|
||||
pointsDictionary.Add(pointCount++, new Point(temperature, fanSpeed));
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ArgumentException("An error occurred while parsing the fan curve points string" +
|
||||
$"\n\n{ex.Message}", ex);
|
||||
}
|
||||
|
||||
return pointsDictionary;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user