@@ -17,13 +17,8 @@ The above copyright notice and this permission notice shall be included in all c
17
17
namespace Framework . WebAPI . Host
18
18
{
19
19
using System ;
20
- using System . Diagnostics ;
21
20
using System . IO ;
22
21
using System . Reflection ;
23
- using System . Runtime . InteropServices ;
24
- using System . ServiceProcess ;
25
-
26
- using Framework . WinAPI ;
27
22
28
23
using Microsoft . Extensions . Hosting ;
29
24
@@ -35,59 +30,13 @@ public static class ProgramUtilities
35
30
36
31
public static void StartWebService ( string [ ] args , Func < string [ ] , IHostBuilder > buildHost )
37
32
{
38
- if ( RunsAsService ( ) )
39
- {
40
- Environment . CurrentDirectory = BaseDirectory ;
41
- ServiceBase . Run ( new ServiceBase [ ] { new WebAPiService ( ) { HostBuilder = buildHost } } ) ;
42
- }
43
- else
44
- {
45
- buildHost ( args ) . Build ( ) . Run ( ) ;
46
- LogManager . Shutdown ( ) ;
47
- }
48
- }
49
-
50
- public static bool RunsAsService ( )
51
- {
52
- var commandline = System . Environment . CommandLine ;
53
-
54
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) && Microsoft . Azure . Web . DataProtection . Util . IsAzureEnvironment ( ) == false )
55
- {
56
- if ( IsUnderIisExpress ( ) )
57
- {
58
- return false ;
59
- }
60
-
61
- return WinAPIWrapper . CheckForConsoleWindow ( ) && IsUnderWindowsServiceManager ( ) ;
62
- }
63
-
64
- return false ; // never can be a windows service
65
- }
66
-
67
- public static bool IsUnderIisExpress ( )
68
- {
69
- var currentProcess = Process . GetCurrentProcess ( ) ;
70
- if ( string . CompareOrdinal ( currentProcess . ProcessName , @"iisexpress" ) == 0 )
71
- {
72
- return true ;
73
- }
74
-
75
- var parentProcess = currentProcess . Parent ( ) ;
76
- if ( parentProcess != null &&
77
- ( string . CompareOrdinal ( parentProcess . ProcessName , @"iisexpress" ) == 0 ||
78
- string . CompareOrdinal ( parentProcess . ProcessName , @"VSIISExeLauncher" ) == 0 ) )
79
- {
80
- return true ;
81
- }
33
+ Environment . CurrentDirectory = BaseDirectory ;
82
34
83
- return false ;
84
- }
85
-
86
- public static bool IsUnderWindowsServiceManager ( )
87
- {
88
- var currentProcess = Process . GetCurrentProcess ( ) ;
89
- var parentProcess = currentProcess . Parent ( ) ;
90
- return ( parentProcess != null && parentProcess . ProcessName == @"services" ) ;
35
+ var host = buildHost ( args ) ;
36
+ host . UseWindowsService ( ) ;
37
+
38
+ host . Build ( ) . Run ( ) ;
39
+ LogManager . Shutdown ( ) ;
91
40
}
92
41
}
93
42
}
0 commit comments