Пример #1
0
        public string GetDeviceStateVariable(string deviceName, string variableName)
        {
            string             finalResponse = null;
            GenericDeviceState state         = requestDelegate(deviceName);

            foreach (PropertyInfo prop in state.GetType().GetProperties())
            {
                if (prop.Name == variableName)
                {
                    try {
                        object objAttr = prop.GetCustomAttribute(typeof(StateResponseFormatAttribute));
                        StateResponseFormatAttribute attr = objAttr as StateResponseFormatAttribute;
                        object objValue = state.GetType().GetProperty(variableName).GetValue(state);
                        if (objValue != null)
                        {
                            finalResponse = String.Format(attr.ResponseFormat, objValue);
                        }
                        else
                        {
                            finalResponse = attr.NullFormat;
                        }
                    } catch {
                        finalResponse = "An error occurred. Please check your Alexa configuration.";
                    }
                }
            }
            return(finalResponse);
        }
Пример #2
0
        void Form1_stationListUpdated(GenericDeviceState state)
        {
            if (this.stationsListBox.InvokeRequired)
            {
                StateUpdated d = new StateUpdated(Form1_stationListUpdated);
                this.Invoke(d, new object[] { state });
            }
            else
            {
                if (state is OnkyoState)
                {
                    OnkyoState st = (OnkyoState)state;
                    stationsListBox.Items.Clear();
                    stationsListBox.Items.AddRange(st.CurrentList);
                    seekLabel.Text   = st.CurrentSeekPosition;
                    volumeLabel.Text = st.CurrentVolume.ToString();
                    powerLabel.Text  = st.CurrentPowerState ? "On" : "Off";
                }
                if (state is HeatmiserState)
                {
                    HeatmiserState st = (HeatmiserState)state;
                    tempValueLabel.Text         = st.CurrentAirTemp.ToString().Insert(2, ".") + "C";
                    setTempValueLabel.Text      = st.SetRoomTemp.ToString() + "C";
                    hotWaterValueLabel.Text     = st.IsHotWater ? "Yes" : "No";
                    heatingValueLabel.Text      = st.IsHeating ? "Yes" : "No";
                    holidayValueLabel.Text      = st.IsOnHoliday ? "Yes" : "No";
                    rateOfChangeValueLabel.Text = st.RateOfChange.ToString() + "Min";
                }
                if (state is PCState)
                {
                    if (((PCState)state).PCName == "StudyPC")
                    {
                        studyPCOnOffLabel.Text = ((PCState)state).IsOn ? "On" : "Off";
                    }
                    else if (((PCState)state).PCName == "LoungePC")
                    {
                        mediaCenterOnOffLabel.Text = ((PCState)state).IsOn ? "On" : "Off";
                    }
                }
                if (state is HolidayManagerState)
                {
                    HolidayManagerState st = (HolidayManagerState)state;

                    //DialogResult dr = DialogResult.Yes;
                    //if (holidaysDataGrid.DataSource != null) {
                    //    dr = MessageBox.Show("Holiday list updated. Refresh the screen?", "Holidays Updated", MessageBoxButtons.YesNo);
                    //}

                    //if (dr == DialogResult.Yes) {
                    List <PlannedHoliday> copy = st.PlannedHolidays.ToList <PlannedHoliday>();
                    System.ComponentModel.BindingList <PlannedHoliday> bl = new System.ComponentModel.BindingList <PlannedHoliday>(copy);
                    bl.AllowNew = bl.AllowRemove = bl.AllowEdit = true;
                    holidaysDataGrid.DataSource = bl;
                    //}
                }
            }
        }
 public DeviceStateChangedEventArgs(GenericDeviceState state)
 {
     DeviceState = state;
 }