11using ASCOM . Alpaca ;
22using ASCOM . Common ;
3- using ASCOM . Common . Interfaces ;
4- using Microsoft . AspNetCore . Components ;
5- using Microsoft . AspNetCore . Components . Web ;
63using System . Diagnostics ;
74using System . Net . NetworkInformation ;
85using System . Reflection ;
@@ -19,17 +16,17 @@ public class Program
1916 //Change this to a unique value
2017 //You should offer a way for the end user to customize this via the command line so it can be changed in the case of a collision.
2118 //This supports --urls=http://*:port by default.
22- internal const int DefaultPort = 1234 ;
19+ internal const int DefaultPort = 31234 ;
2320
2421 //Fill these out
2522 internal const string Manufacturer = "Your name here" ;
23+
2624 internal const string ServerName = "A friendly name for the server" ;
2725 internal const string ServerVersion = "1.0" ;
2826
29- internal static ASCOM . Common . Interfaces . ILogger Logger ;
30-
31- internal static IHostApplicationLifetime Lifetime ;
27+ internal static ASCOM . Common . Interfaces . ILogger ? Logger ;
3228
29+ internal static IHostApplicationLifetime ? Lifetime ;
3330
3431 public static void Main ( string [ ] args )
3532 {
@@ -40,12 +37,11 @@ public static void Main(string[] args)
4037 //For Debug ConsoleLogger is very nice. For production TraceLogger is recommended.
4138 Logger = new ASCOM . Tools . ConsoleLogger ( ) ;
4239
43-
4440 #region Startup and Logging
41+
4542 Logger . LogInformation ( $ "{ ServerName } version { ServerVersion } ") ;
4643 Logger . LogInformation ( $ "Running on: { RuntimeInformation . OSDescription } .") ;
4744
48-
4945 //If already running start browser
5046 try
5147 {
@@ -62,12 +58,15 @@ public static void Main(string[] args)
6258 }
6359 else
6460 {
65- //This may need to be changed to a global lock of some sort.
66- if ( System . Diagnostics . Process . GetProcessesByName ( System . IO . Path . GetFileNameWithoutExtension ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ) . Count ( ) > 1 )
61+ Assembly ? entryAssembly = Assembly . GetEntryAssembly ( ) ;
62+ if ( entryAssembly != null )
6763 {
68- Logger . LogInformation ( "Detected driver already running, starting web browser on IP and Port" ) ;
69- StartBrowser ( ServerSettings . ServerPort ) ;
70- return ;
64+ if ( Process . GetProcessesByName ( entryAssembly . Location ) . Length > 1 )
65+ {
66+ Logger . LogInformation ( "Detected driver already running, starting web browser on IP and Port" ) ;
67+ StartBrowser ( ServerSettings . ServerPort ) ;
68+ return ;
69+ }
7170 }
7271 }
7372 }
@@ -88,7 +87,6 @@ public static void Main(string[] args)
8887 return ;
8988 }
9089
91-
9290 //Turn off Authentication. Once off the user can change the password and re-enable authentication
9391 if ( args ? . Any ( str => str . Contains ( "--reset-auth" ) ) ?? false )
9492 {
@@ -104,10 +102,7 @@ public static void Main(string[] args)
104102
105103 if ( ! args ? . Any ( str => str . Contains ( "--urls" ) ) ?? true )
106104 {
107- if ( args == null )
108- {
109- args = new string [ 0 ] ;
110- }
105+ args ??= [ ] ;
111106
112107 Logger . LogInformation ( "No startup url args detected, binding to saved server settings." ) ;
113108
@@ -136,9 +131,9 @@ public static void Main(string[] args)
136131 args = temparray ;
137132 }
138133
139- var builder = WebApplication . CreateBuilder ( args ) ;
134+ var builder = WebApplication . CreateBuilder ( args ?? [ ] ) ;
140135
141- #endregion
136+ #endregion Startup and Logging
142137
143138 //ToDo you can add devices here
144139
@@ -148,7 +143,7 @@ public static void Main(string[] args)
148143 //Load the configuration
149144 ASCOM . Alpaca . DeviceManager . LoadConfiguration ( new AlpacaConfiguration ( ) ) ;
150145
151- //Add a safety monitor with device id 0. You can load any number of the same device with different ids or load other devices with Load* functions.
146+ //Add a safety monitor with device id 0. You can load any number of the same device with different ids or load other devices with Load* functions.
152147 //You may want to inject settings and logging here to the Driver Instance.
153148 //For each device you add you should add a setting page to the settings folder and an entry in the Shared NavMenu
154149 ASCOM . Alpaca . DeviceManager . LoadSafetyMonitor ( 0 , new Drivers . BasicMonitor ( ) , "Really Basic Safety Monitor" , ServerSettings . GetDeviceUniqueId ( "SafetyMonitor" , 0 ) ) ;
@@ -170,7 +165,7 @@ public static void Main(string[] args)
170165 //Use Authentication
171166 ASCOM . Alpaca . Razor . StartupHelpers . ConfigureAuthentication ( builder . Services ) ;
172167 //Add User Service
173- builder . Services . AddScoped < IUserService , UserService > ( ) ;
168+ builder . Services . AddScoped < IUserService , Data . UserService > ( ) ;
174169
175170 var app = builder . Build ( ) ;
176171
@@ -199,19 +194,19 @@ public static void Main(string[] args)
199194
200195 app . MapFallbackToPage ( "/_Host" ) ;
201196
202- if ( ServerSettings . AutoStartBrowser )
197+ if ( ServerSettings . AutoStartBrowser )
203198 {
204199 try
205200 {
206201 StartBrowser ( ServerSettings . ServerPort ) ;
207202 }
208- catch ( Exception ex )
203+ catch ( Exception ex )
209204 {
210205 Logger . LogWarning ( ex . Message ) ;
211206 }
212207 }
213208
214- #endregion
209+ #endregion Finish Building and Start server
215210
216211 Lifetime = app . Lifetime ;
217212
@@ -223,8 +218,6 @@ public static void Main(string[] args)
223218
224219 //Start the Alpaca Server
225220 app . Run ( ) ;
226-
227-
228221 }
229222
230223 /// <summary>
0 commit comments