public void SaveHisto(long modId, string signalName, string value, DateTime dt) { try { lock (_lockObject) { using (DominoDbContext localDbContext = new DominoDbContext(config.GetConnectionString("DefaultConnection"))) { HistoriansTable signalRecord = new HistoriansTable(); if (signalRecord == null) { return; } signalRecord.configID = modId; signalRecord.dt_update = dt; signalRecord.signalName = signalName; signalRecord.value = value; localDbContext.Histo.Add(signalRecord); localDbContext.SaveChanges(); logger.Debug("insert histo " + value + " for mod" + modId); } } } catch (Exception ex) { logger.Error(ex, "", null); throw; } }
public void SaveValue(long modId, string signalName, string value) { try { lock (_lockObject) { using (DominoDbContext localDbContext = new DominoDbContext(config.GetConnectionString("DefaultConnection"))) { bool bCreated = false; List <ValuesTable> signalRecords = localDbContext.Values.Where(m => m.configID == modId && m.signalName == signalName).ToList(); ValuesTable signalRecord; if (signalRecords.Count == 0) //ligne non trouvée { signalRecord = new ValuesTable(); signalRecord.configID = modId; signalRecord.signalName = signalName; bCreated = true; } else { signalRecord = signalRecords.FirstOrDefault(); } signalRecord.dt_update = DateTime.Now; if (signalRecord.value != value) { signalRecord.dt_changed = DateTime.Now; } signalRecord.value = value; if (bCreated) { localDbContext.Values.Add(signalRecord); } else { localDbContext.Values.Update(signalRecord); } localDbContext.SaveChanges(); logger.Debug("update value " + value + " for mod" + modId); } } } catch (Exception ex) { logger.Error(ex, "", null); throw; } }
public void SetHWStatus(string name, int status) { //lock (_lockObject) { using (DominoDbContext localDbContext = new DominoDbContext(config.GetConnectionString("DefaultConnection"))) { var hw = localDbContext.Hardware.FirstOrDefault(x => x.name == name); if (hw == null) { hw = new HardwareTable(); hw.name = name; hw.enabled = 1; } hw.status = status; localDbContext.SaveChanges(); } } }