protected void Page_Load(object sender, EventArgs e)
    {
        //don't let them create a user if a user already exists
        OSAEObjectCollection objects = new OSAEObjectCollection();
        objects = OSAEObjectManager.GetObjectsByType("PERSON");

        if (objects.Count > 0)
        {
            Response.Redirect("~/Default.aspx");
        }
    }
        void xmppCon_OnRosterItem(object sender, agsXMPP.protocol.iq.roster.RosterItem item)
        {
            bool found = false;

            this.Log.Info(String.Format("Received Contact {0}", item.Jid.Bare));

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("PERSON");

            foreach (OSAEObject oObj in objects)
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(oObj.Name);
                if (OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "JabberID").Value == item.Jid.Bare)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                OSAEObjectManager.ObjectAdd(item.Jid.Bare, item.Jid.Bare, "PERSON", "", "", true);
                OSAEObjectPropertyManager.ObjectPropertySet(item.Jid.Bare, "JabberID", item.Jid.Bare, "Jabber");
            }
        }
示例#3
0
        void xmppCon_OnPresence(object sender, agsXMPP.protocol.client.Presence pres)
        {
            Log.Info(String.Format("Received Presence from: {0} show: {1} status: {2}", pres.From.ToString(), pres.Show.ToString(), pres.Status));

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("PERSON");

            foreach (OSAEObject oObj in objects)
            {
                OSAEObject obj = OSAEObjectManager.GetObjectByName(oObj.Name);

                if (OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "JabberID").Value == pres.From.Bare)
                {
                    if (pres.Show.ToString() == "away")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "JabberStatus", "Idle", "Jabber");
                    }
                    else if (pres.Show.ToString() == "NONE")
                    {
                        OSAEObjectPropertyManager.ObjectPropertySet(obj.Name, "JabberStatus", "Online", "Jabber");
                    }
                    break;
                }
            }
        }
