parent
2590bd50b0
commit
a3125734ec
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"ExpandedNodes": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"SelectedNode": "\\hass-workstation-service.sln",
|
||||||
|
"PreviewInSolutionExplorer": false
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationRevision>4</ApplicationRevision>
|
||||||
|
<ApplicationVersion>1.0.0.*</ApplicationVersion>
|
||||||
|
<BootstrapperEnabled>True</BootstrapperEnabled>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<CreateDesktopShortcut>True</CreateDesktopShortcut>
|
||||||
|
<GenerateManifests>True</GenerateManifests>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<IsRevisionIncremented>True</IsRevisionIncremented>
|
||||||
|
<IsWebBootstrapper>False</IsWebBootstrapper>
|
||||||
|
<ManifestCertificateThumbprint>820B7EDF3E26E24BB4C25B177A05B3D0C77BF73A</ManifestCertificateThumbprint>
|
||||||
|
<ManifestKeyFile>hass-workstation-service_TemporaryKey.pfx</ManifestKeyFile>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>bin\publish\</PublishDir>
|
||||||
|
<PublishUrl>bin\publish\</PublishUrl>
|
||||||
|
<PublishProtocol>ClickOnce</PublishProtocol>
|
||||||
|
<PublishReadyToRun>False</PublishReadyToRun>
|
||||||
|
<PublishSingleFile>False</PublishSingleFile>
|
||||||
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>False</SelfContained>
|
||||||
|
<SignatureAlgorithm>sha256RSA</SignatureAlgorithm>
|
||||||
|
<SignManifests>True</SignManifests>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<TrustUrlParameters>False</TrustUrlParameters>
|
||||||
|
<UpdateEnabled>False</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||||
|
-->
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
</Project>
|
@ -1,64 +0,0 @@
|
|||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
using System;
|
|
||||||
using System.ServiceProcess;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace hass_workstation_service.ServiceHost
|
|
||||||
{
|
|
||||||
|
|
||||||
public class ServiceBaseLifetime : ServiceBase, IHostLifetime
|
|
||||||
{
|
|
||||||
private IHostApplicationLifetime ApplicationLifetime { get; }
|
|
||||||
private readonly TaskCompletionSource<object> _delayStart = new TaskCompletionSource<object>();
|
|
||||||
|
|
||||||
public ServiceBaseLifetime(IHostApplicationLifetime applicationLifetime)
|
|
||||||
{
|
|
||||||
ApplicationLifetime = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Task WaitForStartAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
cancellationToken.Register(() => _delayStart.TrySetCanceled());
|
|
||||||
ApplicationLifetime.ApplicationStopping.Register(Stop);
|
|
||||||
|
|
||||||
new Thread(Run).Start(); // Otherwise this would block and prevent IHost.StartAsync from finishing.
|
|
||||||
return _delayStart.Task;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Run(this); // This blocks until the service is stopped.
|
|
||||||
_delayStart.TrySetException(new InvalidOperationException("Stopped without starting"));
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_delayStart.TrySetException(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
Stop();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called by base.Run when the service is ready to start.
|
|
||||||
protected override void OnStart(string[] args)
|
|
||||||
{
|
|
||||||
_delayStart.TrySetResult(null);
|
|
||||||
base.OnStart(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called by base.Stop. This may be called multiple times by service Stop, ApplicationStopping, and StopAsync.
|
|
||||||
// That's OK because StopApplication uses a CancellationTokenSource and prevents any recursion.
|
|
||||||
protected override void OnStop()
|
|
||||||
{
|
|
||||||
ApplicationLifetime.StopApplication();
|
|
||||||
base.OnStop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
namespace hass_workstation_service.ServiceHost
|
|
||||||
{
|
|
||||||
|
|
||||||
public static class ServiceBaseLifetimeHostExtensions
|
|
||||||
{
|
|
||||||
public static IHostBuilder UseServiceBaseLifetime(this IHostBuilder hostBuilder)
|
|
||||||
{
|
|
||||||
return hostBuilder.ConfigureServices((hostContext, services) => services.AddSingleton<IHostLifetime, ServiceBaseLifetime>());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task RunAsServiceAsync(this IHostBuilder hostBuilder, CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
return hostBuilder.UseServiceBaseLifetime().Build().RunAsync(cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<_LastSelectedProfileId>C:\Users\Maurits\Documents\Repo\hass-desktop-service\Properties\PublishProfiles\ClickOnceProfile.pubxml</_LastSelectedProfileId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
Binary file not shown.
Loading…
Reference in new issue