private bool ProcessAppLogEntry(string line, AppLogEntryType type) { if (type == AppLogEntryType.NewSession) { throw new ArgumentException("Use ProcessNewIrmaSessionAndLogEntry method", nameof(type)); } // deconstruct line: [<timestamp>]| Receiving ..: | JSON object var lineParts = line.Split('|'); var timestamp = DateTime.Parse(lineParts[0].Trim('[').Trim(']')); dynamic json = JsonConvert.DeserializeObject <dynamic>(lineParts[2].Trim()); // check the sessionId int sessionId = json.sessionId; if (sessionId == 0 || sessionId != _currentIrmaSession.AppSessionId) { return(false); } // create the log entry var appLogEntry = new IrmaAppLogEntry(); appLogEntry.Id = Guid.NewGuid(); appLogEntry.Timestamp = timestamp; appLogEntry.Type = type; appLogEntry.IrmaSessionId = _currentIrmaSession.Id; // add and save _context.Add(appLogEntry); _context.SaveChanges(); return(true); }
private bool ProcessNewIrmaSessionAndLogEntry(string line, Guid uploadSessionId) { // deconstruct line: [<timestamp>]| Sending ..: | JSON object var lineParts = line.Split('|'); var timestamp = DateTime.Parse(lineParts[0].Trim('[').Trim(']')); dynamic json = JsonConvert.DeserializeObject <dynamic>(lineParts[2].Trim()); string url = json.request.u; string sessionToken = url.After("/irma/"); // create new IrmaSession var irmaSession = new IrmaSession(); irmaSession.Id = Guid.NewGuid(); irmaSession.UploadSessionId = uploadSessionId; irmaSession.Timestamp = timestamp; irmaSession.AppSessionId = json.sessionId; irmaSession.SessionToken = sessionToken; // create the log entry var appLogEntry = new IrmaAppLogEntry(); appLogEntry.Id = Guid.NewGuid(); appLogEntry.Timestamp = timestamp; appLogEntry.Type = AppLogEntryType.NewSession; appLogEntry.IrmaSessionId = irmaSession.Id; // keep track of the new IrmaSession for future lines _currentIrmaSession = irmaSession; // add and save _context.Add(irmaSession); _context.Add(appLogEntry); _context.SaveChanges(); return(true); }