void Test() { MySqlHelper taskHelper = new MySqlHelper(); MySqlHelper resultHelper = new MySqlHelper(); TaskDbHandler taskDbHandler = new AmazonTaskDbHandler(taskHelper); ResultDbHandler resultDbHandler = new AmazonResultDbHandler(resultHelper); OrderListHandler orderListHandler = new OrderListHandler("加拿大", new List <string> { "ATVPDKIKX0DER" }, "AKIAJTPVS26NBX7CKCGA", "ALM27M18VEIRS", "0f5708dECCx680pEVPFq40bNg4SLz3L0cb9lYpqm"); IDictionary <string, string> dic = orderListHandler.GetParameterDic("2017-02-28T16:00:00Z"); string html = orderListHandler.GetOrderListHtml(dic); //orderListHandler.GetMainInfoDicList(html, null); }
private string GetHtmlByPostTryThreeTimes(bool isFirstPage, string createAfter, string nextToken, OrderListHandler orderListHandler, Action <Exception> writeLog) { int tryTimes = 0; string html = null; bool isException = true; //设置为4次 int maxTryTimes = 4; while (tryTimes <= maxTryTimes && isException) { tryTimes++; try { var parameterDic = isFirstPage ? orderListHandler.GetParameterDic(createAfter) : orderListHandler.GetNextTokenParameterDic(nextToken); html = orderListHandler.GetOrderListHtml(parameterDic); isException = false; } catch (Exception e) { isException = true; if (tryTimes > maxTryTimes) { throw; } Console.WriteLine($"GetHtmlByPostTryThreeTimes : {tryTimes}"); Exception exception = new Exception($"tryTimes:{tryTimes * 5} mins", e); writeLog?.Invoke(exception); Thread.Sleep(tryTimes * 5 * 1000 * 60); } } return(html); }