示例#4
0
 protected void applyPersonPropertySecurity(string objName, string objMinTrust, string propName, string propType, string propTrust)
 {
     if (Convert.ToInt32(Session["TrustLevel"].ToString()) < Convert.ToInt32(propTrust))
     {
         txtPropValue.Visible     = false;
         btnPropSave.Visible      = false;
         lblPropName.Visible      = false;
         lblSourceName.Visible    = false;
         lblTrustLevel.Visible    = true;
         lblInterestLevel.Visible = false;
         btnEditPropList.Visible  = false;
         ddlPropValue.Visible     = false;
     }
     else if (propName == "Security Level")
     {
         OSAEObjectCollection osaAdmins = OSAE.OSAEObjectManager.GetObjectsByPropertyValue("Security Level", "Admin");
         string sL = OSAEObjectPropertyManager.GetObjectPropertyValue(objName, propName).Value;
         if (sL == "Admin" && osaAdmins.Count() < 2)
         {
             txtPropValue.Visible     = false;
             btnPropSave.Visible      = false;
             lblPropName.Visible      = false;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = false;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
         else if (Session["SecurityLevel"].ToString() == "Admin")
         {
             txtPropValue.Visible     = false;
             btnPropSave.Visible      = true;
             lblPropName.Visible      = true;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = true;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = true;
         }
         else
         {
             txtPropValue.Visible     = false;
             btnPropSave.Visible      = false;
             lblPropName.Visible      = false;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = false;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
     }
     else if (propName == "Trust Level")
     {
         if (Session["SecurityLevel"].ToString() == "Admin")
         {
             txtPropValue.Visible     = true;
             btnPropSave.Visible      = true;
             lblPropName.Visible      = true;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = true;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
         else
         {
             txtPropValue.Visible     = false;
             btnPropSave.Visible      = false;
             lblPropName.Visible      = false;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = false;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
     }
     else if (Session["UserName"].ToString() != objName && Session["SecurityLevel"].ToString() != "Admin")
     {
         txtPropValue.Visible     = false;
         btnPropSave.Visible      = false;
         lblPropName.Visible      = false;
         lblSourceName.Visible    = false;
         lblTrustLevel.Visible    = true;
         lblInterestLevel.Visible = false;
         btnEditPropList.Visible  = false;
         ddlPropValue.Visible     = false;
     }
     else if (propType == "Password")
     {
         if (Session["SecurityLevel"].ToString() == "Admin" || Session["UserName"].ToString() == objName)
         {
             txtPropValue.Visible     = true;
             btnPropSave.Visible      = true;
             lblPropName.Visible      = false;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = true;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
         else
         {
             txtPropValue.Visible     = false;
             btnPropSave.Visible      = false;
             lblPropName.Visible      = false;
             lblSourceName.Visible    = false;
             lblTrustLevel.Visible    = true;
             lblInterestLevel.Visible = false;
             btnEditPropList.Visible  = false;
             ddlPropValue.Visible     = false;
         }
     }
 }
        /// <summary>
        /// OSA Plugin Interface - Commands the be processed by the plugin
        /// </summary>
        /// <param name="method">Method containging the command to run</param>
        public override void ProcessCommand(OSAEMethod method)
        {
            string methodName     = method.MethodName;
            string objectName     = method.ObjectName;
            string combinedString = objectName + "_" + methodName;

            //get the called objects properties to see if there is a computer objet defined
            OSAEObject calledObject = OSAEObjectManager.GetObjectByName(method.ObjectName);
            OSAEObjectPropertyCollection ComputerProperty  = calledObject.Properties;
            OSAEObjectCollection         eventGhostObjects = OSAEObjectManager.GetObjectsByType("Computer");
            OSAEObject computer = new OSAEObject();

            //if there are no properties defined then grab the first available Computer object
            //logging.AddToLog("The Count of the Computer Properties is : " + ComputerProperty.Count, true);
            if (ComputerProperty.Count == 0)
            {
                //get the last object in the list

                foreach (OSAEObject test in eventGhostObjects)
                {
                    computer = test;
                }

                //add log entry if mulptiple computer objects were dectected and no property was used to select which object
                if (eventGhostObjects.Count > 1)
                {
                    Log.Info("There are multiple eventghost computer objects detected.  " + computer.Name + " with an address of: " + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "IPAddress") + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package.  Please add a property called 'Computer' with a value of the object name of the computer you wish to transmit the UDP packet to.");
                }
            }
            // if the object type contains a property with ID "Computer" use that property to select the appropriate object
            else
            {
                OSAEObjectProperty whichComputer = OSAEObjectPropertyManager.GetObjectPropertyValue(calledObject.Name, "Computer");
                computer = eventGhostObjects.Find(whichComputer.Value);

                //check to see if a computer object was found if none print the logged property value and select another object to use
                if (computer == null)
                {
                    foreach (OSAEObject test in eventGhostObjects)
                    {
                        computer = test;
                    }

                    if (eventGhostObjects.Count > 1)
                    {
                        Log.Info("A computer object was unable to be matched to " + whichComputer.Value + " please ensure that " + calledObject.Name + " contains a property called Computer with a value mathing the name of the appropriate computer object.");
                        Log.Info(computer.Name + " with an address of: " + computer.Address + ":" + OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "EventGhost Port") + " is being used to transmit the package.");
                    }
                }
            }

            //logging.AddToLog(address, true);
            //logging.AddToLog(objectName, true);
            //logging.AddToLog(combinedString, true);

            //get the server address indicated in the address for the object passed to the method
            string ipAddress = computer.Address;

            //check to make sure computer object has address, if not assume local host
            if (ipAddress.Equals("", StringComparison.Ordinal))
            {
                ipAddress = "Localhost";
            }
            OSAEObjectProperty portAddress = OSAEObjectPropertyManager.GetObjectPropertyValue(computer.Name, "Port");

            //if no value for port use default value of 33333
            Log.Debug("The port being used is: " + portAddress.Value);
            int port = 0;

            //Log.Debug("The port being used is: " + portAddress.Value);

            if ((portAddress.Value).Equals("", StringComparison.Ordinal))
            {
                port = 33333;
            }
            else
            {
                port = Int32.Parse(portAddress.Value);
                Log.Debug("The port being used is: " + portAddress.Value);
            }
            //logging.AddToLog(port, true);
            //logging.AddToLog(ipAddress, true);
            IPAddress  serverAddr = IPAddress.Parse(ipAddress);
            IPEndPoint endPoint   = new IPEndPoint(serverAddr, port);

            Log.Debug("The ipEndPoint is:" + ipAddress + ":" + port);

            //send the updpacket
            UdpClient udp = new UdpClient();

            byte[] sendBytes = Encoding.ASCII.GetBytes(combinedString);
            udp.Send(sendBytes, sendBytes.Length, endPoint);


            ////if not value for port use default value of 33333
            //int port = 0;

            //if ((portAddress.Value).Equals("",StringComparison.Ordinal))
            //    port = 33333;
            //else
            //    port = Int32.Parse(portAddress.Value);

            ////logging.AddToLog(port, true);
            ////logging.AddToLog(ipAddress, true);
            //IPAddress serverAddr = IPAddress.Parse(ipAddress);
            //IPEndPoint endPoint = new IPEndPoint(serverAddr, port);

            ////send the updpacket
            //UdpClient udp = new UdpClient();
            //byte[] sendBytes = Encoding.ASCII.GetBytes(combinedString);
            //udp.Send(sendBytes, sendBytes.Length, endPoint);
        }
示例#6
0
    private void loadPlugins()
    {
        pluginList = new BindingList <PluginDescription>();
        OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByBaseType("PLUGIN");

        foreach (OSAEObject o in objs)
        {
            PluginDescription desc = new PluginDescription();

            desc.Name     = o.Name;
            desc.Computer = o.Container;
            desc.Enabled  = o.Enabled;
            if (o.State.Value == "ON")
            {
                desc.Status = "Running";
            }
            else
            {
                desc.Status = "Stopped";
            }

            pluginList.Add(desc);
            Log.Info("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID);
        }

        /*
         * pluginList = new BindingList<PluginDescription>();
         * List<string> osapdFiles = new List<string>();
         * string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories);
         * osapdFiles.AddRange(pluginFile);
         *
         *
         * foreach (string path in osapdFiles)
         * {
         * if (!string.IsNullOrEmpty(path))
         * {
         *  PluginDescription desc = new PluginDescription();
         *
         *  desc.Deserialize(path);
         *  desc.Status = "No Object";
         *  desc.Enabled = false;
         *
         *  if (desc.WikiUrl.Trim() == "")
         *      desc.WikiUrl = "http://www.opensourceautomation.com/wiki/index.php?title=Plugins";
         *
         *  OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type);
         *  foreach (OSAEObject o in objs)
         *  {
         *      if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name)
         *      {
         *          desc.Name = o.Name;
         *          if (o.Enabled == 1)
         *              desc.Enabled = true;
         *          if (o.State.Value == "ON")
         *              desc.Status = "Running";
         *          else
         *              desc.Status = "Stopped";
         *
         *          pluginList.Add(desc);
         *          Log.Info("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID);
         *      }
         *  }
         * }
         * }
         */

        // TODO: Load all other objects with base type of PLUGIN.  These objects represent plugins on client instances.  Maybe make a separate grid since it wont be able to load the osapd files on the clients

        checkForUpdates();
        gvPlugins.DataSource = pluginList;
        gvPlugins.DataBind();
    }
示例#7
0
        public void Timer_Tick(object sender, EventArgs eArgs)
        {
            try
            {
                foreach (XBMCSystem r in Systems)
                {
                    this.Log.Debug("Checking " + r.Name + " - pinging: " + r.Pinging.ToString());
                    if (!r.Pinging)
                    {
                        if (!r.Connected)
                        {
                            this.Log.Info("Removing system from list");
                            Systems.Remove(r);
                        }
                    }
                }

                OSAEObjectCollection XBMCInstances = OSAEObjectManager.GetObjectsByType("XBMC System");
                foreach (OSAEObject obj in XBMCInstances.ToList())
                {
                    foreach (XBMCSystem r in Systems)
                    {
                        if (obj.Name == r.Name)
                        {
                            XBMCInstances.Remove(obj);
                        }
                    }
                }
                foreach (OSAEObject obj in XBMCInstances)
                {
                    string ip = "", username = "", password = "";
                    int    port = 0;

                    foreach (OSAEObjectProperty p in obj.Properties)
                    {
                        switch (p.Name)
                        {
                        case "IP":
                            ip = p.Value;
                            break;

                        case "Port":
                            port = Int32.Parse(p.Value);
                            break;

                        case "Username":
                            username = p.Value;
                            break;

                        case "Password":
                            password = p.Value;
                            break;
                        }
                    }
                    this.Log.Debug("Creating new XBMC System connection: " + obj.Name + " - " + ip);
                    XBMCSystem system = new XBMCSystem(obj.Name, ip, port, username, password);
                    if (system.Connect())
                    {
                        Systems.Add(system);
                    }
                }
            }
            catch (Exception ex)
            {
                this.Log.Error("Error on timer tick", ex);
            }
        }
        /// <summary>
        /// Returns a Dataset of all objects in a specified container
        /// </summary>
        /// <param name="ContainerName"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByContainer(string ContainerName)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();
            try
            {
                if (ContainerName == string.Empty)
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name is null ORDER BY object_name ASC";
                }
                else
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object WHERE container_name=@ContainerName ORDER BY object_name ASC";
                    command.Parameters.AddWithValue("@ContainerName", ContainerName);
                }

                dataset = OSAESql.RunQuery(command);
                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                        obj.State.Value = dr["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                        obj.BaseType = dr["base_type"].ToString();
                        obj.LastUpd = dr["last_updated"].ToString();
                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }

                    return objects;
                }

                return objects;
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectsByContainer error: " + ex.Message, true);
                return objects;
            }
        }
示例#9
0
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;
            Log   = new General.OSAELog(pName);
            Log.Debug("Running interface");

            OSAEObjectType objt = OSAEObjectTypeManager.ObjectTypeLoad("ONKYO RECEIVER");

            OSAEObjectTypeManager.ObjectTypeUpdate(objt.Name, objt.Name, objt.Description, pName, "THING", objt.Owner, objt.SysType, objt.Container, objt.HideRedundant);

            _UDPListen              = new UDPListen();
            _UDPSend                = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                    case "Communication Type":
                        r.Type = prop.Value;
                        break;

                    case "IP":
                        r.IP = prop.Value;
                        break;

                    case "Network Port":
                        try
                        { r.NetworkPort = Int32.Parse(prop.Value); }
                        catch
                        { r.NetworkPort = 0; }
                        break;

                    case "COM Port":
                        try
                        { r.ComPort = Int32.Parse(prop.Value); }
                        catch
                        { r.ComPort = 0; }
                        break;
                    }
                }

                receivers.Add(r);
                Log.Debug("Added receiver to list: " + r.Name);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        Log.Debug("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    { //not implemented
                    }
                    else
                    {
                        Log.Info(r.Name + " - Properties not set");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error creating connection to receiver", ex); }
            }
            Log.Info("Run Interface Complete");
        }
    protected void btnAddFile_Click(object sender, EventArgs e)
    {
        xType = ddlExportType.SelectedValue;
        //string aF = createExportFileName(xType, ddlObjToExport.SelectedValue);
        ExportObject exObj       = new ExportObject(ddlObjToExport.SelectedValue, xType);
        string       fileLstName = @ddlObjToExport.SelectedValue + "::" + xType;

        if (lstFileList.Width.Value < fileLstName.Length * 7)
        {
            lstFileList.Width = fileLstName.Length * 7;
        }
        if (inFileList(fileLstName))
        {
            // Do nothing, Object already in the Export List.
        }
        else
        {
            if (ddlExportType.SelectedValue == "Screen")
            {
                OSAEObjectCollection screenObjects = OSAEObjectManager.GetObjectsByContainer(ddlObjToExport.SelectedValue);
                foreach (OSAEObject obj in screenObjects)
                {
                    if (obj.Type == "CONTROL USER SELECTOR" || obj.Type == "CONTROL SCREEN OBJECTS")
                    {
                        // Do not create objects for:  User Selector or Screen Objects
                    }
                    else
                    {
                        fileLstName = @obj.Name + "::Object";
                        if (lstFileList.Width.Value < fileLstName.Length * 7)
                        {
                            lstFileList.Width = fileLstName.Length * 7;
                        }
                        if (inFileList(fileLstName))
                        {
                            // Do nothing, Object already in the List.
                        }
                        else
                        {
                            // Add Object To File List
                            lstFileList.Items.Add(fileLstName);

                            // Check if object has External Files (Images or Files)
                            checkForExternal(obj.Name);
                        }
                    }
                }
            }
            else
            {
                // // Add Object To File List
                lstFileList.Items.Add(fileLstName);

                // Check if object has External Files (Images or Files)
                checkForExternal(ddlObjToExport.SelectedValue);
            }
        }

        if (lstFileList.Items.Count > 0)
        {
            lblZipName.Visible = true;
            txtZipName.Visible = true;
            btnExport.Visible  = true;
            btnExport.Enabled  = true;
            btnClear2.Visible  = true;
            btnClear2.Enabled  = true;
        }
        else
        {
            btnExport.Visible = false;
            btnExport.Enabled = false;
            btnClear2.Visible = false;
            btnClear2.Enabled = false;
        }
    }
