Esempio n. 1
0
        private async void startAllButton_Click(object sender, EventArgs e)
        {
            dbChecker = new DbChecker();
            bool firstStep  = dbChecker.CheckIntProcessFromDb("step_1");
            bool secondStep = dbChecker.CheckIntProcessFromDb("step_2");

            startAllButton.Enabled = false;
            if (!firstStep)
            {
                string link = "https://agrotender.com.ua/kompanii/region_ukraine/t10.html";
                isActive  = true;
                firstStep = await Worker(link);
            }

            if (firstStep)
            {
                if (!secondStep)
                {
                    panel3.Visible = true;
                    isActive       = true;
                    InitProcessMonitoring();
                    abortButton.Enabled = false;
                    secondStep          = await MainCompWorker();
                }
                if (secondStep)
                {
                    panel3.Visible = false;
                    isActive       = true;
                    InitProcessMonitoring();
                    abortButton.Enabled = true;
                    abortButton.Text    = "Pause";
                    DetailCompWorker();
                }
            }
        }
Esempio n. 2
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, DbChecker dbChecker)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseSpaStaticFiles();

            app.UseRouting();

            app.UseMiddleware <JwtCookiesHandler>();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseCookiePolicy(new CookiePolicyOptions
            {
                MinimumSameSitePolicy = SameSiteMode.Strict,
                HttpOnly = HttpOnlyPolicy.Always,
                Secure   = CookieSecurePolicy.Always
            });

            app.UseMiddleware <OkBadResultHandler>();

            app.UseEndpoints(endpoints => endpoints.MapControllers());

            app.UseEndpoints(endpoints =>
            {
                endpoints.Map("api/{*any}", async context =>
                {
                    await new ApiResult(Bad.BadRequest)
                    .WriteToResponse(context.Response);
                });
            });

            app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";

                if (env.IsDevelopment())
                {
                    spa.UseReactDevelopmentServer("start");
                }
            });

            dbChecker.CheckAll();
        }
Esempio n. 3
0
        public async Task <bool> MainCompWorker()
        {
            dbChecker = new DbChecker();
            int max = await dbChecker.GetMaxCountDB("category");

            LinkToCompanyParser parser = new LinkToCompanyParser();

            curentValueProgress = 0;
            ActivateVisibilityMonitor();

            for (int i = 1; i <= max; i++)
            {
                if (!isActive)
                {
                    return(true);
                }

                (string link, int categoryId) = await dbChecker.GetLinkAndIdByKey(i, "category");

                if (link == "0" || link == "")
                {
                    continue;
                }

                for (int j = 1; j <= 100; j++)
                {
                    curentValueProgress++;
                    prepareProcessUpdate((max - 7) * 100);

                    if (!isActive)
                    {
                        return(true);
                    }
                    var result = await parser.Parse(j, link, i);

                    if (result == null)
                    {
                        curentValueProgress += (100 - j);
                        prepareProcessUpdate((max - 7) * 100);
                        break;
                    }

                    ShowTotalParsed();
                    OnNewData?.Invoke(this, result);
                    Console.WriteLine($"Цикл страницы {j} завершен");
                }
            }

            dbChecker.PutIntProcessToDb("step_2", 0, true);
            dbChecker.PutIntProcessToDb("internal-string-time-elapsed", 0, false);
            isActive = false;
            FinishProcessMonitoring();
            return(true);
        }
Esempio n. 4
0
        public async void ShowTotalParsed()
        {
            dbChecker = new DbChecker();
            (int links, int companyes, int phones, int faxes, int emails) = await dbChecker.GetParsedData();

            ParsedLinksBox.Text  = links.ToString();
            CompParsedBox.Text   = companyes.ToString();
            PhonesParsedBox.Text = phones.ToString();
            FaxParsedBox.Text    = faxes.ToString();
            EmailParsedBox.Text  = emails.ToString();
        }
        private static void StartJob()
        {
            var dbChecker = new DbChecker();
            var timer     = new System.Timers.Timer();

            timer.Interval = 60000;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(dbChecker.RequestToDb);
            timer.Enabled  = true;
            // If AutoReset=false then the timer will only tick once
            timer.AutoReset = true;
            timer.Start();
        }
Esempio n. 6
0
        public async void DetailCompWorker()
        {
            ActivateVisibilityMonitor();
            dbChecker           = new DbChecker();
            curentValueProgress = 0;
            DetailCompanyParser detailParser = new DetailCompanyParser();
            string whatTable = "temp";
            int    maxKey    = await dbChecker.GetMaxCountDB(whatTable);

            int linkId = await dbChecker.GetMaxCountDB();

            if (linkId == 0)
            {
                linkId = 1;
            }

            for (int i = linkId + 1; i < maxKey; i++)
            {
                curentValueProgress = i;
                totalProcessUpdate(maxKey);

                if (!isActive)
                {
                    return;
                }

                (string link, int categoryId) = await dbChecker.GetLinkAndIdByKey(i, whatTable);

                var result = await detailParser.Parse(0, link, categoryId);

                dbChecker.markCompanyAsParsed(i);
                ShowTotalParsed();
                OnNewData?.Invoke(this, result);
            }
            FinishProcessMonitoring();
            isActive = false;
            startAllButton.Enabled = true;
            abortButton.Enabled    = false;
            Message("All work is done!");
        }