Skip to content

Commit

Permalink
Fixed typos and capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
jnm2 committed Mar 3, 2019
1 parent 9c1f4c0 commit 6af402b
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Expand Up @@ -6,7 +6,7 @@
<GitCommitCountPadLength>3</GitCommitCountPadLength>

<!--
Set this to true when asp.net cor extensions are built out of band.
Set this to true when ASP.NET Core extensions are built out of band.
This will be needed whenever a change is made to the extensions that don't need an update to the
service utils package.
It should be false for every other case.
Expand Down
32 changes: 16 additions & 16 deletions README.md
@@ -1,14 +1,14 @@
# .NET Standard based Windows Service support for .NET
# .NET Standard-based Windows Service support for .NET

This repo contains a library for running a .NET Core application as windows service, without
This repo contains a library for running a .NET Core application as Windows service without
the need for a wrapper assembly or the full (desktop) .NET Framework.
It is built using P/Invoke calls into native windows assemblies.
It is built using P/Invoke calls into native Windows assemblies.

Usage scenarios include:
* Running on Windows Nano Server (no full framework but can run windows services)
* Shipping a modern service application using the latest .NET core version to systems
* Running on Windows Nano Server (no full framework but can run Windows services)
* Shipping a modern service application using the latest .NET Core version to systems
where you cannot upgrade to new versions of .NET, but you want to use new framework features.
* Build truly portable applications that can for example run as service on windows and as daemon on linux,
* Build truly portable applications that can for example run as service on Windows and as daemon on Linux,
just using runtime checks / switches

## How to use the example application
Expand All @@ -34,14 +34,14 @@ The "Services" administrative tool should show the service:
...
Successfully unregistered service "Demo .NET Core Service" ("Demo ASP.NET Core Service running on .NET Core")
```
Note that the service may show up as `disabled` for some time until all tools accessing the windows services apis have been closed.
See this [Stackoverflow question](http://stackoverflow.com/questions/20561990/how-to-solve-the-specified-service-has-been-marked-for-deletion-error).
Note that the service may show up as `disabled` for some time until all tools accessing the Windows services APIs have been closed.
See this [Stack Overflow question](http://stackoverflow.com/questions/20561990/how-to-solve-the-specified-service-has-been-marked-for-deletion-error).

## API

Add a NuGet package reference to `DasMulli.Win32.ServiceUtils`.

Write a windows service using:
Write a Windows service using:

```c#
using DasMulli.Win32.ServiceUtils;
Expand Down Expand Up @@ -76,10 +76,10 @@ You can then register your service via sc.exe (run cmd / powershell as administr

`sc.exe create MyService DisplayName= "My Service" binpath= "C:\Program Files\dotnet\dotnet.exe C:\path\to\MyService.dll --run-as-service"`

Now go the services console / task manager and start your service.
Now go to Services or Task Manager and start your service.

Not that `sc` will install your service as `SYSTEM` user which has way to many access rights to run things like web apps.
See [it's reference](https://technet.microsoft.com/en-us/library/cc990289(v=ws.11).aspx) for more options.
Note that `sc` will install your service as `SYSTEM` user which has way to many access rights to run things like web apps.
See [its reference](https://technet.microsoft.com/en-us/library/cc990289(v=ws.11).aspx) for more options.

If you want to get rid of it again, use:

Expand All @@ -88,20 +88,20 @@ If you want to get rid of it again, use:
You can also create a service that registers itself like the example provided by
taking a look at [the sample source](./samples/TestService/Program.cs).

Also take a look at the [ASP.NET Core MVC sample](./samples/MvcTestService), which has additional logic to set the correct working directory.
Also take a look at the [ASP.NET Core MVC sample](./samples/MvcTestService) which has additional logic to set the correct working directory.
When running it in development and not from the published output, be sure to pass `--preserve-working-directory` to it when registering
so that it will run from the project directory (e.g. run `dotnet run --register-service --preserve-working-directory` from and administrative
command prompt).

## Pause & Continue support

To create a service that supports being paused and later continued or stopped, implement `IPausableWin32Service` which extends `IWin32Service` by `Pause()` and `Continue()` methods
you can use to implement your pause&continue logic.
you can use to implement your pause & continue logic.

## Limitations

* No custom exceptions / error codes. Everything will throw a `Win32Exception` if something goes wrong (It's message should be
interpretable on windows).
* No custom exceptions / error codes. Everything will throw a `Win32Exception` if something goes wrong (Its message should be
interpretable on Windows).
* All exceptions thrown by the service implementation will cause the service host
to report exit code -1 / 0xffffffff to the service control manager.
* Currently, no direct support for services supporting commands such as power event and system shutdown
Expand Down
20 changes: 10 additions & 10 deletions samples/MvcTestService/Program.cs
Expand Up @@ -54,7 +54,7 @@ public static void Main(string[] args)
}
catch (Exception ex)
{
WriteLine($"An error ocurred: {ex.Message}");
WriteLine($"An error occurred: {ex.Message}");
}
}

Expand All @@ -73,7 +73,7 @@ private static void RunAsService(string[] args)
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
}

