Exemplo n.º 1
0
        public static void DefineOrUpdateDeviceProperty(device_propertys dp)
        {
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                device_propertys existing_dp = db.device_propertys.FirstOrDefault(d => d.name == dp.name);

                if (existing_dp == null)
                {
                    db.device_propertys.AddObject(dp);
                }
                else
                {
                    existing_dp.friendly_name = dp.friendly_name;
                    existing_dp.value_data_type = dp.value_data_type;
                    existing_dp.default_value = dp.default_value;

                    foreach (var option in db.device_property_options.Where(p => p.device_property_id == existing_dp.id).ToArray())
                    {
                        db.DeleteObject(option);
                    }

                    foreach (device_property_options dpo in dp.device_property_options)
                        existing_dp.device_property_options.Add(new device_property_options { name = dpo.name });

                }
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void DefineOrUpdateProperty(scene_property p)
        {
            if (p != null)
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    scene_property existing_property = db.scene_property.FirstOrDefault(ep => ep.name == p.name);

                    if (existing_property == null)
                    {
                        db.scene_property.AddObject(p);
                    }
                    else
                    {
                        //Update
                        existing_property.friendly_name = p.friendly_name;
                        existing_property.description = p.description;
                        existing_property.value_data_type = p.value_data_type;
                        existing_property.defualt_value = p.defualt_value;

                        foreach (var option in db.scene_property_option.Where(o => o.scene_property_id == existing_property.id).ToArray())
                        {
                            db.DeleteObject(option);
                        }

                        foreach (scene_property_option spo in p.scene_property_option)
                            existing_property.scene_property_option.Add(new scene_property_option { option = spo.option });

                    }
                    db.SaveChanges();
                }
            }
        }
 public static void Run(builtin_command_que cmd)
 {
     using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
     {
         db.builtin_command_que.AddObject(cmd);
         db.SaveChanges();
         BuiltinCommandAddedToQue(cmd.id);
     }
 }
 public static void Run(device_type_command_que cmd)
 {
     using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
     {
         db.device_type_command_que.AddObject(cmd);
         db.SaveChanges();
         DeviceTypeCommandAddedToQue(cmd.id);
     }
 }
        void btn_Click_Property_Set(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            scene_property property = (scene_property)btn.Tag;

            string arg = String.Empty;

            switch ((Data_Types)property.value_data_type)
            {
                case Data_Types.NONE:
                    break;
                case Data_Types.DECIMAL:
                case Data_Types.INTEGER:
                case Data_Types.SHORT:
                case Data_Types.BYTE:
                    //NumericUpDown have built in self validation
                    if (pnlSceneProperties.Controls.ContainsKey(property.id + "-proparg"))
                        arg = ((NumericUpDown)pnlSceneProperties.Controls[property.id + "-proparg"]).Value.ToString();
                    break;
                case Data_Types.BOOL:
                    if (pnlSceneProperties.Controls.ContainsKey(property.id + "-proparg"))
                        arg = ((CheckBox)pnlSceneProperties.Controls[property.id + "-proparg"]).Checked.ToString();
                    break;
                case Data_Types.STRING:
                    if (pnlSceneProperties.Controls.ContainsKey(property.id + "-proparg"))
                        arg = ((TextBox)pnlSceneProperties.Controls[property.id + "-proparg"]).Text;
                    break;
                case Data_Types.LIST:
                    if (pnlSceneProperties.Controls.ContainsKey(property.id + "-proparg"))
                        arg = ((ComboBox)pnlSceneProperties.Controls[property.id + "-proparg"]).Text;
                    break;
            }

            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                scene scene = db.scenes.FirstOrDefault(s => s.id == Scene_ID);
                if (scene != null)
                {
                    if (scene.scene_property_value.Any(sp => sp.scene_property_id == property.id))
                        scene.scene_property_value.FirstOrDefault(sp => sp.scene_property_id == property.id).value = arg;
                    else
                        scene.scene_property_value.Add(new scene_property_value { value = arg, scene_property_id = property.id });

                    db.SaveChanges();
                }
            }
            zvsEntityControl.CallSceneModified(this, Scene_ID);
        }
Exemplo n.º 6
0
        private void btnAddOne_Click(object sender, EventArgs e)
        {
            group selected_group = (group)cboGroups.SelectedItem;

            if (selected_group != null)
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    foreach (device d in lstNotAdded.SelectedObjects)
                    {
                        db.group_devices.AddObject(new group_devices { device_id = d.id, group_id = selected_group.id });
                    }
                    db.SaveChanges();
                }
                zvsEntityControl.CallDeviceModified(this, "group");
                RebindGroup();
            }
        }
Exemplo n.º 7
0
 public static void InstallBuiltInCommand(builtin_commands c)
 {
     using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
     {
         builtin_commands existing_c = db.builtin_commands.FirstOrDefault(cmd => cmd.name == c.name);
         if (existing_c == null)
         {
             db.builtin_commands.AddObject(c);
         }
         else
         {
             existing_c.friendly_name = c.friendly_name;
             existing_c.custom_data1 = c.custom_data1;
             existing_c.custom_data2 = c.custom_data2;
             existing_c.show_on_dynamic_obj_list = c.show_on_dynamic_obj_list;
             existing_c.arg_data_type = c.arg_data_type;
         }
         db.SaveChanges();
     }
 }
Exemplo n.º 8
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Object Name
            if (String.IsNullOrEmpty(textBoxName.Text))
                MessageBox.Show("Invalid Object Name", zvsEntityControl.zvsNameAndVersion);
            else
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    device d = db.devices.FirstOrDefault(o => o.id == device_id);
                    if (d != null)
                    {
                        d.friendly_name = textBoxName.Text;
                        db.SaveChanges();

                        //Call event
                        zvsEntityControl.CallDeviceModified(this, "friendly_name");
                    }
                }
            }
        }
