/// <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(); } }
/// <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(); } }
/// <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(); } }
/// <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(); } }