/// <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);
        }
コード例 #2
0
        /// <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())
                {
                    // It is desired to block starting the service, but that prevents the installer completes
                    // when the device is not installed. (vital=yes causes failure, vital=no becomes hung.)
                    // As a workaround, service continues to start, but with error log message.
                    Trace.TraceError("Failed to start up Delcom Light component. Service continues to run, but the device is not recognized without restart of the service.");
                    lightControl     = null;
                    this.delcomLight = null;
                }
            }
            // 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>
        /// Set ILightControl interface, RemoteRecoderSync, and start processing thread.
        /// </summary>
        /// <param name="remoteRecorder">Remote recorder controller. Cannot be null.</param>
        /// <param name="lightControl">Light control interface. May be null.</param>
        public void Start(RemoteRecorderSync remoteRecorder, ILightControl lightControl)
        {
            if (remoteRecorder == null)
            {
                throw new ArgumentException("remoteRecorder cannot be null.");
            }
            if (this.inputProcessThread != null)
            {
                throw new ApplicationException("StateMachine.Start() is called while running.");
            }

            this.remoteRecorder = remoteRecorder;
            this.light          = lightControl ?? new EmptyLightControl();

            this.inputProcessThread = new Thread(this.InputProcessLoop);
            TraceVerbose.Trace("State machine is starting.");
            inputProcessThread.Start();
        }
        /// <summary>
        /// Set ILightControl interface, RemoteRecoderSync, and start processing thread.
        /// </summary>
        /// <param name="remoteRecorder">Remote recorder controller. Cannot be null.</param>
        /// <param name="lightControl">Light control interface. May be null.</param>
        public void Start(RemoteRecorderSync remoteRecorder, ILightControl lightControl)
        {
            if (remoteRecorder == null)
            {
                throw new ArgumentException("remoteRecorder cannot be null.");
            }
            if (this.inputProcessThread != null)
            {
                throw new ApplicationException("StateMachine.Start() is called while running.");
            }

            this.remoteRecorder = remoteRecorder;
            this.light = lightControl ?? new EmptyLightControl();

            this.inputProcessThread = new Thread(this.InputProcessLoop);
            TraceVerbose.Trace("State machine is starting.");
            inputProcessThread.Start();
        }