示例#11
0
        public override void RunInterface(string pluginName)
        {
            try
            {
                pName           = pluginName;
                Log             = new General.OSAELog(pName);
                FirstUpdateRun  = true;
                FirstForcastRun = true;
                Log.Info("Running Interface");
                OwnTypes();

                OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("WEATHER");
                if (objects.Count == 0)
                {
                    OSAEObjectManager.ObjectAdd("Weather", "", "Weather Data", "WEATHER", "", "", 30, true);
                    WeatherObjName = "Weather";
                }
                else
                {
                    WeatherObjName = objects[0].Name;
                }

                Log.Info("Linked to Weather object to store data.");
                try
                {
                    if (bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Metric").Value))
                    {
                        Metric = true;
                        Log.Info("Using metric units");
                    }
                }
                catch {}

                try
                {
                    gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Debug").Value);
                }
                catch
                { Log.Info("The WUnderground Object Type seems to be missing the Debug Property!"); }
                Log.Info("Debug Mode Set to " + gDebug);

                try
                {
                    pKey = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Key").Value;
                    if (pKey.Length < 1)
                    {
                        Log.Info("!!! You need an WUnderground Key for full weather feeds !!!");
                    }
                    else
                    {
                        Log.Info("Found WUnderground Key (" + pKey + ")");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error reading your Key.", ex); }

                try
                {
                    pCity = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "City").Value;
                    if (pCity.Length < 1)
                    {
                        Log.Info("!!! You need a City for full weather feeds !!!");
                    }
                    else
                    {
                        Log.Info("Found WUnderground City (" + pCity + ")");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error reading your City.", ex); }

                try
                {
                    pState = OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "State").Value;
                    if (pState.Length < 1)
                    {
                        Log.Info("!!! You need a State for full weather feeds !!!");
                    }
                    else
                    {
                        Log.Info("Found State (" + pState + ")");
                    }
                }
                catch (Exception ex)
                { Log.Error("Error reading your State.", ex); }


                Conditionsupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Conditions Interval").Value);
                if (Conditionsupdatetime > 0)
                {
                    ConditionsUpdateTimer          = new System.Timers.Timer();
                    ConditionsUpdateTimer.Interval = Conditionsupdatetime * 60000;
                    ConditionsUpdateTimer.Start();
                    ConditionsUpdateTimer.Elapsed += new ElapsedEventHandler(ConditionsUpdateTime);

                    updateConditionsThread = new Thread(new ThreadStart(updateconditions));
                    updateConditionsThread.Start();

                    //  Thread.Sleep(10000);
                }
                else
                {
                    latitude  = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "latitude").Value;
                    longitude = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "longitude").Value;
                    if (gDebug)
                    {
                        Log.Debug("Read in properties: Lat=" + latitude + ", Long=" + longitude);
                    }
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstUpdateRun);

                Forecastupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Forecast Interval").Value);
                if (Forecastupdatetime > 0)
                {
                    ForecastUpdateTimer          = new System.Timers.Timer();
                    ForecastUpdateTimer.Interval = Forecastupdatetime * 60000;
                    ForecastUpdateTimer.Start();
                    ForecastUpdateTimer.Elapsed += new ElapsedEventHandler(ForecastUpdateTime);

                    updateForecastThread = new Thread(new ThreadStart(updateforecast));
                    updateForecastThread.Start();
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstForcastRun);

                Log.Info("Updated " + WeatherObjName + ", setting Weather object to Updated.");
                OSAE.OSAEMethodManager.MethodQueueAdd(WeatherObjName, "Updated", "", "", pName);

                DayNightUpdateTimer          = new System.Timers.Timer();
                DayNightUpdateTimer.Interval = DayNightupdatetime;
                DayNightUpdateTimer.Start();
                DayNightUpdateTimer.Elapsed += new ElapsedEventHandler(DayNightUpdateTime);

                updateDayNightThread = new Thread(new ThreadStart(updateDayNight));
                updateDayNightThread.Start();
            }
            catch (Exception ex)
            { Log.Error("Error initializing the plugin ", ex); }
        }
示例#12
0
        private void loadPlugins()
        {
            pluginList = new BindingList <PluginDescription>();
            List <string> osapdFiles = new List <string>();

            string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories);
            osapdFiles.AddRange(pluginFile);
            bool bFoundObject = false;

            foreach (string path in osapdFiles)
            {
                if (!string.IsNullOrEmpty(path))
                {
                    bFoundObject = false;
                    PluginDescription desc = new PluginDescription();

                    desc.Deserialize(path);
                    desc.Status  = "No Object";
                    desc.Enabled = false;
                    this.Log.Info(desc.Type + ":  Plugin DLL found, Desc ID = " + desc.ID);
                    OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type);
                    foreach (OSAEObject o in objs)
                    {
                        if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name)
                        {
                            desc.Name    = o.Name;
                            bFoundObject = true;
                            if (o.Enabled == 1)
                            {
                                desc.Enabled = true;
                            }
                            if (o.State.Value == "ON")
                            {
                                desc.Status = "Running";
                            }
                            else if (o.State.Value == "OFF")
                            {
                                desc.Status = "Stopped";
                            }
                            else
                            {
                                desc.Status = o.State.Value;
                            }

                            this.Log.Info(desc.Type + ":  Plugin Object found, Object Name = " + o.Name);
                            pluginList.Add(desc);
                        }
                    }
                    // Here we try to create the Object if none was found above, we need a valid Object Type for this.
                    if (bFoundObject == false)
                    {
                        this.Log.Info(desc.Type + ":  Plugin Object Missing!");
                        bool bObjectTypeExists = OSAEObjectTypeManager.ObjectTypeExists(desc.Type);
                        if (bObjectTypeExists)
                        {
                            this.Log.Info(desc.Type + ":  Valid Object Type found.  Attempting to create Object...");
                            OSAEObjectManager.ObjectAdd(desc.Type, desc.Type, desc.Type + " plugin's Object", desc.Type, "", "SYSTEM", false);
                            OSAEObject obj = OSAEObjectManager.GetObjectByName(desc.Type);
                            if (obj != null)
                            {
                                desc.Name    = obj.Name;
                                desc.Enabled = false;
                                if (obj.State.Value == "ON")
                                {
                                    desc.Status = "Running";
                                }
                                else if (obj.State.Value == "OFF")
                                {
                                    desc.Status = "Stopped";
                                }
                                else
                                {
                                    desc.Status = obj.State.Value;
                                }

                                this.Log.Info(desc.Type + ":  Plugin Object now found!");
                                pluginList.Add(desc);
                            }
                        }
                        else
                        {
                            this.Log.Info(desc.Type + ":  NO Valid Object Type found!  I cannot create an Object!  Please run Install.sql for this plugin.");
                        }
                    }
                }
            }
            dgLocalPlugins.ItemsSource = pluginList;
        }
