//public delegate void StepStartHandler(); //public delegate void StepSuccessHandler(); //public delegate void StepFailedHandler(); //public StepStartHandler OnStartStep; //public StepSuccessHandler OnStepSuccess; //public StepFailedHandler OnStepFailed; private Step CreateNextStep() { using (var db = new Entities()) { if (this.NextStepId != null) { int? nextStepType = GetNextStepType(this.NextStepId); if(nextStepType != null) { Step nextStep; switch (nextStepType) { case 1: nextStep = new EnterPageStep(this.NextStepId.Value, this.Context); break; case 2: nextStep = new EnterInputStep(this.NextStepId.Value, this.Context); break; case 3: nextStep = new ClickStep(this.NextStepId.Value, this.Context); break; case 4: nextStep = new MatchingStep(this.NextStepId.Value, this.Context); break; case 5: nextStep = new GetCaptchaStep(this.NextStepId.Value, this.Context); break; case 6: nextStep = new GetOTPStep(this.NextStepId.Value, this.Context); break; default: nextStep = new EnterPageStep(this.NextStepId.Value, this.Context); break; } return nextStep; } else { return null; } } else { return null; } } }
public void InitTransactionModel(string fromAccountNumber, int fromBankId, string toAccountNumber, int toBankId, decimal amount, string content) { using (var db = new Entities()) { var account = db.Accounts.Where(x => x.AccountNumber == fromAccountNumber && x.BankId == fromBankId).FirstOrDefault(); if(account != null) { this.TransactionModel.UserName = account.UserName; this.TransactionModel.Password = account.Password; this.TransactionModel.FromAccountName = fromAccountNumber; this.TransactionModel.FromBankId = fromBankId; this.TransactionModel.ToAccountNumber = toAccountNumber; this.TransactionModel.ToBankId = toBankId; this.TransactionModel.Amount = amount; this.TransactionModel.Content = content; } } }
private int? GetNextStepType(int? nextStepId) { if(nextStepId != null) { using (var db = new Entities()) { var step = db.Steps.Where(x => x.Bank.Id == this.Context.BankId && x.CurrentStepId == nextStepId).FirstOrDefault(); if(step != null) { return step.StepTypeId; } else { return null; } } } else { return null; } }
private async Task<ResponseResult> GetOTPResult(string PhoneNumber, string Reference) { return await Task.Run(() => { while (true) { using (var db = new Entities()) { var OTPModel = db.OTPs.Where(x => x.To == PhoneNumber && x.Ref == Reference && x.Passed == false).FirstOrDefault(); if (OTPModel != null && !string.IsNullOrWhiteSpace(OTPModel.Result)) { OTPModel.Passed = true; db.Entry(OTPModel).State = EntityState.Modified; db.SaveChanges(); ResponseResult ResponseResult = new ResponseResult() { Status = ResponseStatusEnum.Successful, Data = OTPModel.Result }; return ResponseResult; } Task.Delay(1000); } } }); }
private async Task<ResponseResult> GetCaptChaResult(int Id) { return await Task.Run(() => { while (true) { using (var db = new Entities()) { var captchaModel = db.Captchas.Where(x => x.Id == Id).FirstOrDefault(); if (captchaModel != null && !string.IsNullOrWhiteSpace(captchaModel.Result)) { captchaModel.Passed = true; db.Entry(captchaModel).State = EntityState.Modified; db.SaveChanges(); ResponseResult captchaResult = new ResponseResult() { Status = ResponseStatusEnum.Successful, Data = captchaModel.Result }; return captchaResult; } Task.Delay(1000); } } }); }
public void Initialize(int currentStepId, StepContext context) { using (var db = new Entities()) { var step = db.Steps.Where(x => x.Bank.Id == context.BankId && x.CurrentStepId == currentStepId).FirstOrDefault(); if (step != null) { this.Context = context; this.CurrentStepId = currentStepId; this.Name = step.Name; this.Url = step.Url; this.PreviousStepId = step.PreviousStepId; this.Sign = step.Sign; this.Pattern = step.Pattern; this.XPath = step.XPath; this.XPathAttribute = step.XPathAttribute; this.NextStepId = step.NextStepId0;// default next step this.SecondNextStepId = step.NextStepId1;// default next step this.InputType = step.InputType.Name; this.QueryStrings = step.QueyStrings.InitHttpRequestParams(';'); this.Params = step.Params.InitHttpRequestParams(';'); } } }
public StepContext(int bankId) { using (var db = new Entities()) { // To Do: Init TransactionModel //this.TransactionModel = this.BankId = bankId; var bank = db.Banks.Where(x => x.Id == bankId).FirstOrDefault(); if(bank != null) { switch (bank.WebBrowser.Name.ToLower()) { case "chrome": WebDriver = new ChromeDriver(); break; case "phantomjs": PhantomJSOptions options = new PhantomJSOptions(); if (!string.IsNullOrWhiteSpace(bank.UserAgent)) { //"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36" options.AddAdditionalCapability("phantomjs.page.settings.userAgent", bank.UserAgent); } PhantomJSDriverService defaultService = PhantomJSDriverService.CreateDefaultService(); defaultService.HideCommandPromptWindow = true; defaultService.LoadImages = false; WebDriver = new PhantomJSDriver(defaultService, options); break; default: WebDriver = new ChromeDriver(); break; } WaitDriver = new WebDriverWait(WebDriver, new TimeSpan(0, 0, bank.TimeOut.Value)); ShortWaitDriver = new WebDriverWait(WebDriver, new TimeSpan(0, 0, bank.TimeOut.Value / 2)); httpClient = new HttpClient() { Timeout = new TimeSpan(0, 0, bank.TimeOut.Value) }; TransactionModel = new BankTransaction(); } } }