Exemplo n.º 9
0
        public static void DefineOrUpdateProgramOption(program_options opt)
        {
            if (opt != null)
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    program_options existing_option = db.program_options.FirstOrDefault(o => o.name == opt.name);

                    if (existing_option == null)
                    {
                        db.program_options.AddObject(opt);
                    }
                    else
                    {
                        //Update
                        existing_option.name = opt.name;
                        existing_option.value = opt.value;
                    }
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 10
0
        protected Plugin(string Plugin_Name, string Plugin_Friendly_Name, string Plugin_Description)
        {
            _name = Plugin_Name;
            Friendly_Name = Plugin_Friendly_Name;
            Description = Plugin_Description;

            using (var context = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                plugin pl = context.plugins.FirstOrDefault(p => p.name == this._name);

                if (pl != null)
                {
                    pl.friendly_name = Friendly_Name;
                    pl.description = Description;
                }
                else
                {
                    pl = new plugin { name = _name, friendly_name = Friendly_Name, description = Description };
                    context.plugins.AddObject(pl);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 11
0
        private void btnDeleteGroup_Click(object sender, EventArgs e)
        {
            if (cboGroups.SelectedIndex > -1)
            {
                group g = (group)cboGroups.SelectedItem;
                if (g != null)
                {
                    if (
                        MessageBox.Show("Are you sure you want to delete the " + g.name + " group?",
                                        "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        DialogResult.Yes)
                    {
                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                        {
                            db.groups.DeleteObject(g);
                            db.SaveChanges();

                            zvsEntityControl.CallDeviceModified(this, "group");
                        }
                        cboGroups.SelectedIndex = cboGroups.Items.Count - 1;
                    }
                }
            }
        }
Exemplo n.º 12
0
        private void btnRemoveOne_Click(object sender, EventArgs e)
        {
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                group selected_group = db.groups.FirstOrDefault(g => g.id == ((group)cboGroups.SelectedItem).id);
                if (selected_group != null)
                {

                    foreach (device d in lstAdded.SelectedObjects)
                    {
                        group_devices device = selected_group.group_devices.FirstOrDefault(gd => gd.device_id == d.id);
                        db.group_devices.DeleteObject(device);
                    }
                    db.SaveChanges();

                    zvsEntityControl.CallDeviceModified(this, "group");
                    RebindGroup();
                }
            }
        }
Exemplo n.º 13
0
        private void btnNewGroup_Click(object sender, EventArgs e)
        {
            AddEditGroupName FormAddEditGroupName = new AddEditGroupName("");
            FormAddEditGroupName.ShowDialog();

            if (FormAddEditGroupName.DialogResult == DialogResult.OK)
            {
                group new_g = group.Creategroup(0, FormAddEditGroupName.gName);

                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    db.groups.AddObject(new_g);
                    db.SaveChanges();
                }
                RebindGroupList();
                cboGroups.SelectedIndex = cboGroups.Items.Count - 1;
            }
        }
Exemplo n.º 14
0
        private void NotificationHandler()
        {
            //osae.AddToLog("Notification: " + m_notification.GetType().ToString(), false);
            switch (m_notification.GetType())
            {
                case ZWNotification.Type.ValueAdded:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                        {
                            device d = GetDevices(db).FirstOrDefault(o => o.node_id == node.ID);
                            if (d != null)
                            {
                                ZWValueID vid = m_notification.GetValueID();
                                Value value = new Value();
                                value.ValueID = vid;
                                value.Label = m_manager.GetValueLabel(vid);
                                value.Genre = vid.GetGenre().ToString();
                                value.Index = vid.GetIndex().ToString();
                                value.Type = vid.GetType().ToString();
                                value.CommandClassID = vid.GetCommandClassId().ToString();
                                value.Help = m_manager.GetValueHelp(vid);
                                bool read_only = m_manager.IsValueReadOnly(vid);
                                node.AddValue(value);

                                string data = "";
                                bool b = m_manager.GetValueAsString(vid, out data);

                                WriteToLog(Urgency.INFO, "[ValueAdded] Node:" + node.ID + ", Label:" + value.Label + ", Data:" + data + ", result: " + b.ToString());

                                //Values are 'unknown' at this point so dont report a value change.
                                DefineOrUpdateDeviceValue(new device_values
                                {
                                    device_id = d.id,
                                    value_id = vid.GetId().ToString(),
                                    label_name = value.Label,
                                    genre = value.Genre,
                                    index = value.Index,
                                    type = value.Type,
                                    commandClassId = value.CommandClassID,
                                    value = data,
                                    read_only = read_only
                                }, true);

                                #region Install Dynamic Commands

                                if (!read_only)
                                {
                                    Data_Types pType = Data_Types.NONE;

                                    //Set param types for command
                                    switch (vid.GetType())
                                    {
                                        case ZWValueID.ValueType.List:
                                            pType = Data_Types.LIST;
                                            break;
                                        case ZWValueID.ValueType.Byte:
                                            pType = Data_Types.BYTE;
                                            break;
                                        case ZWValueID.ValueType.Decimal:
                                            pType = Data_Types.DECIMAL;
                                            break;
                                        case ZWValueID.ValueType.Int:
                                            pType = Data_Types.INTEGER;
                                            break;
                                        case ZWValueID.ValueType.String:
                                            pType = Data_Types.STRING;
                                            break;
                                        case ZWValueID.ValueType.Short:
                                            pType = Data_Types.SHORT;
                                            break;
                                        case ZWValueID.ValueType.Bool:
                                            pType = Data_Types.BOOL;
                                            break;
                                    }

                                    //Install the Node Specific Command
                                    int order;
                                    switch (value.Genre)
                                    {
                                        case "User":
                                            order = 1;
                                            break;
                                        case "Config":
                                            order = 2;
                                            break;
                                        default:
                                            order = 99;
                                            break;
                                    }

                                    device_commands dynamic_dc = new device_commands
                                    {
                                        device_id = d.id,
                                        name = "DYNAMIC_CMD_" + value.Label.ToUpper(),
                                        friendly_name = "Set " + value.Label,
                                        arg_data_type = (int)pType,
                                        help = value.Help,
                                        custom_data1 = value.Label,
                                        custom_data2 = vid.GetId().ToString(),
                                        sort_order = order
                                    };

                                    //Special case for lists add additional info
                                    if (vid.GetType() == ZWValueID.ValueType.List)
                                    {
                                        //Install the allowed options/values
                                        String[] options;
                                        if (m_manager.GetValueListItems(vid, out options))
                                            foreach (string option in options)
                                                dynamic_dc.device_command_options.Add(new device_command_options { name = option });
                                    }

                                    DefineOrUpdateDeviceCommand(dynamic_dc);
                                }
                                #endregion
                            }
                        }
                        break;
                    }

                case ZWNotification.Type.ValueRemoved:
                    {
                        try
                        {
                            Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                            ZWValueID vid = m_notification.GetValueID();
                            Value val = node.GetValue(vid);

                            WriteToLog(Urgency.INFO, "[ValueRemoved] Node:" + node.ID + ",Label:" + m_manager.GetValueLabel(vid));

                            node.RemoveValue(val);
                            //TODO: Remove from values and command table
                        }
                        catch (Exception ex)
                        {
                            WriteToLog(Urgency.ERROR, "ValueRemoved error: " + ex.Message);
                        }
                        break;
                    }

                case ZWNotification.Type.ValueChanged:
                    {
                        //try
                        //{
                            Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                            ZWValueID vid = m_notification.GetValueID();
                            Value value = new Value();
                            value.ValueID = vid;
                            value.Label = m_manager.GetValueLabel(vid);
                            value.Genre = vid.GetGenre().ToString();
                            value.Index = vid.GetIndex().ToString();
                            value.Type = vid.GetType().ToString();
                            value.CommandClassID = vid.GetCommandClassId().ToString();
                            value.Help = m_manager.GetValueHelp(vid);
                            bool read_only = m_manager.IsValueReadOnly(vid);

                            string data = GetValue(vid);
                            //m_manager.GetValueAsString(vid, out data);

                            WriteToLog(Urgency.INFO,"[ValueChanged] Node:" + node.ID + ", Label:" + value.Label + ", Data:" + data);
                            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                            {
                                device d = GetDevices(db).FirstOrDefault(o => o.node_id == node.ID);

                                if (d != null)
                                {
                                   // d.last_heard_from = DateTime.Now;
                                    //db.SaveChanges();

                                    //Update Device Commands
                                   if (!read_only)
                                    {
                                        //User commands are more important so lets see them first in the GUIs
                                        int order;
                                        switch (value.Genre)
                                        {
                                            case "User":
                                                order = 1;
                                                break;
                                            case "Config":
                                                order = 2;
                                                break;
                                            default:
                                                order = 99;
                                                break;
                                        }

                                        device_commands dc = d.device_commands.FirstOrDefault(c => c.custom_data2 == vid.GetId().ToString());

                                        if (dc != null)
                                        {
                                            //After Value is Added, Value Name other value properties can change so update.
                                            dc.friendly_name = "Set " + value.Label;
                                            dc.help = value.Help;
                                            dc.custom_data1 = value.Label;
                                            dc.sort_order = order;
                                        }
                                    }

                                    //Some dimmers take x number of seconds to dim to desired level.  Therefor the level recieved here initially is a
                                    //level between old level and new level. (if going from 0 to 100 we get 84 here).
                                    //To get the real level repoll the device a second or two after a level change was recieved.
                                    bool EnableDimmerRepoll = false;
                                    bool.TryParse(device_property_values.GetDevicePropertyValue(d.id, "ENABLEREPOLLONLEVELCHANGE"), out EnableDimmerRepoll);

                                    if (FinishedInitialPoll && EnableDimmerRepoll)
                                    {
                                        switch (node.Label)
                                        {
                                            case "Multilevel Switch":
                                            case "Multilevel Power Switch":
                                                {

                                                    switch (value.Label)
                                                    {
                                                        case "Basic":
                                                            device_values dv_basic = d.device_values.FirstOrDefault(v => v.value_id == vid.GetId().ToString());
                                                            if (dv_basic != null)
                                                            {
                                                                string prevVal = dv_basic.value;
                                                                //If it is truely new
                                                                if (!prevVal.Equals(data))
                                                                {
                                                                    System.Timers.Timer t = new System.Timers.Timer();
                                                                    t.Interval = 5000;
                                                                    t.Elapsed += (sender, e) =>
                                                                    {
                                                                        m_manager.RefreshNodeInfo(m_homeId, (byte)d.node_id);
                                                                        t.Enabled = false;
                                                                    };
                                                                    t.Enabled = true;
                                                                }
                                                            }
                                                            break;
                                                    }
                                                    break;
                                                }
                                        }
                                    }

                                    DefineOrUpdateDeviceValue(new device_values
                                    {
                                        device_id = d.id,
                                        value_id = vid.GetId().ToString(),
                                        label_name = value.Label,
                                        genre = value.Genre,
                                        index = value.Index,
                                        type = value.Type,
                                        commandClassId = value.CommandClassID,
                                        value = data,
                                        read_only = read_only
                                    });
                                }
                                else
                                {
                                    WriteToLog(Urgency.WARNING, "Getting changes on an unknown device!");
                                }

                            }
                        //}
                        //catch (Exception ex)
                        //{
                        //    WriteToLog(Urgency.ERROR, "error: " + ex.Message);
                        //}
                        break;
                    }

                case ZWNotification.Type.Group:
                    {
                        WriteToLog(Urgency.INFO, "[Group]"); ;
                        break;
                    }

                case ZWNotification.Type.NodeAdded:
                    {
                        // if this node was in zwcfg*.xml, this is the first node notification
                        // if not, the NodeNew notification should already have been received
                        //if (GetNode(m_notification.GetHomeId(), m_notification.GetNodeId()) == null)
                        //{
                            Node node = new Node();
                            node.ID = m_notification.GetNodeId();
                            node.HomeID = m_notification.GetHomeId();
                            m_nodeList.Add(node);

                            WriteToLog(Urgency.INFO, "[NodeAdded] ID:" + node.ID.ToString() + " Added");
                        //}
                        break;
                    }

                case ZWNotification.Type.NodeNew:
                    {
                        // Add the new node to our list (and flag as uninitialized)
                        Node node = new Node();
                        node.ID = m_notification.GetNodeId();
                        node.HomeID = m_notification.GetHomeId();
                        m_nodeList.Add(node);

                        WriteToLog(Urgency.INFO, "[NodeNew] ID:" + node.ID.ToString() + " Added");
                        break;
                    }

                case ZWNotification.Type.NodeRemoved:
                    {
                        foreach (Node node in m_nodeList)
                        {
                            if (node.ID == m_notification.GetNodeId())
                            {
                                WriteToLog(Urgency.INFO, "[NodeRemoved] ID:" + node.ID.ToString());
                                m_nodeList.Remove(node);
                                break;
                            }
                        }
                        break;
                    }

                case ZWNotification.Type.NodeProtocolInfo:
                    {
                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                        {
                            Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                            if (node != null)
                            {
                                node.Label = m_manager.GetNodeType(m_homeId, node.ID);
                            }
                            string deviceName = "UNKNOWN";
                            device_types device_type = null;

                            if (node != null)
                            {
                                WriteToLog(Urgency.INFO, "[Node Protocol Info] " + node.Label);

                                switch (node.Label)
                                {
                                    case "Toggle Switch":
                                    case "Binary Toggle Switch":
                                    case "Binary Switch":
                                    case "Binary Power Switch":
                                    case "Binary Scene Switch":
                                    case "Binary Toggle Remote Switch":
                                        deviceName = "OpenZWave Switch " + node.ID;
                                        device_type = GetDeviceType("SWITCH", db);
                                        break;
                                    case "Multilevel Toggle Remote Switch":
                                    case "Multilevel Remote Switch":
                                    case "Multilevel Toggle Switch":
                                    case "Multilevel Switch":
                                    case "Multilevel Power Switch":
                                    case "Multilevel Scene Switch":
                                        deviceName = "OpenZWave Dimmer " + node.ID;
                                        device_type = GetDeviceType("DIMMER", db);
                                        break;
                                    case "Multiposition Motor":
                                    case "Motor Control Class A":
                                    case "Motor Control Class B":
                                    case "Motor Control Class C":
                                        deviceName = "Variable Motor Control " + node.ID;
                                        device_type = GetDeviceType("DIMMER", db);
                                        break;
                                    case "General Thermostat V2":
                                    case "Heating Thermostat":
                                    case "General Thermostat":
                                    case "Setback Schedule Thermostat":
                                    case "Setpoint Thermostat":
                                    case "Setback Thermostat":
                                    case "Thermostat":
                                        deviceName = "OpenZWave Thermostat " + node.ID;
                                        device_type = GetDeviceType("THERMOSTAT", db);
                                        break;
                                    case "Static PC Controller":
                                    case "Static Controller":
                                    case "Portable Remote Controller":
                                    case "Portable Installer Tool":
                                    case "Static Scene Controller":
                                    case "Static Installer Tool":
                                        deviceName = "OpenZWave Controller " + node.ID;
                                        device_type = GetDeviceType("CONTROLLER", db);
                                        break;
                                    case "Secure Keypad Door Lock":
                                    case "Advanced Door Lock":
                                    case "Door Lock":
                                    case "Entry Control":
                                        deviceName = "OpenZWave Door Lock " + node.ID;
                                        device_type = GetDeviceType("DOORLOCK", db);
                                        break;
                                    case "Alarm Sensor":
                                    case "Basic Routing Alarm Sensor":
                                    case "Routing Alarm Sensor":
                                    case "Basic Zensor Alarm Sensor":
                                    case "Zensor Alarm Sensor":
                                    case "Advanced Zensor Alarm Sensor":
                                    case "Basic Routing Smoke Sensor":
                                    case "Routing Smoke Sensor":
                                    case "Basic Zensor Smoke Sensor":
                                    case "Zensor Smoke Sensor":
                                    case "Advanced Zensor Smoke Sensor":
                                    case "Routing Binary Sensor":
                                    case "Routing Multilevel Sensor":
                                        deviceName = "OpenZWave Sensor " + node.ID;
                                        device_type = GetDeviceType("SENSOR", db);
                                        break;
                                    default:
                                        {
                                            WriteToLog(Urgency.INFO, "[Node Label] " + node.Label);
                                            break;
                                        }
                                }
                                if (device_type != null)
                                {

                                    device ozw_device = GetDevices(db).FirstOrDefault(d => d.node_id == node.ID);
                                    //If we dont already have the device
                                    if (ozw_device == null)
                                    {
                                        ozw_device = new device
                                        {
                                            node_id = node.ID,
                                            device_types = device_type,
                                            friendly_name = deviceName
                                        };

                                        db.devices.AddObject(ozw_device);
                                        db.SaveChanges();

                                        ozw_device.CallAdded(new EventArgs());
                                    }

                                    #region Last Event Value Storeage
                                    //Node event value placeholder
                                    DefineOrUpdateDeviceValue(new device_values
                                    {
                                        device_id = ozw_device.id,
                                        value_id = LaastEventNameValueId,
                                        label_name = "Last Node Event Value",
                                        genre = "Custom",
                                        index = "0",
                                        type = "Byte",
                                        commandClassId = "0",
                                        value = "0",
                                        read_only = true
                                    });

                                    #endregion
                                }
                                else
                                    WriteToLog(Urgency.WARNING, string.Format("Found unknown device '{0}', node #{1}!", node.Label, node.ID));

                            }
                        }
                        break;
                    }

                case ZWNotification.Type.NodeNaming:
                    {
                        string ManufacturerNameValueId = "9999058723211334120";
                        string ProductNameValueId = "9999058723211334121";
                        string NodeLocationValueId = "9999058723211334122";
                        string NodeNameValueId = "9999058723211334123";

                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {

                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        if (node != null)
                        {
                            node.Manufacturer = m_manager.GetNodeManufacturerName(m_homeId, node.ID);
                            node.Product = m_manager.GetNodeProductName(m_homeId, node.ID);
                            node.Location = m_manager.GetNodeLocation(m_homeId, node.ID);
                            node.Name = m_manager.GetNodeName(m_homeId, node.ID);

                            device d = GetDevices(db).FirstOrDefault(o => o.node_id == node.ID);
                            if (d != null)
                            {
                                //lets store the manufacturer name and product name in the values table.
                                //Giving ManufacturerName a random value_id 9999058723211334120
                                DefineOrUpdateDeviceValue(new device_values
                                {
                                    device_id = d.id,
                                    value_id = ManufacturerNameValueId,
                                    label_name = "Manufacturer Name",
                                    genre = "Custom",
                                    index = "0",
                                    type = "String",
                                    commandClassId = "0",
                                    value = node.Manufacturer,
                                    read_only = true
                                });
                                DefineOrUpdateDeviceValue(new device_values
                                {
                                    device_id = d.id,
                                    value_id = ProductNameValueId,
                                    label_name = "Product Name",
                                    genre = "Custom",
                                    index = "0",
                                    type = "String",
                                    commandClassId = "0",
                                    value = node.Product,
                                    read_only = true
                                });
                                DefineOrUpdateDeviceValue(new device_values
                                {
                                    device_id = d.id,
                                    value_id = NodeLocationValueId,
                                    label_name = "Node Location",
                                    genre = "Custom",
                                    index = "0",
                                    type = "String",
                                    commandClassId = "0",
                                    value = node.Location,
                                    read_only = true
                                });
                                DefineOrUpdateDeviceValue(new device_values
                                {
                                    device_id = d.id,
                                    value_id = NodeNameValueId,
                                    label_name = "Node Name",
                                    genre = "Custom",
                                    index = "0",
                                    type = "String",
                                    commandClassId = "0",
                                    value = node.Name,
                                    read_only = true
                                });
                            }
                        }
                        WriteToLog(Urgency.INFO, "[NodeNaming] Node:" + node.ID + ", Product:" + node.Product + ", Manufacturer:" + node.Manufacturer + ")");
                        }
                        break;
                    }

                case ZWNotification.Type.NodeEvent:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());
                        byte gevent = m_notification.GetEvent();

                        if (node != null)
                        {
                            WriteToLog(Urgency.INFO, string.Format("[NodeEvent] Node: {0}, Event Byte: {1}", node.ID, gevent));

                            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                            {
                                #region Last Event Value Storeage
                                device d = GetDevices(db).FirstOrDefault(o => o.node_id == node.ID);
                                if (d != null)
                                {
                                    //Node event value placeholder
                                    device_values dv = d.device_values.FirstOrDefault(v => v.value_id == LaastEventNameValueId);
                                    if (dv != null)
                                    {
                                        dv.value = gevent.ToString();
                                        db.SaveChanges();

                                        //Since events are differently than values fire the value change event every time we recieve the event regardless if
                                        //it is the same value or not.
                                        dv.DeviceValueDataChanged(new device_values.ValueDataChangedEventArgs { device_value_id  = dv.id, previousValue = string.Empty});
                                    }
                                }
                                #endregion
                            }
                        }
                        break;

                    }

                case ZWNotification.Type.PollingDisabled:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());

                        if (node != null)
                        {
                            WriteToLog(Urgency.INFO, "[PollingDisabled] Node:" + node.ID);
                        }

                        break;
                    }

                case ZWNotification.Type.PollingEnabled:
                    {
                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());

                        if (node != null)
                        {
                            WriteToLog(Urgency.INFO, "[PollingEnabled] Node:" + node.ID);
                        }
                        break;
                    }

                case ZWNotification.Type.DriverReady:
                    {
                        m_homeId = m_notification.GetHomeId();
                        WriteToLog(Urgency.INFO, "Initializing: Driver with Home ID 0x" + m_homeId);
                        WriteToLog(Urgency.INFO, "[DriverReady] Initializing...driver with Home ID 0x" + m_homeId);
                        break;
                    }

                case ZWNotification.Type.NodeQueriesComplete:
                    {

                        Node node = GetNode(m_notification.GetHomeId(), m_notification.GetNodeId());

                        if (node != null)
                        {
                            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                            {
                                device d = GetDevices(db).FirstOrDefault(o => o.node_id == node.ID);
                                if (d != null)
                                {
                                    d.last_heard_from = DateTime.Now;
                                }
                                db.SaveChanges();

                                zvsEntityControl.CallDeviceModified(d, "last_heard_from");
                            }

                            WriteToLog(Urgency.INFO, "Initializing: Node " + node.ID + " query complete.");
                            WriteToLog(Urgency.INFO, "[NodeQueriesComplete] Initializing...node " + node.ID + " query complete.");
                        }

                        break;
                    }

                case ZWNotification.Type.AllNodesQueried:
                    {
                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                        {
                            foreach (Node n in m_nodeList)
                            {
                                device d = GetDevices(db).FirstOrDefault(o => o.node_id == n.ID);

                                if (d != null)
                                {
                                    if (device_property_values.GetDevicePropertyValue(d.id, "ENABLEPOLLING").ToUpper().Equals("TRUE"))
                                        EnablePolling(n.ID);
                                }
                            }
                        }

                        WriteToLog(Urgency.INFO, "Ready:  All nodes queried. Plug-in now ready.");
                        IsReady = true;

                        FinishedInitialPoll = true;
                        break;
                    }

                case ZWNotification.Type.AwakeNodesQueried:
                    {
                        using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                        {
                            foreach (Node n in m_nodeList)
                            {
                                device d = GetDevices(db).FirstOrDefault(o => o.node_id == n.ID);

                                if (d != null)
                                {
                                    if (device_property_values.GetDevicePropertyValue(d.id, "ENABLEPOLLING").ToUpper().Equals("TRUE"))
                                        EnablePolling(n.ID);
                                }
                            }
                        }

                        WriteToLog(Urgency.INFO, "Ready:  Awake nodes queried (but not some sleeping nodes).");
                        IsReady = true;

                        FinishedInitialPoll = true;

                        break;
                    }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            scene_commands scmd;
               using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
               {
               if (editing)
                   scmd = db.scene_commands.FirstOrDefault(c => c.id == scenecmd_id_to_edit.Value);
               else
               {
                   scmd = new scene_commands();
                   scmd.device_id = device_id;
                   scmd.scene_id = scene_id.Value;
                   scmd.sort_order = positionInList;
               }

               //Update the command type, command id, and arg
               if (radioBtnTypeCommand.Checked)
               {
                   device_type_commands selected_cmd = (device_type_commands)comboBoxCommands.SelectedItem;
                   if (selected_cmd == null)
                   {
                       MessageBox.Show("Please select a command!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                       return;
                   }
                   scmd.command_id = selected_cmd.id;
                   scmd.command_type_id = (int)command_types.device_type_command;
                   string userInput = GetUserInput((Data_Types)selected_cmd.arg_data_type);

                   if (userInput == null)
                       return;
                   else
                       scmd.arg = userInput;
               }
               else
               {
                   device_commands selected_cmd = (device_commands)comboBoxCommands.SelectedItem;
                   if (selected_cmd == null)
                   {
                       MessageBox.Show("Please select a command!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                       return;
                   }

                   scmd.command_id = selected_cmd.id;
                   scmd.command_type_id = (int)command_types.device_command;

                   string userInput = GetUserInput((Data_Types)selected_cmd.arg_data_type);

                   if (userInput == null)
                       return;
                   else
                       scmd.arg = userInput;
               }

               if (!editing)
                   db.scene_commands.AddObject(scmd);

               db.SaveChanges();
               }
               zvsEntityControl.CallSceneModified(this, null);

               this.Close();
        }
Exemplo n.º 16
0
        protected override bool StartPlugin()
        {
            WriteToLog(Urgency.INFO, this.Friendly_Name + " plugin started.");

            // The USB-UIRT device
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                device usbUirt = GetDevices(db).FirstOrDefault(d => d.node_id == ControllerNodeId);
                //If we dont already have the device
                if (usbUirt == null)
                {
                    usbUirt = new device
                    {
                        node_id = ControllerNodeId,
                        device_types = GetDeviceType("USBUIRT", db),
                        friendly_name = "USB-UIRT"
                    };

                    db.devices.AddObject(usbUirt);
                    db.SaveChanges();

                    usbUirt.CallAdded(new EventArgs());
                }
            }

            IsReady = true;
            return true;
        }
