Beispiel #1
0
        public static OSAEMethodCollection GetObjectMethods(string ObjectName)
        {
            DataSet dataset = new DataSet();
            OSAEMethodCollection methods = new OSAEMethodCollection();

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    command.CommandText = "SELECT method_id, method_name, method_label FROM osae_v_object_method WHERE UPPER(object_name) = UPPER(@ObjectName) OR UPPER(object_alias) = UPPER(@ObjectName) ORDER BY method_name";
                    command.Parameters.AddWithValue("@ObjectName", ObjectName);
                    dataset = OSAESql.RunQuery(command);
                }

                foreach (DataRow drp in dataset.Tables[0].Rows)
                {
                    OSAEMethod method = new OSAEMethod();
                    method.MethodName  = drp["method_name"].ToString();
                    method.MethodLabel = drp["method_label"].ToString();
                    method.Id          = int.Parse(drp["method_id"].ToString());
                    method.ObjectName  = ObjectName;
                    methods.Add(method);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectMethods error: " + ex.Message, true);
            }

            return(methods);
        }
Beispiel #2
0
 public void ExecuteCommand(OSAEMethod method)
 {
     try
     {
         _plugin.ProcessCommand(method);
     }
     catch (Exception ex)
     { Log.Error(PluginName + " - Process Command Error", ex); }
 }
        public static List <OSAEMethod> GetMethodsInQueue()
        {
            List <OSAEMethod> methods = new List <OSAEMethod>();

            using (MySqlCommand command = new MySqlCommand())
            {
                command.CommandText = "SELECT method_queue_id, object_name, address, method_name, method_label, parameter_1, parameter_2, object_owner FROM osae_v_method_queue WHERE object_owner != 'SYSTEM' ORDER BY entry_time";
                DataSet dataset = OSAESql.RunQuery(command);

                foreach (DataRow row in dataset.Tables[0].Rows)
                {
                    object methodId    = row["method_queue_id"];
                    object methodName  = row["method_name"];
                    object methodLabel = row["method_label"];
                    object objectName  = row["object_name"];
                    object parameter1  = row["parameter_1"];
                    object parameter2  = row["parameter_2"];
                    object address     = row["address"];
                    object owner       = row["object_owner"];

                    OSAEMethod method = new OSAEMethod();

                    // These parameters should never be null so we won't check them
                    method.Id          = int.Parse(methodId.ToString());
                    method.MethodName  = methodName.ToString();
                    method.MethodLabel = methodLabel.ToString();
                    method.ObjectName  = objectName.ToString();

                    // These parameters could be null
                    if (parameter1 != null)
                    {
                        method.Parameter1 = parameter1.ToString();
                    }

                    if (parameter2 != null)
                    {
                        method.Parameter2 = parameter2.ToString();
                    }

                    if (address != null)
                    {
                        method.Address = address.ToString();
                    }

                    if (owner != null)
                    {
                        method.Owner = owner.ToString();
                    }

                    methods.Add(method);
                }
            }

            return(methods);
        }
        public static List<OSAEMethod> GetMethodsInQueue()
        {
            List<OSAEMethod> methods = new List<OSAEMethod>();

            using (MySqlCommand command = new MySqlCommand())
            {
                command.CommandText = "SELECT method_queue_id, object_name, address, method_name, method_label, parameter_1, parameter_2, object_owner FROM osae_v_method_queue ORDER BY entry_time";
                DataSet dataset = OSAESql.RunQuery(command);

                foreach (DataRow row in dataset.Tables[0].Rows)
                {
                    object methodId = row["method_queue_id"];
                    object methodName = row["method_name"];
                    object methodLabel = row["method_label"];
                    object objectName = row["object_name"];
                    object parameter1 = row["parameter_1"];
                    object parameter2 = row["parameter_2"];
                    object address = row["address"];
                    object owner = row["object_owner"];

                    OSAEMethod method = new OSAEMethod();

                    // These parameters should never be null so we won't check them
                    method.Id = int.Parse(methodId.ToString());
                    method.MethodName = methodName.ToString();
                    method.MethodLabel = methodLabel.ToString();
                    method.ObjectName = objectName.ToString();

                    // These parameters could be null
                    if (parameter1 != null)
                    {
                        method.Parameter1 = parameter1.ToString();
                    }

                    if (parameter2 != null)
                    {
                        method.Parameter2 = parameter2.ToString();
                    }

                    if (address != null)
                    {
                        method.Address = address.ToString();
                    }

                    if (owner != null)
                    {
                        method.Owner = owner.ToString();
                    }

                    methods.Add(method);
                }
            }

            return methods;
        }
 public void ExecuteCommand(OSAEMethod method)
 {
     try
     {
         _plugin.ProcessCommand(method);
     }
     catch (Exception ex)
     {
         logging.AddToLog(PluginName + " - Process Command Error: " + ex.Message, true);
     }
 }
