Merge branch 'chreese-debug' into develop

#21-media-commands
sleevezipper 4 years ago
commit a8f749557f

@ -1,4 +1,6 @@
using hass_workstation_service.Communication; using hass_workstation_service.Communication;
using Serilog;
using Serilog.Core;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -70,7 +72,6 @@ namespace hass_workstation_service.Domain.Sensors
var explorerProcesses = Process.GetProcessesByName("explorer") var explorerProcesses = Process.GetProcessesByName("explorer")
.Select(p => p.Id.ToString()) .Select(p => p.Id.ToString())
.ToHashSet(); .ToHashSet();
var REprocessid = new Regex(@"(?<=Handle="").*?(?="")", RegexOptions.Compiled); var REprocessid = new Regex(@"(?<=Handle="").*?(?="")", RegexOptions.Compiled);
var numberOfLogonSessionsWithExplorer = new ManagementObjectSearcher(scope, new SelectQuery("SELECT * FROM Win32_SessionProcess")).Get() var numberOfLogonSessionsWithExplorer = new ManagementObjectSearcher(scope, new SelectQuery("SELECT * FROM Win32_SessionProcess")).Get()
@ -79,8 +80,18 @@ namespace hass_workstation_service.Domain.Sensors
.Select(mo => mo["Antecedent"].ToString()) .Select(mo => mo["Antecedent"].ToString())
.Distinct() .Distinct()
.Count(); .Count();
int numberOfUserDesktops = 1;
// this can fail sometimes, that's why we set numberOfUserDesktops to 1
try
{
numberOfUserDesktops = new ManagementObjectSearcher(scope, new SelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count - 1; // don't count Service desktop
}
catch
{
}
var numberOfUserDesktops = new ManagementObjectSearcher(scope, new SelectQuery("select * from win32_Perfrawdata_TermService_TerminalServicesSession")).Get().Count - 1; // don't count Service desktop
var numberOflogonUIProcesses = Process.GetProcessesByName("LogonUI").Length; var numberOflogonUIProcesses = Process.GetProcessesByName("LogonUI").Length;
if (numberOflogonUIProcesses >= numberOfUserDesktops) if (numberOflogonUIProcesses >= numberOfUserDesktops)
@ -93,8 +104,9 @@ namespace hass_workstation_service.Domain.Sensors
else else
return PCUserStatuses.InUse; return PCUserStatuses.InUse;
} }
catch catch (Exception e)
{ {
Log.Logger.Error(e, "Exception in SessionStateSensor");
return PCUserStatuses.Unknown; return PCUserStatuses.Unknown;
} }
} }

@ -26,7 +26,6 @@
<ItemGroup> <ItemGroup>
<None Remove="hass-workstation-service.pdb" /> <None Remove="hass-workstation-service.pdb" />
<None Remove="libSkiaSharp.dll" /> <None Remove="libSkiaSharp.dll" />
<None Remove="UserInterface.exe" />
<None Remove="UserInterface.pdb" /> <None Remove="UserInterface.pdb" />
</ItemGroup> </ItemGroup>
@ -34,9 +33,6 @@
<Content Include="libSkiaSharp.dll"> <Content Include="libSkiaSharp.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>
<Content Include="UserInterface.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save