BuildWebHost(args).RunAsService(ServiceName);
}

Expand Down Expand Up @@ -136,18 +136,18 @@ private static void DisplayHelp()
{
WriteLine(ServiceDescription);
WriteLine();
WriteLine("This demo application is intened to be run as windows service. Use one of the following options:");
WriteLine("This demo application is intended to be run as Windows service. Use one of the following options:");
WriteLine();
WriteLine(" --register-service Registers and starts this program as a windows service named \"" + ServiceDisplayName + "\"");
WriteLine(" --register-service Registers and starts this program as a Windows service named \"" + ServiceDisplayName + "\"");
WriteLine(" All additional arguments will be passed to ASP.NET Core's WebHostBuilder.");
WriteLine();
WriteLine(" --preserve-working-directory Saves the current working directory to the service configuration.");
WriteLine(" Set this wenn running via 'dotnet run' or when the application content");
WriteLine(" is not located nex to the application.");
WriteLine(" Set this when running via 'dotnet run' or when the application content");
WriteLine(" is not located next to the application.");
WriteLine();
WriteLine(" --unregister-service Removes the windows service creatd by --register-service.");
WriteLine(" --unregister-service Removes the Windows service created by --register-service.");
WriteLine();
WriteLine(" --interactive Runs the underlying asp.net core app. Useful to test arguments.");
WriteLine(" --interactive Runs the underlying ASP.NET Core app. Useful to test arguments.");
}

private static string EscapeCommandLineArgument(string arg)
Expand All @@ -160,10 +160,10 @@ private static string EscapeCommandLineArgument(string arg)

public static IWebHost BuildWebHost(string[] args)
{
/*
/*
* create an override configuration based on the command line args
* to work around ASP.NET Core issue https://github.com/aspnet/MetaPackages/issues/221
* wich should be fixed in 2.1.0.
* which should be fixed in 2.1.0.
*/
var configuration = new ConfigurationBuilder().AddCommandLine(args).Build();

Expand Down
10 changes: 5 additions & 5 deletions samples/TestService/Program.cs
Expand Up @@ -44,7 +44,7 @@ public static void Main(string[] args)
}
catch (Exception ex)
{
Console.WriteLine($"An error ocurred: {ex.Message}");
Console.WriteLine($"An error occurred: {ex.Message}");
}
}

Expand Down Expand Up @@ -109,11 +109,11 @@ private static void DisplayHelp()
{
Console.WriteLine(ServiceDescription);
Console.WriteLine();
Console.WriteLine("This demo application is intened to be run as windows service. Use one of the following options:");
Console.WriteLine(" --register-service Registers and starts this program as a windows service named \"" + ServiceDisplayName + "\"");
Console.WriteLine("This demo application is intended to be run as Windows service. Use one of the following options:");
Console.WriteLine(" --register-service Registers and starts this program as a Windows service named \"" + ServiceDisplayName + "\"");
Console.WriteLine(" All additional arguments will be passed to ASP.NET Core's WebHostBuilder.");
Console.WriteLine(" --unregister-service Removes the windows service creatd by --register-service.");
Console.WriteLine(" --interactive Runs the underlying asp.net core app. Useful to test arguments.");
Console.WriteLine(" --unregister-service Removes the Windows service created by --register-service.");
Console.WriteLine(" --interactive Runs the underlying ASP.NET Core app. Useful to test arguments.");
}

