protected void UpdateLampDb(LampNode record) { using (var db = new DatabaseClient()) { db.AddOrUpdate(record); // Update the record to the database } }
public void AddOrUpdate(LampNode node) { lock (SyncRoot) { var table = GetTable(); // Try to insert record. If that fails with a duplicate key, then try update // Old code checked for existence first and then decided, but this was // race condition sensitive. try { InsertRecord(table, node); } catch (LiteException lE) { if (lE.ErrorCode == LiteException.INDEX_DUPLICATE_KEY) { UpdateRecord(table, node); } else { throw lE; // Some other error } } } }
public LampClient(LampNode data) { _node = data; StateSet = true; Url = data.Url; Name = data.Name; }
public LampClient(string url, string name) { Url = url; Name = name; _node = new LampNode(); StateSet = false; }
public LampNode SetLampStateExtended(string id, SetLampDataExtended data) { LampNode record = null; RuntimeMonitor.Monitor.RegisterCall("LampSet"); record = GetLamp(id); record.ProcessStateChanges(data); RequestSequencer.Sequencer.Schedule(new LampRequest(id, data)); return(record); }
private async Task UpdateSingleLamp(DatabaseClient db, LampNode lamp) { RuntimeMonitor.Monitor.RegisterCall("UpdateSingleLamp"); var lampClient = new LampClient(lamp); try { await lampClient.GetState(); db.AddOrUpdate(lampClient.Node); } catch { // Error is ok; if the lamp is not seen, it will be removed } }
private void UpdateRecord(ILiteCollection <LampNode> table, LampNode node) { var currentLamp = table.FindOne(rec => rec.Name.ToLower() == node.Name.ToLower()); if (currentLamp != null) { // Update currentLamp.Url = node.Url; currentLamp.On = node.On; currentLamp.Online = node.Online; currentLamp.LastSeen = node.LastSeen; currentLamp.Red = node.Red; currentLamp.Green = node.Green; currentLamp.Blue = node.Blue; currentLamp.NodeType = node.NodeType; table.Update(currentLamp); } }
private void InsertRecord(ILiteCollection <LampNode> table, LampNode node) { table.Insert(node); }