public async System.Threading.Tasks.Task ProcessPosting() { await System.Threading.Tasks.Task.Run(() => { lock (PostSessionList) { using (SwarmData context = new SwarmData()) { while (PostSessionList.Count > 0) { PharoSession session = PostSessionList.Dequeue(); if (session == null) { continue; } if (session.Id == new Guid("00000000-0000-0000-0000-000000000000")) { continue; } PharoSession original = context.PharoSessions.FirstOrDefault(s => s.Id == session.Id); if (original == null) { context.PharoSessions.Add(session); } else { context.Entry(original).CurrentValues.SetValues(session); } context.SaveChanges(); } } } }); }
public async System.Threading.Tasks.Task ProcessPosting() { await System.Threading.Tasks.Task.Run(() => { lock (PostSessionList) { using (SwarmData context = new SwarmData()) { while (PostSessionList.Count > 0) { Session session = PostSessionList.Dequeue(); if (session == null) { continue; } if (session.Id == new Guid("00000000-0000-0000-0000-000000000000")) { continue; } Session original = context.Sessions .Include("Breakpoints") .Include("Events") .Include("PathNodes") .Include("CodeFiles") .FirstOrDefault(s => s.Id == session.Id); if (original == null) { context.Sessions.Add(session); } else { context.Entry(original).CurrentValues.SetValues(session); if (session.Breakpoints != null) { foreach (Breakpoint item in session.Breakpoints) { if (!original.Breakpoints.Any(x => x.Id == item.Id)) { original.Breakpoints.Add(item); } } } if (session.CodeFiles != null) { foreach (CodeFile item in session.CodeFiles) { if (!original.CodeFiles.Any(x => x.Id == item.Id)) { original.CodeFiles.Add(item); } } } if (session.Events != null) { foreach (Event item in session.Events) { if (!original.Events.Any(x => x.Id == item.Id)) { original.Events.Add(item); } } } if (session.PathNodes != null) { foreach (PathNode item in session.PathNodes) { if (!original.PathNodes.Any(x => x.Id == item.Id)) { original.PathNodes.Add(item); } } } } context.SaveChanges(); } } } }); }