/// <summary> /// Start handler. /// MSDN documentaion recommends not to rely on args in general. /// We use config file for any parameters and ignore command line args. /// </summary> protected override void OnStart(string[] args) { EnsureCertificateValidation(); ILightControl lightControl = null; this.stateMachine = new StateMachine(); this.remoteRecorderSync = new RemoteRecorderSync((IStateMachine)this.stateMachine); if (string.Compare(Properties.Settings.Default.DeviceType, "Delcom", StringComparison.OrdinalIgnoreCase) == 0) { // Set up of Delcom light (with button) device. this.delcomLight = new DelcomLight((IStateMachine)this.stateMachine); lightControl = this.delcomLight as ILightControl; if (!this.delcomLight.Start()) { Trace.TraceError("Failed to start up Delcom Light component. Terminate."); throw new ApplicationException("Failed to start up Delcom Light component. Terminate."); } } // TODO: add here for device specific start up when another device type is added. else { throw new InvalidOperationException("Specified device type is not supported: " + Properties.Settings.Default.DeviceType); } // Start processing of the state machine. this.stateMachine.Start(this.remoteRecorderSync, lightControl); }
/// <summary> /// Stop handler. /// </summary> protected override void OnStop() { if (this.remoteRecorderSync != null) { this.remoteRecorderSync.Stop(); this.remoteRecorderSync = null; } if (this.delcomLight != null) { this.delcomLight.Stop(); this.delcomLight = null; } if (this.stateMachine != null) { this.stateMachine.Stop(); this.stateMachine = null; } }