GetObjectProperties() public static method

The the properties of an object
public static GetObjectProperties ( string ObjectName ) : OSAEObjectPropertyCollection
ObjectName string The object to get the proeprties of
return OSAEObjectPropertyCollection
        /// <summary>
        /// Returns an OSAEObject with the specified name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByName(string name)
        {
            MySqlCommand command = new MySqlCommand();
            DataSet      dataset = new DataSet();

            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_name=@Name";
                command.Parameters.AddWithValue("@Name", name);
                dataset = OSAESql.RunQuery(command);

                if (dataset.Tables[0].Rows.Count > 0)
                {
                    OSAEObject obj = new OSAEObject(dataset.Tables[0].Rows[0]["object_name"].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(), int.Parse(dataset.Tables[0].Rows[0]["enabled"].ToString()));
                    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.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);

                    obj.Methods = GetObjectMethods(obj.Name);

                    return(obj);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByName (" + name + ")error: " + ex.Message, true);
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <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_alias, 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_alias, 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 AND enabled = 1 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_alias"].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);
            }
        }
        public static OSAEObjectCollection GetObjectsByOwner(string ObjectOwner)
        {
            OSAEObjectCollection objects = new OSAEObjectCollection();

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    DataSet    dataset = new DataSet();
                    OSAEObject obj     = new OSAEObject();

                    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 owned_by=@ObjectOwner";
                    command.Parameters.AddWithValue("@ObjectOwner", ObjectOwner);
                    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.Properties = OSAEObjectPropertyManager.GetObjectProperties(obj.Name);
                            obj.Methods    = GetObjectMethods(obj.Name);
                            objects.Add(obj);
                        }

                        return(objects);
                    }
                }

                return(objects);
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectsByBaseType error: " + ex.Message, true);
                return(objects);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// Returns an OSAEObject with the specified address
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public static OSAEObject GetObjectByAddress(string address)
        {
            OSAEObject obj = null;

            try
            {
                using (MySqlCommand command = new MySqlCommand())
                {
                    DataSet dataset = new DataSet();

                    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 WHERE address=@Address";
                    command.Parameters.AddWithValue("@Address", address);
                    dataset = OSAESql.RunQuery(command);

                    if (dataset.Tables[0].Rows.Count > 0)
                    {
                        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.ToInt16(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);
                        return(obj);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.GetLogger().AddToLog("API - GetObjectByAddress (" + address + ")error: " + ex.Message, true);
                return(obj);
            }
        }