public static bool HaveSameValuesWith(this BankLogs first, BankLogs second) { return first.CardNumber == second.CardNumber && first.Date == second.Date && first.Reason == second.Reason && first.Time == second.Time && first.Amount == second.Amount && first.AmountLeft == second.AmountLeft && first.TransactionType == second.TransactionType) }
public override void OnReceive(Context context, Intent intent) { if (intent.Action != IntentAction) { return; } Log.Debug("SMS", "SMS Broadcase called!"); SmsMessage[] messages = Telephony.Sms.Intents.GetMessagesFromIntent(intent); var body = ""; var isFromSamanBank = messages[0].MessageBody.StartsWith(T.BankHeader); // Assemble Partial Messages in body variable of type string if (isFromSamanBank) { Log.Debug("SMS", "First part contains T.BankHeader"); body += messages[0].MessageBody; for (var i = 1; i < messages.Length; i++) { var lastPartOfMessage = messages[i].MessageBody.Split(new[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Last(); if (Regex.Match(lastPartOfMessage, T.TimePattern).Success) { body += messages[i].MessageBody; Log.Debug("SMS", "Adding part to body finished!"); break; } body += messages[i].MessageBody; Log.Debug("SMS", "Part is still adding to body!"); } } // Parse body var log = body.ParseSms(); var haveData = (log == null) ? "is null!" : "contains value!"; Log.Debug("SMS", $"body parsed to a SMS and {haveData}"); // Add to db if (log != null) { if (LastItemAdded == null || !log.HaveSameValuesWith(LastItemAdded)) { DataAccessLayer.Data.AddLog(log); LastItemAdded = log; } Log.Debug("SMS", $"Attemp to add to database..."); } }
private string InsertUpdateData(BankLogs data, string path) { try { var db = new SQLiteConnection(Platform, path); if (db.Insert(data) != 0) { db.Update(data); } return("Ok"); } catch (SQLiteException ex) { return(ex.Message); } }
public object Get(GetBankLogs request) { // Retrieve the block parameters (BlockParameter fromBlock, BlockParameter toBlock) = AppServices.getBlockParameterConfiguration(request.FromBlock, request.ToBlock, (request.Success == SuccessFilter.All) && (request.InternalReferenceHash.IsEmpty() == true)); // Create the filter variables for selecting only the requested log entries object[] ft1 = (request.InternalReferenceHash.IsEmpty() == true ? null : new object[] { request.InternalReferenceHash.HexToByteArray() }); object[] ft2 = { (uint)request.AccountType }; object[] ft3 = (request.Success == SuccessFilter.All ? null : (request.Success == SuccessFilter.Positive ? new object[] { true } : new object[] { false })); // Retrieve the contract info var contract = AppServices.web3.Eth.GetContract(AppModelConfig.BANK.abi, AppServices.GetEcosystemAdr(request.ContractAdr).BankContractAdr); // Create the filter input to extract the requested log entries var filterInput = contract.GetEvent("LogBank").CreateFilterInput(filterTopic1: ft1, filterTopic2: ft2, filterTopic3: ft3, fromBlock: fromBlock, toBlock: toBlock); // Extract all the logs as specified by the filter input var res = AppServices.web3.Eth.Filters.GetLogs.SendRequestAsync(filterInput).Result; // Create the return instance var logs = new BankLogs() { EventLogs = new List <BankEventLog>() }; // Interate through all the returned logs and add them to the logs list for (int i = res.Length - 1; i >= 0; i--) { var log = new BankEventLog(); log.BlockNumber = Convert.ToUInt64(res[i].BlockNumber.HexValue, 16); log.InternalReferenceHash = res[i].Topics[1].ToString(); log.AccountType = (AccountType)Convert.ToUInt64(res[i].Topics[2].ToString(), 16); log.Success = res[i].Topics[3].ToString().EndsWith("1"); log.PaymentAccountHash = res[i].Data.Substring(2 + 0 * 64, 64).EnsureHexPrefix(); log.PaymentSubject = res[i].Data.Substring(2 + 1 * 64, 64).EnsureHexPrefix().StartsWith("0x000000") ? Convert.ToUInt64(res[i].Data.Substring(2 + 1 * 64, 64), 16).ToString() : res[i].Data.Substring(2 + 1 * 64, 64).EnsureHexPrefix(); log.Info = AppModelConfig.isEmptyHash(res[i].Data.Substring(2 + 2 * 64, 64).EnsureHexPrefix()) ? "0x0" : AppModelConfig.FromHexString(res[i].Data.Substring(2 + 2 * 64, 64)); log.Timestamp = Convert.ToUInt64(res[i].Data.Substring(2 + 3 * 64, 64), 16); log.TransactionType = (TransactionType)Convert.ToUInt64(res[i].Data.Substring(2 + 4 * 64, 64), 16); log.Amount = Convert.ToUInt64(res[i].Data.Substring(2 + 5 * 64, 64), 16); logs.EventLogs.Add(log); } // Return the list of bond logs return(logs); }
public static string AddLog(BankLogs log) { try { var db = GetConnection(); if (db.Insert(log) != 0) { db.Update(log); } if (Utilities.MainActivity?.ItemAdapter != null) { Utilities.MainActivity.ItemAdapter.NotifyDataSetChanged(); } return("Ok"); } catch (SQLiteException e) { return(e.Message); } }
public static BankLogs ParseSms(this string sms) { if (!sms.Contains(T.BankHeader)) return null; var dataModel = new BankLogs(); string[] lines = sms.Split(new[] { System.Environment.NewLine }, StringSplitOptions.None); try { for (int i = 0; i < lines.Length; i++) { var text = lines[i]; var lineType = text.GetStatementType(); if (lineType == StatementType.TransactionInfo) { var textModified = text.Replace(T.Mablagh, "").Replace(T.Be, ""); string[] words = textModified.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (words[0] == T.Variz) { dataModel.TransactionType = TransactionTypes.Variz; if (words[1] == T.Sood) { dataModel.Reason = T.Sood; dataModel.Amount = words[2].Replace(T.Rial, ""); } else { dataModel.Amount = words[1].Replace(T.Rial, ""); } } else if (words[0] == T.Bardasht) { dataModel.TransactionType = TransactionTypes.Bardasht; dataModel.Amount = words[1]; dataModel.Reason = string.Join(" ", words.Skip(2)); } else if (words[0] == T.Vorod) { dataModel.TransactionType = TransactionTypes.Login; } } else if (lineType == StatementType.AccountInfo) { string[] words = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); dataModel.CardNumber = words[1]; } else if (lineType == StatementType.RemainingInfo) { string[] words = text.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); dataModel.AmountLeft = words[1]; } else if (lineType == StatementType.DateInfo) { dataModel.Date = text; } else if (lineType == StatementType.TimeInfo) { dataModel.Time = text; } } } catch { return null; } return dataModel; }