Exemplo n.º 17
0
        private void button_SaveTask_Click(object sender, EventArgs e)
        {
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                scheduled_tasks SelectedTask = db.scheduled_tasks.FirstOrDefault(o => o.id == ((scheduled_tasks)dataListTasks.SelectedObject).id);
                if (SelectedTask != null)
                {
                    //Action
                    if (comboBox_ActionsTask.SelectedIndex != -1)
                    {
                        scene SelectedScene = (scene)comboBox_ActionsTask.SelectedItem;
                        if (SelectedScene != null)
                            SelectedTask.Scene_id = SelectedScene.id;
                    }
                    else
                    {
                        MessageBox.Show("Error Saving\n\nPlease select a scene to activate before saving.", ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //Task Name
                    if (textBox_TaskName.Text != "")
                        SelectedTask.friendly_name = textBox_TaskName.Text;
                    else
                    {
                        MessageBox.Show("Error Saving\n\nTask name not vaild.", ProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //Frequency
                    SelectedTask.Frequency = (int)Enum.Parse(typeof(scheduled_tasks.frequencys), comboBox_FrequencyTask.SelectedItem.ToString());

                    //Endabled
                    SelectedTask.Enabled = checkBox_EnabledTask.Checked;

                    //DateTime
                    SelectedTask.StartTime = dateTimePickerStartTask.Value;

                    //Recur Days
                    if (comboBox_FrequencyTask.SelectedValue.ToString().Equals(scheduled_tasks.frequencys.Daily.ToString()))
                    {
                        SelectedTask.RecurDays = (int)numericUpDownOccurDays.Value;
                    }
                    else if (comboBox_FrequencyTask.SelectedValue.ToString().Equals(scheduled_tasks.frequencys.Seconds.ToString()))
                    {
                        SelectedTask.RecurSeconds = (int)numericUpDownOccurSeconds.Value;
                    }
                    else if (comboBox_FrequencyTask.SelectedValue.ToString().Equals(scheduled_tasks.frequencys.Weekly.ToString()))
                    {
                        #region Weekly
                        SelectedTask.RecurWeeks = (int)numericUpDownOccurWeeks.Value;
                        SelectedTask.RecurMonday = checkBox_RecurMonday.Checked;
                        SelectedTask.RecurTuesday = checkBox_RecurTuesday.Checked;
                        SelectedTask.RecurWednesday = checkBox_RecurWednesday.Checked;
                        SelectedTask.RecurThursday = checkBox_RecurThursday.Checked;
                        SelectedTask.RecurFriday = checkBox_RecurFriday.Checked;
                        SelectedTask.RecurSaturday = checkBox_RecurSaturday.Checked;
                        SelectedTask.RecurSunday = checkBox_RecurSunday.Checked;
                        #endregion
                    }
                    else if (comboBox_FrequencyTask.SelectedValue.ToString().Equals(scheduled_tasks.frequencys.Monthly.ToString()))
                    {
                        #region Monthly
                        SelectedTask.RecurMonth = (int)numericUpDownOccurMonths.Value;
                        SelectedTask.RecurDay01 = checkBoxDay01.Checked;
                        SelectedTask.RecurDay02 = checkBoxDay02.Checked;
                        SelectedTask.RecurDay03 = checkBoxDay03.Checked;
                        SelectedTask.RecurDay04 = checkBoxDay04.Checked;
                        SelectedTask.RecurDay05 = checkBoxDay05.Checked;
                        SelectedTask.RecurDay06 = checkBoxDay06.Checked;
                        SelectedTask.RecurDay07 = checkBoxDay07.Checked;
                        SelectedTask.RecurDay08 = checkBoxDay08.Checked;
                        SelectedTask.RecurDay09 = checkBoxDay09.Checked;
                        SelectedTask.RecurDay10 = checkBoxDay10.Checked;
                        SelectedTask.RecurDay11 = checkBoxDay11.Checked;
                        SelectedTask.RecurDay12 = checkBoxDay12.Checked;
                        SelectedTask.RecurDay13 = checkBoxDay13.Checked;
                        SelectedTask.RecurDay14 = checkBoxDay14.Checked;
                        SelectedTask.RecurDay15 = checkBoxDay15.Checked;
                        SelectedTask.RecurDay16 = checkBoxDay16.Checked;
                        SelectedTask.RecurDay17 = checkBoxDay17.Checked;
                        SelectedTask.RecurDay18 = checkBoxDay18.Checked;
                        SelectedTask.RecurDay19 = checkBoxDay19.Checked;
                        SelectedTask.RecurDay20 = checkBoxDay20.Checked;
                        SelectedTask.RecurDay21 = checkBoxDay21.Checked;
                        SelectedTask.RecurDay22 = checkBoxDay22.Checked;
                        SelectedTask.RecurDay23 = checkBoxDay23.Checked;
                        SelectedTask.RecurDay24 = checkBoxDay24.Checked;
                        SelectedTask.RecurDay25 = checkBoxDay25.Checked;
                        SelectedTask.RecurDay26 = checkBoxDay26.Checked;
                        SelectedTask.RecurDay27 = checkBoxDay27.Checked;
                        SelectedTask.RecurDay28 = checkBoxDay28.Checked;
                        SelectedTask.RecurDay29 = checkBoxDay29.Checked;
                        SelectedTask.RecurDay30 = checkBoxDay30.Checked;
                        SelectedTask.RecurDay31 = checkBoxDay31.Checked;
                        #endregion
                    }

                    db.SaveChanges();

                    zvsEntityControl.CallScheduledTaskModified(this, "multiple_properties");
                }
            }
        }
Exemplo n.º 18
0
        private void btnEdit_Click_1(object sender, EventArgs e)
        {
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                group selected_group = db.groups.FirstOrDefault(g => g.id == ((group)cboGroups.SelectedItem).id);
                if (selected_group != null)
                {
                    AddEditGroupName FormAddEditGroupName = new AddEditGroupName(selected_group.name);
                    FormAddEditGroupName.ShowDialog();

                    if (FormAddEditGroupName.DialogResult == DialogResult.OK)
                    {
                        selected_group.name = FormAddEditGroupName.gName;
                        db.SaveChanges();
                        zvsEntityControl.CallDeviceModified(this, "group");
                    }
                }
            }
        }
        private void btn_Save_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_name.Text))
            {
                MessageBox.Show("Please enter a name for this trigger.", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                ActiveControl = txt_name;
                return;
            }

            if (string.IsNullOrEmpty(txTriggertValue.Text))
            {
                MessageBox.Show("Please enter a trigger value for this trigger.", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                ActiveControl = txt_name;
                return;
            }

            device_values selected_device_value = (device_values)cmbo_devicevalues.SelectedItem;
            if (selected_device_value == null)
            {
                MessageBox.Show("Please select a device value for this trigger.", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                ActiveControl = cmbo_devicevalues;
                return;
            }

            scene selected_scene = (scene)cmbo_scene.SelectedItem;
            if (selected_scene == null)
            {
                MessageBox.Show("Please select a scene for this trigger.", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                ActiveControl = cmbo_scene;
                return;
            }

            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                device_value_triggers trigger_to_edit;
                if (trigger_to_edit_id.HasValue)
                {
                    trigger_to_edit = db.device_value_triggers.FirstOrDefault(o => o.id == trigger_to_edit_id.Value);
                }
                else
                {
                    trigger_to_edit = new device_value_triggers();
                }

                trigger_to_edit.device_value_id = selected_device_value.id;
                trigger_to_edit.enabled = true;
                trigger_to_edit.trigger_value = txTriggertValue.Text;
                trigger_to_edit.trigger_operator = (int)cmbo_operator.SelectedItem;
                trigger_to_edit.scene_id = selected_scene.id;
                trigger_to_edit.Name = txt_name.Text;
                trigger_to_edit.enabled = checkBoxEnabled.Checked;
                trigger_to_edit.trigger_type = (int)device_value_triggers.TRIGGER_TYPE.Basic;

                //if we are not editing add new trigger to trigger list
                if (!trigger_to_edit_id.HasValue)
                    db.device_value_triggers.AddObject(trigger_to_edit);

                db.SaveChanges();
            }
            zvsEntityControl.CallTriggerModified(this, "modified");
            this.Close();
        }
Exemplo n.º 20
0
        void ExecuteScene_DoWork(object sender, DoWorkEventArgs e)
        {
            //Use a new context here to thread safety
            using (zvsEntities2 context = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                //Find Scene
                scene _scene = context.scenes.FirstOrDefault(s => s.id == (long)e.Argument);
                if (_scene != null)
                {
                    e.Result = (long)e.Argument;
                    errorCount = 0;
                    foreach (scene_commands sCMD in _scene.scene_commands.OrderBy(o => o.sort_order))
                    {
                        switch ((command_types)sCMD.command_type_id)
                        {
                            case command_types.builtin:
                                {
                                    builtin_commands cmd = context.builtin_commands.FirstOrDefault(c => c.id == sCMD.command_id);
                                    if (cmd != null)
                                    {
                                        if (cmd.name.Equals("TIMEDELAY"))
                                        {
                                            int delay = 0;
                                            int.TryParse(sCMD.arg, out delay);
                                            if (delay > 0)
                                                System.Threading.Thread.Sleep(delay * 1000);
                                        }
                                        else
                                        {
                                            Waiting = true;
                                            builtin_command_que.BuiltinCommandRunCompleteEvent += new builtin_command_que.BuiltinCommandRunCompleteEventHandler(builtin_command_que_BuiltinCommandRunCompleteEvent);

                                            builtin_command_que b_cmd = builtin_command_que.Createbuiltin_command_que(0, sCMD.arg, sCMD.command_id);
                                            context.builtin_command_que.AddObject(b_cmd);
                                            context.SaveChanges();
                                            CmdWaitingForProcessingQueID = b_cmd.id;
                                            //trigger the event
                                            builtin_command_que.BuiltinCommandAddedToQue(b_cmd.id);

                                            while (Waiting)
                                                System.Threading.Thread.Sleep(300);

                                            builtin_command_que.BuiltinCommandRunCompleteEvent -= new builtin_command_que.BuiltinCommandRunCompleteEventHandler(builtin_command_que_BuiltinCommandRunCompleteEvent);
                                        }
                                    }
                                    break;
                                }
                            case command_types.device_command:
                                {
                                    Waiting = true;
                                    device_command_que.DeviceCommandRunCompleteEvent += new device_command_que.DeviceCommandRunCompleteEventHandler(device_command_que_DeviceCommandRunCompleteEvent);

                                    device_command_que d_cmd = device_command_que.Createdevice_command_que(0, sCMD.device_id.Value, sCMD.command_id, sCMD.arg);
                                    context.device_command_que.AddObject(d_cmd);
                                    context.SaveChanges();
                                    CmdWaitingForProcessingQueID = d_cmd.id;
                                    device_command_que.DeviceCommandAddedToQue(d_cmd.id);

                                    while (Waiting)
                                        System.Threading.Thread.Sleep(300);

                                    device_command_que.DeviceCommandRunCompleteEvent -= new device_command_que.DeviceCommandRunCompleteEventHandler(device_command_que_DeviceCommandRunCompleteEvent);

                                    break;
                                }
                            case command_types.device_type_command:
                                {
                                    Waiting = true;
                                    device_type_command_que.DeviceTypeCommandRunCompleteEvent += new device_type_command_que.DeviceTypeCommandRunCompleteEventHandler(device_type_command_que_DeviceTypeCommandRunCompleteEvent);

                                    device_type_command_que dt_cmd = device_type_command_que.Createdevice_type_command_que(0, sCMD.command_id, sCMD.device_id.Value, sCMD.arg);
                                    context.device_type_command_que.AddObject(dt_cmd);
                                    context.SaveChanges();
                                    CmdWaitingForProcessingQueID = dt_cmd.id;
                                    device_type_command_que.DeviceTypeCommandAddedToQue(dt_cmd.id);

                                    while (Waiting)
                                        System.Threading.Thread.Sleep(300);

                                    device_type_command_que.DeviceTypeCommandRunCompleteEvent -= new device_type_command_que.DeviceTypeCommandRunCompleteEventHandler(device_type_command_que_DeviceTypeCommandRunCompleteEvent);

                                    break;
                                }
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        private void deleteCommandToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to delete the selected scene command(s)?",
                                zvsEntityControl.zvsNameAndVersion,
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    foreach (scene_commands selected_sceneCMD in dataListViewSceneCMDs.SelectedObjects)
                    {
                        scene_commands cmd = db.scene_commands.FirstOrDefault(c => c.id == selected_sceneCMD.id);
                        if (cmd != null)
                            db.scene_commands.DeleteObject(cmd);
                    }

                    db.SaveChanges();

                    zvsEntityControl.CallSceneModified(this, null);
                }
            }
        }
Exemplo n.º 22
0
        private void dataListViewScenes_ModelDropped_1(object sender, ModelDropEventArgs e)
        {
            int TargetIndex = 0;

            //Handle if dropped into empty Action box
            if (e.TargetModel == null)
                TargetIndex = 0;
            else
                TargetIndex = e.DropTargetIndex;

            if (e.SourceModels[0].GetType().Equals(typeof(scene)))
            {
                switch (e.DropTargetLocation)
                {
                    case DropTargetLocation.AboveItem:
                        //offset = 0
                        dataListViewScenes.MoveObjects(TargetIndex, e.SourceModels);
                        dataListViewScenes.SelectedObjects = e.SourceModels;
                        break;
                    case DropTargetLocation.BelowItem:
                        //offset = 1
                        dataListViewScenes.MoveObjects(TargetIndex +1, e.SourceModels);
                        dataListViewScenes.SelectedObjects = e.SourceModels;
                        break;
                }
            }

            //SAve the sort order to the DB
            foreach (scene scene_in_list in dataListViewScenes.Objects)
            {
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    scene scene = db.scenes.FirstOrDefault(s => s.id == scene_in_list.id);
                    if (scene != null)
                    {
                        scene.sort_order = dataListViewScenes.IndexOf(scene_in_list);
                    }
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 23
0
        private void dataListViewSceneCMDs_ModelDropped(object sender, ModelDropEventArgs e)
        {
            int TargetIndex = 0;

            //Handle if dropped into empty Action box
            if (e.TargetModel == null)
                TargetIndex = 0;
            else
                TargetIndex = e.DropTargetIndex;

            // Handle Device Drop
            if (e.SourceModels[0].GetType().Equals(typeof(device)))
            {
                scene scene = (scene)dataListViewScenes.SelectedObject;
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    scene selected_scene = db.scenes.FirstOrDefault(c => c.id == scene.id);
                    if (selected_scene != null)
                    {
                        if (selected_scene.is_running)
                        {
                            MessageBox.Show("Cannot modify scene when it is running.", ProgramName);
                            return;
                        }

                        foreach (device selected_device in e.SourceModels)
                        {
                            if (selected_device != null)
                            {
                                int pos = TargetIndex;
                                switch (e.DropTargetLocation)
                                {
                                    case DropTargetLocation.BelowItem:
                                        pos += 1;
                                        break;
                                }

                                AddEditSceneDeviceCMD addCMDform = new AddEditSceneDeviceCMD(null, selected_device.id, selected_scene.id, pos);
                                addCMDform.ShowDialog();

                            }
                        }
                    }
                }
            }
            else if (e.SourceModels[0].GetType().Equals(typeof(scene_commands)))
            {
                //Rearrage Actions
                scene scene = (scene)dataListViewScenes.SelectedObject;
                using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
                {
                    scene selected_scene = db.scenes.FirstOrDefault(c => c.id == scene.id);
                    if (selected_scene != null)
                    {
                        if (selected_scene.is_running)
                        {
                            MessageBox.Show("Cannot modify scene when it is running.", ProgramName);
                            return;
                        }

                        switch (e.DropTargetLocation)
                        {
                            case DropTargetLocation.AboveItem:
                                //offset = 0
                                dataListViewSceneCMDs.MoveObjects(TargetIndex, e.SourceModels);
                                dataListViewSceneCMDs.SelectedObjects = e.SourceModels;
                                break;
                            case DropTargetLocation.BelowItem:
                                //offset = 1
                                dataListViewSceneCMDs.MoveObjects(TargetIndex + 1, e.SourceModels);
                                dataListViewSceneCMDs.SelectedObjects = e.SourceModels;
                                break;
                        }

                        //SAve the sort order to the DB
                        foreach (scene_commands cmd in dataListViewSceneCMDs.Objects)
                        {
                            scene_commands scene_cmd = db.scene_commands.FirstOrDefault(s => s.id == cmd.id);
                            if (scene_cmd != null)
                            {
                                scene_cmd.sort_order = dataListViewSceneCMDs.IndexOf(cmd);
                            }
                            db.SaveChanges();
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
        private void AddNewTask()
        {
            scheduled_tasks task = new scheduled_tasks { friendly_name = "New Task", Frequency = (int)scheduled_tasks.frequencys.Daily, Scene_id = 0, Enabled = false };

            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                db.scheduled_tasks.AddObject(task);
                db.SaveChanges();
                zvsEntityControl.CallScheduledTaskModified(this, "added");
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            builtin_commands selected_cmd = (builtin_commands)comboBoxCommand.SelectedItem;

            scene_commands scmd;
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                if (editing)
                    scmd = db.scene_commands.FirstOrDefault(c => c.id == scenecmd_id_to_edit.Value);
                else
                {
                    scmd = new scene_commands();
                    scmd.scene_id = selected_scene_id.Value;
                }
                scmd.command_type_id = (int)command_types.builtin;
                scmd.command_id = selected_cmd.id;

                //Do Custom things for some Builtin Commands
                switch (selected_cmd.name)
                {
                    case "REPOLL_ME":
                        {
                            device d = (device)cmbo.SelectedItem;

                            if (d == null)
                            {
                                MessageBox.Show("Please select a deice!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            else
                                scmd.arg = d.id.ToString();

                            break;
                        }
                    case "GROUP_ON":
                    case "GROUP_OFF":
                        {
                            group g = (group)cmbo.SelectedItem;
                            if (g == null)
                            {
                                MessageBox.Show("Please select a group!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                return;
                            }
                            else
                                scmd.arg = g.id.ToString();

                            break;
                        }
                    default:
                        switch ((Data_Types)selected_cmd.arg_data_type)
                        {
                            case Data_Types.NONE:
                                scmd.arg = string.Empty;
                                break;
                            case Data_Types.BOOL:
                                scmd.arg = cb.Checked.ToString();
                                break;
                            case Data_Types.LIST:
                                if (String.IsNullOrEmpty(cmbo.Text))
                                {
                                    MessageBox.Show("Please select a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                scmd.arg = cmbo.Text;
                                break;
                            case Data_Types.STRING:
                                if (String.IsNullOrEmpty(tbx.Text))
                                {
                                    MessageBox.Show("Please enter a vaule!", zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                    return;
                                }
                                scmd.arg = tbx.Text;
                                break;
                            case Data_Types.BYTE:
                            case Data_Types.DECIMAL:
                            case Data_Types.INTEGER:
                            case Data_Types.SHORT:
                                scmd.arg = Numeric.Value.ToString();
                                break;
                        }
                        break;
                }

                if (!editing)
                    db.scene_commands.AddObject(scmd);

                db.SaveChanges();
            }
            zvsEntityControl.CallSceneModified(this, null);

            this.Close();
        }
Exemplo n.º 26
0
        protected void CreateNewInfraredDevice(string deviceName)
        {
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                device ir_device = GetDevices(db).FirstOrDefault(d => d.friendly_name == deviceName);
                if (ir_device == null)
                {
                    ir_device = new device
                    {
                        device_types = GetDeviceType("INFRARED", db),
                        friendly_name = deviceName
                    };

                    db.devices.AddObject(ir_device);
                    db.SaveChanges();

                    ir_device.CallAdded(new EventArgs());
                }
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Save Dynamic Settings
            #region Dynamic Settings
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                plugin p = db.plugins.FirstOrDefault(o => o.name.Equals(APIName));
                if (p != null)
                {
                    //SAVE PLUGIN SETTINGS
                    if (p.plugin_settings != null)
                    {
                        //SAVE SETTIMGS
                        foreach (plugin_settings ps in p.plugin_settings)  //For Each Plugin Setting
                        {
                            string Identifer = ps.id + "-plugin_setting_arg";
                            foreach (Control c in pnlSettings.Controls)  //Find Control
                            {
                                if (c.Name.Equals(Identifer))
                                {
                                    switch ((Data_Types)c.Tag)  //Save entered setting depending on type.
                                    {
                                        case Data_Types.NONE:
                                            break;
                                        case Data_Types.DECIMAL:
                                        case Data_Types.INTEGER:
                                        case Data_Types.SHORT:
                                        case Data_Types.BYTE:
                                        case Data_Types.COMPORT:
                                            ps.value = ((NumericUpDown)c).Value.ToString();
                                            break;
                                        case Data_Types.BOOL:
                                            ps.value = ((CheckBox)c).Checked.ToString();
                                            break;
                                        case Data_Types.STRING:
                                            ps.value = ((TextBox)c).Text;
                                            break;
                                        case Data_Types.LIST:
                                            ps.value = ((ComboBox)c).Text;
                                            break;
                                    }
                                }
                            }
                        }
                    }

                    //Save Builtin Settings
                    #region Enable/Disable
                    Plugin zvsPlugin = (Plugin)cbEnablePlugin.Tag;
                    if (zvsPlugin != null)
                    {
                        if (cbEnablePlugin.Checked)
                        {
                            //Enable
                            if (!zvsPlugin.Enabled)
                            {
                                zvsPlugin.Enabled = true;
                                p.enabled = true;
                                zvsPlugin.Initialize();
                                zvsPlugin.Start();
                            }
                        }
                        else
                        {
                            //Disable
                            if (zvsPlugin.Enabled)
                            {
                                zvsPlugin.Enabled = false;
                                p.enabled = false;

                                if (zvsPlugin.IsRunning)
                                    zvsPlugin.Stop();
                            }
                        }
                    }
                    #endregion

                    db.SaveChanges();
                    labelStatus.Text = string.Format("{0} - {1} settings saved.", DateTime.Now.ToLongTimeString(),p.friendly_name);
                }
            }
            //labelStatus.Text = "Save Failed.";
            //MessageBox.Show("Error saving " + _p.friendly_name + " settings." + Environment.NewLine + Environment.NewLine + ex.Message, zvsEntityControl.zvsNameAndVersion, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            #endregion
        }
Exemplo n.º 28
0
        private void AddScene()
        {
            scene new_s = new scene { friendly_name = "New Scene", sort_order = dataListViewScenes.GetItemCount() + 1 };
            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                db.scenes.AddObject(new_s);
                db.SaveChanges();

                //todo: might case concurency issues
                zvsEntityControl.CallSceneModified(this, new_s.id);
            }
        }
Exemplo n.º 29
0
 void ExecuteScene_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     using (zvsEntities2 context = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
     {
         scene _scene = context.scenes.FirstOrDefault(s => s.id == (long)e.Result);
         if (_scene != null)
         {
             _scene.is_running = false;
             context.SaveChanges();
         }
     }
     zvsEntityControl.SceneRunComplete((long)e.Result, errorCount);
     ExecuteScene.DoWork -= new DoWorkEventHandler(ExecuteScene_DoWork);
     ExecuteScene.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(ExecuteScene_RunWorkerCompleted);
 }
        void btn_Click_Property_Set(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            string arg = String.Empty;

            switch ((Data_Types)btn.Tag)
            {
                case Data_Types.NONE:
                    break;
                case Data_Types.DECIMAL:
                case Data_Types.INTEGER:
                case Data_Types.SHORT:
                case Data_Types.BYTE:
                    //NumericUpDown have built in self validation
                    if (pnlSettings.Controls.ContainsKey(btn.Name + "-proparg"))
                        arg = ((NumericUpDown)pnlSettings.Controls[btn.Name + "-proparg"]).Value.ToString();
                    break;
                case Data_Types.BOOL:
                    if (pnlSettings.Controls.ContainsKey(btn.Name + "-proparg"))
                        arg = ((CheckBox)pnlSettings.Controls[btn.Name + "-proparg"]).Checked.ToString();
                    break;
                case Data_Types.STRING:
                    if (pnlSettings.Controls.ContainsKey(btn.Name + "-proparg"))
                        arg = ((TextBox)pnlSettings.Controls[btn.Name + "-proparg"]).Text;
                    break;
                case Data_Types.LIST:
                    if (pnlSettings.Controls.ContainsKey(btn.Name + "-proparg"))
                        arg = ((ComboBox)pnlSettings.Controls[btn.Name + "-proparg"]).Text;
                    break;
            }

            using (zvsEntities2 db = new zvsEntities2(zvsEntityControl.GetzvsConnectionString))
            {
                device_propertys dp = db.device_propertys.FirstOrDefault(p => p.name == btn.Name);
                if (dp != null)
                {
                    device device = db.devices.FirstOrDefault(d => d.id == device_id);
                    if (device != null)
                    {
                        device_property_values dpv = device.device_property_values.FirstOrDefault(v => v.device_property_id == dp.id);
                        if (dpv != null)
                            dpv.value = arg;
                        else
                            db.device_property_values.AddObject(new device_property_values { device_id = device_id, value = arg, device_property_id = dp.id });

                        db.SaveChanges();
                    }
                }
            }
        }