Exemple #1
0
        /// <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 int InsertAdif(Station station, Qso row, int minutesAccept = 10)
        {
            int result = -1;

            row.StationId = station.StationId;

            if (SearchDuplicates(station, row, minutesAccept)?.Length == 0)
            {
                this.Log.Add(row);
                if (this.SaveChanges() > 0)
                {
                    _logger.LogInformation($"Insert QSO {AdifHelper.ConvertToString(row)} in Log {station.StationId}");
                    result = row.QsoId;
                }
            }
            else
            {
                _logger.LogWarning($"Duplicate for QSO {AdifHelper.ConvertToString(row)} in Log {station.StationId}");
            }

            return(result);
        }