Skip to content

Commit

Permalink
Display name and events finished
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterKottas committed Dec 14, 2017
1 parent 3d10ad2 commit d3ab916
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 5 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ Community, feel encouraged to add more templates if you find something missing/u
Console.WriteLine("Service {0} stopped", name);
service.Stop();
});
serviceConfig.OnInstall(service =>
{
Console.WriteLine("Service {0} installed", name);
});
serviceConfig.OnUnInstall(service =>
{
Console.WriteLine("Service {0} uninstalled", name);
});
serviceConfig.OnPause(service =>
{
Console.WriteLine("Service {0} paused", name);
});
serviceConfig.OnContinue(service =>
{
Console.WriteLine("Service {0} continued", name);
});

serviceConfig.OnError(e =>
{
Expand All @@ -119,7 +139,7 @@ Community, feel encouraged to add more templates if you find something missing/u
10. Run the service with **username:YOUR_USERNAME**, **password:YOUR_PASSWORD** and **action:install** which installs it for the given account.
11. Run the service with **built-in-account:(NetworkService|LocalService|LocalSystem)** and **action:install** which installs it for the given built in account. Defaults to **LocalSystem**.
12. Run the service with **description:YOUR_DESCRIPTION** and it setup description for the service.
13. Run the service with **displayName:YOUR_DISPLAY_NAME** and it setup Display name for the service.
13. Run the service with **display-name:YOUR_DISPLAY_NAME** and it setup Display name for the service.
14. Run the service with **name:YOUR_NAME** and it setup name for the service.
15. Run the service with **start-immediately:(true|false)** to start service immediately after install. Defaults to **true**.
16. You can find the complete example in PeterKottas.DotNetCore.Example project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,25 @@ public void OnError(Action<Exception> onError)
{
config.OnServiceError = onError;
}

public void OnPause(Action<SERVICE> onPause)
{
config.OnServicePause = onPause;
}

public void OnInstall(Action<SERVICE> onInstall)
{
config.OnServiceInstall = onInstall;
}

public void OnUnInstall(Action<SERVICE> onUnInstall)
{
config.OnServiceUnInstall = onUnInstall;
}

public void OnContinue(Action<SERVICE> onContinue)
{
config.OnServiceContinue = onContinue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public HostConfiguration()

public Action<SERVICE> OnServiceStop { get; set; }

public Action<SERVICE> OnServiceInstall { get; set; }

public Action<SERVICE> OnServiceUnInstall { get; set; }

public Action<SERVICE> OnServicePause { get; set; }

public Action<SERVICE> OnServiceContinue { get; set; }

public Action<Exception> OnServiceError { get; set; }

public List<string> ExtraArguments { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<Version>2.0.3</Version>
<AssemblyVersion>2.0.3.0</AssemblyVersion>
<FileVersion>2.0.3.0</FileVersion>
<AssemblyVersion>2.0.4.0</AssemblyVersion>
<FileVersion>2.0.4.0</FileVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DasMulli.Win32.ServiceUtils" Version="1.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>PeterKottas.DotNetCore.WindowsService</id>
<title>PeterKottas.DotNetCore.WindowsService</title>
<version>2.0.3</version>
<version>2.0.4</version>
<authors>Peter Kottas</authors>
<description>Easiest to use library that allows one to host .net core as windows services there is.</description>
<summary>.NET Core Windows service</summary>
Expand Down
34 changes: 33 additions & 1 deletion Source/PeterKottas.DotNetCore.WindowsService/ServiceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static int Run(Action<HostConfigurator<SERVICE>> runAction)
});
config.AddParameter(new CmdArgParam()
{
Key = "displayName",
Key = "display-name",
Description = "Service display name",
Value = val =>
{
Expand Down Expand Up @@ -294,6 +294,7 @@ private static void Uninstall(HostConfiguration<SERVICE> config, ServiceControll
}
new Win32ServiceManager().DeleteService(config.Name);
Console.WriteLine($@"Successfully unregistered service ""{config.Name}"" (""{config.Description}"")");
config.OnServiceUnInstall?.Invoke(config.Service);
}
catch (Exception e)
{
Expand All @@ -312,6 +313,37 @@ private static void StopService(HostConfiguration<SERVICE> config, ServiceContro
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(1000));
Console.WriteLine($@"Successfully stopped service ""{config.Name}"" (""{config.Description}"")");
config.OnServiceStop?.Invoke(config.Service);
}
else
{
Console.WriteLine($@"Service ""{config.Name}"" (""{config.Description}"") is already stopped or stop is pending.");
}
}

private static void PauseService(HostConfiguration<SERVICE> config, ServiceController sc)
{
if (!(sc.Status == ServiceControllerStatus.Paused | sc.Status == ServiceControllerStatus.PausePending))
{
sc.Pause();
sc.WaitForStatus(ServiceControllerStatus.Paused, TimeSpan.FromMilliseconds(1000));
Console.WriteLine($@"Successfully paused service ""{config.Name}"" (""{config.Description}"")");
config.OnServicePause?.Invoke(config.Service);
}
else
{
Console.WriteLine($@"Service ""{config.Name}"" (""{config.Description}"") is already paused or stop is pending.");
}
}

private static void ContinueService(HostConfiguration<SERVICE> config, ServiceController sc)
{
if (!(sc.Status == ServiceControllerStatus.Running | sc.Status == ServiceControllerStatus.ContinuePending))
{
sc.Continue();
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(1000));
Console.WriteLine($@"Successfully stopped service ""{config.Name}"" (""{config.Description}"")");
config.OnServiceContinue?.Invoke(config.Service);
}
else
{
Expand Down

0 comments on commit d3ab916

Please sign in to comment.