Example #1
0
 private void ProcessButtonReceived(clsButton button, string command, string payload)
 {
     if (string.Compare(command, Topic.command.ToString()) == 0 && payload == "ON")
     {
         log.Debug("PushButton: " + button.Number);
         OmniLink.Controller.SendCommand(enuUnitCommand.Button, 0, (ushort)button.Number);
     }
 }
 private void ProcessButtonReceived(clsButton button, Topic command, string payload)
 {
     if (command == Topic.command && Enum.TryParse(payload, true, out UnitCommands cmd) && cmd == UnitCommands.ON)
     {
         log.Debug("PushButton: {id}", button.Number);
         OmniLink.SendCommand(enuUnitCommand.Button, 0, (ushort)button.Number);
     }
 }
Example #3
0
        private async Task PublishButtonState(clsButton button)
        {
            // Simulate a momentary press
            await PublishAsync(button.ToTopic(Topic.state), "ON");

            await Task.Delay(1000);

            await PublishAsync(button.ToTopic(Topic.state), "OFF");
        }
        public static Switch ToConfig(this clsButton button)
        {
            Switch ret = new Switch();

            ret.name          = Global.mqtt_discovery_name_prefix + button.Name;
            ret.state_topic   = button.ToTopic(Topic.state);
            ret.command_topic = button.ToTopic(Topic.command);
            return(ret);
        }
        public static Switch ToConfig(this clsButton button)
        {
            Switch ret = new Switch();

            ret.unique_id     = $"{Global.mqtt_prefix}button{button.Number.ToString()}";
            ret.name          = Global.mqtt_discovery_name_prefix + button.Name;
            ret.state_topic   = button.ToTopic(Topic.state);
            ret.command_topic = button.ToTopic(Topic.command);
            return(ret);
        }
Example #6
0
        public ucButton(clsButton cbtn)
        {
            InitializeComponent();
            FontList  = new ObservableCollection <string>();
            this.cbtn = cbtn;
            populateFontFamilyCombobox();
            updateTb();

            DataContext = this;
        }
Example #7
0
        public object createCompleteButtonWithClass(clsButton clsBtn, clsButtonAction clsBtnAction)
        {
            Grid buttonGrid = (Grid)createGrid();

            buttonGrid.Name = "Button";
            buttonClass     = clsBtn;
            buttonClass["propButtonAction"] = clsBtnAction;
            buttonGrid.DataContext          = buttonClass;
            buttonGrid.Children.Add((Button)createButton());

            object sendbuttonGridAsObject = (object)buttonGrid;

            return(sendbuttonGridAsObject);
        }
Example #8
0
        public object createCompleteButton()
        {
            Grid buttonGrid = (Grid)createGrid();

            buttonGrid.Name        = "Button";
            buttonClass            = new clsButton();
            buttonClass["propId"]  = Guid.NewGuid();
            buttonGrid.DataContext = buttonClass;
            buttonGrid.Children.Add((Button)createButton());

            object sendbuttonGridAsObject = (object)buttonGrid;

            return(sendbuttonGridAsObject);
        }
Example #9
0
        private void ListViewDesignedItem_Click(object sender, EventArgs e)
        {
            object gridChildren = (object)((Grid)((ListViewItem)sender).Content).Children[0];

            if (gridChildren.ToString().Contains("TextBlock"))
            {
                textBlockClass = new clsTextblock();
                textBlockClass = (clsTextblock)((Grid)((ListViewItem)sender).Content).DataContext;
                ((Grid)((ListViewItem)sender).Content).DataContext = textBlockClass;
                customWindowForControlProperties.Visibility        = Visibility.Visible;
                Switcher.Switch(new ucTextBlock(textBlockClass));
            }
            if (gridChildren.ToString().Contains("Image"))
            {
                imageClass = new clsImage();
                imageClass = (clsImage)((Grid)((ListViewItem)sender).Content).DataContext;
                ((Grid)((ListViewItem)sender).Content).DataContext = imageClass;
                customWindowForControlProperties.Visibility        = Visibility.Visible;
                Switcher.Switch(new ucImage(imageClass));
            }
            if (gridChildren.ToString().Contains("Button"))
            {
                buttonClass = new clsButton();
                buttonClass["propButtonAction"] = buttonActionClass;
                buttonClass = (clsButton)((Grid)((ListViewItem)sender).Content).DataContext;
                ((Grid)((ListViewItem)sender).Content).DataContext = buttonClass;
                customWindowForControlProperties.Visibility        = Visibility.Visible;
                Switcher.Switch(new ucButton(buttonClass));
            }
            if (gridChildren.ToString().Contains("TextBox"))
            {
                textBoxClass = new clsTextBox();
                textBoxClass = (clsTextBox)((Grid)((ListViewItem)sender).Content).DataContext;
                ((Grid)((ListViewItem)sender).Content).DataContext = textBoxClass;
                customWindowForControlProperties.Visibility        = Visibility.Visible;
                Switcher.Switch(new ucTextBox(textBoxClass));
            }
            if (gridChildren.ToString().Contains("ComboBox"))
            {
                listViewDesign.SelectedIndex = ((ListView)((Grid)((ListViewItem)sender).Content).Parent).Items.IndexOf(((Grid)((ListViewItem)sender).Content));
                comboboxClass = new clsComboBox();
                comboboxClass = (clsComboBox)((Grid)((ListViewItem)sender).Content).DataContext;
                ((Grid)((ListViewItem)sender).Content).DataContext = comboboxClass;
                customWindowForControlProperties.Visibility        = Visibility.Visible;
                Switcher.Switch(new ucComboBox(comboboxClass));
            }
        }
