Skip to content

Commit d371677

Browse files
committed
Clean up abnormal exit during startup
Remove Telescope dependency on AstroUtils Bump version to 6.6.0.15
1 parent a022122 commit d371677

8 files changed

Lines changed: 111 additions & 90 deletions

File tree

DeviceHub/App.xaml.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ protected override void OnStartup( StartupEventArgs e )
6262
}
6363
}
6464
}
65-
catch ( Exception xcp )
65+
catch ( Exception )
6666
{
67-
string msg = $"DeviceHub caught a fatal exception during startup\r\n{xcp.Message}";
68-
MessageBox.Show( msg, "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop );
67+
//string msg = $"DeviceHub caught a fatal exception during startup\r\n{xcp.Message}";
68+
//MessageBox.Show( msg, "DeviceHub", MessageBoxButton.OK, MessageBoxImage.Stop );
6969

7070
if ( Application.Current != null )
7171
{
@@ -94,7 +94,5 @@ private static T GetAssemblyAttribute<T>( bool inherit )
9494

9595
return (T)assembly.GetCustomAttributes( typeof( T ), inherit ).First();
9696
}
97-
98-
9997
}
10098
}

DeviceHub/Business Object Classes/ASCOM Classes/LocalServer.cs

Lines changed: 55 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static class Server
2525
private static int _domesInUse; // Keeps a count on the total number of domes alive.
2626
private static int _focusersInUse; // Keeps a count on the total number of focusers alive.
2727
private static int _serverLocks; // Keeps a lock count on this application.
28-
private static List<Type> _driverTypes; // Served COM object types
28+
private static List<Type> _driverTypes; // Served COM object types
2929
private static List<ClassFactory> _classFactories; // Served COM object class factories
3030
private static readonly string _appId = "{4f90ea04-044f-444e-963e-b52db2a87575}"; // Our AppId
3131
private static readonly Object _lockObject = new object();
@@ -34,7 +34,7 @@ public static class Server
3434

3535
private static TraceLogger Logger { get; set; }
3636

37-
private static GarbageCollection GarbageCollector {get; set;}
37+
private static GarbageCollection GarbageCollector { get; set; }
3838

3939
private static MainWindow MainWindow { get; set; } // Reference to the main view
4040
private static MainWindowViewModel ViewModel { get; set; } // Reference to the main view model
@@ -157,72 +157,84 @@ internal static void Startup( string[] args )
157157

158158
ServiceInjector.InjectUIServices( MainWindow );
159159