示例#13
0
        public override void RunInterface(string pluginName)
        {
            logging.AddToLog("Running interface", false);
            pName = pluginName;
            OSAEObjectTypeManager.ObjectTypeUpdate("ONKYO RECEIVER", "ONKYO RECEIVER", "Onkyo Receiver", pluginName, "ONKYO RECEIVER", 0, 0, 0, 1);

            _UDPListen              = new UDPListen();
            _UDPSend                = new UDPSend();
            _UDPListen.OnkyoDevice += new DelegateOnkyoReply(OnkyoMessageHandler);

            _UDPListen.Listen();
            _UDPSend.Send();

            OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("ONKYO RECEIVER");

            foreach (OSAEObject obj in objects)
            {
                Receiver r = new Receiver(obj.Name);
                foreach (OSAEObjectProperty prop in obj.Properties)
                {
                    switch (prop.Name)
                    {
                    case "Communication Type":
                        r.Type = prop.Value;
                        break;

                    case "IP":
                        r.IP = prop.Value;
                        break;

                    case "Network Port":
                        try
                        {
                            r.NetworkPort = Int32.Parse(prop.Value);
                        }
                        catch
                        {
                            r.NetworkPort = 0;
                        }
                        break;

                    case "COM Port":
                        try
                        {
                            r.ComPort = Int32.Parse(prop.Value);
                        }
                        catch
                        {
                            r.ComPort = 0;
                        }
                        break;
                    }
                }

                receivers.Add(r);
                logging.AddToLog("Added receiver to list: " + r.Name, false);

                try
                {
                    if (r.Type == "Network" && r.IP != "" && r.NetworkPort != 0)
                    {
                        logging.AddToLog("Creating TCP Client: ip-" + r.IP + " port-" + r.NetworkPort, false);
                        r.tcpClient = new TcpClient(r.IP, r.NetworkPort);

                        //get a network stream from server
                        r.clientSockStream = r.tcpClient.GetStream();

                        // create new writer and reader stream to send and receive
                        r.clientStreamWriter = new StreamWriter(r.clientSockStream);
                        r.clientStreamReader = new StreamReader(r.clientSockStream);

                        //Start listening
                        r.Connect();
                    }
                    else if (r.Type == "Serial" && r.ComPort != 0)
                    {
                        //not implemented
                    }
                    else
                    {
                        logging.AddToLog(r.Name + " - Properties not set", true);
                    }
                }
                catch (Exception ex)
                {
                    logging.AddToLog("Error creating connection to receiver: " + ex.Message, true);
                }
            }
            logging.AddToLog("Run Interface Complete", false);
        }
