Ejemplo n.º 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
            });
        }
Ejemplo n.º 2
0
        public void Index(IndexShopContext context)
        {
            CheckContextType(context);

            var xmlInfo = Db.GetShop(context.ShopId);

            context.ShopName = xmlInfo.Name;

            var file = DoDownloadIfNeed(context, xmlInfo);

            context.SetProgress(30, 100);
            if (file.HasError)
            {
                context.Finish();
                context.IsError = true;

                return;
            }

            DoIndexShop(xmlInfo.ShopId, file, true, context.NeedSoldOut);
            context.SetProgress(60, 100);
            if (context.NeedLink)
            {
                DoLink();
                context.SetProgress(90, 100);
            }
            Wait();
            LogResult();
        }
Ejemplo n.º 3
0
        public IActionResult IndexShop(
            int id,
            bool downloadFresh = false,
            bool needLink      = true,
            bool needSoldOut   = true,
            bool clean         = true)
        {
            var context = new IndexShopContext(id, downloadFresh, needLink, needSoldOut);
            var worker  = new IndexWorker(_settings, context, _works, _dbHelper);

            return(_works.AddToQueue(worker.Index, context, QueuePriority.Parallel, clean));
        }