public uint Register(string unique) { if (unique == null) { return(0); } // check db for existing DetectorID using (var context = new LightningContext()) { var found = context.Detectors.Where(x => x.Devicecode == unique).Select(x => x.Id).FirstOrDefault(); if (found != 0) { return(found); } else { var nextId = context.Detectors.Max(x => x.Id) + 1; context.Detectors.Add(new Detectors() { Id = nextId, Devicecode = unique }); context.SaveChanges(); return(nextId); } } }
public void StoreInDB() { Rawpackets packet = new Rawpackets { Data = RawBytes, Port = IPPort.ToString(), Address = IPAddress.ToString(), }; using (var context = new LightningContext()) { context.Add(packet); context.SaveChanges(); } }
public void StoreInDB(LightningContext context) { if (!packet.IsReady()) { throw new InvalidOperationException("Packet not constructed properly"); } try { context.Add(packet); Process(context); context.SaveChanges(); } catch (Exception ex) { Console.Write(ex.Message); if (ex.InnerException != null) { Console.Write(ex.InnerException.Message); } } }
public void StoreInDB(LightningContext context) { if (!packet.IsReady()) { throw new InvalidDataException("Packet not constructed properly"); } Console.WriteLine($"Status Packet storing on thread {Thread.CurrentThread.ManagedThreadId}"); try { context.Add(packet); context.SaveChanges(); } catch (Exception e) { if (e.InnerException != null) { Console.WriteLine($"{e.InnerException.Message} : storing status"); } else { Console.WriteLine($"{e.Message} : storing status"); } } }