private void ShowDataOnHand(bool forceLocal) { if (!forceLocal) { //decide whether to use local inahlt file or download a fresh one from the internet var whichSource = groupBoxSource.Controls.OfType <RadioButton>().FirstOrDefault(n => n.Checked); if (whichSource.Text.Equals("internet") && (textBoxUsername.Text.Length == 0 || textBoxPassword.Text.Length == 0)) { MessageBox.Show("Please enter both username and password.", "Credentials Needed"); return; } listBoxInhalt.DataSource = GetDaysListingPerSource().Where((entry) => WithinDateRange(entry)).ToList(); } else { //use local inhalt file otherwise listBoxInhalt.DataSource = LocalStore.GetDataDaysListing().Where((entry) => WithinDateRange(entry)).ToList(); } var numFilesTicked = LocalStore.TickOffListboxFileItems("listBoxInhalt", Helper.UserSettings().ExtraFolder); Helper.ListBoxClearAndScrollToBottom(listBoxInhalt); buttonDayDataDownload.Enabled = listBoxInhalt.Items.Count > 0; labelDatafilesCount.Text = $"{numFilesTicked} files local"; }
//initialize the app private void InitializeShareViewer() { daysBack.Maximum = 300; // represents trading days!! daysBack.Minimum = 0; daysBack.Value = 100; // represents trading days!! Change event wont fire at this stage (which is good) //don't allow future dates calendarFrom.MaxDate = DateTime.Today; calendarFrom.MinDate = DateTime.Today.AddDays(-Helper.ActualDaysBackToEncompassTradingDays(DateTime.Today, 300)); Helper.Log("Debug", $"calendarFrom MinDate= {calendarFrom.MinDate.ToShortDateString()}"); calendarTo.MaxDate = DateTime.Today; //set From date initially to sync with numericUpDown TradingDays calendarFrom.SetDate(DateTime.Today.AddDays(-Helper.ActualDaysBackToEncompassTradingDays(DateTime.Today, 100))); calendarTo.SetDate(DateTime.Today); labelBackFrom.Text = "ending Today"; //load ShareList listBoxShareList.DataSource = LocalStore.ReadShareList(); labelNumShares.Text = $"{listBoxShareList.Items.Count} shares"; //possibly enable the New AllTables button //buttonNewAllTables.Enabled = listBoxShareList.Items.Count > 0; //buttonAddToAllTables.Enabled = listBoxShareList.Items.Count > 0; ; // labelDatafilesCount.Text = ""; }
private void AllTableRepairForm_Load(object sender, EventArgs e) { listBoxRepairShares.DataSource = LocalStore.ShareListByName(); listBoxRepairShares.ClearSelected(); }
internal static void DownloadFromStack(ConcurrentStack <String> cs, String userName, String passWord) { var appUserSettings = Helper.UserSettings(); var url = appUserSettings.SharesUrl; //eg = "http://www.bsb-software.de/rese/"; string item; if (cs.Count > 0 && cs.TryPop(out item)) { //NOTE, there may be a leading 'tick' at the beginning of item //make sure to not let it mess up the file name! Match m = Regex.Match(item, @"(\d{4}_\d{2}_\d{2}.TXT) (\d+) "); if (m.Success) { string targetFile = m.Groups[1].Value; Int64 targetFileReportedSize = Convert.ToInt64(m.Groups[2].Value); var webResource = url + $"/{targetFile}"; var webClient = new WebClient(); webClient.Credentials = new NetworkCredential(userName, passWord); var localFilename = appUserSettings.ExtraFolder + @"\" + targetFile; var fileInfo = new FileInfo(localFilename); if (!File.Exists(localFilename) || (fileInfo.Length < targetFileReportedSize)) { try { var downloadTask = webClient.DownloadFileTaskAsync(webResource, localFilename); var awaiter = downloadTask.GetAwaiter(); awaiter.OnCompleted(() => { Helper.Log("Info", $"{targetFile} downloaded."); Helper.DecrementProgressCountdown("progressBarDownload", "labelBusyDownload"); var totalFiles = 0; if (Helper.MarkListboxItem("listBoxInhalt", item, out totalFiles) == 0) { Helper.Status($"Done. {totalFiles} files downloaded."); } //go get another (even if stack is empty, since we want to exit down below) DownloadFromStack(cs, userName, passWord); }); } catch (Exception e) { Helper.LogStatus("Error", $"Exception: {e.Message}"); Helper.Log("Error", "Download terminated early."); cs.Clear(); MessageBox.Show(e.Message, "An error ocurred - download will end early.", MessageBoxButtons.OK); cs.Clear(); } } else { Helper.Log("Warn", $"{targetFile} exists, skipping file."); Helper.DecrementProgressCountdown("progressBarDownload", "labelBusyDownload"); var totalFiles = 0; Helper.MarkListboxItem("listBoxInhalt", item, out totalFiles); //go get another (even if stack is empty, since we want to exit down below) DownloadFromStack(cs, userName, passWord); } } else { Helper.LogStatus("Warn", $"skipping malformed entry {item}"); Helper.DecrementProgressCountdown("progressBarDownload", "labelBusyDownload"); //go get another (even if stack is empty, since we want to exit down below) DownloadFromStack(cs, userName, passWord); } } else { if (cs.Count == 0) { //exit route... for each concurrent task Helper.Log("Info", $"Exiting DownloadFromStack. NumDownloadTasksActive={NumDownloadTasksActive}"); NumDownloadTasksActive--; if (NumDownloadTasksActive == 0) { LocalStore.TickOffListboxFileItems("listBoxInhalt", appUserSettings.ExtraFolder); Helper.HoldWhileDownloadingDayData(false); } } } }
private bool BleatForSpan() { //firstly, daysBack span MUST BE 100 days //if (daysBack.Value > 100) //{ // MessageBox.Show("The trading days span MAY NOT be set to more 100 days for this operation", "Add new Data",MessageBoxButtons.OK,MessageBoxIcon.Warning); // return true; //} if (daysBack.Value != 100) { MessageBox.Show("The trading days span MUST = 100 days for this operation", "Add new Data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(true); } var wantedStartDate = Helper.GetCompressedDate(calendarFrom.SelectionStart); var wantedEndDate = Helper.GetCompressedDate(calendarTo.SelectionStart); var onhandShareSummary = LocalStore.GetAllTableSummaryForShare(2); var firstDayOnHand = onhandShareSummary.FirstDay; var lastDayOnHand = onhandShareSummary.LastDay; if (String.Compare(wantedStartDate, firstDayOnHand, true) < 0) { var msg = $"The requested date span ({wantedStartDate} - {wantedEndDate}) starts at an EARLIER date than that which is currently held in the All-Tables.\n\n" + $"Either create a NEW 100 day set of All-Tables (with required date span) or set the start date later than '{wantedStartDate}'"; MessageBox.Show(msg, "Overlay not allowed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(true); } else { //OK. The requested date span starts late enough. //Does it end too early? if (String.Compare(wantedEndDate, lastDayOnHand) < 0) { //yes var msg = $"The requested date span ({wantedStartDate} - {wantedEndDate}) ends at an EARLIER date than that which is currently held in the All-Tables ({lastDayOnHand}).\n\n" + $"This will mean already processed days will have to be re processed again later."; MessageBox.Show(msg, "All-Tables data overlay Protection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(true); } else { if (String.Compare(wantedEndDate, lastDayOnHand) == 0) { var msg = $"We already have data in the All-Tables up until {wantedEndDate} !"; MessageBox.Show(msg, "All-Tables data overlay Protection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(true); } else { //finally, we can tell user how many new days data he is trying to add var lastDayOnHandDT = Helper.ConvertCompressedDateToDateTime(lastDayOnHand); int addDays = (calendarTo.SelectionStart - lastDayOnHandDT).Days; var msg = $"Add new trading data for the {addDays} calendar day(s) beyond last data on hand ({lastDayOnHand})?\n(Takes some time)"; if (MessageBox.Show(msg, "Add New Data to All-Tables", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK) { return(false); // user can proceed to next check } return(true); // user cancelled, so dont proceed } } } }