public void Send(string code, long timestamp, Dictionary <Enums.MeasureType, double> measurements, string codeAgr) { if (code.Length != 4 || codeAgr.Length != 4) { throw new ArgumentException("Invalid code"); } try{ int.Parse(code); int.Parse(codeAgr); } catch { throw new ArgumentOutOfRangeException("It must be number."); } if (measurements.Count <= 0) { try { } catch (Exception e) { throw new ArgumentException("Dictionary is empty."); } } if (timestamp < 1528236934 || timestamp > 1546300800) { throw new ArgumentOutOfRangeException("Timestamp is out of range."); } using (var data = new LocalBaseDBContex()) { LocalBase lb = new LocalBase() { AgregatorCode = codeAgr, DeviceCode = code, TimeStamp = (Datas.UnixTimeToDateTime(timestamp)).ToString(), Voltage = measurements[MeasureType.voltage], Eletricity = measurements[MeasureType.electricity], ActivePower = measurements[MeasureType.activePower], ReactivePower = measurements[MeasureType.reactivePower] }; data.LocalBaseData.Add(lb); data.SaveChanges(); } Console.WriteLine("Message from [{0}] added in LocalDataBase at {1}.", code, Datas.UnixTimeToDateTime(timestamp)); }
public static void DeleteFromLocal(IAMIAgregator agregator) { using (var data = new LocalBaseDBContex()) { var AgregatorBase = from d in data.LocalBaseData select d; foreach (var lb in AgregatorBase) { if (lb.AgregatorCode == agregator.agregatorCode) { data.LocalBaseData.Remove(lb); } } Console.WriteLine("Measurements for Agregator [{0}] are deleted from LocalDataBase.", agregator.agregatorCode); data.SaveChanges(); } }