CreateResponse _create(out bool isExpire, long startTime, string btcAddr, double rubAmount, string phoneFrom, string forwardtobtc = null, int dempingpercent = 0, int forwardint = 0, string forwardfraction = "0") { isExpire = false; string hash = ""; try { if (btcAddr == "" || btcAddr == null) { return(null); } TicketClientCreateResponse ticket = App.ticketClient.Create(rubAmount, phoneFrom, btcAddr, App.LAST_PARSED_RATE.client.max_execute_time_sec); hash = (new BtcAddressModel(App.db)) .Create( startTime, btcAddr, ticket.account, //phone to ticket.comment, ticket.btc_amount, App.LAST_PARSED_RATE.GetClientNameOnPath(), phoneFrom, ticket.ip, ticket.email ); if (forwardtobtc != null) { (new BtcAddressForwardModel(App.db)) .Create(btcAddr, forwardtobtc, dempingpercent, forwardint, forwardfraction); } return(new CreateResponse() { account = ticket.account, comment = ticket.comment, hash = hash, btc_amount = ticket.btc_amount.ToString() }); } catch (Exception e) { if (e.Message == "expire") { isExpire = true; } } if (hash != "" && hash != null && hash != String.Empty) { (new BtcAddressModel(App.db)).Remove(hash); } return(null); }
//парсим email, ищем заявку там string _getResultByEmail(long requestId, long startTime, string btcAddr, double rubAmount, string phoneFrom, string forwardtobtc, int dempingpercent, int forwardint, string forwardfraction) { //в течении следующих time_check_email_sec проверяем email long maxTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds() + App.settings.data.time_check_email_sec; while (DateTimeOffset.UtcNow.ToUnixTimeSeconds() < maxTime) { var emails = App.emailParser.GetLastByClient(App.LAST_PARSED_RATE.client); TicketClientCreateResponse ticketByEmail = null; CreateResponse createResponseByEmail = EmailParser.Find(emails, btcAddr, phoneFrom, out ticketByEmail); if (createResponseByEmail == null) //еще не пришло, ждем { Thread.Sleep(500); continue; } try { if (forwardtobtc != null) { (new BtcAddressForwardModel(App.db)) .Create(btcAddr, forwardtobtc, dempingpercent, forwardint, forwardfraction); } } catch (Exception e) { } try { (new BtcAddressModel(App.db)).Create(startTime, btcAddr, ticketByEmail.account, //phone to ticketByEmail.comment, ticketByEmail.btc_amount, App.LAST_PARSED_RATE.GetClientNameOnPath(), phoneFrom, ticketByEmail.ip, ticketByEmail.email); } catch (Exception e) { } createResponseByEmail.other = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("type_get", "complicated") }.ToArray(); try { (new LogRequestModel(App.db)).SetResponse(requestId, createResponseByEmail.toJson()); } catch (Exception e) { } return(createResponseByEmail.toJson()); } return(null); //после парсинга не даем переключаться на следующий клиент, всегда выходим }
public static CreateResponse Find(List <KeyValuePair <EmailIdentity, TicketClientCreateResponse> > list, string btcAddress, string phoneFrom, out TicketClientCreateResponse ticket) { ticket = null; phoneFrom = PhoneHelper.PhoneReplacer(phoneFrom).Trim(); btcAddress = btcAddress.Trim().ToLower(); if (!list .Exists(el => (PhoneHelper.PhoneReplacer(el.Key.phoneFrom).Trim()) == phoneFrom && el.Key.btcAddr.Trim().ToLower() == btcAddress ) ) { return(null); } ticket = list .Where(el => (PhoneHelper.PhoneReplacer(el.Key.phoneFrom).Trim()) == phoneFrom && el.Key.btcAddr.Trim().ToLower() == btcAddress ) .First() .Value; if (ticket == null) { return(null); } return(new CreateResponse() { account = ticket.account, comment = ticket.comment, hash = btcAddress, btc_amount = ticket.btc_amount.ToString() }); }