Beispiel #6
0
 public override void ProcessCommand(OSAEMethod method)
 {
     this.Log.Info("RECEIVED: " + method.ObjectName + " - " + method.MethodName);
     sMethod = method.MethodName;
     camName = method.ObjectName;
     camobj = OSAEObjectManager.GetObjectByName(camName);
     if (sMethod == "SNAPSHOT")
     {
         string i = DateTime.Now.ToLongTimeString();
         string j = DateTime.Now.ToShortDateString();
         i = i.Replace(":", "_");
         j = j.Replace("/", "_");
         i = j + "_" + i;
         i = i.Replace(" ", "");
         try
         {
             string camSnapShot = camobj.Property("camSnapShot").Value;
             string camSloc = camobj.Property("Save Location").Value;
             camSloc = camSloc + @"\";
             string filename = camSloc + camName + "_" + i + ".jpg";
             var URI = new Uri(renameingSys(camSnapShot, "",""));
             WebClient wc = new WebClient();
             wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
             wc.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback2);
             wc.DownloadFile(URI, filename);  
             this.Log.Info(filename + " was created");
         }
         catch (Exception ex)
         {
             this.Log.Error("An error occurred durning the snapshot!!!: " + ex.Message);
         }
     }
     else
     {
         try
         {
             WebClient wc = new WebClient();
             sProperty = camobj.Property(sMethod).Value.ToString();
             wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
             wc.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadStringCallback2);
             sProperty = renameingSys(sProperty, method.Parameter1, method.Parameter2);
             wc.UploadStringAsync(new Uri(sProperty), "POST", "");
             this.Log.Info("SENT TO: " + method.ObjectName + ": " + sProperty);
         }
         catch (Exception ex)
         {
             this.Log.Error("An error occurred!!!: " + ex.Message);
         }
     }
     this.Log.Info("===================================================");
 }
        public void OnMessageReceived(string msgType, string message, string from, DateTime timestamp)
        {
            osae.AddToLog("received message: " + msgType + " | " + message, false);
            switch (msgType)
            {
                case "plugin":
                    string[] arguments = message.Split('|');

                    if (arguments[1] == "True")
                        osae.ObjectStateSet(arguments[0], "ON");
                    else if (arguments[1] == "False")
                        osae.ObjectStateSet(arguments[0], "OFF");

                    foreach (Plugin p in plugins)
                    {

                        if (p.PluginName == arguments[0])
                        {
                            OSAEObject obj = osae.GetObjectByName(p.PluginName);
                            if (obj != null)
                            {
                                bool isSystemPlugin = false;
                                foreach (ObjectProperty p2 in obj.Properties)
                                {
                                    if (p2.Name == "System Plugin")
                                    {
                                        if (p2.Value == "TRUE")
                                            isSystemPlugin = true;
                                        break;
                                    }
                                }
                                if (arguments[1] == "True" && !p.Enabled && !isSystemPlugin)
                                {
                                    osae.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 1);
                                    try
                                    {
                                        if (p.ActivatePlugin())
                                            p.addin.RunInterface(p.PluginName);
                                        osae.AddToLog("Activated plugin: " + p.PluginName, false);
                                    }
                                    catch (Exception ex)
                                    {
                                        osae.AddToLog("Error activating plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                                    }
                                }
                                else if (arguments[1] == "False" && p.Enabled && !isSystemPlugin)
                                {
                                    osae.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 0);
                                    try
                                    {
                                        p.addin.Shutdown();
                                        p.addin = null;
                                        GC.Collect();
                                        p.Enabled = false;
                                        osae.AddToLog("Deactivated plugin: " + p.PluginName, false);
                                    }
                                    catch (Exception ex)
                                    {
                                        osae.AddToLog("Error stopping plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                                    }
                                }
                            }
                        }
                    }
                    break;
                case "method":
                    string[] items = message.Split('|');
                    DataTable dt = new DataTable();
                    DataColumn col1 = new DataColumn("object_name");
                    DataColumn col2 = new DataColumn("object_owner");
                    DataColumn col3 = new DataColumn("method_name");
                    DataColumn col4 = new DataColumn("parameter_1");
                    DataColumn col5 = new DataColumn("parameter_2");
                    DataColumn col6 = new DataColumn("address");
                    col1.DataType = System.Type.GetType("System.String");
                    col2.DataType = System.Type.GetType("System.String");
                    col3.DataType = System.Type.GetType("System.String");
                    col4.DataType = System.Type.GetType("System.String");
                    col5.DataType = System.Type.GetType("System.String");
                    col6.DataType = System.Type.GetType("System.String");
                    dt.Columns.Add(col1);
                    dt.Columns.Add(col2);
                    dt.Columns.Add(col3);
                    dt.Columns.Add(col4);
                    dt.Columns.Add(col5);
                    dt.Columns.Add(col6);
                    DataRow row = dt.NewRow();
                    row[col1] = items[0].Trim();
                    row[col2] = items[1].Trim();
                    row[col3] = items[2].Trim();
                    row[col4] = items[3].Trim();
                    row[col5] = items[4].Trim();
                    row[col6] = items[5].Trim();
                    dt.Rows.Add(row);

                    OSAEMethod method = new OSAEMethod(row["method_name"].ToString(), row["object_name"].ToString(), row["parameter_1"].ToString(), row["parameter_2"].ToString(), row["address"].ToString(), row["object_owner"].ToString());
                    dt = null;

                    if (method.ObjectName == "SERVICE-" + osae.ComputerName)
                    {
                        if (method.MethodName == "RESTART PLUGIN")
                        {
                            foreach (Plugin p in plugins)
                            {
                                if (p.PluginName == method.Parameter1)
                                {
                                    OSAEObject obj = osae.GetObjectByName(p.PluginName);
                                    if (obj != null)
                                    {
                                        disablePlugin(p);
                                        enablePlugin(p);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Plugin plugin in plugins)
                        {
                            string x = row["object_owner"].ToString().ToLower();
                            string y = row["object_name"].ToString().ToLower();

                            if (plugin.Enabled == true && (row["object_owner"].ToString().ToLower() == plugin.PluginName.ToLower() || row["object_name"].ToString().ToLower() == plugin.PluginName.ToLower()))
                            {
                                plugin.addin.ProcessCommand(method);
                            }
                        }
                    }
                    break;
                case "enablePlugin":
                    string[] plug = message.Split('|');

                    if (plug[0] == "ENABLEPLUGIN")
                    {
                        foreach (Plugin p in plugins)
                        {
                            if (p.PluginName == plug[1])
                            {
                                OSAEObject obj = osae.GetObjectByName(p.PluginName);
                                if (obj != null)
                                {
                                    if (plug[2] == "True")
                                    {
                                        enablePlugin(p);
                                    }
                                    else if (plug[2] == "False")
                                    {
                                        disablePlugin(p);
                                    }
                                }
                            }
                        }
                    }

                    break;
            }
        }
        public override void ProcessCommand(OSAEMethod method)
        {
            logging.AddToLog("Found Command: " + method.MethodName + " | param1: " + method.Parameter1 + " | param2: " + method.Parameter2 + " | obj: " + method.ObjectName + " | addr: " + method.Address , false);
            //process command
            try
            {
                if (method.Address.Length > 0)
                {

                    int address;
                    byte instance = 0;
                    byte nid;
                    if (int.TryParse(method.Address.Substring(1), out address))
                    {
                        nid = (byte)address;
                    }
                    else
                    {
                        nid = (byte)Int32.Parse(method.Address.Substring(1).Split('-')[0]);
                        instance = (byte)Int32.Parse(method.Address.Substring(1).Split('-')[1]);
                    }
                    Node node = GetNode(m_homeId, nid);
                    OSAEObject obj = OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString());

                    if (method.MethodName == "NODE NEIGHBOR UPDATE")
                    {
                        logging.AddToLog("Requesting Node Neighbor Update: " + obj.Name, true);
                        m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                        if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNodeNeighborUpdate, false, nid))
                        {
                            logging.AddToLog("Request Node Neighbor Update Failed: " + obj.Name, true);
                            m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                        }
                    }
                    else if (method.MethodName == "ENABLE POLLING")
                        enablePolling(nid);
                    else if(method.MethodName == "ON")
                    {
                        int val = 255;
                        if (method.Parameter1 != "")
                            val = Int32.Parse(method.Parameter1);
                        Value v = new Value();
                        foreach (Value value in node.Values)
                        {
                            if ((obj.BaseType == "BINARY SWITCH" && value.Label == "Switch") || obj.BaseType == "MULTILEVEL SWITCH" && value.Label == "Level")
                            {
                                v = value;
                            }
                        }

                        //m_manager.SetNodeOn(m_homeId, nid);

                        if(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).BaseType == "BINARY SWITCH")
                            m_manager.SetValue(v.ValueID, true);
                        else if(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).BaseType == "MULTILEVEL SWITCH")
                            m_manager.SetValue(v.ValueID, (byte)val);

                        OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        logging.AddToLog("Turned on: " + method.ObjectName, false);
                    }
                    else if(method.MethodName == "OFF")
                    {
                        Value v = new Value();
                        foreach (Value value in node.Values)
                        {
                            if ((obj.BaseType == "BINARY SWITCH" && value.Label == "Switch") || obj.BaseType == "MULTILEVEL SWITCH" && value.Label == "Level")
                            {
                                v = value;
                            }
                        }

                        if (OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).BaseType == "BINARY SWITCH")
                            m_manager.SetValue(v.ValueID, false);
                        else if (OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).BaseType == "MULTILEVEL SWITCH")
                            m_manager.SetValue(v.ValueID, (byte)0);

                        //m_manager.SetNodeOff(m_homeId, nid);
                        OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        logging.AddToLog("Turned off: " + method.ObjectName, false);
                    }
                    else
                    {
                        foreach (Value value in node.Values)
                        {
                            if (value.Label == method.MethodName)
                            {
                                if (method.Parameter1 != "")
                                {
                                    if (value.Type == ZWValueID.ValueType.String)
                                        m_manager.SetValue(value.ValueID, method.Parameter1);
                                    else if (value.Type == ZWValueID.ValueType.List)
                                        m_manager.SetValueListSelection(value.ValueID, method.Parameter1);
                                    else if (value.Type == ZWValueID.ValueType.Int)
                                        m_manager.SetValue(value.ValueID, Int32.Parse(method.Parameter1));
                                    else if (value.Type == ZWValueID.ValueType.Byte)
                                        m_manager.SetValue(value.ValueID, (byte)Int32.Parse(method.Parameter1));
                                    else if (value.Type == ZWValueID.ValueType.Bool)
                                    {
                                        if (method.Parameter1 == "TRUE")
                                            m_manager.SetValue(value.ValueID, true);
                                        else
                                            m_manager.SetValue(value.ValueID, false);
                                    }
                                    else if (value.Type == ZWValueID.ValueType.Decimal)
                                        m_manager.SetValue(value.ValueID, Convert.ToSingle(method.Parameter1));

                                    logging.AddToLog("Set " + method.MethodName + " to " + method.Parameter1 + ": " + method.ObjectName, false);
                                }
                                else if(value.Type == ZWValueID.ValueType.Button)
                                {
                                    if (value.Label == method.MethodName)
                                    {
                                        m_manager.PressButton(value.ValueID);
                                        m_manager.ReleaseButton(value.ValueID);
                                    }
                                }
                            }
                        }

                    }
                }
                else
                {
                    #region Controller Commands
                    try
                    {
                        byte nid = 0xff;
                        if (method.Parameter1 != "")
                            nid = (byte)Int32.Parse(method.Parameter1.Substring(1));

                        switch (method.MethodName)
                        {
                            //case "ADD CONTROLLER":
                            //    m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                            //    if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.AddController, false, nid))
                            //    {
                            //        logging.AddToLog("Add Controller Failed", true);
                            //        m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                            //    }
                            //    //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added.", "");
                            //    break;
                            //case "REMOVE CONTROLLER":
                            //    m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                            //    if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveController, false, nid))
                            //    {
                            //        logging.AddToLog("Remove Controller Failed", true);
                            //        m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                            //    }
                            //    //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being removed.", "");
                            //    break;
                            case "ADD DEVICE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.AddDevice, false, nid))
                                {
                                    logging.AddToLog("Add Device Failed", true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "REMOVE DEVICE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveDevice, false, nid))
                                {
                                    OSAEObjectManager.ObjectDelete(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name);
                                }
                                else
                                {
                                    logging.AddToLog("Remove Device Failed", true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "REMOVE FAILED NODE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveFailedNode, false, nid))
                                {
                                    OSAEObjectManager.ObjectDelete(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name);
                                }
                                else
                                {
                                    logging.AddToLog("Remove Failed Node Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "RESET CONTROLLER":
                                logging.AddToLog("Resetting Controller", true);
                                m_manager.ResetController(m_homeId);
                                //DataSet ds = osae.GetObjectsByType("ZWAVE DIMMER");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                //ds = osae.GetObjectsByType("ZWAVE BINARY SWITCH");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                //ds = osae.GetObjectsByType("ZWAVE THERMOSTAT");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                break;
                            case "NODE NEIGHBOR UPDATE":
                                logging.AddToLog("Requesting Node Neighbor Update: Z" + nid.ToString(), true);
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNodeNeighborUpdate, false, nid))
                                {
                                    logging.AddToLog("Request Node Neighbor Update Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "NETWORK UPDATE":
                                logging.AddToLog("Requesting Network Update", true);
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNetworkUpdate, false, nid))
                                {
                                    logging.AddToLog("Request Network Update Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "ENABLE POLLING":
                                enablePolling(nid);
                                break;
                        }

                    }
                    catch (Exception ex)
                    {
                        logging.AddToLog("Controller command failed (" + method.MethodName + "): " + ex.Message + " -- " + ex.StackTrace
                            + " -- " + ex.InnerException, true);
                    }
                    #endregion
                }

            }
            catch (Exception ex)
            {
                logging.AddToLog("Error Processing Command - " + ex.Message + " -" + ex.InnerException, true);
            }
        }
        private void MethodMessageReceived(PacketHeader header, Connection connection, string message)
        {
            Log.Info("<- Command: " + message);
            string[] items = message.Split('|');
            //ObjectName + " | " + MethodName + " | " + Parameter1 + " | " + Parameter2 + " | " + Address + " | " + Owner + " | " +From, new IPEndPoint(IPAddress.Broadcast, 10051));

            OSAEMethod method = new OSAEMethod(items[0].Trim(), items[1].Trim(), "", items[2].Trim(), items[3].Trim(), items[4].Trim(), items[5].Trim(), items[6].Trim());
            Log.Info("Created Method object." + method.ObjectName);
            if (method.ObjectName == "SERVICE-" + Common.ComputerName)
            {
                if (method.MethodName == "RESTART PLUGIN")
                {
                    foreach (Plugin p in plugins)
                    {
                        if (p.PluginName == method.Parameter1)
                        {
                            bool found = OSAEObjectManager.ObjectExists(p.PluginName);
                            if (found)
                            {
                                stopPlugin(p);
                                startPlugin(p);
                            }
                        }
                    }
                }
                else if (method.MethodName == "START PLUGIN")
                {
                    foreach (Plugin p in plugins)
                    {
                        if (p.PluginName == method.Parameter1)
                        {
                            bool found = OSAEObjectManager.ObjectExists(p.PluginName);
                            if (found) startPlugin(p);
                        }
                    }
                }
                else if (method.MethodName == "STOP PLUGIN")
                {
                    foreach (Plugin p in plugins)
                    {
                        if (p.PluginName == method.Parameter1)
                        {
                            bool found = OSAEObjectManager.ObjectExists(p.PluginName);
                            if (found) stopPlugin(p);
                        }
                    }
                }
            }
            else
            {
                Log.Info("Passing Method to: " + method.ObjectName);
                foreach (Plugin plugin in plugins)
                {
                    //This exposes a flaw in the Ownership of distributed plugins.   
                    Log.Info("does " + method.ObjectName + " = " + plugin.PluginName);
                    if (plugin.Running && method.ObjectName == plugin.PluginName)
                    {
                        plugin.ExecuteCommand(method);
                        Log.Info("Passed Method to: " + method.ObjectName);
                    }
                }
            }
        }
        private void MethodMessageReceived(PacketHeader header, Connection connection, string message)
        {
            string[] items = message.Split('|');

            OSAEMethod method = new OSAEMethod(items[2].Trim(), "", items[0].Trim(), items[3].Trim(), items[4].Trim(), items[5].Trim(), items[1].Trim());

            if (method.ObjectName == "SERVICE-" + Common.ComputerName)
            {
                if (method.MethodName == "RESTART PLUGIN")
                {
                    foreach (Plugin p in plugins)
                    {
                        if (p.PluginName == method.Parameter1)
                        {
                            OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName);

                            if (obj != null)
                            {
                                disablePlugin(p);
                                enablePlugin(p);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (Plugin plugin in plugins)
                {
                    if (plugin.Enabled == true && (method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower()))
                    {
                        plugin.ExecuteCommand(method);
                    }
                }
            }
        }
 /// <summary>
 /// A command has been passed to the plugin to be processed.
 /// Not all plugins will support commands but the method must be implemented
 /// </summary>
 /// <param name="method">The information required to process the command</param>
 public abstract void ProcessCommand(OSAEMethod method);
 public void ExecuteCommand(OSAEMethod method)
 {
     try
     {
         _plugin.ProcessCommand(method);
     }
     catch (Exception ex)
     {
         this.Log.Error(PluginName + " - Process Command Error", ex);
     }
 }
 public void ExecuteCommand(OSAEMethod method)
 {
     try
     {
         _plugin.ProcessCommand(method);
     }
     catch (Exception ex)
     {
         logging.AddToLog(PluginName + " - Process Command Error: " + ex.Message, true);
     }
 }
Beispiel #14
0
        public override void ProcessCommand(OSAEMethod method)
        {
            logging.AddToLog("Found Command: " + method.MethodName + " | param1: " + method.Parameter1 + " | param2: " + method.Parameter2 + " | obj: " + method.ObjectName + " | addr: " + method.Address , false);
            //process command
            try
            {
                if (method.Address.Length > 0)
                {
                    int address;
                    byte instance = 0;
                    byte nid;
                    if (int.TryParse(method.Address.Substring(1), out address))
                    {
                        nid = (byte)address;
                    }
                    else
                    {
                        nid = (byte)Int32.Parse(method.Address.Substring(1).Split('-')[0]);
                        instance = (byte)Int32.Parse(method.Address.Substring(1).Split('-')[1]);
                    }
                    Node node = GetNode(m_homeId, nid);

                    if (method.MethodName == "NODE NEIGHBOR UPDATE")
                    {
                        logging.AddToLog("Requesting Node Neighbor Update: " + OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name, true);
                        m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                        if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNodeNeighborUpdate, false, nid))
                        {
                            logging.AddToLog("Request Node Neighbor Update Failed: " + OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name, true);
                            m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                        }
                    }
                    else if (method.MethodName == "ENABLE POLLING")
                        enablePolling(nid);
                    else if(method.MethodName == "ON")
                    {
                        m_manager.SetNodeOn(m_homeId, nid);
                        OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        logging.AddToLog("Turned on: " + method.ObjectName, false);

                        //foreach (Value value in node.Values)
                        //    {
                        //        if (value.Label == "Switch")
                        //            m_manager.SetValue(value.ValueID, true);
                        //    }
                        //OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        //logging.AddToLog("Turned light on: " + method.ObjectName, false);
                    }
                    else if(method.MethodName == "OFF")
                    {
                        m_manager.SetNodeOff(m_homeId, nid);
                        OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        logging.AddToLog("Turned off: " + method.ObjectName, false);

                        //foreach (Value value in node.Values)
                        //{
                        //    if (value.Label == "Switch")
                        //        m_manager.SetValue(value.ValueID, false);
                        //}
                        //OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        //logging.AddToLog("Turned light off: " + method.ObjectName, false);
                    }
                    else
                    {
                        if (method.Parameter1 != "")
                        {
                            foreach (Value value in node.Values)
                            {
                                if (value.Label == method.MethodName)
                                {
                                    if (value.Type == "String")
                                        m_manager.SetValue(value.ValueID, method.Parameter1);
                                    else if (value.Type == "List")
                                        m_manager.SetValueListSelection(value.ValueID, method.Parameter1);
                                    else if (value.Type == "Int")
                                        m_manager.SetValue(value.ValueID, Int32.Parse(method.Parameter1));
                                    else if (value.Type == "Byte")
                                        m_manager.SetValue(value.ValueID, (byte)Int32.Parse(method.Parameter1));
                                    else if (value.Type == "Bool")
                                    {
                                        if (method.Parameter1 == "TRUE")
                                            m_manager.SetValue(value.ValueID, true);
                                        else
                                            m_manager.SetValue(value.ValueID, false);
                                    }
                                    else if (value.Type == "Decimal")
                                        m_manager.SetValue(value.ValueID, Convert.ToSingle(method.Parameter1));

                                    logging.AddToLog("Set " + method.MethodName + " to " + method.Parameter1 + ": " + method.ObjectName, false);
                                }
                            }
                        }

                        //switch (node.Label)
                        //{
                        //    #region Binary Switch
                        //    case "Binary Switch":
                        //    case "Binary Power Switch":
                        //        if (method.MethodName == "ON")
                        //        {
                        //            if (instance != 0)
                        //            {
                        //                foreach (Value value in node.Values)
                        //                {
                        //                    if (value.Label == "Switch" && value.ValueID.GetInstance() == instance)
                        //                        m_manager.SetValue(value.ValueID, true);
                        //                }

                        //            }
                        //            else
                        //                m_manager.SetNodeOn(m_homeId, nid);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        //            logging.AddToLog("Turned light on: " + method.ObjectName, false);
                        //        }
                        //        else
                        //        {
                        //            if (instance != 0)
                        //            {
                        //                foreach (Value value in node.Values)
                        //                {
                        //                    if (value.Label == "Switch" && value.ValueID.GetInstance() == instance)
                        //                        m_manager.SetValue(value.ValueID, false);
                        //                }

                        //            }
                        //            else
                        //                m_manager.SetNodeOff(m_homeId, nid);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        //            logging.AddToLog("Turned light off: " + method.ObjectName, false);
                        //        }
                        //        break;
                        //    #endregion

                        //    #region Dimmers
                        //    case "Multilevel Switch":
                        //    case "Multilevel Power Switch":
                        //    case "Multilevel Scene Switch":
                        //        if (method.MethodName == "ON")
                        //        {
                        //            byte lvl;
                        //            if (method.Parameter1 != "")
                        //                lvl = (byte)Int32.Parse(method.Parameter1);
                        //            else if (OSAEObjectPropertyManager.GetObjectPropertyValue(method.ObjectName, "Default Dim").Value != "")
                        //                lvl = (byte)Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(method.ObjectName, "Default Dim").Value);
                        //            else
                        //                lvl = (byte)100;

                        //            m_manager.SetNodeLevel(m_homeId, nid, lvl);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        //            logging.AddToLog("Turned light on: " + method.ObjectName + "|" + method.Parameter1, false);
                        //        }
                        //        else
                        //        {
                        //            m_manager.SetNodeOff(m_homeId, nid);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        //            logging.AddToLog("Turned light off: " + method.ObjectName, false);
                        //        }
                        //        break;
                        //    #endregion

                        //    #region Thermostats
                        //    case "General Thermostat V2":
                        //        if (method.MethodName == "ON")
                        //        {
                        //            m_manager.SetNodeOn(m_homeId, nid);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "ON", pName);
                        //            logging.AddToLog("Turned thermostat on: " + method.ObjectName, false);
                        //        }
                        //        else if (method.MethodName == "OFF")
                        //        {
                        //            m_manager.SetNodeOff(m_homeId, nid);
                        //            OSAEObjectStateManager.ObjectStateSet(method.ObjectName, "OFF", pName);
                        //            logging.AddToLog("Turned thermostat off: " + nid.ToString(), false);
                        //        }
                        //        else if (method.MethodName == "COOLSP")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Cooling 1")
                        //                {
                        //                    m_manager.SetValue(value.ValueID, Convert.ToSingle(method.Parameter1));
                        //                    logging.AddToLog("Set cool target temperature to " + method.Parameter1 + ": " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "HEATSP")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Heating 1")
                        //                {
                        //                    m_manager.SetValue(value.ValueID, Convert.ToSingle(method.Parameter1));
                        //                    logging.AddToLog("Set heat target temperature to " + method.Parameter1 + ": " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "UNIT OFF")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Off");
                        //                    logging.AddToLog("Set Unit Mode to Off: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "HEAT")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Heat");
                        //                    logging.AddToLog("Set Unit Mode to Heat: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "COOL")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Cool");
                        //                    logging.AddToLog("Set Unit Mode to Cool: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "AUTO")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Auto");
                        //                    logging.AddToLog("Set Unit Mode to Auto: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "AUX HEAT")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Aux Heat");
                        //                    logging.AddToLog("Set Unit Mode to Aux Heat: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "FAN ON")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Fan Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "On Low");
                        //                    logging.AddToLog("Set Fan Mode to On: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        else if (method.MethodName == "FAN AUTO")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Fan Mode")
                        //                {
                        //                    m_manager.SetValueListSelection(value.ValueID, "Auto Low");
                        //                    logging.AddToLog("Set Fan Mode to Auto: " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        break;
                        //    #endregion

                        //    #region MultiSensor
                        //    case "Binary Routing Sensor":
                        //        if (method.MethodName == "SET WAKEUP INTERVAL")
                        //        {
                        //            foreach (Value value in node.Values)
                        //            {
                        //                if (value.Label == "Wake-up Interval")
                        //                {
                        //                    m_manager.SetValue(value.ValueID, Convert.ToSingle(method.Parameter1));
                        //                    logging.AddToLog("Set wake-up interval to " + method.Parameter1 + ": " + method.ObjectName, false);
                        //                }
                        //            }
                        //        }
                        //        break;
                        //    #endregion
                        //}
                    }
                }
                else
                {
                    #region Controller Commands
                    try
                    {
                        byte nid = 0xff;
                        if (method.Parameter1 != "")
                            nid = (byte)Int32.Parse(method.Parameter1.Substring(1));

                        switch (method.MethodName)
                        {
                            //case "ADD CONTROLLER":
                            //    m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                            //    if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.AddController, false, nid))
                            //    {
                            //        logging.AddToLog("Add Controller Failed", true);
                            //        m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                            //    }
                            //    //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being added.", "");
                            //    break;
                            //case "REMOVE CONTROLLER":
                            //    m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                            //    if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveController, false, nid))
                            //    {
                            //        logging.AddToLog("Remove Controller Failed", true);
                            //        m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                            //    }
                            //    //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Put the target controller into receive configuration mode.\nThe PC Z-Wave Controller must be within 2m of the controller being removed.", "");
                            //    break;
                            case "ADD DEVICE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.AddDevice, false, nid))
                                {
                                    logging.AddToLog("Add Device Failed", true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Press the program button on the Z-Wave device to add it to the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being added.", "");
                                break;
                            case "REMOVE DEVICE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveDevice, false, nid))
                                {
                                    OSAEObjectManager.ObjectDelete(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name);
                                }
                                else
                                {
                                    logging.AddToLog("Remove Device Failed", true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                //osae.MethodQueueAdd(osae.GetPluginName("GUI CLIENT", osae.ComputerName), "POPUP MESSAGE", "Press the program button on the Z-Wave device to remove it from the network.\nFor security reasons, the PC Z-Wave Controller must be close to the device being removed.", "");
                                break;
                            case "REMOVE FAILED NODE":
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RemoveFailedNode, false, nid))
                                {
                                    OSAEObjectManager.ObjectDelete(OSAEObjectManager.GetObjectByAddress("Z" + nid.ToString()).Name);
                                }
                                else
                                {
                                    logging.AddToLog("Remove Failed Node Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "RESET CONTROLLER":
                                logging.AddToLog("Resetting Controller and deleting all ZWave objects", true);
                                m_manager.ResetController(m_homeId);
                                //DataSet ds = osae.GetObjectsByType("ZWAVE DIMMER");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                //ds = osae.GetObjectsByType("ZWAVE BINARY SWITCH");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                //ds = osae.GetObjectsByType("ZWAVE THERMOSTAT");
                                //foreach (DataRow dr in ds.Tables[0].Rows)
                                //    osae.ObjectDelete(dr["object_name"].ToString());
                                break;
                            case "NODE NEIGHBOR UPDATE":
                                logging.AddToLog("Requesting Node Neighbor Update: Z" + nid.ToString(), true);
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNodeNeighborUpdate, false, nid))
                                {
                                    logging.AddToLog("Request Node Neighbor Update Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "NETWORK UPDATE":
                                logging.AddToLog("Requesting Network Update", true);
                                m_manager.OnControllerStateChanged += m_controllerStateChangedHandler;
                                if (!m_manager.BeginControllerCommand(m_homeId, ZWControllerCommand.RequestNetworkUpdate, false, nid))
                                {
                                    logging.AddToLog("Request Network Update Failed: Z" + nid.ToString(), true);
                                    m_manager.OnControllerStateChanged -= m_controllerStateChangedHandler;
                                }
                                break;
                            case "ENABLE POLLING":
                                enablePolling(nid);
                                break;
                        }

                    }
                    catch (Exception ex)
                    {
                        logging.AddToLog("Controller command failed (" + method.MethodName + "): " + ex.Message + " -- " + ex.StackTrace
                            + " -- " + ex.InnerException, true);
                    }
                    #endregion
                }

            }
            catch (Exception ex)
            {
                logging.AddToLog("Error Processing Command - " + ex.Message + " -" + ex.InnerException, true);
            }
        }
        public static OSAEMethodCollection GetObjectMethods(string ObjectName)
        {
            DataSet dataset = new DataSet();
            OSAEMethodCollection methods = new OSAEMethodCollection();

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    command.CommandText = "SELECT method_id, method_name FROM osae_v_object_method WHERE object_name=@ObjectName ORDER BY method_name";
                    command.Parameters.AddWithValue("@ObjectName", ObjectName);
                    dataset = OSAESql.RunQuery(command);
                }

                foreach (DataRow drp in dataset.Tables[0].Rows)
                {
                    OSAEMethod method = new OSAEMethod();
                    method.MethodName = drp["method_name"].ToString();
                    method.Id = int.Parse(drp["method_id"].ToString());
                    method.ObjectName = ObjectName;
                    methods.Add(method);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectMethods error: " + ex.Message, true);
            }

            return methods;
        }
 public abstract void ProcessCommand(OSAEMethod method);
        public void OnMessageReceived(OSAEWCFMessage message)
        {
            logging.AddToLog("received message: " + message.Type + " | " + message, false);

            switch (message.Type)
            {
                case OSAEWCFMessageType.PLUGIN:
                    string[] arguments = message.Message.Split('|');

                    if (arguments[1] == "True")
                        OSAEObjectStateManager.ObjectStateSet(arguments[0], "ON", sourceName);
                    else if (arguments[1] == "False")
                        OSAEObjectStateManager.ObjectStateSet(arguments[0], "OFF", sourceName);

                    foreach (Plugin p in plugins)
                    {
                        if (p.PluginName == arguments[0])
                        {
                            OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName);

                            if (obj != null)
                            {
                                bool isSystemPlugin = false;
                                foreach (OSAEObjectProperty p2 in obj.Properties)
                                {
                                    if (p2.Name == "System Plugin")
                                    {
                                        if (p2.Value == "TRUE")
                                            isSystemPlugin = true;
                                        break;
                                    }
                                }
                                if (arguments[1] == "True" && !p.Enabled && !isSystemPlugin)
                                {
                                    OSAEObjectManager.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 1);
                                    try
                                    {
                                        enablePlugin(p);
                                        logging.AddToLog("Activated plugin: " + p.PluginName, false);
                                    }
                                    catch (Exception ex)
                                    {
                                        logging.AddToLog("Error activating plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                                    }
                                }
                                else if (arguments[1] == "False" && p.Enabled && !isSystemPlugin)
                                {
                                    OSAEObjectManager.ObjectUpdate(p.PluginName, p.PluginName, obj.Description, obj.Type, obj.Address, obj.Container, 0);
                                    try
                                    {
                                        disablePlugin(p);
                                        logging.AddToLog("Deactivated plugin: " + p.PluginName, false);
                                    }
                                    catch (Exception ex)
                                    {
                                        logging.AddToLog("Error stopping plugin (" + p.PluginName + "): " + ex.Message + " - " + ex.InnerException, true);
                                    }
                                }
                            }
                        }
                    }
                    break;
                case OSAEWCFMessageType.METHOD:
                    string[] items = message.Message.Split('|');

                    OSAEMethod method = new OSAEMethod(items[2].Trim(), "", items[0].Trim(), items[3].Trim(), items[4].Trim(), items[5].Trim(), items[1].Trim());

                    if (method.ObjectName == "SERVICE-" + Common.ComputerName)
                    {
                        if (method.MethodName == "RESTART PLUGIN")
                        {
                            foreach (Plugin p in plugins)
                            {
                                if (p.PluginName == method.Parameter1)
                                {
                                    OSAEObject obj = OSAEObjectManager.GetObjectByName(p.PluginName);

                                    if (obj != null)
                                    {
                                        disablePlugin(p);
                                        enablePlugin(p);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (Plugin plugin in plugins)
                        {
                            if (plugin.Enabled == true && (method.Owner.ToLower() == plugin.PluginName.ToLower() || method.ObjectName.ToLower() == plugin.PluginName.ToLower()))
                            {
                                plugin.ExecuteCommand(method);
                            }
                        }
                    }
                    break;
            }
        }
 public override void ProcessCommand(OSAEMethod method)
 {
     this.Log.Info("Received Command: " + method.MethodName + " | to Cam: " + method.ObjectName);
     camName = method.ObjectName;
     // OSAEObject obj = OSAEObjectManager.GetObjectByName(camName);
     camIpAddress = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "IP Address").Value;
     camPort = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Port").Value;
     camUser = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Username").Value;
     camPass = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Password").Value;
     camStream = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Stream Address").Value;
     camSnapShot = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "camSnapShot").Value;
     ptzUP = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzUP").Value;
     ptzDOWN = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzDOWN").Value;
     ptzLEFT = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzLEFT").Value;
     ptzRIGHT = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzRIGHT").Value;
     ptzIN = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzIN").Value;
     ptzOUT = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzOUT").Value;
     ptzFOCUSIN = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzFOCUSIN").Value;
     ptzFOCUSOUT = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzFOCUSOUT").Value;
     ptzPRESET1 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET1").Value;
     ptzPRESET2 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET2").Value;
     ptzPRESET3 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET3").Value;
     ptzPRESET4 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET4").Value;
     ptzPRESET5 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET5").Value;
     ptzPRESET6 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "ptzPRESET6").Value;
     CUSTOM1 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM1").Value;
     CUSTOM2 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM2").Value;
     CUSTOM3 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM3").Value;
     CUSTOM4 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM4").Value;
     CUSTOM5 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM5").Value;
     CUSTOM6 = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "CUSTOM6").Value;
     camSloc = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Save Location").Value;
     camDegrees = OSAEObjectPropertyManager.GetObjectPropertyValue(camName, "Degrees").Value;
     camSloc = camSloc + @"\";
     if (method.Parameter1 != "")
     {
         camDegrees = method.Parameter1;
     }
     if (method.Parameter2 != "")
     {
         camOptional = method.Parameter2;
     }
     sMethod = method.MethodName;
     WebClient wc = new WebClient();
     wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
     if (sMethod == "UP")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzUP)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "DOWN")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzDOWN)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "LEFT")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzLEFT)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "RIGHT")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzRIGHT)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "IN")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzIN)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "OUT")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzOUT)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "FOCUSIN")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzFOCUSIN)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "FOCUSOUT")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzFOCUSOUT)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET1")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET1)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET2")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET2)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET3")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET3)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET4")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET4)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET5")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET5)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "PRESET6")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(ptzPRESET6)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM1")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM1)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM2")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM2)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM3")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM3)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM4")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM4)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM5")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM5)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "CUSTOM6")
     {
         try
         {
             wc.UploadStringAsync(new Uri(replaceFielddata(CUSTOM6)), "POST", "");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "SNAPSHOT")
     {
         string i = DateTime.Now.ToLongTimeString();
         string j = DateTime.Now.ToShortDateString();
         i = i.Replace(":", "_");
         j = j.Replace("/", "_");
         i = j + "_" + i;
         i = i.Replace(" ", "");
         try
         {
             var URI = new Uri(replaceFielddata(camSnapShot));
             wc.DownloadFile(URI, camSloc + camName + "_" + i + ".jpg");
             this.Log.Info(camSloc + camName + "_" + i + ".jpg was created");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     else if (sMethod == "SETUP")
     {
         try
         {
             //System.Windows.Forms.MessageBox.Show("Test");
         }
         catch (Exception ex)
         {
             this.Log.Info("An error occurred!!!: " + ex.Message);
         }
     }
     this.Log.Info("===================================================");
 }