コード例 #1
0
        /// <summary>
        /// Get all blocks.
        /// </summary>
        /// <param name="controlType">A value to filter blocks by its control connections.</param>
        /// <returns>A list of blocks controlable with accessory decoders.</returns>
        public IEnumerable <ElementBase> GetAll(ControlModule.ModuleType controlType)
        {
            string             sql   = string.Empty;
            ElementBase        item  = null;
            List <ElementBase> items = new List <ElementBase>();

            Logger.LogDebug(this, "[CLASS].GetAll({0})", controlType);

            try
            {
                Connect();

                sql = @"SELECT 
                        " + ElementManager.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + ElementManager.SQL_TABLE + @" 
                    ORDER BY 
                        name Asc, 
                        id   Asc";

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    while (reader.Read())
                    {
                        item = ElementManager.ReadEntityRecord(reader);
                        if (item != null &&
                            (controlType == ControlModule.ModuleType.Undefined ||
                             controlType == ControlModule.ModuleType.Accessory && item.AccessoryConnections != null && item.AccessoryConnections.Length > 0 ||
                             controlType == ControlModule.ModuleType.Sensor && item.FeedbackConnections != null && item.FeedbackConnections.Length > 0))
                        {
                            items.Add(item);
                        }
                    }
                }

                return(items);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets all elements from a specified switchboard panel.
        /// </summary>
        /// <param name="panel">The switchboard panel.</param>
        /// <returns>The requested list of <see cref="ElementBase"/>.</returns>
        public List <ElementBase> GetByPanel(SwitchboardPanel panel)
        {
            string             sql   = string.Empty;
            ElementBase        item  = null;
            List <ElementBase> items = new List <ElementBase>();

            Logger.LogDebug(this, "[CLASS].GetByPanel([{0}])", panel);

            try
            {
                Connect();

                sql = @"SELECT 
                        " + ElementManager.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + ElementManager.SQL_TABLE + @" 
                    WHERE 
                        panelid = @panelid";

                SetParameter("panelid", panel.ID);

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    while (reader.Read())
                    {
                        item = ElementManager.ReadEntityRecord(reader);
                        if (item != null)
                        {
                            item.SwitchboardPanel = panel;
                            items.Add(item);
                        }
                    }
                }

                return(items);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
コード例 #3
0
        /// <summary>
        /// Get a element by its coordinates.
        /// </summary>
        /// <param name="coords">The element position.</param>
        /// <returns>The requested instance of <see cref="ElementBase"/> or <c>null</c> if the element cannot be found.</returns>
        public ElementBase GetByCoordinates(Coordinates coords)
        {
            int    id;
            string sql = string.Empty;

            Logger.LogDebug(this, "[CLASS].GetByCoordinates([{0}])", coords);

            try
            {
                Connect();

                sql = @"SELECT 
                        " + ElementManager.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + ElementManager.SQL_TABLE + @" 
                    WHERE 
                        x = @x And 
                        y = @y";

                SetParameter("x", coords.X);
                SetParameter("y", coords.Y);

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    if (reader.Read())
                    {
                        return(ElementManager.ReadEntityRecord(reader));
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
コード例 #4
0
        /// <summary>
        /// Read a category from the current reader record.
        /// </summary>
        internal static ElementBase ReadEntityRecord(SQLiteDataReader reader)
        {
            //"id, panelid, name, x, y, rotation, type, status"

            ElementBase record = ElementManager.CreateInstance(reader.GetInt32(6));

            record.ID = reader.GetInt32(0);
            record.SwitchboardPanel = new SwitchboardPanel(reader.GetInt32(1));
            record.Name             = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
            record.X        = reader.IsDBNull(3) ? 1 : reader.GetInt32(3);
            record.Y        = reader.IsDBNull(4) ? 1 : reader.GetInt32(4);
            record.Rotation = reader.IsDBNull(5) ? ElementBase.RotationStep.Step0 : (ElementBase.RotationStep)reader.GetInt32(5);

            if (ElementBase.IsAccessoryElement(record))
            {
                ((IAccessory)record).SetAccessoryStatus(reader.IsDBNull(7) ? ElementBase.STATUS_UNDEFINED : reader.GetInt32(7), false);
            }

            return(record);
        }
コード例 #5
0
        /// <summary>
        /// Recupera las propiedades de una Administración/Operadora.
        /// </summary>
        /// <param name="id">The element unique identifier (DB).</param>
        /// <returns>The requested instance of <see cref="ElementBase"/> or <c>null</c> if the element cannot be found.</returns>
        public ElementBase GetByID(Int64 id)
        {
            string sql = string.Empty;

            Logger.LogDebug(this, "[CLASS].GetByID({0})", id);

            try
            {
                Connect();

                sql = @"SELECT 
                        " + ElementManager.SQL_FIELDS_SELECT + @" 
                    FROM 
                        " + ElementManager.SQL_TABLE + @" 
                    WHERE 
                        id = @id";

                SetParameter("id", id);

                using (SQLiteDataReader reader = ExecuteReader(sql))
                {
                    if (reader.Read())
                    {
                        return(ElementManager.ReadEntityRecord(reader));
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                Logger.LogError(this, ex);

                throw;
            }
            finally
            {
                Disconnect();
            }
        }
コード例 #6
0
 /// <summary>
 /// Creates a element instance from the specified type.
 /// </summary>
 /// <param name="elementType">Element type corresponding of the enumeration type.</param>
 /// <returns>The requested instance.</returns>
 public static ElementBase CreateInstance(int elementType)
 {
     return(ElementManager.CreateInstance((ElementBase.ElementType)elementType));
 }