コード例 #1
0
        public void SetUp()
        {
            stubProjectMonitor = new StubProjectMonitor("project");

            mockLampController = new Mock <ILampController>(MockBehavior.Strict);
            ILampController lampController = mockLampController.Object as ILampController;

            configuration           = new X10Configuration();
            configuration.Enabled   = true;
            configuration.StartTime = DateTime.Parse("08:00");
            configuration.EndTime   = DateTime.Parse("18:00");
            configuration.ActiveDays[(int)DayOfWeek.Sunday]    = false;
            configuration.ActiveDays[(int)DayOfWeek.Monday]    = true;
            configuration.ActiveDays[(int)DayOfWeek.Tuesday]   = true;
            configuration.ActiveDays[(int)DayOfWeek.Wednesday] = true;
            configuration.ActiveDays[(int)DayOfWeek.Thursday]  = true;
            configuration.ActiveDays[(int)DayOfWeek.Friday]    = true;
            configuration.ActiveDays[(int)DayOfWeek.Saturday]  = false;

            stubCurrentTimeProvider = new StubCurrentTimeProvider();
            stubCurrentTimeProvider.SetNow(new DateTime(2005, 11, 03, 12, 00, 00));
            Assert.AreEqual(DayOfWeek.Thursday, stubCurrentTimeProvider.Now.DayOfWeek);

            new X10Controller(
                stubProjectMonitor,
                stubCurrentTimeProvider,
                configuration,
                lampController);
        }
コード例 #2
0
        public void ShouldCreateTheCm11DriverBasedOnType()
        {
            X10Configuration configuration = new X10Configuration();

            configuration.DeviceType = ControllerType.CM11.ToString();
            configuration.ComPort    = "COM1";

            LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration);

            try
            {
                IX10LowLevelDriver driver = factory.getDriver();
                // factory will return null driver if it can't create one - caller needs to check!
                if (driver != null)
                {
                    Assert.IsInstanceOfType(typeof(Cm11LowLevelDriver), driver, "driver should be correct type");
                }
            }
            catch (ApplicationException appEx)
            {
                // this test only works if COM1 is available...fail if the message is anything other than
                // something about the com port not being there.
                Assert.IsTrue(appEx.InnerException.Message.Contains("The port 'COM1' does not exist."), "threw an exception, but the message was wrong");
            }
        }
コード例 #3
0
        public void CanBindToDefaultConfiguration()
        {
            X10SettingsControl control = new X10SettingsControl();

            X10Configuration configuration = new X10Configuration();

            control.BindX10Controls(configuration);
        }
コード例 #4
0
        public X10Controller(IProjectMonitor monitor, DateTimeProvider dateTimeProvider, X10Configuration configuration, ILampController lampController)
        {
            if (configuration != null && configuration.Enabled)
            {
                Trace.WriteLine("New X10Controller created");
                this.lampController   = lampController;
                this.dateTimeProvider = dateTimeProvider;
                this.configuration    = configuration;
                this.monitor          = monitor;

                monitor.Polled += new MonitorPolledEventHandler(Monitor_Polled);
            }
        }
コード例 #5
0
        public void SetUp()
        {
            x10LowLevelDriverMock = new Mock <IX10LowLevelDriver>(MockBehavior.Strict);

            X10Configuration configuration = new X10Configuration();

            configuration.SuccessUnitCode  = GREEN_LAMP_DEVICE_CODE;
            configuration.BuildingUnitCode = YELLOW_LAMP_DEVICE_CODE;
            configuration.FailureUnitCode  = RED_LAMP_DEVICE_CODE;
            IX10LowLevelDriver x10LowLevelDriver = x10LowLevelDriverMock.Object as IX10LowLevelDriver;

            lampController = new LampController(configuration, x10LowLevelDriver);
        }
コード例 #6
0
        public void SetUp()
        {
            x10LowLevelDriverMock        = new DynamicMock(typeof(IX10LowLevelDriver));
            x10LowLevelDriverMock.Strict = true;

            X10Configuration configuration = new X10Configuration();

            configuration.SuccessUnitCode  = GREEN_LAMP_DEVICE_CODE;
            configuration.BuildingUnitCode = YELLOW_LAMP_DEVICE_CODE;
            configuration.FailureUnitCode  = RED_LAMP_DEVICE_CODE;
            IX10LowLevelDriver x10LowLevelDriver = x10LowLevelDriverMock.MockInstance as IX10LowLevelDriver;

            lampController = new LampController(configuration, x10LowLevelDriver);
        }
コード例 #7
0
        public void ShouldCreateTheCm17aDriverBasedOnType()
        {
            X10Configuration configuration = new X10Configuration();

            configuration.DeviceType = ControllerType.CM17A.ToString();
            configuration.ComPort    = "COM1";

            LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration);
            IX10LowLevelDriver    driver  = factory.getDriver();

            // factory will return null driver if it can't create one - caller needs to check!
            if (driver != null)
            {
                Assert.IsInstanceOfType(typeof(Cm17LowLevelDriver), driver);
            }
        }