private static string EscapeCommandLineArgument(string arg)
Expand Down
2 changes: 1 addition & 1 deletion samples/TestService/TestWin32Service.cs
Expand Up @@ -46,7 +46,7 @@ public void Start(string[] startupArguments, ServiceStoppedCallback serviceStopp
.UseConfiguration(config)
.Build();

// Make sure the windows service is stopped if the
// Make sure the Windows service is stopped if the
// ASP.NET Core stack stops for any reason
webHost
.Services
Expand Down
Expand Up @@ -5,7 +5,7 @@
namespace DasMulli.AspNetCore.Hosting.WindowsServices
{
/// <summary>
/// Extensions to web host builder for windows service hosting scenarios
/// Extensions to web host builder for Windows service hosting scenarios
/// </summary>
public static class WebHostExtensions
{
Expand Down
Expand Up @@ -8,7 +8,7 @@ namespace DasMulli.AspNetCore.Hosting.WindowsServices
{
/// <inheritdoc />
/// <summary>
/// Provides an implementation of a service that hosts an asp.net core application
/// Provides an implementation of a service that hosts an ASP.NET Core application
/// </summary>
/// <seealso cref="T:DasMulli.Win32.ServiceUtils.IWin32Service" />
[PublicAPI]
Expand All @@ -21,7 +21,7 @@ public class WebHostService : IWin32Service
public string ServiceName { get; }

/// <summary>
/// Initializes a new instance of the <see cref="WebHostService"/> class which hosts the sepcified host as a windows service.
/// Initializes a new instance of the <see cref="WebHostService"/> class which hosts the specified host as a Windows service.
/// </summary>
/// <param name="host">The host to run as a service.</param>
/// <param name="serviceName">Name of the service to run. If <c>null</c>, set to the name of the entry assembly</param>
Expand Down
2 changes: 1 addition & 1 deletion src/DasMulli.Win32.ServiceUtils/HashCode.cs
Expand Up @@ -5,7 +5,7 @@ namespace DasMulli.Win32.ServiceUtils
{
/// <summary>
/// Simplifies the work of hashing.
/// Taken from https://rehansaeed.com/gethashcode-made-easy/", and modified with Reshaper
/// Taken from https://rehansaeed.com/gethashcode-made-easy/ and modified with ReSharper.
/// </summary>
internal struct HashCode
{
Expand Down
2 changes: 1 addition & 1 deletion src/DasMulli.Win32.ServiceUtils/IPausableWin32Service.cs
Expand Up @@ -2,7 +2,7 @@
{
/// <inheritdoc />
/// <summary>
/// Interface to allow implementing windows services that can start and stop as well as pause and continue in between.
/// Interface to allow implementing Windows services that can start and stop as well as pause and continue in between.
/// Note that after a call to Pause(), the service can receive either Continue() or Stop()
/// </summary>
public interface IPausableWin32Service : IWin32Service
Expand Down
4 changes: 2 additions & 2 deletions src/DasMulli.Win32.ServiceUtils/IWin32Service.cs
Expand Up @@ -7,7 +7,7 @@
public delegate void ServiceStoppedCallback();

/// <summary>
/// Interface to allow implementing simple windows services that can start and stop
/// Interface to allow implementing simple Windows services that can start and stop
/// </summary>
public interface IWin32Service
{
Expand All @@ -20,7 +20,7 @@ public interface IWin32Service
string ServiceName { get; }

/// <summary>
/// Starts the service with the startup arguments received from windows.
/// Starts the service with the startup arguments received from Windows.
/// </summary>
/// <param name="startupArguments">The startup arguments.</param>
/// <param name="serviceStoppedCallback">The service stopped callback the service can call if it stopped without being requested to stop.</param>
Expand Down
6 changes: 3 additions & 3 deletions src/DasMulli.Win32.ServiceUtils/IWin32ServiceStateMachine.cs
Expand Up @@ -4,7 +4,7 @@ namespace DasMulli.Win32.ServiceUtils
{
/// <summary>
/// Interface to implement advanced services through custom handling all service state events.
///
///
/// See <see cref="SimpleServiceStateMachine"/> for a sample implementation.
/// </summary>
[PublicAPI]
Expand All @@ -15,12 +15,12 @@ public interface IWin32ServiceStateMachine
/// Use the provided <paramref name="statusReportCallback"/> to notify the service manager about
/// state changes such as started, paused etc.
/// </summary>
/// <param name="startupArguments">The startup arguments passed via windows' service configuration.</param>
/// <param name="startupArguments">The startup arguments passed via Windows' service configuration.</param>
/// <param name="statusReportCallback">The status report callback.</param>
void OnStart(string[] startupArguments, ServiceStatusReportCallback statusReportCallback);

/// <summary>
/// Called when a command was received from windows' service system.
/// Called when a command was received from Windows' service system.
/// </summary>
/// <param name="command">The received command.</param>
/// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms683241(v=vs.85).aspx </param>
Expand Down
Expand Up @@ -4,8 +4,8 @@
namespace DasMulli.Win32.ServiceUtils
{
/// <summary>
/// Implemets the state machine to handle a simple service that only implement starting and stopping.
/// These simple services are implemented by configruming to the <see cref="IWin32Service"/> protocol.
/// Implements the state machine to handle a simple service that only implement starting and stopping.
/// These simple services are implemented by configuring to the <see cref="IWin32Service"/> protocol.
/// </summary>
/// <seealso cref="DasMulli.Win32.ServiceUtils.IWin32ServiceStateMachine" />
public sealed class PausableServiceStateMachine : IWin32ServiceStateMachine
Expand All @@ -27,7 +27,7 @@ public PausableServiceStateMachine(IPausableWin32Service serviceImplementation)
/// Use the provided <paramref name="statusReportCallback" /> to notify the service manager about
/// state changes such as started, paused etc.
/// </summary>
/// <param name="startupArguments">The startup arguments passed via windows' service configuration.</param>
/// <param name="startupArguments">The startup arguments passed via Windows' service configuration.</param>
/// <param name="statusReportCallback">The status report callback.</param>
[SuppressMessage("ReSharper", "ParameterHidesMember")]
public void OnStart(string[] startupArguments, ServiceStatusReportCallback statusReportCallback)
Expand All @@ -47,7 +47,7 @@ public void OnStart(string[] startupArguments, ServiceStatusReportCallback statu
}

/// <summary>
/// Called when a command was received from windows' service system.
/// Called when a command was received from Windows' service system.
/// </summary>
/// <param name="command">The received command.</param>
/// <param name="commandSpecificEventType">Type of the command specific event. See description of dwEventType at https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx </param>
Expand Down
Expand Up @@ -31,7 +31,7 @@ public enum ServiceAcceptedControlCommandsFlags : uint
PauseContinueStop = PauseContinue | Stop,

/// <summary>
/// The shutdown command is accepted which notfies the service about a system shutdown.
/// The shutdown command is accepted which notifies the service about a system shutdown.
/// This event can only be sent by the system.
/// </summary>
Shutdown = 0x00000004,
Expand All @@ -42,12 +42,12 @@ public enum ServiceAcceptedControlCommandsFlags : uint
ParamChange = 0x00000008,

/// <summary>
/// Tndicates that the service is a network service that can re-read its binding parameters without needing to be restarted.
/// Indicates that the service is a network service that can re-read its binding parameters without needing to be restarted.
/// </summary>
NetBindChange = 0x00000010,

/// <summary>
/// Indicates that the service can perform pre-sutdown tasks.
/// Indicates that the service can perform pre-shutdown tasks.
/// This event can only be sent by the system.
/// </summary>
PreShutdown = 0x00000100,
Expand All @@ -59,7 +59,7 @@ public enum ServiceAcceptedControlCommandsFlags : uint
HardwareProfileChange = 0x00000020,

/// <summary>
/// The service can react to power status cahnges.
/// The service can react to power status changes.
/// This event can only be sent by the system.
/// </summary>
PowerEvent = 0x00000040,
Expand Down
4 changes: 2 additions & 2 deletions src/DasMulli.Win32.ServiceUtils/ServiceControlCommand.cs
Expand Up @@ -53,13 +53,13 @@ public enum ServiceControlCommand : uint

/// <summary>
/// Notifies a network service that a disabled binding
/// has ben enabled and that it should add the new binding.
/// has been enabled and that it should add the new binding.
/// </summary>
NetBindEnable = 0x00000009,

/// <summary>
/// Notifies a network service that one of its bindings
/// has ben disabled and that it should remove the binding.
/// has been disabled and that it should remove the binding.
/// </summary>
NetBindDisable = 0x0000000A,

Expand Down
4 changes: 2 additions & 2 deletions src/DasMulli.Win32.ServiceUtils/ServiceDefinition.cs
Expand Up @@ -3,7 +3,7 @@
namespace DasMulli.Win32.ServiceUtils
{
/// <summary>
/// Contains settings for a windows service registration.
/// Contains settings for a Windows service registration.
/// </summary>
[PublicAPI]
public class ServiceDefinition
Expand Down Expand Up @@ -37,7 +37,7 @@ public class ServiceDefinition
/// This includes the path to the executable as well as the
/// arguments to be passed to it.
/// </summary>
/// <value>
/// <value>
/// The binary path of the service.
/// This includes the path to the executable as well as the
/// arguments to be passed to it.
Expand Down

0 comments on commit 6af402b

Please sign in to comment.