Example #10
0
        public List <NameContract> ListButtons()
        {
            log.Debug("ListButtons");

            List <NameContract> names = new List <NameContract>();

            for (ushort i = 1; i < WebServiceModule.OmniLink.Controller.Buttons.Count; i++)
            {
                clsButton unit = WebServiceModule.OmniLink.Controller.Buttons[i];

                if (unit.DefaultProperties == false)
                {
                    names.Add(new NameContract()
                    {
                        id = i, name = unit.Name
                    });
                }
            }
            return(names);
        }
Example #11
0
        public List <NameContract> ListButtons()
        {
            Event.WriteVerbose("WebService", "ListButtons");

            List <NameContract> names = new List <NameContract>();

            for (ushort i = 1; i < WebService.HAC.Buttons.Count; i++)
            {
                clsButton unit = WebService.HAC.Buttons[i];

                if (unit.DefaultProperties == false)
                {
                    names.Add(new NameContract()
                    {
                        id = i, name = unit.Name
                    });
                }
            }
            return(names);
        }
Example #12
0
        private void PublishButtons()
        {
            log.Debug("Publishing buttons");

            for (ushort i = 1; i < OmniLink.Controller.Buttons.Count; i++)
            {
                clsButton button = OmniLink.Controller.Buttons[i];

                if (button.DefaultProperties == true)
                {
                    MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config", null, MqttQualityOfServiceLevel.AtMostOnce, true);
                    continue;
                }

                // Buttons are always off
                MqttClient.PublishAsync(button.ToTopic(Topic.state), "OFF", MqttQualityOfServiceLevel.AtMostOnce, true);

                MqttClient.PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i.ToString()}/config",
                                        JsonConvert.SerializeObject(button.ToConfig()), MqttQualityOfServiceLevel.AtMostOnce, true);
            }
        }
Example #13
0
        private void PublishButtons()
        {
            log.Debug("Publishing {type}", "buttons");

            for (ushort i = 1; i <= OmniLink.Controller.Buttons.Count; i++)
            {
                clsButton button = OmniLink.Controller.Buttons[i];

                if (button.DefaultProperties == true)
                {
                    PublishAsync(button.ToTopic(Topic.name), null);
                    PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config", null);
                    continue;
                }

                // Buttons are off unless momentarily pressed
                PublishAsync(button.ToTopic(Topic.state), "OFF");

                PublishAsync(button.ToTopic(Topic.name), button.Name);
                PublishAsync($"{Global.mqtt_discovery_prefix}/switch/{Global.mqtt_prefix}/button{i}/config",
                             JsonConvert.SerializeObject(button.ToConfig()));
            }
        }
