public Qso[] SearchDuplicates(AdifRow adif, int minutesAccept) { return(this.Log.Where(Q => Q.CALL.ToUpper() == adif.CALL.ToUpper() && Q.BAND.ToLower() == adif.BAND.ToLower() && Math.Abs((Converters.GetDateTime(Q.QSO_DATE, Q.TIME_ON) - Converters.GetDateTime(adif.QSO_DATE, adif.TIME_ON)).TotalMinutes) < minutesAccept )?.ToArray()); }
/// <summary> /// Get ADIF Record /// POST:stations/{stationId}/get_record /// </summary> /// <param name="callSign"></param> /// <returns></returns> public string GetRecord(string callSign) { string response = "NO_RECORD"; using (HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(this.config.BaseUrl), DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue("Bearer", GenerateToken()) } }) { string action = $"restricted/stations/{config.StationId}/get_record"; try { Task.Run(async() => { HttpResponseMessage responseMessage = await httpClient.PostAsync(action, new StringContent($"\"{callSign}\"", Encoding.UTF8, "application/json")); if (responseMessage.StatusCode == HttpStatusCode.OK) { AdifRow record = JsonConvert.DeserializeObject <AdifRow>(responseMessage.Content.ReadAsStringAsync().Result); response = AdifHelper.ConvertToString(record); } else { throw new Exception($"{Path.Combine(httpClient.BaseAddress.AbsoluteUri, action)} returned {responseMessage.StatusCode}"); } }).GetAwaiter().GetResult(); } catch { } } return(response); }
public static AdifRow CheckDupToAdif(CheckDupRequest checkDupRequest) { AdifRow adif = new AdifRow() { CALL = checkDupRequest.Call, MODE = checkDupRequest.Mode, QSO_DATE = DateTime.UtcNow.ToString("yyyyMMdd"), TIME_ON = DateTime.UtcNow.ToString("HHmm") }; if (!string.IsNullOrEmpty(checkDupRequest.Freq) && checkDupRequest?.Freq != "0") { double freq; if (double.TryParse(checkDupRequest.Freq, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out freq)) { freq = freq / 1000; adif.FREQ = freq.ToString("F6", CultureInfo.InvariantCulture); adif.BAND = AdifHelper.FreqToBand(freq); } } if (!string.IsNullOrEmpty(checkDupRequest.State) && checkDupRequest?.State != "0") { adif.STATE = checkDupRequest.State; } return(adif); }
public static Qso Convert(AdifRow adifRow, Station station = null) { var obj = JsonConvert.DeserializeObject <Qso>(JsonConvert.SerializeObject(adifRow)); if (station != null) { obj.StationId = station.StationId; } return(obj); }
public static string ConvertToString(AdifRow row) { StringBuilder sbRow = new StringBuilder(); foreach (var pi in row.GetType().GetRuntimeProperties()) { var v = pi.GetValue(row, null) as string; if (!string.IsNullOrEmpty(v)) { sbRow.Append(MakeTagValue(pi.Name, v)); } } return($"{sbRow.ToString()}<EOR>"); }
public async Task <IActionResult> PostQso([FromRoute] int stationId, [FromBody] AdifRow adifRow, [FromRoute] int minutesAccept = 10) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!StationExists(stationId)) { return(NotFound()); } else { try { Station station = _context.Station.Find(stationId); Qso[] duplicates = _context.SearchDuplicates(station, adifRow, minutesAccept) ?? new Qso[0]; if (duplicates.Length > 0) { var duplicateQso = duplicates.First(); return(RedirectToAction("GetQso", "Public", new { duplicateQso.StationId, duplicateQso.QsoId })); } else { Qso qso = Converters.Convert(adifRow, station); _context.Log.Add(qso); await _context.SaveChangesAsync(); return(CreatedAtRoute(new { id = qso.QsoId }, qso)); } } catch (Exception exc) { _logger.LogError(exc.Message, null); return(BadRequest(exc.Message)); } } }
public static string ConvertToAdifRow(string record) { AdifRow AdifRow = new AdifRow(); record = record.Replace("<eor>", ""); string[] x = Regex.Split(record.Replace("\n", "").Replace("\r", ""), @"<([^:]+):\d+[^>]*>").ToArray(); List <string> l = new List <string>(x); l.RemoveAt(0); x = l.ToArray(); var dic = new Dictionary <string, string>(); if (x.Length % 2 == 0) { for (int i = 0; i < x.Length; i++) { if (!string.IsNullOrEmpty(x[i + 1])) { dic.Add(x[i].ToUpper(), x[i + 1]); } i++; } if (dic.ContainsKey("BAND") && dic.ContainsKey("FREQ")) { dic["BAND"] = AdifHelper.FreqToBand(double.Parse(dic["FREQ"], CultureInfo.InvariantCulture)); } else if (dic.ContainsKey("FREQ")) { dic.Add("BAND", AdifHelper.FreqToBand(double.Parse(dic["FREQ"], CultureInfo.InvariantCulture))); } } return(JsonConvert.SerializeObject(dic)); }