Пример #1
0
        public bool Start(BillingCompanyInfo billingCompanyInfo)
        {
            bool               result = false;
            Logging            log    = new Logging();
            ReferenceGenerator refGen = new ReferenceGenerator();
            string             refNum = refGen.GenerateReference();

            try
            {
                // Load all the rules for the LoadManager
                LoadManagerRules       loadManagerRules = new LoadManagerRules();
                List <LoadManagerRule> rules            = loadManagerRules.LoadRules();

                // Call the scrape session to initialise the scrape
                ScrapeSession scrapeSession = new ScrapeSession();
                scrapeSession.CreateScrapeSession(rules, billingCompanyInfo);
                result = true;
            }
            catch (Exception ex)
            {
                result = false;
                log.LogMessage(Enumeration.LoggingPriority.High, refNum, ex);
            }

            return(result);
        }
        public void CreateLoadManagerTest(BillingCompanyInfo billingCompanyInfo)
        {
            LoadManagerService MyService = new LoadManagerService();

            bool retVal = MyService.CreateLoadManager(billingCompanyInfo);

            Assert.IsTrue(retVal);
        }
        public bool CreateLoadManager(BillingCompanyInfo billingCompanyInfo)
        {
            ReferenceGenerator refNumber = new ReferenceGenerator();
            string refNum = refNumber.GenerateReference();

            LoadManager loadManager = new LoadManager();
            loadManager.Start(billingCompanyInfo);

            return true;
        }
 public void CreateScrapeSession(List<LoadManagerRule> rules, BillingCompanyInfo billingCompanyInfo)
 {
     throw new NotImplementedException();
 }
        public void CreateScrapeSession(List <LoadManagerRule> rules, BillingCompanyInfo billingCompanyInfo)
        {
            Logging            log    = new Logging();
            ReferenceGenerator refGen = new ReferenceGenerator();
            string             refNum = refGen.GenerateReference();

            try
            {
                // Get scraping scripts per billing company
                log.LogMessage(Enumeration.LoggingPriority.Low, refNum, "Get scraping scripts per billing company");
                BillingCompany        getScrapingScripts = new BillingCompany(new BillingCompanyId(billingCompanyInfo.BillingCompanyId), billingCompanyInfo.BillingCompanyName);
                List <ScrapingScript> scrapingScripts    = getScrapingScripts.GetScrapingScripts();


                foreach (var scrapingScript in scrapingScripts)
                {
                    // Process errors
                    if (scrapingScript.ErrorCode == 91)
                    {
                        BrokenScript brokenScript = new BrokenScript(Enumeration.ErrorCode.BrokenScript, scrapingScript.ScriptSiteURL, DateTime.Now);
                    }
                }

                // Call the 3rd party provider to perform the scrape
                log.LogMessage(Enumeration.LoggingPriority.Low, refNum, "Call the 3rd party provider to perform the scrape");
                ScraperProvider   scraperProvider = new ScraperProvider();
                List <ScrapeData> scrapeData      = scraperProvider.RequestScrape();

                foreach (var data in scrapeData)
                {
                    // Process errors
                    if (data.ErrorCode == 91)
                    {
                        BillingCompanySiteDown siteDown = new BillingCompanySiteDown(Enumeration.ErrorCode.BillingCompanySiteDown, "", DateTime.Now);
                    }
                    else if (data.ErrorCode == 92)
                    {
                        CustomerActionRequired custActionReq = new CustomerActionRequired(Enumeration.ErrorCode.CustomerActionRequired, "", DateTime.Now);
                    }
                    else if (data.ErrorCode == 93)
                    {
                        IncorrectAccount incorrectAcc = new IncorrectAccount(Enumeration.ErrorCode.IncorrectAccount, "", DateTime.Now);
                    }
                    else if (data.ErrorCode == 94)
                    {
                        InvalidCredentials invalidCredentials = new InvalidCredentials(Enumeration.ErrorCode.InvalidCredentials, "", DateTime.Now);
                    }
                }

                // Save scraped data to the Repo
                log.LogMessage(Enumeration.LoggingPriority.Low, refNum, "Save scraped data to the Repo");
                ScrapeDataRepository     scrapeDataRepo = new ScrapeDataRepository();
                List <LoadManagerErrors> saveErrors     = scrapeDataRepo.SaveScrapeData(scrapeData);

                foreach (var saveError in saveErrors)
                {
                    // Process errors
                    if (saveError.ErrorCode == 91)
                    {
                        UnableToCheckDataIntegrity unableToCheckDataIntegrity = new UnableToCheckDataIntegrity(Enumeration.ErrorCode.UnableToCheckDataIntegrity, saveError.Message, DateTime.Now);
                    }
                }
            }
            catch (Exception ex)
            {
                // Process errors

                log.LogMessage(Enumeration.LoggingPriority.High, refNum, ex);
            }
        }