protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogDebug($"{nameof(EqslUploadService)} is starting."); stoppingToken.Register(() => _logger.LogDebug($"{nameof(EqslUploadService)} background task is stopping.")); while (!stoppingToken.IsCancellationRequested) { _logger.LogDebug($"{nameof(EqslUploadService)} task doing background work."); using (IServiceScope scope = _provider.CreateScope()) { using (var context = scope.ServiceProvider.GetRequiredService <QSOColletorContext>()) { foreach (Station station in context.Station) { try { var QsosToSend = context.Log.Where(Q => Q.StationId == station.StationId && (Q.EQSL_QSL_SENT != "Y" || string.IsNullOrEmpty(Q.EQSL_QSL_SENT))).ToArray(); var adif = AdifHelper.ExportAsADIF(QsosToSend); var c = new Uploader(); if (c.UploadAdif(adif, station.Callsign, station.HamID)) { //update QSOs foreach (Qso qso in QsosToSend) { qso.EQSL_QSL_SENT = "Y"; qso.EQSL_QSLSDATE = DateTime.UtcNow.ToString("yyyyMMdd"); context.SaveChanges(); _logger.LogInformation($"{qso.CALL},{qso.QSO_DATE},{qso.MODE},{qso.BAND} has been uploaded to eQSL.cc"); } } } catch (Exception exc) { _logger.LogError(exc.Message); } } } } await Task.Delay(new TimeSpan(_config.JobInterval, 0, 0)); } _logger.LogDebug($"{nameof(EqslUploadService)} background task is stopping."); }
public ContentResult ExportLog(int stationId) { var station = _context.Station.Where(S => S.StationId == stationId).First <Station>(); if (station != null) { return(new ContentResult() { Content = AdifHelper.ExportAsADIF(_context.Log.Where(Q => Q.StationId == stationId)?.ToArray <AdifRow>()), StatusCode = 200 }); } else { return(new ContentResult() { StatusCode = 404 }); } }