src: dotnet: testing

This commit is contained in:
Bill Zissimopoulos 2017-04-06 23:48:58 -07:00
parent 0cfc730745
commit f219885939
2 changed files with 28 additions and 11 deletions

View File

@ -17,6 +17,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Security.AccessControl; using System.Security.AccessControl;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
@ -679,7 +680,10 @@ namespace Fsp.Interop
{ {
DllPath = Microsoft.Win32.Registry.GetValue(KeyName, "InstallDir", null) as String; DllPath = Microsoft.Win32.Registry.GetValue(KeyName, "InstallDir", null) as String;
if (null != DllPath) if (null != DllPath)
Module = LoadLibraryW(DllPath + DllName); {
DllPath = Path.Combine(DllPath, Path.Combine("bin", DllName));
Module = LoadLibraryW(DllPath);
}
if (IntPtr.Zero == Module) if (IntPtr.Zero == Module)
throw new DllNotFoundException("cannot load " + DllName); throw new DllNotFoundException("cannot load " + DllName);
} }

View File

@ -31,7 +31,7 @@ namespace Fsp
public const UInt32 EVENTLOG_INFORMATION_TYPE = 0x0004; public const UInt32 EVENTLOG_INFORMATION_TYPE = 0x0004;
/* ctor/dtor */ /* ctor/dtor */
Service(String ServiceName) public Service(String ServiceName)
{ {
_CreateResult = Api.FspServiceCreate(ServiceName, OnStart, OnStop, null, out _Service); _CreateResult = Api.FspServiceCreate(ServiceName, OnStart, OnStop, null, out _Service);
Api.SetUserContext(_Service, this); Api.SetUserContext(_Service, this);
@ -46,13 +46,14 @@ namespace Fsp
} }
/* control */ /* control */
public int Run() public void Run()
{ {
if (0 > _CreateResult) if (0 > _CreateResult)
{ {
Log(EVENTLOG_ERROR_TYPE, Log(EVENTLOG_ERROR_TYPE,
String.Format("The service cannot be created (Status={0:X}).", _CreateResult)); String.Format("The service {0} cannot be created (Status={1:X}).",
return (int)Api.FspWin32FromNtStatus(_CreateResult); GetType().FullName, _CreateResult));
return;
} }
Api.FspServiceAllowConsoleMode(_Service); Api.FspServiceAllowConsoleMode(_Service);
Int32 Result = Api.FspServiceLoop(_Service); Int32 Result = Api.FspServiceLoop(_Service);
@ -60,25 +61,37 @@ namespace Fsp
if (0 > _CreateResult) if (0 > _CreateResult)
{ {
Log(EVENTLOG_ERROR_TYPE, Log(EVENTLOG_ERROR_TYPE,
String.Format("The service has failed to run (Status={0:X}).", Result)); String.Format("The service {0} has failed to run (Status={1:X}).",
return (int)Api.FspWin32FromNtStatus(Result); GetType().FullName, _CreateResult));
return;
} }
return (int)ExitCode;
} }
public void Stop() public void Stop()
{ {
if (0 > _CreateResult) if (0 > _CreateResult)
return; throw new InvalidOperationException();
Api.FspServiceStop(_Service); Api.FspServiceStop(_Service);
} }
public void RequestTime(UInt32 Time) public void RequestTime(UInt32 Time)
{ {
if (0 > _CreateResult)
throw new InvalidOperationException();
Api.FspServiceRequestTime(_Service, Time); Api.FspServiceRequestTime(_Service, Time);
} }
public int ExitCode public int ExitCode
{ {
get { return (int)Api.FspServiceGetExitCode(_Service); } get
set { Api.FspServiceSetExitCode(_Service, (UInt32)value); } {
if (0 > _CreateResult)
throw new InvalidOperationException();
return (int)Api.FspServiceGetExitCode(_Service);
}
set
{
if (0 > _CreateResult)
throw new InvalidOperationException();
Api.FspServiceSetExitCode(_Service, (UInt32)value);
}
} }
public static void Log(UInt32 Type, String Message) public static void Log(UInt32 Type, String Message)
{ {