public async Task GetCodeA(DeviceModel device) { string result = String.Empty; CodeResponce codeResponce = null; try { RestService restService = new RestService(configuration.RestServerUrl, "GetCodePW"); restService.Timeout = configuration.ServerTimeOut; //for test = (string hash, string crc, int type) codeResponce = await restService.PostAndGet <CodeResponce>(new CodeRequest { AndroidIDmacHash = device.AndroidIDmacHash, CRC = this.CRC, TypeDeviceID = device.TypeDeviceID }); } catch (AggregateException e) { if (e.InnerExceptions[0].Data.Count > 0) { result = e.InnerExceptions[0].Data["message"].ToString(); } else { result = "undefinedException"; } } catch (Exception e) { result = String.Format("Error = " + e.Message); } if (codeResponce != null) { await UpdateOrCreateCodeAToSql(codeResponce); } OnCodeChanged(); }
private async Task UpdateOrCreateCodeAToSql(CodeResponce codeResponce) { try { pairDeviceService = FactorySingleton.Factory.Get <PairDeviceService>(); await pairDeviceService.UpdateOrCreateCodeAToSql(codeResponce); } catch (Exception e) { var err = e.Message; } }
public async Task UpdateOrCreateCodeAToSql(CodeResponce codeResponce) { if (codeResponce == null) { return; } try { if (sqliteService == null) { sqliteService = new SQLiteService <CodeResponceSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName)); } } catch (Exception exp) { sqliteService = null; } if (sqliteService != null) { try { CodeResponceSQL currentCodeAResponce = new CodeResponceSQL { Id = 1, Code = codeResponce.Code, Hash = codeResponce.Hash, ResultCode = codeResponce.ResultCode, Date = ConverterHelper.ConvertDateTimeToMillisec(DateTime.Now).ToString() }; var codeResponcesOld = await sqliteService.Get("1"); if (codeResponcesOld != null) { await sqliteService.Update(currentCodeAResponce); } else { await sqliteService.Insert(currentCodeAResponce); } } catch (Exception ex) { var err = ex.Message; throw ex; } } }
//from REST public async Task GetCodeA(DeviceModel device, TextBox tb) { string cCRC = "ASDASDYHRdasf"; //only for test string result = String.Empty; CodeResponce codeResponce = null; //pairDeviceService = FactorySingleton.Factory.Get<PairDeviceService>(); //pairDeviceService.GetCodeA(new DeviceModel { AndroidIDmacHash = "hash", codeA = }); //tb.Text = codeResponce.Code.ToString(); try { IConfiguration config = FactorySingleton.Factory.Get <Configuration>(); RestService restService = new RestService(config.RestServerUrl, "GetCodePW"); restService.Timeout = 10000; //for test = (string hash, string crc, int type) codeResponce = await restService.PostAndGet <CodeResponce>(new CodeRequest { AndroidIDmacHash = device.AndroidIDmacHash, CRC = cCRC, TypeDeviceID = device.TypeDeviceID }); } catch (AggregateException e) { if (e.InnerExceptions[0].Data.Count > 0) { result = e.InnerExceptions[0].Data["message"].ToString(); } else { tb.Text = "undefinedException"; } } catch (Exception e) { tb.Text = String.Format(e.Message); } if (codeResponce != null) { tb.Text = codeResponce.Code.ToString(); await UpdateOrCreateCodeAToSql(codeResponce); } }
public async Task <int> SynchronizePowerTimeRest(DeviceModel device, DateTime date) { //save powertime to rest service from local sql string result = String.Empty; CodeResponce codeResponce = null; List <PowerPC> listPowerPC = null; try { var allpower = await GetSQLPowerTime(date); if (allpower != null) { listPowerPC = allpower.ToList(); var notsyncpower = listPowerPC.Where(x => !x.IsSynchronized); if (notsyncpower != null) { listPowerPC = notsyncpower.ToList(); } } if (listPowerPC != null && listPowerPC.Count != 0) { RestService restService = new RestService(configuration.RestServerUrl, "PowerPC"); restService.Timeout = configuration.ServerTimeOut; //for test = (string hash, string crc, int type) codeResponce = await restService.PostAndGet <CodeResponce> (new CodeRequestData <PowerPC> { AndroidIDmacHash = device.AndroidIDmacHash, CRC = this.CRC, TypeDeviceID = device.TypeDeviceID, data = listPowerPC }); } else { return(0); } } catch (AggregateException e) { if (e.InnerExceptions[0].Data.Count > 0) { result = e.InnerExceptions[0].Data["message"].ToString(); } else { result = "undefinedException"; } } catch (Exception e) { result = String.Format("Error = " + e.Message); } if (codeResponce != null) { int update = 0; if (codeResponce.ResultCode == 0 && codeResponce.Code < 0) { return(codeResponce.Code); } else { if (codeResponce.ResultCode != 0 && listPowerPC != null && listPowerPC.Count != 0) { update = await UpdateSynchToSql(listPowerPC); } if (update == codeResponce.ResultCode) { return(codeResponce.ResultCode); } } } return(-1); }