static async Task <StationInfo> GetStationWithEventAsync() { string path = "GetStation?data=0"; StationInfo sta = null; HttpResponseMessage response = await client.GetAsync(path); if (response.IsSuccessStatusCode) { sta = await response.Content.ReadAsAsync <StationInfo>(); } int staIndex = (int)Math.Log(sta.Events, 2) + 1; sta = await GetStationInfoAsync(String.Format("GetStation?data={0}", staIndex)); return(sta); }
static async Task RunAsync(String ESPIP) { // Update port # in the following line. client.BaseAddress = new Uri(ESPIP); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); try { StationInfo sta = new StationInfo(); sta = await GetStationWithEventAsync(); while (sta.Events != 0) { Console.WriteLine("Evento stazione rilevato"); sta = await GetStationWithEventAsync(); Console.WriteLine("Ottengo dati stazione"); ShowStation(sta); Console.WriteLine("Pareggio Trigger"); sta = await BalanceTriggerWithEventAsync(sta); Console.WriteLine("Rilettura eventi"); sta = await GetStationWithEventAsync(); System.Threading.Thread.Sleep(2000); } } catch (Exception e) { Console.WriteLine(e.Message); } Console.ReadLine(); }
static void ShowStation(StationInfo staInfo) { Console.WriteLine($"ID: {staInfo.Id}\tBarcode: " + $"{staInfo.Barcode} " + $"FormatoCollo: {staInfo.FormatoCollo}\t Trigger: " + $"{staInfo.Trigger} "); }