private void CreateOrTopupAllTables(bool topUp, List <string> selectedShares) { //Prepare structures needed for the run //Ensure AlTables subfolder exists var alltablesPath = Helper.UserSettings().AllTablesFolder; if (!Directory.Exists(alltablesPath)) { Directory.CreateDirectory(alltablesPath); } //get the All-Shares list into array form string[] allShareArray; if (selectedShares == null) { //usual case, we're doing ALL shares allShareArray = LocalStore.CreateShareArrayFromShareList(); } else { //selective shares (fixing suspect All-Tables) allShareArray = selectedShares.ToArray(); } if (allShareArray.Count() > 0) { DateTime startDate = calendarFrom.SelectionStart; DateTime endDate = calendarTo.SelectionStart; int tradingSpan = Helper.ComputeTradingSpanInclusive(startDate, endDate); string createOrTopup = topUp ? "OVERLAY" : "CREATE"; var msg = $"{createOrTopup} All-tables for the {tradingSpan} trading days up to {endDate.ToShortDateString()} (inclusive)?"; string preserveOrNew = topUp ? "Existing data in the range will be preserved, NEW data will be added." : "All-Table data will be created from scratch."; var extraMsg = $"\n\n{preserveOrNew}\n\nWarning: This may take time!"; if ((MessageBox.Show(msg + extraMsg, $"{allShareArray.Count()} All-Tables will be effected", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes)) { //put some buttons on hold, make progress bar visible etc.. Helper.HoldWhileGeneratingNewAllTables(true, topUp); Helper.Log("Info", Helper.Repeat("==========", 8)); Helper.Log("Info", msg); LocalStore.RefreshNewAllTables(startDate, endDate, tradingSpan, allShareArray, topUp, ""); //will queue up a lot of tasks! } } }
internal void GenerateAllTableSummaryForGrid(Action <int> progress, List <AllTableSummary> summaries) { var allTablesFolder = Helper.UserSettings().AllTablesFolder; var shareLines = LocalStore.CreateShareArrayFromShareList(); int shareCount = 0; foreach (string line in shareLines) { var share = Helper.CreateShareFromLine(line); string allTableFilename = allTablesFolder + $"\\alltable_{share.Number}.at"; //determine First Day, Last Day and number of trading days by inspecting the All-Table file using (FileStream fs = new FileStream(allTableFilename, FileMode.Open)) { //read in entire all-table var atRows = Helper.DeserializeAllTable <AllTable>(fs).Skip(2).ToArray(); var numRows = atRows.Count(); var shareSummary = new AllTableSummary(share); shareSummary.FirstDay = atRows[0].Date; shareSummary.LastDay = atRows[numRows - 1].Date; shareSummary.LastPrice = atRows[numRows - 1].FP; shareSummary.TotalVolume = (uint)atRows.Sum(x => x.FV); shareSummary.AverageDailyVolume = Convert.ToUInt32(104 * atRows.Average(x => x.FV)); shareSummary.LastDayVolume = (uint)atRows.Skip(numRows - 104).Take(14).Sum(x => x.FV); shareSummary.NumberOfTradingDays = (atRows.Count()) / 104; summaries.Add(shareSummary); } shareCount++; //if (shareCount == 10) break; if (progress != null) { progress(shareCount); } } }