diff --git a/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs b/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs index 7b80558..8b18fd7 100644 --- a/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs +++ b/pc/CODEC2 GUI/CODEC2 GUI/DstarInfo.cs @@ -41,6 +41,7 @@ using System.Threading.Tasks; using System.IO; using System.Net.Http.Headers; using System.Reflection; +using System.Xml; namespace CODEC2_GUI { @@ -51,6 +52,21 @@ namespace CODEC2_GUI } + private static HttpClient _client; + private static HttpClient client + { + get + { + if (_client == null) + _client = new HttpClient() { BaseAddress = new Uri("http://apps.dstarinfo.com") }; + return _client; + } + } + private static string eventvalidation; + private static string viewstate; + private static string viewstategenerator; + + private List Repeaters_; public List Repeaters { @@ -59,14 +75,9 @@ namespace CODEC2_GUI if (Repeaters_ == null) { LoadRepeaters(); - if (Repeaters_ == null || Repeaters_.Count == 0) - { - try - { - FetchAndSaveRepeaterList(); - } - catch { } - } + if (Repeaters_ == null) + Repeaters_ = new List(); + } return Repeaters_; } @@ -93,9 +104,26 @@ namespace CODEC2_GUI } } - public bool FetchAndSaveRepeaterList() + public bool FetchAndSaveRepeaterList(string area) { - return false; + bool result = false; + try + { + List rptrs = GetDStarRepeaterByArea(area); + if (rptrs != null && rptrs.Count > 0) + { + SaveRepeaters(rptrs); + Repeaters_ = rptrs; + result = true; + } + } + catch (Exception ex) + { + string msg = "Fetch and save Repeater list failed!"; + System.Diagnostics.Debug.WriteLine(string.Format("{0} {1}", msg, ex.Message)); + throw new ApplicationException(msg, ex); + } + return result; } public bool FetchAndSaveReflectorList() @@ -120,17 +148,214 @@ namespace CODEC2_GUI return result; } + public List GetDStarRepeaterAreas() + { + List rptareas = new List(); + string htmlAreas = string.Empty; + + try + { + if (client != null) + { + HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "D-STAR_Repeater_List.aspx"); + Task resp = client.SendAsync(request); + resp.Wait(); + resp.Result.EnsureSuccessStatusCode(); + + Task strm = resp.Result.Content.ReadAsStreamAsync(); + strm.Wait(); + using (StreamReader sr = new StreamReader(strm.Result, System.Text.Encoding.UTF8)) + { + htmlAreas = sr.ReadToEnd(); + } + } + + viewstate = getHiddenValues(htmlAreas, "id=\"__VIEWSTATE\" value=\""); + viewstategenerator = getHiddenValues(htmlAreas, "id=\"__VIEWSTATEGENERATOR\" value=\""); + eventvalidation = getHiddenValues(htmlAreas, "id=\"__EVENTVALIDATION\" value=\""); + + // parsing HTML select of areas + // start by finding "", ofs + 23); + if (ofs2 > 0) + { + string selVals = htmlAreas.Substring(ofs, ofs2 - ofs); + int ofs3 = 0; + int ofs4 = 0; + while (ofs4 < selVals.Length) + { + ofs4 = selVals.IndexOf("