예제 #1
0
        private DownloadInfo DoDownloadIfNeed(IndexShopContext context, XmlFileInfo xmlInfo)
        {
            var filePath = FilePathHelper.GetFilePath(_settings.DirectoryPath, xmlInfo);

            if (context.DownloadFresh ||
                File.Exists(filePath) == false)
            {
                var downloadContext = new BackgroundBaseContext($"Download:{xmlInfo.Name}", "download");
                downloadContext.Prepare();
                downloadContext.Start();

                context.Contexts.Add(downloadContext);

                var downloader = new FeedsDownloader(_settings.AttemptsToDownload, Db, downloadContext);
                var file       = downloader.Download(_settings.DirectoryPath, xmlInfo);

                downloadContext.Content = "Все скачали";
                downloadContext.Finish();

                return(file);
            }

            return(new DownloadInfo(xmlInfo.ShopId, xmlInfo.NameLatin, xmlInfo.Weight)
            {
                ShopName = xmlInfo.NameLatin,
                FilePath = filePath
            });
        }
예제 #2
0
        private void DownloadAll(List <XmlFileInfo> infos)
        {
            var downloadContext = new BackgroundBaseContext("Download:All", "download");

            downloadContext.Prepare();
            _context.AddContext(downloadContext);

            var downloader = new FeedsDownloader(_settings.AttemptsToDownload, Db, downloadContext);

            downloader.FileDownloaded += HandleDownloadEvent;

            downloadContext.Start();

            downloader.DownloadsAll(_settings.DirectoryPath, infos);

            downloadContext.Content = "Все скачали";
            downloadContext.Finish();
        }