160-
// Create the ViewModel
160+
try
161+
{
162+
// Create the ViewModel
163+
// Any errors starting the view models or device managers will raise an exception and short circuit
164+
// the rest of the startup.
161165

162-
ViewModel = new MainWindowViewModel();
166+
ViewModel = new MainWindowViewModel();
163167

164-
Logger.LogMessage( logId, "Setting the data context for the main view" );
168+
Logger.LogMessage( logId, "Setting the data context for the main view" );
165169

166-
MainWindow.DataContext = ViewModel;
167-
MainWindow.Closing += MainWindow_Closing;
170+
MainWindow.DataContext = ViewModel;
171+
MainWindow.Closing += MainWindow_Closing;
168172

169-
// Load the saved settings to ensure that everyone up-to-date. Be sure to do this
170-
// after the main window is created so we can set its location.
173+
// Load the saved settings to ensure that everyone up-to-date. Be sure to do this
174+
// after the main window is created so we can set its location.
171175

172-
Logger.LogMessage( logId, "Loading the application settings" );
176+
Logger.LogMessage( logId, "Loading the application settings" );
173177

174-
AppSettingsManager.LoadAppSettings();
178+
AppSettingsManager.LoadAppSettings();
175179

176-
Logger.LogMessage( logId, "Loading the device driver settings" );
180+
Logger.LogMessage( logId, "Loading the device driver settings" );
177181

178-
LoadDeviceSettings();
182+
LoadDeviceSettings();
179183

180-
// Register the class factories of the served objects
184+
// Register the class factories of the served objects
181185

182-
Logger.LogMessage( logId, "Registering class factories" );
186+
Logger.LogMessage( logId, "Registering class factories" );
183187

184-
RegisterClassFactories();
188+
RegisterClassFactories();
185189

186-
Logger.LogMessage( logId, "Starting garbage collection" );
190+
Logger.LogMessage( logId, "Starting garbage collection" );
187191

188-
StartGarbageCollection( 60000 ); // Collect garbage once a minute.
189-
190-
try
191-
{
192-
Logger.LogMessage( logId, "Starting main view" );
192+
StartGarbageCollection( 60000 ); // Collect garbage once a minute.
193193

194-
ShowMainWindow();
194+
try
195+
{
196+
Logger.LogMessage( logId, "Starting main view" );
195197

196-
Logger.LogMessage( logId, "The main view has closed" );
197-
}
198-
finally
199-
{
200-
Logger.LogMessage( logId, "Saving the application settings" );
201-
AppSettingsManager.SaveAppSettings();
198+
ShowMainWindow();
202199

203-
// Revoke the class factories immediately.
204-
// Don't wait until the thread has stopped before
205-
// we perform revocation!!!
200+
Logger.LogMessage( logId, "The main view has closed" );
201+
}
202+
finally
203+
{
204+
Logger.LogMessage( logId, "Saving the application settings" );
205+
AppSettingsManager.SaveAppSettings();
206206

207-
RevokeClassFactories();
207+
// Revoke the class factories immediately.
208+
// Don't wait until the thread has stopped before
209+
// we perform revocation!!!
208210

209-
Logger.LogMessage( logId, "Disposing the main view and viewmodel." );
211+
RevokeClassFactories();
210212

211-
MainWindow.DataContext = null;
212-
MainWindow = null;
213-
ViewModel.Dispose();
214-
ViewModel = null;
213+
Logger.LogMessage( logId, "Disposing the main view and viewmodel." );
215214

216-
Logger.LogMessage( logId, "Unregistering all services" );
215+
MainWindow.DataContext = null;
216+
MainWindow = null;
217+
ViewModel.Dispose();
218+
ViewModel = null;
217219

218-
ServiceContainer.Instance.ClearAllServices();
220+
Logger.LogMessage( logId, "Unregistering all services" );
219221

220-
// Now stop the Garbage Collector task.
222+
ServiceContainer.Instance.ClearAllServices();
221223

222-
Logger.LogMessage( logId, "Stopping garbage collection" );
224+
// Now stop the Garbage Collector task.
223225

224-
StopGarbageCollection();
226+
Logger.LogMessage( logId, "Stopping garbage collection" );
225227

228+
StopGarbageCollection();
229+
}
230+
}
231+
catch ( Exception )
232+
{
233+
// Any exception from starting the view models or device managers will bring us here.
234+
// The exception was already logged via the AppLogger so we have nothing more to do but close the Logger and return.
235+
}
236+
finally
237+
{
226238
Logger.LogMessage( logId, "Local server is shutting down" );
227239
Logger.Dispose();
228240
}

DeviceHub/Business Object Classes/Globals.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,36 @@ public static TraceLogger AppLogger
9090
return _appLogger;
9191
}
9292
}
93+
94+
public static double ConditionHA( double ha )
95+
{
96+
double lowerBound = -12.0;
97+
double upperBound = 12.0;
98+
double range = upperBound - lowerBound;
99+
100+
double retval = ha;
101+
102+
while ( retval < lowerBound )
103+
{
104+
retval += range;
105+
}
106+
107+
while ( retval > upperBound )
108+
{
109+
retval -= range;
110+
}
111+
112+
return retval;
113+
}
114+
115+
public static void CloseAppLogger()
116+
{
117+
if ( _appLogger != null )
118+
{
119+
_appLogger.Enabled = false;
120+
_appLogger.Dispose();
121+
_appLogger = null;
122+
}
123+
}
93124
}
94125
}

DeviceHub/Business Object Classes/Telescope Classes/DevHubTelescopeStatus.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public double CalculateHourAngle( double rightAscension )
121121
// This method does not validate the RA!!
122122

123123
double retval = SiderealTime - rightAscension;
124-
retval = ConditionHA( retval );
124+
retval = Globals.ConditionHA( retval );
125125

126126
return retval;
127127
}
@@ -176,26 +176,26 @@ private bool CalculateCounterWeightUp( PierSide pierSide, double hourAngle )
176176
return retval;
177177
}
178178

