private async Task LoadPlansToRextremaWS(IList <NewPlan> plans, bool isFirstStart) { try { await _throttler.WaitAsync(); var stopWath = new Stopwatch(); stopWath.Start(); var data = new { isFirstStart = isFirstStart ? "1" : "0", PLAN_NAME = string.Join("||", plans.Select(x => x.PLAN_NAME)), SPONSOR_DFE_NAME = string.Join("||", plans.Select(x => x.SPONSOR_DFE_NAME)), SPONS_DFE_MAIL_US_CITY = string.Join("||", plans.Select(x => x.SPONS_DFE_MAIL_US_CITY)), SPONS_DFE_MAIL_US_STATE = string.Join("||", plans.Select(x => x.SPONS_DFE_MAIL_US_STATE)), TOT_PARTCP_BOY_CNT = string.Join("||", plans.Select(x => x.TOT_PARTCP_BOY_CNT)), FORM_TAX_PRD = string.Join("||", plans.Select(x => x.FORM_TAX_PRD)), SPONS_DFE_MAIL_US_ZIP = string.Join("||", plans.Select(x => x.SPONS_DFE_MAIL_US_ZIP)), SPONS_DFE_PHONE_NUM = string.Join("||", plans.Select(x => x.SPONS_DFE_PHONE_NUM)), ADMIN_SIGNED_NAME = string.Join("||", plans.Select(x => x.ADMIN_SIGNED_NAME)), SPONS_SIGNED_NAME = string.Join("||", plans.Select(x => x.SPONS_SIGNED_NAME)), TOT_ASSETS_BOY_AMT = string.Join("||", plans.Select(x => x.TOT_ASSETS_BOY_AMT)), TOT_ASSETS_EOY_AMT = string.Join("||", plans.Select(x => x.TOT_ASSETS_EOY_AMT)), SPONS_DFE_PN = string.Join("||", plans.Select(x => x.SPONS_DFE_PN)), SPONS_DFE_EIN = string.Join("||", plans.Select(x => x.SPONS_DFE_EIN)), DATE_RECEIVED = string.Join("||", plans.Select(x => x.DATE_RECEIVED)), ACK_ID = string.Join("||", plans.Select(x => x.ACK_ID)), SPONS_DFE_MAIL_US_ADDRESS = string.Join("||", plans.Select(x => x.SPONS_DFE_MAIL_US_ADDRESS)) }; var httpResponseMessage = await FlurlHelper.RunActionOnRixtremaWsWithRetry("AddPlanLoad", data); if (httpResponseMessage == null || httpResponseMessage.FCT.Result != "Success") { var errorString = string.Format("Error process AddPlanLoad action. Response: {0}", ObjectExtentions.ToJson(httpResponseMessage)); Logger.Log(errorString); _prgLabel.Text = "Error process AddPlanLoad action"; throw new Exception("Error process AddPlanLoad action"); } _totalSuccessPlansSendedToCheck += plans.Count; stopWath.Stop(); _prgLabel.Text = string.Format("AddPlanLoad for part Success. {0} of {1}. Duration {2}", _prgLine.Value, _prgLine.Maximum, stopWath.Elapsed); _prgLine.Value += plans.Count; _totalPlansSendedToCheck += plans.Count; } catch (Exception ex) { Logger.Log("Error process AddPlanLoad action! Ex " + ex); } finally { _throttler.Release(); } }
public async Task AddPlanLoad() { _addPlansLoadStopwatch.Restart(); _prgLabel.Text = "Begin AddPlanLoad..."; var curYear = DateTime.Now.Year - 1; var file5500PrivYear = Path.Combine(_baseDir, string.Format("f_5500_{0}_all.csv", curYear - 1)); var fileSCH_HPrivYear = Path.Combine(_baseDir, string.Format("F_SCH_H_{0}_all.csv", curYear - 1)); var privYearPlans = GetPlansFromFiles(fileSCH_HPrivYear, file5500PrivYear); var plansCombined = privYearPlans; if (DateTime.Now.Month != 1) // for the Jan there is no data for current year! { var file5500 = Path.Combine(_baseDir, string.Format("f_5500_{0}_all.csv", curYear)); var fileSCH_H = Path.Combine(_baseDir, string.Format("F_SCH_H_{0}_all.csv", curYear)); var plans = GetPlansFromFiles(fileSCH_H, file5500); plansCombined = plans.Union(privYearPlans); } var tasks = new List <Task>(); bool isFirstStart = true; foreach (var newPlansBatch in plansCombined.Union(privYearPlans).Batch(40)) { if (isFirstStart) { await LoadPlansToRextremaWS(newPlansBatch, true); isFirstStart = false; } tasks.Add(LoadPlansToRextremaWS(newPlansBatch, false)); } await Task.WhenAll(tasks); var httpResponseMessage = await FlurlHelper.RunActionOnRixtremaWsWithRetry("FINISHADDPLANLOAD"); List <dynamic> newPlans = httpResponseMessage.FCT.NewPlans; _totalNewPlans = newPlans.Count; var len = newPlans.Select(x => x.IdToKeySponsorNamePair).Where(x => ((string)x).Length > 100).ToList(); Logger.Log(len.ToJson()); File.WriteAllText(_baseDir + @"\_DownloadPDF.csv", string.Join("\r\n", newPlans.Select(x => x.IdToKeySponsorNamePair)) + "\r\n"); _prgLabel.Text = "Ready"; _prgLine.Value = 0; _prgLine.Maximum = 0; var qaData = new { Total = _totalPlansSendedToCheck, Success = _totalSuccessPlansSendedToCheck, New = _totalNewPlans }.ToJson(); _addPlansLoadStopwatch.Stop(); _qualityControl.CreateEvent(QualityActionsAliases.UPDFUND_LOAD, qaData, _addPlansLoadStopwatch.Elapsed); }