コード例 #8
0
 public LampController(X10Configuration configuration, IX10LowLevelDriver lowLevelDriver)
 {
     if (configuration != null)
     {
         int successUnitCode           = configuration.SuccessUnitCode;
         int buildingUnitCode          = configuration.BuildingUnitCode;
         int failureUnitCode           = configuration.FailureUnitCode;
         LowLevelDriverFactory factory = new LowLevelDriverFactory(configuration);
         if (lowLevelDriver == null)
         {
             lowLevelDriver = factory.getDriver();
         }
         red    = new Lamp("red", failureUnitCode, lowLevelDriver);
         yellow = new Lamp("yellow", buildingUnitCode, lowLevelDriver);
         green  = new Lamp("green", successUnitCode, lowLevelDriver);
     }
 }
コード例 #9
0
 public void PersistX10TabSettings(X10Configuration configuration)
 {
     configuration.Enabled          = checkBoxX10Enabled.Checked;
     configuration.ComPort          = (listBoxComPort.SelectedItem ?? "COM0").ToString();
     configuration.DeviceType       = comboBoxControllerType.SelectedItem.ToString();
     configuration.HouseCode        = listBoxHouseCode.SelectedItem.ToString();
     configuration.StartTime        = dateTimePickerStartTime.Value;
     configuration.EndTime          = dateTimePickerEndTime.Value;
     configuration.FailureUnitCode  = listBoxFailureUnitCode.SelectedIndex + 1;
     configuration.BuildingUnitCode = listBoxBuildingUnitCode.SelectedIndex + 1;
     configuration.SuccessUnitCode  = listBoxSuccessUnitCode.SelectedIndex + 1;
     configuration.ActiveDays[(int)DayOfWeek.Sunday]    = checkBoxActiveSunday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Monday]    = checkBoxActiveMonday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Tuesday]   = checkBoxActiveTuesday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Wednesday] = checkBoxActiveWednesday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Thursday]  = checkBoxActiveThursday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Friday]    = checkBoxActiveFriday.Checked;
     configuration.ActiveDays[(int)DayOfWeek.Saturday]  = checkBoxActiveSaturday.Checked;
 }
コード例 #10
0
        public void BindX10Controls(X10Configuration configuration)
        {
            checkBoxX10Enabled.Checked = configuration.Enabled;

            String[] houseCodes = Enum.GetNames(typeof(HouseCode));
            Array.Sort(houseCodes);
            listBoxHouseCode.Items.AddRange(houseCodes);
            listBoxHouseCode.SelectedItem = configuration.HouseCode;

            String[] deviceTypes = Enum.GetNames(typeof(ControllerType));
            Array.Sort(deviceTypes);
            comboBoxControllerType.Items.AddRange(deviceTypes);
            comboBoxControllerType.SelectedItem = configuration.DeviceType;

            String[] availableComPorts = SerialPort.GetPortNames();
            listBoxComPort.Items.AddRange(availableComPorts);
            if (availableComPorts.Length == 0)
            {
                labelStatus.Text           = "Problem: no COM ports found!";
                labelStatus.Visible        = true;
                checkBoxX10Enabled.Checked = false;
                checkBoxX10Enabled.Enabled = false;
                UpdateEnabledState();
                return;
            }
            comboBoxControllerType.SelectedItem = configuration.DeviceType;
            listBoxComPort.SelectedItem         = configuration.ComPort;

            listBoxFailureUnitCode.SelectedIndex  = configuration.FailureUnitCode - 1;
            listBoxBuildingUnitCode.SelectedIndex = configuration.BuildingUnitCode - 1;
            listBoxSuccessUnitCode.SelectedIndex  = configuration.SuccessUnitCode - 1;

            checkBoxActiveSunday.Checked    = configuration.ActiveDays[(int)DayOfWeek.Sunday];
            checkBoxActiveMonday.Checked    = configuration.ActiveDays[(int)DayOfWeek.Monday];
            checkBoxActiveTuesday.Checked   = configuration.ActiveDays[(int)DayOfWeek.Tuesday];
            checkBoxActiveWednesday.Checked = configuration.ActiveDays[(int)DayOfWeek.Wednesday];
            checkBoxActiveThursday.Checked  = configuration.ActiveDays[(int)DayOfWeek.Thursday];
            checkBoxActiveFriday.Checked    = configuration.ActiveDays[(int)DayOfWeek.Friday];
            checkBoxActiveSaturday.Checked  = configuration.ActiveDays[(int)DayOfWeek.Saturday];

            dateTimePickerStartTime.Value = timeWithGoodDate(configuration.StartTime);
            dateTimePickerEndTime.Value   = timeWithGoodDate(configuration.EndTime);
        }
コード例 #11
0
 public LowLevelDriverFactory(X10Configuration configuration)
 {
     this.configuration = configuration;
 }