//Get saved to local sql code A public async Task <Pair> GetPair() { Pair pair = null; try { if (sqliteService == null) { sqliteService = new SQLiteService <CodeResponceSQL>(sqlitePlatform, await fileSystemService.GetPath(configuration.SqlDatabaseName)); } } catch (Exception exp) { sqliteService = null; } if (sqliteService != null) { try { CodeResponceSQL codeResponcesSQL = await sqliteService.Get("1"); if (codeResponcesSQL != null) { //DateTime saved = ConverterHelper.ConvertMillisecToDateTime(Convert.ToInt64(codeResponcesSQL.Date)); //DateTime expiredtime = saved.AddSeconds(configuration.TimeOutValidCodeASecond); //DateTime now = DateTime.Now; //bool exp = now > expiredtime; pair = new Pair { CodeA = codeResponcesSQL.Code, CodeB = 0, ErrorMessage = string.Empty, isCodeAExpired = (DateTime.Now > (ConverterHelper.ConvertMillisecToDateTime(Convert.ToInt64(codeResponcesSQL.Date)).AddSeconds(configuration.TimeOutValidCodeASecond))), TimeOutValidCodeA = configuration.TimeOutValidCodeASecond }; } } catch (Exception ex) { pair = new Pair { CodeA = 0, CodeB = 0, ErrorMessage = ex.Message, isCodeAExpired = true, TimeOutValidCodeA = configuration.TimeOutValidCodeASecond }; } } return(pair);// await Helper.Complete(pair); }
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; } } }