179-
private double ConditionHA( double ha )
180-
{
181-
double lowerBound = -12.0;
182-
double upperBound = 12.0;
183-
double range = upperBound - lowerBound;
179+
//private double ConditionHA( double ha )
180+
//{
181+
// double lowerBound = -12.0;
182+
// double upperBound = 12.0;
183+
// double range = upperBound - lowerBound;
184184

185-
double retval = ha;
185+
// double retval = ha;
186186

187-
while ( retval < lowerBound )
188-
{
189-
retval += range;
190-
}
187+
// while ( retval < lowerBound )
188+
// {
189+
// retval += range;
190+
// }
191191

192-
while ( retval > upperBound )
193-
{
194-
retval -= range;
195-
}
192+
// while ( retval > upperBound )
193+
// {
194+
// retval -= range;
195+
// }
196196

197-
return retval;
198-
}
197+
// return retval;
198+
//}
199199

200200
#endregion
201201
}

DeviceHub/DeviceManagers/TelescopeManager.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88

9-
using ASCOM.Astrometry.AstroUtils;
109
using ASCOM.Astrometry.Transform;
1110
using ASCOM.DeviceInterface;
1211

@@ -24,16 +23,13 @@ public partial class TelescopeManager : DeviceManagerBase, ITelescopeManager, ID
2423

2524
private static TelescopeManager _instance = null;
2625

27-
private static AstroUtils AstroUtils { get; set; }
28-
2926
public static TelescopeManager Instance
3027
{
3128
get
3229
{
3330
if ( _instance == null )
3431
{
3532
_instance = new TelescopeManager();
36-
throw new Exception( "Unable to instantiate the TelescopeManager!" );
3733
}
3834

3935
return _instance;
@@ -44,23 +40,7 @@ public static TelescopeManager Instance
4440

4541
static TelescopeManager()
4642
{
47-
string caller = "TelescopeManager static ctor";
4843
TelescopeID = "";
49-
LogAppMessage( "Initialization started.", caller );
50-
51-
try
52-
{
53-
LogAppMessage( "Creating AstroUtils instance", caller );
54-
55-
AstroUtils = new AstroUtils();
56-
}
57-
catch (Exception xcp)
58-
{
59-
string msg = $"Unable to create an instance of AstroUtils. Details follow:\r\n\r\n{xcp}";
60-
LogAppMessage( msg, "TelescopeManager static constructor" );
61-
}
62-
63-
LogAppMessage( "Initialization complete", caller );
6444
}
6545

6646
public static void SetTelescopeID( string id )
@@ -741,7 +721,7 @@ public PierSide GetTargetSideOfPier( double rightAscension, double declination )
741721
{
742722
// Unable to get side-of-pier for this German Equatorial Mount so we need to simulate it.
743723

744-
double hourAngle = AstroUtils.ConditionHA( Status.SiderealTime - rightAscension );
724+
double hourAngle = Globals.ConditionHA( Status.SiderealTime - rightAscension );
745725
PierSide currentSOP = Status.SideOfPier;
746726
PierSide destinationSOP = currentSOP; // Favor the current side-of-pier for 0 hour angle;
747727

DeviceHub/ViewModel Classes/MainWindowViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public MainWindowViewModel()
7676
sb.Append( "Please contact the ASCOM Support Team for assistance." );
7777
ShowMessage( sb.ToString(), "Fatal Device Hub Startup Error", MessageBoxButton.OK, MessageBoxImage.Error );
7878

79-
Application.Current.Shutdown();
79+
throw;
8080
}
8181

8282
LogAppMessage( "Setting the active device to Telescope", caller );
@@ -95,7 +95,7 @@ public MainWindowViewModel()
9595
Messenger.Default.Register<ObjectCountMessage>( this, ( action ) => UpdateObjectsCount( action ) );
9696

9797
LogAppMessage( "Application Initializaiton is complete.", caller );
98-
98+
Globals.CloseAppLogger();
9999
}
100100

101101
#region Public Properties

Inno Setup/ASCOM Device Hub Setup.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
;
55

66
#define MyAppName "ASCOM.DeviceHub"
7-
#define MyAppVersion "6.6.0.14"
7+
#define MyAppVersion "6.6.0.15"
88
#define MyDestSubdirName "DeviceHub"
99
; #define MyPlatformRoot "D:\Github Repos\ASCOMPlatform\"
1010
#define MyPlatformRoot "D:\My Projects\Visual Studio 2022\Ascom\"

ProductAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
// You can specify all the values or you can default the Build and Revision Numbers
2121
// by using the '*' as shown below:
2222
// [assembly: AssemblyVersion("1.0.*")]
23-
[assembly: AssemblyVersion( "6.6.0.14" )]
23+
[assembly: AssemblyVersion( "6.6.0.15" )]

0 commit comments

Comments
 (0)