Beispiel #1
0
        private bool ProcessAndUpdateIrmaSession(string line, Guid sessionMetadataId)
        {
            // deconstruct line: [<timestamp>] TRACE HTTP JSON response: 200 {"sessionPtr":{"u": ... }
            var     timestamp          = DateTime.Parse(line.Between("[", "]"));
            dynamic json               = JsonConvert.DeserializeObject <dynamic>(line.Between("response=", " status=200").Trim());
            string  url                = json.sessionPtr.u;
            string  sessionToken       = url.After("/irma/");
            var     irmaJsSessionToken = json.token;

            // get the corresponding irma session of this upload session and its entries
            var irmaSession = _context.IrmaSessions
                              .Where(sessions => sessions.UploadSessionId == sessionMetadataId)
                              .Include(sessions => sessions.AppLogEntries)
                              .FirstOrDefault(session => session.SessionToken == sessionToken);

            // validate existence, if not continue with the next session
            if (irmaSession == null)
            {
                _currentIrmaSession = null;
                Debug.WriteLine("No corresponding irma session found for line: " + line);
                return(true);
            }


            var successAppLogEntry = irmaSession.AppLogEntries.FirstOrDefault(x => x.Type == AppLogEntryType.Success);

            if (successAppLogEntry == null)
            {
                // incomplete session, don't use it but continue
                _currentIrmaSession = null;
                Debug.WriteLine("No successAppLogEntry found for line: " + line);
                return(true);
            }
            // validate session has not finished yet
            if (timestamp >= successAppLogEntry.Timestamp)
            {
                return(false);
            }

            // update session with js session token for connecting data
            irmaSession.IrmaJsSessionToken = irmaJsSessionToken;

            // keep track of the irma session for future lines
            _currentIrmaSession = irmaSession;

            _context.SaveChanges();

            return(true);
        }
Beispiel #2
0
        public bool ProcessServerLog(IFormFile serverLog, Guid sessionMetadataId)
        {
            using (var reader = new StreamReader(serverLog.OpenReadStream()))
            {
                while (reader.Peek() >= 0)
                {
                    var line    = reader.ReadLine();
                    var success = ProcessServerLogLine(line, sessionMetadataId);
                    if (!success)
                    {
                        throw new LogProcessingException("Processing server log unsuccessful at line: " + line);
                    }
                }
            }

            // reset current irma session for the next upload session
            _currentIrmaSession = null;
            return(true);
        }
        public UploadSession CreateNewUploadSession(DateTime date,
                                                    string location,
                                                    string description,
                                                    bool usesQuic,
                                                    bool isStationary,
                                                    bool isWifi,
                                                    bool isMostly4G,
                                                    bool isMostly3G,
                                                    int sessionNumberUploaded,
                                                    IFormFile applog)
        {
            var success       = false;
            var uploadSession = new UploadSession()
            {
                Id            = Guid.NewGuid(),
                Date          = date,
                Location      = location,
                Description   = description,
                UsesQuic      = usesQuic,
                IsStationary  = isStationary,
                IsWiFi        = isWifi,
                IsMostly4G    = isMostly4G,
                IsMostly3G    = isMostly3G,
                SessionNumber = sessionNumberUploaded
            };

            // save metadata
            _context.Add(uploadSession);
            _context.SaveChanges();

            // convert the app log
            success = ConvertAndSaveAppLog(applog, uploadSession.Id);

            // reset the currentIrmaSession
            _currentIrmaSession = null;
            return(uploadSession);
        }
        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);
        }