public async Task <List <BusConfigurationDB> > GetBusConfigList() { using var conn = new SqliteConnection(ConnString); conn.Open(); var list = new List <BusConfigurationDB>(); var commandText = $"SELECT id, name, configuration, version, bustype FROM master_conf"; var cmd = new SqliteCommand(commandText, conn); using var reader = await cmd.ExecuteReaderAsync(CommandBehavior.Default); while (reader.Read()) { var item = new BusConfigurationDB { Id = reader.GetInt32(0), Name = reader.GetString(1), Configuration = reader.GetString(2), Version = reader.GetInt32(3), BusType = (BusType)reader.GetInt32(4) }; list.Add(item); Log.Information("Name: ${@item.Name} ", item.Name); } return(list); }
public async Task SaveConfiguration(string busName, BusConfigurationDB config) { Log.Debug(busName); if (config?.Id != null) { await GlobalData.UpdateBusEntry(busName, config); } else { await GlobalData.InsertBusEntry(config !); } }
public void UpdateBusConfig(BusConfigurationDB bus) { int index = BusDbConfig !.FindIndex(item => item.Name.Equals(bus.Name)); if (index != -1) { BusDbConfig[index] = bus; } else { BusDbConfig.Add(bus); } }
private async Task NoConfigFoundForBus(string name) { var errorReport = new HamBusError { ErrorNum = HamBusErrorNum.NoConfigure, Message = $"No configuration found: Please go to http://localhost/7300" }; var newConf = new BusConfigurationDB { Name = name, Version = 1, }; await GlobalData.InsertBusEntry(newConf); errorReport.IncSerial(); await Clients.Caller.SendAsync(SignalRCommands.ErrorReport, errorReport); }
public async Task InsertBusEntry(BusConfigurationDB conf) { using var conn = new SqliteConnection(ConnString); conn.Open(); using var transaction = conn.BeginTransaction(); var cmd = conn.CreateCommand(); cmd.CommandText = "insert into master_conf ( version, name, configuration, bustype) values ( @version, @name, @conf, @bustype)"; cmd.Parameters.AddWithValue("@version", conf.Version); cmd.Parameters.AddWithValue("@name", conf.Name); cmd.Parameters.AddWithValue("@bustype", (int)conf.BusType); cmd.Parameters.AddWithValue("@conf", conf.Configuration); cmd.Prepare(); await cmd.ExecuteNonQueryAsync(); await transaction.CommitAsync(); }
public async Task <BusConfigurationDB?> QueryBusByName(string name) { BusConfigurationDB?busConf = null; using var conn = new SqliteConnection(ConnString); try { conn.Open(); var commandText = $"SELECT * FROM master_conf where name = '{name.ToLower()}'"; var cmd = new SqliteCommand(commandText, conn); var reader = await cmd.ExecuteReaderAsync(CommandBehavior.Default); if (reader.HasRows) { await reader.ReadAsync(); busConf = new BusConfigurationDB { Id = (long)reader["id"], Name = (string)reader["name"], Version = (long)reader["version"] }; var btype = (long)reader["bustype"]; busConf.BusType = ConvertToBustype(btype); //busConf.BusType = (BusType) Convert.ToInt32( (long) reader["bustype"]); busConf.Configuration = (string)reader["configuration"]; } return(busConf); } catch (Exception e) { Log.Error("globalDataServiceSqlite: Exception {@e}", e); return(null); } }