/// <summary>
 /// Main application entry point.
 /// </summary>
 private static void Main()
 {
     LightsManager lightsManager = null;
     try
     {
         LightsDeviceController lightsDeviceController = new LightsDeviceController(Config.GetUsbProductId(), Config.GetUsbVendorId(), Config.GetUsbUsage(), Config.GetUsbUsagePage(), Config.GetWaitForDeviceRetryPeriod(), Config.GetUsbControlTransferType());
         lightsManager = new LightsManager(lightsDeviceController, Config.GetLightsManagerPort(), Config.GetNotificationManagerHost(), Config.GetNotificationManagerPort(), Config.GetRegistrationRetryPeriod(), Config.GetUsbProtocolType());
         Thread thread = new Thread(lightsManager.Start);
         thread.Start();
         Console.WriteLine("Press any key to terminate...");
         Console.ReadKey(true);
         lightsManager.Stop();
         thread.Join();
         Console.WriteLine("Press any key to close...");
         Console.ReadKey(true);
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e);
         Console.ReadKey(true);
     }
     finally
     {
         if (lightsManager != null)
         {
             lightsManager.Dispose();
         }
     }
 }
 public void TestStopAndStopAgain()
 {
     LightsManager lightsManager = null;
     try
     {
         LightsDeviceController lightsDeviceController = new LightsDeviceController(0, 0, 0, 0);
         lightsManager = new LightsManager(lightsDeviceController);
         lightsManager.Start();
         Assert.That(lightsManager.Running, NUnit.Framework.Is.True);
         lightsManager.Stop();
         Assert.That(lightsManager.Running, NUnit.Framework.Is.False);
         lightsManager.Stop();
         Assert.That(lightsManager.Running, NUnit.Framework.Is.False);
     }
     finally
     {
         if (lightsManager != null)
         {
             lightsManager.Dispose();
         }
     }
 }
        public void TestHandleCommandForServerDownRequest()
        {
            // Mocks
            Mock<ILightsDeviceController> mockLightsDeviceController = this.mockFactory.CreateMock<ILightsDeviceController>();
            mockLightsDeviceController.Expects.One.Method(x => x.Start());
            mockLightsDeviceController.Expects.One.Method(x => x.Stop());
            mockLightsDeviceController.IgnoreUnexpectedInvocations = true;

            // One for HandleCommand; one for Stop
            mockLightsDeviceController.Expects.Exactly(2).Method(x => x.SendCommand(null)).WithAnyArguments().WillReturn(LightsDeviceResult.Ack);

            // Run
            StatusRequest request = new StatusRequest(false);
            LightsManager lightsManager = null;
            try
            {
                lightsManager = new LightsManager(mockLightsDeviceController.MockObject, UsbProtocolType.DasBlinkenlichten);
                lightsManager.Start();
                Assert.That(lightsManager.Running, NUnit.Framework.Is.True);
                lightsManager.HandleCommand(request, EventArgs.Empty);
                lightsManager.Stop();
                Assert.That(lightsManager.Running, NUnit.Framework.Is.False);
            }
            finally
            {
                if (lightsManager != null)
                {
                    lightsManager.Dispose();
                }
            }

            this.mockFactory.VerifyAllExpectationsHaveBeenMet();
        }