Пример #1
0
        //radiobutton source changed
        private void radioButtonSource_CheckedChanged(object sender, EventArgs e)
        {
            listBoxInhalt.DataSource = GetDaysListingPerSource().Where((entry) => WithinDateRange(entry)).ToList();
            LocalStore.TickOffListboxFileItems("listBoxInhalt", Helper.UserSettings().ExtraFolder);

            Helper.ListBoxClearAndScrollToBottom(listBoxInhalt);
            buttonDayDataDownload.Enabled = listBoxInhalt.Items.Count > 0;
        }
Пример #2
0
        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";
        }
Пример #3
0
        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);
                    }
                }
            }
        }