Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add ServiceBase #22920

Merged
merged 15 commits into from
Aug 4, 2017
Merged

Add ServiceBase #22920

merged 15 commits into from
Aug 4, 2017

Conversation

weshaggard
Copy link
Member

This change add ServiceBase and some of the missing ServiceController APIs that are in .NET Framework.

resolves https://github.com/dotnet/corefx/issues/6024

The ported ServiceBase matches desktop except the dependency on EventLog is removed as we don't have EventLog support in .NET Core (at least not yet).

The port doesn't include ServiceInstaller or ServiceProcessInstaller as we don't want to pull forward the entire Installer abstraction into .NET Core. So while we have ServiceBase a .NET Core hosted service will need to be installed/removed using other methods (sc.exe, installers, or via code like our test service).

As part of the testing work I removed our dependency on the old native service and started using our new managed service which uses ServiceBase.

PTAL @stephentoub @ericstj

@TravisTheTechie @dasMulli it would be great if you guys could take a look as well.

TODO:
 - Need to add tests

Porting Notes:
 - Excludes EventLog dependency
 - Removes latebound dependency on messagebox

Doesn't include ServiceInstaller but for testing purposes
ported parts of it into TestServiceInstaller class that
will be used for testing ServiceBase.
The managed TestService now has a simple ServiceBase TestService
that logs all the events it recieves to a file.

The project also as a simple TestServiceInstaller that will allow
for programatic install and removal of a service.

The main entry point provides a simple way to create/remove/run
the TestService.
Update test project to use the new managed TestService instead of
the old native test service and adjust the existing tests to account
for those changes.

Add basic ServiceBase tests. It isn't possible to test all the different
events so only test the ones that we can reliably tests.

The communication between the service and the tests is via a text file
which isn't ideal but it is the simpliest option of the various options
to work. All the tests need to call Stop to ensure the log file is flushed
to disk and we have all the content we need in it.
@weshaggard
Copy link
Member Author

test Outerloop NETFX x86 Release Build
test Outerloop Windows x64 Debug Build

public struct SERVICE_DELAYED_AUTOSTART_INFO
{
public bool fDelayedAutostart;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unnecessary semicolon

public struct SERVICE_DESCRIPTION
{
public IntPtr description;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Unnecessary semicolon

return false;

// no slashes or backslash allowed
foreach (char c in serviceName.ToCharArray())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToCharArray() unnecessarily allocates a char array

Initialize(true);
}

if (Environment.OSVersion.Version.Major >= 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check still needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

_status.controlsAccepted = _status.controlsAccepted | AcceptOptions.ACCEPT_SHUTDOWN;
}

if (Environment.OSVersion.Version.Major < 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed.

set
{
if (value == null)
throw new ArgumentNullException("value");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nameof(value)

if (value == null)
throw new ArgumentNullException("value");

if (string.Compare(value, _name, StringComparison.OrdinalIgnoreCase) == 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string.Equals

// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect license header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out. I decided to not include this file at all but I forget to remove it from my original commit.



using System;
using System.ComponentModel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run the codeformatter? Usings shouldn't be nested.

public struct SessionChangeDescription
{
private SessionChangeReason _reason;
private int _id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: readonly

}
}
}
//catch { }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be removed or commented back in (along with //try)

@weshaggard
Copy link
Member Author

@MattGal
Copy link
Member

MattGal commented Aug 3, 2017

@weshaggard the ?s are actually tests that didn't run at all for that configuration (no matching work item) but til recently we had a bug that showed them as ?. (@ChadNedzlek I believe has already fixed this but it hasn't been rolled out)

I'll take a look since it's definitely showing runs that I'd label as complete and passed as failures, then hand off to the FR team as needed.

@MattGal
Copy link
Member

MattGal commented Aug 3, 2017

@weshaggard this is freaky, there's some kind of MC bug. The failing test in all cases of those 4 runs is System.Runtime.Performance.Tests, which is timing out. Example log here.

I will raid a FR issue and tag you / Chad. There's something definitely wrong about how this is getting rendered (I'm guessing there have been several builds of this, one of which succeeded, and stomped finding that)

edit - these comments were before I realized job restarting had happened

@weshaggard
Copy link
Member Author

(I'm guessing there have been several builds of this, one of which succeeded, and stomped finding that)

Yes that is why I have an open request to split the results across the different legs.

@weshaggard
Copy link
Member Author

test Linux x64 Release Build

We have always had a "not supported" netstandard fallback but we
put the real implementation in a netstandard windows build but that
is also a little bit of a lie because we don't support it on things
like UWP. So instead the real implementation should be under netcoreapp
windows which is the only one we really support.
We no longer need to skip because the tests are now netcoreapp
and netfx specific so we won't try to run them on uap now.
@@ -2,8 +2,9 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard;
netcoreapp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I will remove it and just leave netstandard and netfx given we have to have a netstandard ref now for compat with the older package.

@@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
netstandard-Windows_NT;
netcoreapp-Windows_NT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means UWP no longer gets a valid impl. I guess that's OK. I doubt any of the API would work from appcontainer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct UWP isn't supporting these. On top of the win32 APIs it requires admin access for most of these actions.

Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo the extraneous netcoreapp ref config

We only need a netsteandard ref that can be shared between netcoreapp
and netstandard.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.ServiceProcess.ServiceController & ServiceBase
6 participants