示例#14
0
        public override void RunInterface(string pluginName)
        {
            try
            {
                FirstRun = true;
                logging.AddToLog("Running Interface", true);
                pName = pluginName;

                OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("WEATHER");
                if (objects.Count == 0)
                {
                    OSAEObjectManager.ObjectAdd("Weather", "Weather Data", "WEATHER", "", "", true);
                    WeatherObjName = "Weather";
                }
                else
                {
                    WeatherObjName = objects[0].Name;
                }


                try
                {
                    if (Boolean.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Metric").Value))
                    {
                        Metric = true;
                        logging.AddToLog("Using metric units", true);
                    }
                }
                catch
                {
                }


                Conditionsupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Conditions Interval").Value);
                if (Conditionsupdatetime > 0)
                {
                    ConditionsUpdateTimer          = new System.Timers.Timer();
                    ConditionsUpdateTimer.Interval = Conditionsupdatetime * 60000;
                    ConditionsUpdateTimer.Start();
                    ConditionsUpdateTimer.Elapsed += new ElapsedEventHandler(ConditionsUpdateTime);

                    this.updateConditionsThread = new Thread(new ThreadStart(updateconditions));
                    this.updateConditionsThread.Start();

                    Thread.Sleep(5000);
                }
                else
                {
                    latitude  = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "latitude").Value;
                    longitude = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "longitude").Value;
                }

                Forecastupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Forecast Interval").Value);
                if (Forecastupdatetime > 0)
                {
                    ForecastUpdateTimer          = new System.Timers.Timer();
                    ForecastUpdateTimer.Interval = Forecastupdatetime * 60000;
                    ForecastUpdateTimer.Start();
                    ForecastUpdateTimer.Elapsed += new ElapsedEventHandler(ForecastUpdateTime);

                    this.updateForecastThread = new Thread(new ThreadStart(updateforecast));
                    this.updateForecastThread.Start();
                }

                DayNightUpdateTimer          = new System.Timers.Timer();
                DayNightUpdateTimer.Interval = DayNightupdatetime;
                DayNightUpdateTimer.Start();
                DayNightUpdateTimer.Elapsed += new ElapsedEventHandler(DayNightUpdateTime);

                this.updateDayNightThread = new Thread(new ThreadStart(updateDayNight));
                this.updateDayNightThread.Start();
            }
            catch (Exception ex)
            {
                logging.AddToLog("Error initializing the plugin " + ex.Message, true);
            }
        }
