Example #1
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            var path = Directory.GetCurrentDirectory() + AppSettings.GetImagePath();

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var delete = DownloadLoader.DeleteAllCache(path);

            ProgressLabel.Content     = "";
            EstimateTimeLabel.Content = "";
            ProgressBar.Value         = 0;
            SetupListBox();
            ToggleButton(true);
            MessageBox.Show(delete ? "Caches deleted" : "No caches to deleted");
        }
Example #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //var tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
            //var token = tokenSource.Token;
            //if (_running)
            //{
            //    _tokenSource.Cancel();
            //    _running = false;
            //    return;
            //}
            //running = true;

            ToggleButton(false);
            var testlist = XmlReader.GetXmlFiles(AppSettings.GetXmlFileName());
            var lists    = DownloadLoader.Partition(testlist, 5);

            SetupTimer();
            // Create and collect tasks in list

            _starttime = DateTime.Now;

            var tasks = lists.Select(list => Task.Factory.StartNew(() =>
            {
                var worker         = new DownloadWorker();
                worker.Progressed += (o, args) =>
                {
                    lock (this)
                    {
                        _count++;
                    }
                    Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate
                    {
                        var procent           = ((100 * _count) / testlist.Count);
                        ProgressBar.Value     = procent;
                        ProgressLabel.Content = procent + "%";

                        //CountLabel.Content = "Total items cleanse: " + _count;

                        if (_count > 0)
                        {
                            EstimateTimeLabel.Content = "Time: " + EstimateTime(testlist.Count).ToString();
                        }
                    });
                };

                var path = Directory.GetCurrentDirectory() + AppSettings.GetImagePath();

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                var result = worker.DownloadeImage(list.ToList(), path);
                return(result);
            }, _tokenSource.Token)).ToList();

            Task.Factory.StartNew(() =>
            {
                var results = new List <Log>();

                // Wait till all tasks completed

                foreach (var result in tasks.Select(task => task.Result))
                {
                    results.AddRange(result.ToList());
                }
                var path = Directory.GetCurrentDirectory() + AppSettings.GetLogPath();

                _timer.Stop();

                LogMaker.MakeListLog(results, path);
            }, _tokenSource.Token);
            SetupListBox();
        }