public async Task <int> StartUp() { // do we need a new access token if (localSettings.Values["access_token"] == null || localSettings.Values["access_token_expire"] == null || !IsTokenValid(Convert.ToDateTime(localSettings.Values["access_token_expire"].ToString()))) { if (await GetAPIToken() == null) { return(1001); } } // get the device detail SystemDetail systemDetail = await CashGenicAPIService.GetSystem(localSettings.Values["access_token"].ToString()); if (systemDetail == null) { return(1000); } else { // fire new system connected event NewSystemConnectedArgs args = new NewSystemConnectedArgs(); args.system = systemDetail; OnNewSystemConnected(args); _ = Task.Factory.StartNew(() => RunSystem()); } return(0); }
public static async Task <SystemDetail> GetSystem(string token) { var client = GetClient(); var request = new RestRequest("system", Method.GET); request.AddHeader("Authorization", "Bearer " + token); IRestResponse response = await client.ExecuteAsync(request); if (response.StatusCode == HttpStatusCode.OK) { try { SystemDetail systemDetail = JsonConvert.DeserializeObject <SystemDetail>(response.Content); return(systemDetail); // SystemDetail.FromJson(response.Content); }catch (Exception ex) { return(null); } } else { return(null); } }
public static string ToJson(this SystemDetail self) => JsonConvert.SerializeObject(self, CashGenicClient.Converter.Settings);