Skip to content

Commit

Permalink
fine tuning monitoring lib sample code
Browse files Browse the repository at this point in the history
  • Loading branch information
DevtechProfile committed Jan 19, 2022
1 parent 1c3a65a commit 902b060
Show file tree
Hide file tree
Showing 15 changed files with 220 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitoringLibTestApp", "ConsoleApp1\MonitoringLibTestApp.csproj", "{89EA1324-86F3-48D9-B610-600FCE74CEC3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitoringLibTestApp", "source\MonitoringLibTestApp\MonitoringLibTestApp.csproj", "{89EA1324-86F3-48D9-B610-600FCE74CEC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "..\..\OpenHardwareMonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "source\OpenHardwareMonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapFrameX.Monitoring.Contracts", "..\..\CapFrameX.Monitoring.Contracts\CapFrameX.Monitoring.Contracts.csproj", "{2F0D1227-BE4F-4501-B3A2-66A753ED742C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapFrameX.Monitoring.Contracts", "source\CapFrameX.Monitoring.Contracts\CapFrameX.Monitoring.Contracts.csproj", "{2F0D1227-BE4F-4501-B3A2-66A753ED742C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ The hardware monitoring library is based on [OpenHardareMonitor](https://github.
</packages>
```

See "MonitoringLibTestApp" example code how to integrate the customized library.
Potential conflicts with the Nuget packages can be solved via Package Manger Console. Just tpye "Update-Package -reinstall". The calling application must run as administrator. See "MonitoringLibTestApp" example code how to integrate the customized library.

# Requirements
* .NET 4.7.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Reactive, Version=4.3.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\MonitoringLibTestApp\ConsoleApp1\packages\System.Reactive.4.3.2\lib\net46\System.Reactive.dll</HintPath>
<HintPath>..\..\packages\System.Reactive.4.3.2\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\MonitoringLibTestApp\ConsoleApp1\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\MonitoringLibTestApp\ConsoleApp1\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\MonitoringLibTestApp\ConsoleApp1\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
Expand Down
3 changes: 2 additions & 1 deletion source/CapFrameX.Sensor/SensorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ public void StartSensorLogging()

public void StopSensorLogging()
{
Observable.Timer(_currentLoggingTimespan).Subscribe(_ =>
Observable.Timer(_currentLoggingTimespan)
.Subscribe(_ =>
{
_isLoggingActive = false;
});
Expand Down
37 changes: 25 additions & 12 deletions source/CapFrameX/App.config
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<appSettings>
<add key="WebserviceUri" value="https://capframex.com/api/"/>
<add key="OAuthClientId" value="application"/>
<add key="OAuthClientSecret" value="13e2d80b-32e7-4d48-b2fe-29c44bca7958"/>
<add key="OAuthAuthorizationEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/auth"/>
<add key="OAuthTokenEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/token"/>
<add key="ManageProfilePageUrl" value="https://capframex.com/auth/realms/CapFrameX/account"/>
<add key="OAuthUserinfoEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/userinfo"/>
<add key="ContactFormUriTemplate" value="https://capframex.com/support?openform=true&amp;subject={0}&amp;message={1}&amp;email={2}"/>
<add key="WebserviceUri" value="https://capframex.com/api/" />
<add key="OAuthClientId" value="application" />
<add key="OAuthClientSecret" value="13e2d80b-32e7-4d48-b2fe-29c44bca7958" />
<add key="OAuthAuthorizationEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/auth" />
<add key="OAuthTokenEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/token" />
<add key="ManageProfilePageUrl" value="https://capframex.com/auth/realms/CapFrameX/account" />
<add key="OAuthUserinfoEndpoint" value="https://capframex.com/auth/realms/CapFrameX/protocol/openid-connect/userinfo" />
<add key="ContactFormUriTemplate" value="https://capframex.com/support?openform=true&amp;subject={0}&amp;message={1}&amp;email={2}" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand All @@ -25,4 +26,16 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
1 change: 0 additions & 1 deletion source/CapFrameX/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ private void Application_Startup(object sender, StartupEventArgs e)
var processListFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
@"CapFrameX\Resources\");


if (!Directory.Exists(configFolder))
{
Directory.CreateDirectory(configFolder);
Expand Down
File renamed without changes.
23 changes: 0 additions & 23 deletions source/MonitoringLibTestApp/ConsoleApp1/ConsoleApp1/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,46 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
<HintPath>..\..\packages\Microsoft.Extensions.Logging.Abstractions.5.0.0\lib\net461\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<HintPath>..\packages\Serilog.2.9.0\lib\net46\Serilog.dll</HintPath>
<HintPath>..\..\packages\Serilog.2.9.0\lib\net46\Serilog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
<HintPath>..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
<HintPath>..\..\packages\System.ComponentModel.Annotations.4.7.0\lib\net461\System.ComponentModel.Annotations.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
<HintPath>..\..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
<HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Reactive, Version=4.3.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reactive.4.3.2\lib\net46\System.Reactive.dll</HintPath>
<HintPath>..\..\packages\System.Reactive.4.3.2\lib\net46\System.Reactive.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
Expand All @@ -89,14 +92,15 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\CapFrameX.Monitoring.Contracts\CapFrameX.Monitoring.Contracts.csproj">
<ProjectReference Include="..\CapFrameX.Monitoring.Contracts\CapFrameX.Monitoring.Contracts.csproj">
<Project>{2F0D1227-BE4F-4501-B3A2-66A753ED742C}</Project>
<Name>CapFrameX.Monitoring.Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\OpenHardwareMonitor\OpenHardwareMonitorLib.csproj">
<ProjectReference Include="..\OpenHardwareMonitor\OpenHardwareMonitorLib.csproj">
<Project>{b0397530-545a-471d-bb74-027ae456df1a}</Project>
<Name>OpenHardwareMonitorLib</Name>
</ProjectReference>
Expand Down
57 changes: 57 additions & 0 deletions source/MonitoringLibTestApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Globalization;
using System.Reactive.Linq;
using System.Runtime.InteropServices;

namespace MonitoringLibTestApp
{
public class Program
{
private const double SAMPLE_INTERVAL_MS = 1000;
private static ConsoleEventDelegate _handler;
private static IDisposable _sensorUpdateHeartBeat;
private static SensorService _sensorService = new SensorService();

static void Main(string[] args)
{
_handler = new ConsoleEventDelegate(ConsoleEventCallback);
SetConsoleCtrlHandler(_handler, true);

_sensorService.ActivateAllSensors();
_sensorUpdateHeartBeat = GetSensorUpdateHeartBeat();

Console.ReadKey();
}

private static IDisposable GetSensorUpdateHeartBeat()
{
return Observable
.Timer(DateTimeOffset.UtcNow, TimeSpan.FromMilliseconds(SAMPLE_INTERVAL_MS))
.Subscribe(x =>
{
_sensorService.UpdateSensors();

Console.Clear();
Console.WriteLine($"{_sensorService.CpuTemp.ToString("F1", CultureInfo.InvariantCulture)} °C");
Console.WriteLine($"{_sensorService.CPUFrequency.ToString("F0", CultureInfo.InvariantCulture)} MHz");
Console.WriteLine($"{_sensorService.CpuPPT.ToString("F0", CultureInfo.InvariantCulture)} W");
Console.WriteLine($"{_sensorService.VCoreVoltage.ToString("F1", CultureInfo.InvariantCulture)} V");
});
}

private delegate bool ConsoleEventDelegate(int eventType);
[DllImport("kernel32.dll", SetLastError = true)]

private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add);

static bool ConsoleEventCallback(int eventType)
{
if (eventType == 2)
{
_sensorUpdateHeartBeat?.Dispose();
_sensorService.Computer?.Close();
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public SensorService()
{
CPUEnabled = true,
};

Computer.Open();
}

Expand Down Expand Up @@ -52,7 +53,6 @@ public void UpdateSensors()
// loop through the data
foreach (var sensor in hardware.Sensors)
{
_sensorConfig.SetSensorIsActive(sensor.IdentifierString, true);
switch (sensor.SensorType)
{
case SensorType.Temperature when sensor.Name.Contains("CPU Package"):
Expand Down Expand Up @@ -124,5 +124,25 @@ public void UpdateSensors()
}
}
}

public void ActivateAllSensors()
{
for (int i = 0; i < Computer.Hardware.Length; i++)
{
IHardware hardware = Computer.Hardware[i];
if (hardware.HardwareType == HardwareType.CPU)
{
// only fire the update when found
hardware.Update();

// loop through the sensors
foreach (var sensor in hardware.Sensors)
{
// activate sensor
_sensorConfig.SetSensorIsActive(sensor.IdentifierString, true);
}
}
}
}
}
}
Loading

0 comments on commit 902b060

Please sign in to comment.