示例#15
0
        public override void RunInterface(string pluginName)
        {
            try
            {
                FirstUpdateRun  = true;
                FirstForcastRun = true;
                Log.Info("Running Interface");
                pName = pluginName;

                OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("WEATHER");
                if (objects.Count == 0)
                {
                    OSAEObjectManager.ObjectAdd("Weather", "Weather Data", "WEATHER", "", "", true);
                    WeatherObjName = "Weather";
                }
                else
                {
                    WeatherObjName = objects[0].Name;
                }

                Log.Info("Linked to Weather object to store data.");
                try
                {
                    if (Boolean.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Metric").Value))
                    {
                        Metric = true;
                        this.Log.Info("Using metric units");
                    }
                }
                catch
                {
                }

                Conditionsupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Conditions Interval").Value);
                if (Conditionsupdatetime > 0)
                {
                    ConditionsUpdateTimer          = new System.Timers.Timer();
                    ConditionsUpdateTimer.Interval = Conditionsupdatetime * 60000;
                    ConditionsUpdateTimer.Start();
                    ConditionsUpdateTimer.Elapsed += new ElapsedEventHandler(ConditionsUpdateTime);

                    this.updateConditionsThread = new Thread(new ThreadStart(updateconditions));
                    this.updateConditionsThread.Start();

                    //  Thread.Sleep(10000);
                }
                else
                {
                    latitude  = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "latitude").Value;
                    longitude = OSAEObjectPropertyManager.GetObjectPropertyValue(WeatherObjName, "longitude").Value;
                    Log.Debug("Read in properties: Lat=" + latitude + ", Long=" + longitude);
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstUpdateRun);

                Forecastupdatetime = Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Forecast Interval").Value);
                if (Forecastupdatetime > 0)
                {
                    ForecastUpdateTimer          = new System.Timers.Timer();
                    ForecastUpdateTimer.Interval = Forecastupdatetime * 60000;
                    ForecastUpdateTimer.Start();
                    ForecastUpdateTimer.Elapsed += new ElapsedEventHandler(ForecastUpdateTime);

                    this.updateForecastThread = new Thread(new ThreadStart(updateforecast));
                    this.updateForecastThread.Start();
                }

                do
                {
                    Thread.Sleep(5000);
                } while (FirstForcastRun);


                DayNightUpdateTimer          = new System.Timers.Timer();
                DayNightUpdateTimer.Interval = DayNightupdatetime;
                DayNightUpdateTimer.Start();
                DayNightUpdateTimer.Elapsed += new ElapsedEventHandler(DayNightUpdateTime);

                this.updateDayNightThread = new Thread(new ThreadStart(updateDayNight));
                this.updateDayNightThread.Start();
            }
            catch (Exception ex)
            {
                this.Log.Error("Error initializing the plugin ", ex);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified property
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByPropertyValue(string property, string value)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                command.CommandText = "SELECT object_name, object_alias, object_description, object_type, address, container_name, min_trust_level, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state, last_updated FROM osae_v_object_property WHERE property_name=@Property AND UPPER(property_value) = UPPER(@Value)";
                command.Parameters.AddWithValue("@Property", property);
                command.Parameters.AddWithValue("@Value", value);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dataset.Tables[0].Rows)
                    {
                        obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].ToString(), dataset.Tables[0].Rows[0]["object_alias"].ToString(), dataset.Tables[0].Rows[0]["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dataset.Tables[0].Rows[0]["address"].ToString(), dataset.Tables[0].Rows[0]["container_name"].ToString(), Convert.ToUInt16(dataset.Tables[0].Rows[0]["min_trust_level"].ToString()), (dataset.Tables[0].Rows[0]["enabled"].ToString() != "0"));
                        obj.State.Value = dataset.Tables[0].Rows[0]["state_name"].ToString();
                        obj.State.TimeInState = Convert.ToInt64(dataset.Tables[0].Rows[0]["time_in_state"]);
                        obj.BaseType = dataset.Tables[0].Rows[0]["base_type"].ToString();
                        obj.LastUpd = dataset.Tables[0].Rows[0]["last_updated"].ToString();
                        obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                        obj.Methods = GetObjectMethods(obj.Name);
                        objects.Add(obj);
                    }
                    return objects;
                }
                else
                    return null;
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByPropertyValue (" + property + ") error: " + ex.Message, true);
                return null;
            }
        }
        private void search()
        {
            try
            {
                Guid uuid = BluetoothService.L2CapProtocol;
                BluetoothDeviceInfo bdi;
                BluetoothAddress    ba;
                byte tmp;
                bool found = false;
                int  discarded;

                bc = new BluetoothClient();

                bc.InquiryLength = new TimeSpan(0, 0, 0, int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Discover Length").Value), 0);
                nearosaeDevices  = bc.DiscoverDevices(10, false, false, true);

                for (int j = 0; j < nearosaeDevices.Length; j++)
                {
                    string addr = nearosaeDevices[j].DeviceAddress.ToString();

                    Object obj = OSAEObjectManager.GetObjectByAddress(addr);

                    if (obj == null)
                    {
                        if (OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Learning Mode").Value == "TRUE")
                        {
                            OSAEObjectManager.ObjectAdd(nearosaeDevices[j].DeviceName, nearosaeDevices[j].DeviceName, "BLUETOOTH DEVICE", nearosaeDevices[j].DeviceAddress.ToString(), string.Empty, true);
                            OSAEObjectPropertyManager.ObjectPropertySet(nearosaeDevices[j].DeviceName, "Discover Type", "0", gAppName);
                            if (gDebug)
                            {
                                Log.Debug(addr + " - " + nearosaeDevices[j].DeviceName + ": added to OSA");
                            }
                        }
                    }
                }

                OSAEObjectCollection objects = OSAEObjectManager.GetObjectsByType("BLUETOOTH DEVICE");

                foreach (OSAEObject obj in objects)
                {
                    found = false;
                    string address   = obj.Address;
                    byte[] byteArray = HexEncoding.GetBytes(address, out discarded);
                    tmp          = byteArray[0];
                    byteArray[0] = byteArray[5];
                    byteArray[5] = tmp;
                    tmp          = byteArray[1];
                    byteArray[1] = byteArray[4];
                    byteArray[4] = tmp;
                    tmp          = byteArray[2];
                    byteArray[2] = byteArray[3];
                    byteArray[3] = tmp;
                    ba           = new BluetoothAddress(byteArray);
                    bdi          = new BluetoothDeviceInfo(ba);
                    if (gDebug)
                    {
                        Log.Debug("Begin search for " + address);
                    }

                    for (int j = 0; j < nearosaeDevices.Length; j++)
                    {
                        if (nearosaeDevices[j].DeviceAddress.ToString() == address)
                        {
                            found = true;
                            if (gDebug)
                            {
                                Log.Debug(address + " - " + obj.Name + ": found with DiscoverDevices");
                            }
                        }
                    }
                    if (!found)
                    {
                        if (gDebug)
                        {
                            Log.Debug(address + " - " + obj.Name + ": failed with DiscoverDevices");
                        }
                    }

                    try
                    {
                        if (!found && (int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 2 || Int32.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0))
                        {
                            if (gDebug)
                            {
                                Log.Debug(address + " - " + obj.Name + ": attempting GetServiceRecords");
                            }

                            bdi.GetServiceRecords(uuid);
                            found = true;
                            if (gDebug)
                            {
                                Log.Debug(address + " - " + obj.Name + " found with GetServiceRecords");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (gDebug)
                        {
                            Log.Debug(address + " - " + obj.Name + " failed GetServiceRecords. exception: " + ex.Message);
                        }
                    }

                    try
                    {
                        if (!found && (int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 3 || int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Discover Type").Value) == 0))
                        {
                            if (gDebug)
                            {
                                Log.Debug(address + " - " + obj.Name + ": attempting Connection");
                            }
                            //attempt a connect
                            BluetoothEndPoint ep;
                            ep = new BluetoothEndPoint(bdi.DeviceAddress, BluetoothService.Handsfree);
                            //MessageBox.Show("attempt connect: " + pairedDevices[i].DeviceAddress);
                            bc.Connect(ep);
                            if (gDebug)
                            {
                                Log.Debug(address + " - " + obj.Name + " found with Connect attempt");
                            }
                            bc.Close();
                            found = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(address + " - " + obj.Name + " failed with Connect attempt. exception: " + ex.Message);
                    }

                    if (found)
                    {
                        OSAEObjectStateManager.ObjectStateSet(obj.Name, "ON", gAppName);
                        if (gDebug)
                        {
                            Log.Debug(obj.Name + " Status Updated in osae");
                        }
                    }
                    else
                    {
                        OSAEObjectStateManager.ObjectStateSet(obj.Name, "OFF", gAppName);
                        if (gDebug)
                        {
                            Log.Debug(obj.Name + " Status Updated in osae");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error searching for devices", ex);
            }
        }
示例#18
0
        public override void RunInterface(string pluginName)
        {
            Log.Info("Running interface");
            gAppName = pluginName;
            Log      = new General.OSAELog(gAppName);
            if (OSAEObjectManager.ObjectExists(gAppName))
            {
                Log.Info("Found the XBMC plugin's Object (" + gAppName + ")");
            }
            else
            {
                Log.Info("Could Not Find the XBMC plugin's Object!!! (" + gAppName + ")");
            }

            try
            {
                gDebug = Convert.ToBoolean(OSAEObjectPropertyManager.GetObjectPropertyValue(gAppName, "Debug").Value);
            }
            catch
            { Log.Info("The XBMC Object Type seems to be missing the Debug Property!"); }
            Log.Info("Debug Mode Set to " + gDebug);


            OwnTypes();
            //OSAEObjectTypeManager.ObjectTypeUpdate("XBMC SYSTEM", "XBMC SYSTEM", "XBMC System", pluginName, "XBMC SYSTEM", 0, 0, 0, 1);

            OSAEObjectCollection XBMCInstances = OSAEObjectManager.GetObjectsByType("XBMC System");

            foreach (OSAEObject obj in XBMCInstances)
            {
                string ip = "", username = "", password = "";
                int    port = 0;

                foreach (OSAEObjectProperty p in obj.Properties)
                {
                    switch (p.Name)
                    {
                    case "IP":
                        ip = p.Value;
                        break;

                    case "Port":
                        port = Int32.Parse(p.Value);
                        break;

                    case "Username":
                        username = p.Value;
                        break;

                    case "Password":
                        password = p.Value;
                        break;
                    }
                }
                Log.Info("Creating new XBMC System connection: " + obj.Name + " (" + ip + ":" + port + ", user="******")");
                try
                {
                    XBMCSystem system = new XBMCSystem(obj.Name, ip, port, username, password);
                    if (system.Connect())
                    {
                        Systems.Add(system);
                        Log.Info("XBMC System connection Successfull for: " + obj.Name);
                    }
                }
                catch (Exception ex)
                { Log.Error("Error connecting to XBMC system", ex); }
            }

            try
            {
                Clock          = new System.Timers.Timer();
                Clock.Interval = 10000;

                Clock.Elapsed += new ElapsedEventHandler(Timer_Tick);
                Clock.Start();
                if (gDebug)
                {
                    Log.Debug("Timers Started");
                }
            }
            catch (Exception ex)
            { Log.Error("Error starting timers ", ex); }
        }
示例#19
0
        /// <summary>
        /// OSA Plugin Interface - called on start up to allow plugin to do any tasks it needs
        /// </summary>
        /// <param name="pluginName">The name of the plugin from the system</param>
        public override void RunInterface(string pluginName)
        {
            pName = pluginName;

            try
            {
                logging.AddToLog("Starting SysLog...", true);

                logEventsToFile = Boolean.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Log to file").Value);
                port            = int.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(pName, "Port").Value);

                IPEndPoint anyIP       = new IPEndPoint(IPAddress.Any, 0);
                UdpClient  udpListener = new UdpClient(port);

                cts   = new CancellationTokenSource();
                token = cts.Token;

                OSAEObjectCollection c = OSAEObjectManager.GetObjectsByType("SysLog-Trigger");
                if (c.Count > 0)
                {
                    logging.AddToLog("Found " + c.Count + " triggers to watch for", false);
                    GetMatches(c);
                }
                else
                {
                    logging.AddToLog("No SysLog Triggers found to look for creating example", true);
                    OSAEObjectManager.ObjectAdd("SysLog Tigger - Example", "This is an an example trigger created by the plugin which can be deleted", "SysLog-Trigger", "", "", true);
                    OSAEObjectPropertyManager.ObjectPropertySet("SysLog Tigger - Example", "Trigger String", "The string to look for", pName);
                    OSAEObjectPropertyManager.ObjectPropertySet("SysLog Tigger - Example", "Source IP", "192.168.0.1", pName);
                }

                task = Task.Factory.StartNew(() =>
                {
                    while (!token.IsCancellationRequested)
                    {
                        if (udpListener.Available > 0)
                        {
                            try
                            {
                                byte[] bReceive = udpListener.Receive(ref anyIP);
                                string sReceive = Encoding.ASCII.GetString(bReceive);
                                string sourceIP = anyIP.Address.ToString();

                                Task messageProcessor = new Task(() => ProcessEvent(sourceIP, sReceive));
                                messageProcessor.Start();
                            }
                            catch (Exception ex)
                            {
                                logging.AddToLog("Exception occurred in SysLog details: " + ex.Message, true);
                            }
                        }
                        else
                        {
                            token.WaitHandle.WaitOne(300);
                        }
                    }

                    if (token.IsCancellationRequested)
                    {
                        logging.AddToLog("Cancellation Token Set", false);
                    }
                }, token);
            }
            catch (Exception ex)
            {
                logging.AddToLog("Error during RunInterface: " + ex.Message, true);
            }
        }
        /// <summary>
        /// Returns a Dataset of all objects of specified type
        /// </summary>
        /// <param name="ObjectType"></param>
        /// <returns></returns>
        public static OSAEObjectCollection GetObjectsByType(string ObjectType)
        {
            DataSet dataset = new DataSet();
            OSAEObject obj = new OSAEObject();
            OSAEObjectCollection objects = new OSAEObjectCollection();

            using (MySqlCommand command = new MySqlCommand())
            {
                try
                {
                    command.CommandText = "SELECT object_name, object_description, object_type, address, container_name, enabled, state_name, base_type, coalesce(time_in_state, 0) as time_in_state FROM osae_v_object WHERE object_type=@ObjectType";
                    command.Parameters.AddWithValue("@ObjectType", ObjectType);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow dr in dataset.Tables[0].Rows)
                        {
                            obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dataset.Tables[0].Rows[0]["object_type"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), int.Parse(dr["enabled"].ToString()));
                            obj.State.Value = dr["state_name"].ToString();
                            obj.State.TimeInState = Convert.ToInt64(dr["time_in_state"]);
                            obj.BaseType = dr["base_type"].ToString();
                            obj.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                            obj.Methods = OSAEObjectManager.GetObjectMethods(obj.Name);
                            objects.Add(obj);
                        }
                        return objects;
                    }
                    return objects;
                }
                catch (Exception ex)
                {
                    Logging.GetLogger().AddToLog("API - GetObjectsByType error: " + ex.Message, true);
                    return objects;
                }
            }
        }
        public OSAEObjectCollection GetAllObjects()
        {
            MySqlCommand command = new MySqlCommand("SELECT object_name, object_description, object_type_description, container_name, state_label, last_updated, address, enabled, time_in_state, base_type FROM osae_v_object");
            DataSet ds = OSAESql.RunQuery(command);

            OSAEObjectCollection objs = new OSAEObjectCollection();
            OSAEObject obj;

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                obj = new OSAEObject(dr["object_name"].ToString(), dr["object_description"].ToString(), dr["object_type_description"].ToString(), dr["address"].ToString(), dr["container_name"].ToString(), Int32.Parse(dr["enabled"].ToString()));
                obj.LastUpd = dr["last_updated"].ToString();
                obj.State.Value = dr["state_label"].ToString();
                obj.State.TimeInState = long.Parse(dr["time_in_state"].ToString());
                obj.BaseType = dr["base_type"].ToString();
                objs.Add(obj);
            }
            return objs;
        }
示例#22
0
        private void GetMatches(OSAEObjectCollection collection)
        {
            logging.AddToLog("Watching for the following Messages:", false);
            foreach (OSAEObject obj in collection)
            {
                SysLogObject sysLogObj = new SysLogObject();

                sysLogObj.TriggerString = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Trigger String").Value;
                sysLogObj.Source = OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Source IP").Value;
                sysLogObj.ExactMatch = bool.Parse(OSAEObjectPropertyManager.GetObjectPropertyValue(obj.Name, "Exact Match").Value);
                sysLogObj.OsaObjectName = obj.Name;

                lookup.Add(sysLogObj);
                logging.AddToLog("Source IP is: " + sysLogObj.Source , false);

                if (sysLogObj.ExactMatch)
                {
                    logging.AddToLog("Message exactly matches: " + sysLogObj.TriggerString, false);
                }
                else
                {
                    logging.AddToLog("Message Contains: " + sysLogObj.TriggerString, false);
                }
            }
        }
示例#23
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         if (Session["Username"] == null)
         {
             Response.Redirect("~/Default.aspx");
         }
         if (Session["SecurityLevel"].ToString() != "Admin")
         {
             Response.Redirect("~/permissionError.aspx");
         }
         OSAEAdmin adSet = OSAEAdminManager.GetAdminSettings();
         screensLev.Text = adSet.ScreenTrust.ToString();
         string dScreen = adSet.defaultScreen;
         objectsLev.Text               = adSet.ObjectsTrust.ToString();
         objectsAddLev.Text            = adSet.ObjectsAddTrust.ToString();
         objectsUpdateLev.Text         = adSet.ObjectsUpdateTrust.ToString();
         objectsDeleteLev.Text         = adSet.ObjectsDeleteTrust.ToString();
         analyticsLev.Text             = adSet.AnalyticsTrust.ToString();
         manageLev.Text                = adSet.ManagementTrust.ToString();
         objecttypeLev.Text            = adSet.ObjectTypeTrust.ToString();
         objecttypeAddLev.Text         = adSet.ObjectTypeAddTrust.ToString();
         objecttypeUpdateLev.Text      = adSet.ObjectTypeUpdateTrust.ToString();
         objecttypeDeleteLev.Text      = adSet.ObjectTypeDeleteTrust.ToString();
         scriptLev.Text                = adSet.ScriptTrust.ToString();
         scriptAddLev.Text             = adSet.ScriptAddTrust.ToString();
         scriptUpdateLev.Text          = adSet.ScriptUpdateTrust.ToString();
         scriptDeleteLev.Text          = adSet.ScriptDeleteTrust.ToString();
         scriptObjectEventLev.Text     = adSet.ScriptObjectAddTrust.ToString();
         scriptObjectTypeEventLev.Text = adSet.ScriptObjectTypeAddTrust.ToString();
         patternLev.Text               = adSet.PatternTrust.ToString();
         patternAddLev.Text            = adSet.PatternAddTrust.ToString();
         patternUpdateLev.Text         = adSet.PatternUpdateTrust.ToString();
         patternDeleteLev.Text         = adSet.PatternDeleteTrust.ToString();
         readerLev.Text                = adSet.ReaderTrust.ToString();
         readerAddLev.Text             = adSet.ReaderAddTrust.ToString();
         readerUpdateLev.Text          = adSet.ReaderUpdateTrust.ToString();
         readerDeleteLev.Text          = adSet.ReaderDeleteTrust.ToString();
         scheduleLev.Text              = adSet.ScheduleTrust.ToString();
         scheduleAddLev.Text           = adSet.ScheduleAddTrust.ToString();
         scheduleUpdateLev.Text        = adSet.ScheduleUpdateTrust.ToString();
         scheduleDeleteLev.Text        = adSet.ScheduleDeleteTrust.ToString();
         imageLev.Text       = adSet.ImagesTrust.ToString();
         imageAddLev.Text    = adSet.ImagesAddTrust.ToString();
         imageDeleteLev.Text = adSet.ImagesDeleteTrust.ToString();
         logsLev.Text        = adSet.LogsTrust.ToString();
         logsClearLev.Text   = adSet.LogsClearTrust.ToString();
         eventlogLev.Text    = adSet.EventLogTrust.ToString();
         methodlogLev.Text   = adSet.MethodLogTrust.ToString();
         serverlogLev.Text   = adSet.ServerLogTrust.ToString();
         debuglogLev.Text    = adSet.DebugLogTrust.ToString();
         valuesLev.Text      = adSet.ValuesTrust.ToString();
         configLev.Text      = adSet.ConfigTrust.ToString();
         OSAEObjectCollection screens = OSAEObjectManager.GetObjectsByType("SCREEN");
         foreach (OSAEObject s in screens)
         {
             ListItem li = new ListItem(s.Name);
             if (s.Name == dScreen)
             {
                 li.Selected = true;
             }
             mainScreen.Items.Add(li);
         }
         saveSuc.Visible = false;
     }
 }