Example #14
0
        public void loadDesignedTemplate(clsListViewDesignBackground lv)
        {
            XDocument xmlDocument             = XDocument.Load(designXmlFilePath);
            IEnumerable <XElement> designRoot = xmlDocument.Descendants("Design")
                                                .Where(mi => mi.Attribute("id").Value == templateId)
                                                .Elements();

            foreach (XElement control in designRoot)
            {
                if (control.Name == "Background")
                {
                    lv["propBackground"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(control.Value));
                }
                else
                {
                    string id   = control.Attribute("id").Value;
                    string type = control.Attribute("type").Value;

                    switch (type)
                    {
                    case "ComboBox":
                        XElement cboxRoot    = xmlDocument.Descendants(type + "es").FirstOrDefault();
                        XElement cboxDetails = cboxRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        comboboxClass                  = new clsComboBox();
                        comboboxClass["propId"]        = new Guid(id);
                        comboboxClass["propName"]      = cboxDetails.Element("Name").Value;
                        comboboxClass["propInputType"] = cboxDetails.Element("DataType").Value;
                        comboboxClass["propMargin"]    = cboxDetails.Element("Margin").Value == "NaN" ? convertToDoubleFromNaN(cboxDetails.Element("Margin").Value) : convertToDouble(cboxDetails.Element("Margin").Value);
                        comboboxClass["propHeight"]    = cboxDetails.Element("Height").Value == "NaN" ? convertToDoubleFromNaN(cboxDetails.Element("Height").Value) : convertToDouble(cboxDetails.Element("Height").Value);
                        Grid comboboxGrid = (Grid)controlCreator.createCompleteComboboxWithClass(cboxDetails.Element("ComboboxItem").Value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToList(), comboboxClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = comboboxGrid;
                        objectCollection.addObject(objectClass);
                        break;

                    case "TextBox":
                        XElement tboxRoot    = xmlDocument.Descendants(type + "es").FirstOrDefault();
                        XElement tboxDetails = tboxRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        textBoxClass                      = new clsTextBox();
                        textBoxClass["propId"]            = new Guid(id);
                        textBoxClass["propName"]          = tboxDetails.Element("Name").Value;
                        textBoxClass["propContent"]       = tboxDetails.Element("Content").Value;
                        textBoxClass["propHeight"]        = tboxDetails.Element("Height").Value == "NaN" ? convertToDoubleFromNaN(tboxDetails.Element("Height").Value) : convertToDouble(tboxDetails.Element("Height").Value);
                        textBoxClass["propMargin"]        = tboxDetails.Element("Margin").Value == "NaN" ? convertToDoubleFromNaN(tboxDetails.Element("Margin").Value) : convertToDouble(tboxDetails.Element("Margin").Value);
                        textBoxClass["propWidth"]         = tboxDetails.Element("Width").Value == "NaN" ? convertToDoubleFromNaN(tboxDetails.Element("Width").Value) : convertToDouble(tboxDetails.Element("Width").Value);
                        textBoxClass["propAlignment"]     = tboxDetails.Element("HorizontalAlignment").Value;
                        textBoxClass["propInputDataType"] = tboxDetails.Element("DataType").Value;
                        Grid textBoxGrid = (Grid)controlCreator.createCompleteTextBoxWithClass(textBoxClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = textBoxGrid;
                        objectCollection.addObject(objectClass);
                        break;

                    case "TextBlock":
                        XElement tblockRoot    = xmlDocument.Descendants(type + "s").FirstOrDefault();
                        XElement tblockDetails = tblockRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        textBlockClass                   = new clsTextblock();
                        textBlockClass["propId"]         = new Guid(id);
                        textBlockClass["propContent"]    = tblockDetails.Element("Text").Value;
                        textBlockClass["propAlignment"]  = tblockDetails.Element("HorizontalAlignment").Value;
                        textBlockClass["propFontFamily"] = tblockDetails.Element("FontFamily").Value;
                        textBlockClass["propFontSize"]   = double.Parse(tblockDetails.Element("FontSize").Value);
                        textBlockClass["propForeground"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(tblockDetails.Element("Foreground").Value));
                        textBlockClass["propMargin"]     = tblockDetails.Element("Margin").Value == "NaN" ? convertToDoubleFromNaN(tblockDetails.Element("Margin").Value) : convertToDouble(tblockDetails.Element("Margin").Value);;
                        Grid textBlockGrid = (Grid)controlCreator.createCompleteTextblockWithClass(textBlockClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = textBlockGrid;
                        objectCollection.addObject(objectClass);
                        break;

                    case "Button":
                        XElement buttonRoot    = xmlDocument.Descendants(type + "s").FirstOrDefault();
                        XElement buttonDetails = buttonRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        buttonClass                      = new clsButton();
                        buttonActionClass                = new clsButtonAction();
                        buttonClass["propId"]            = new Guid(id);
                        buttonClass["propContent"]       = buttonDetails.Element("Content").Value;
                        buttonClass["propBtnBackground"] = (SolidColorBrush)(new BrushConverter().ConvertFrom(buttonDetails.Element("Background").Value));
                        buttonClass["propForeground"]    = (SolidColorBrush)(new BrushConverter().ConvertFrom(buttonDetails.Element("Foreground").Value));
                        buttonClass["propAlignment"]     = buttonDetails.Element("HorizontalAlignment").Value;
                        buttonClass["propFontFamily"]    = buttonDetails.Element("FontFamily").Value;

                        buttonClass["propHeight"]   = buttonDetails.Element("Height").Value == "NaN" ? convertToDoubleFromNaN(buttonDetails.Element("Height").Value) : convertToDouble(buttonDetails.Element("Height").Value);
                        buttonClass["propMargin"]   = buttonDetails.Element("Margin").Value == "NaN" ? convertToDoubleFromNaN(buttonDetails.Element("Margin").Value) : convertToDouble(buttonDetails.Element("Margin").Value);
                        buttonClass["propWidth"]    = buttonDetails.Element("Width").Value == "NaN" ? convertToDoubleFromNaN(buttonDetails.Element("Width").Value) : convertToDouble(buttonDetails.Element("Width").Value);;
                        buttonClass["propFontSize"] = double.Parse(buttonDetails.Element("FontSize").Value);
                        //To do - open action class - assign the value
                        Grid buttonGrid = (Grid)controlCreator.createCompleteButtonWithClass(buttonClass, buttonActionClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = buttonGrid;
                        objectCollection.addObject(objectClass);
                        break;

                    case "DatePicker":
                        XElement datePickerRoot    = xmlDocument.Descendants(type + "s").FirstOrDefault();
                        XElement datePickerDetails = datePickerRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        datePickerClass                  = new clsDatePicker();
                        datePickerClass["propId"]        = new Guid(id);
                        datePickerClass["propName"]      = datePickerDetails.Element("Name").Value;
                        datePickerClass["propInputType"] = datePickerDetails.Element("DataType").Value;
                        datePickerClass["propHeight"]    = datePickerDetails.Element("Height").Value == "NaN" ? convertToDoubleFromNaN(datePickerDetails.Element("Height").Value) : convertToDouble(datePickerDetails.Element("Height").Value);
                        datePickerClass["propWidth"]     = datePickerDetails.Element("Width").Value == "NaN" ? convertToDoubleFromNaN(datePickerDetails.Element("Width").Value) : convertToDouble(datePickerDetails.Element("Width").Value);
                        Grid datePickerGrid = (Grid)controlCreator.createCompleteDatePickerWithClass(datePickerClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = datePickerGrid;
                        objectCollection.addObject(objectClass);
                        break;

                    case "Image":
                        XElement imageRoot    = xmlDocument.Descendants(type + "s").FirstOrDefault();
                        XElement imageDetails = imageRoot.Descendants(type).Where(mi => mi.Attribute("id").Value == id).FirstOrDefault();
                        imageClass                      = new clsImage();
                        imageClass["propId"]            = new Guid(id);
                        imageClass["propMargin"]        = imageDetails.Element("Margin").Value == "NaN" ? convertToDoubleFromNaN(imageDetails.Element("Margin").Value) : convertToDouble(imageDetails.Element("Margin").Value);
                        imageClass["propImageHeight"]   = imageDetails.Element("Height").Value == "NaN" ? convertToDoubleFromNaN(imageDetails.Element("Height").Value) : convertToDouble(imageDetails.Element("Height").Value);
                        imageClass["propImageWidth"]    = imageDetails.Element("Width").Value == "NaN" ? convertToDoubleFromNaN(imageDetails.Element("Width").Value) : convertToDouble(imageDetails.Element("Width").Value);
                        imageClass["propAlignment"]     = imageDetails.Element("HorizontalAlignment").Value;
                        imageClass["propImageData"]     = imageDetails.Element("ImageData").Value;
                        imageClass["propImageLocation"] = imageDetails.Element("ImageLocation").Value;
                        Grid imageGrid = (Grid)controlCreator.createCompleteImageWithClass(imageClass);
                        objectClass = new clsObject();
                        objectClass["controlObject"] = imageGrid;
                        objectCollection.addObject(objectClass);
                        break;
                    }
                }
            }
        }
 public static string ToTopic(this clsButton button, Topic topic)
 {
     return($"{Global.mqtt_prefix}/button{button.Number.ToString()}/{topic.ToString()}");
 }