Exemple #1
0
        public void AddCompanies(GtMetrics metric)
        {
            if (_CompanyRepo.GetAll().Count() > 0)
            {
                return;
            }
            Company initial = new Company
            {
                Id                      = 1,
                BusinessType            = "Agriculture Equipment",
                City                    = "Grapevine",
                CompanyName             = "Kubota Tractor",
                ConfirmedVersionDate    = new DateTime(2019, 9, 21),
                Contacted               = false,
                Country                 = "United States",
                EndEnterpriseSupport    = null,
                GtMetricsId             = 1,
                GtMetrics               = metric,
                Notes                   = string.Empty,
                PreviousVersion         = null,
                RankingScale            = 1,
                SfVersion               = 11.1,
                SitefinityRetirmentDate = null,
                State_Region            = "Texas",
                Street                  = "1000 Kubota Drive",
                Url                     = "kubotausa.com",
                ZipCode                 = "76051"
            };

            _CompanyRepo.Add(initial);
        }
        public async Task <GtMetrics> GetTest(string url, int companyId)
        {
            var client = new RestClient(url);

            client.Timeout = 5000;
            client.UseSystemTextJson();
            var request = new RestRequest(Method.GET);

            request.AddHeader("Authorization", "Basic c3NjaG9vckBzbW9vdGhmdXNpb24uY29tOjA1YzYyNmE4OTEyMWQwZGM2MzY1Y2E4OTAwMDE0N2Zk");
            request.AlwaysMultipartFormData = true;

            var response = await client.UseJson().ExecuteAsync <GtMetricsDomainModel>(request);

            while (response.Data.state != "completed")
            {
                response = await client.UseJson().ExecuteAsync <GtMetricsDomainModel>(request);

                if (!response.IsSuccessful)
                {
                    throw response.ErrorException;
                }
            }
            GtMetrics FinalResult = new GtMetrics()
            {
                Error                    = response.Data.error,
                Status                   = response.Data.state,
                ReportUrl                = response.Data.results.report_url,
                PageSpeedScore           = response.Data.results.pagespeed_score,
                YSlowScore               = response.Data.results.yslow_score,
                HtmlBytes                = response.Data.results.html_bytes,
                HtmlLoadTime             = response.Data.results.html_load_time,
                PageBytes                = response.Data.results.page_bytes,
                PageLoadTime             = response.Data.results.page_load_time,
                PageElements             = response.Data.results.page_elements,
                FullyLoadedTime          = response.Data.results.fully_loaded_time,
                BackendDuration          = response.Data.results.backend_duration,
                CompanyId                = companyId,
                ConnectionDuration       = response.Data.results.connect_duration,
                DomContentLoadedDuration = response.Data.results.dom_content_loaded_duration,
                DomContentLoadedTime     = response.Data.results.dom_content_loaded_time,
                DomInteractiveTime       = response.Data.results.dom_interactive_time,
                FilmStrip                = response.Data.resources.filmstrip,
                FirstContentfulPaintTime = response.Data.results.first_contentful_paint_time,
                FirstPaintTime           = response.Data.results.first_paint_time,
                HARFile                  = response.Data.resources.har,
                OnloadTime               = response.Data.results.onload_time,
                PageSpeed                = response.Data.resources.pagespeed,
                PageSpeedFiles           = response.Data.resources.pagespeed_files,
                RedirectDuration         = response.Data.results.redirect_duration,
                ReportPdf                = response.Data.resources.report_pdf,
                ReportPdfFull            = response.Data.resources.report_pdf_full,
                RumSpeedIndex            = response.Data.results.rum_speed_index,
                Screenshot               = response.Data.resources.screenshot,
                Video                    = response.Data.resources.video,
                YSlow                    = response.Data.resources.yslow
            };

            return(FinalResult);
        }
Exemple #3
0
        public void AddMetric(GtMetrics metric)
        {
            var exists = _gtMetricsServices.Get(1);

            if (exists == null)
            {
                AddCompanies(metric);
            }
        }
Exemple #4
0
        public async Task <GtMetrics> MakeGtMetric()
        {
            if (_gtMetricsServices.GetAll().Count() > 0)
            {
                return(null);
            }

            GtMetrics initial = await _gtMetricsServices.Test("kubotausa.com", 1);

            return(initial);
        }
Exemple #5
0
 public GtMetrics Get(int companyId)
 {
     try
     {
         GtMetrics Metric = _dbContext.GtMetrics.FirstOrDefault(m => m.CompanyId == companyId);
         if (Metric == null)
         {
             return(null);
         }
         return(Metric);
     }catch (Exception ex)
     {
         return(null);
     }
 }
Exemple #6
0
        public GtMetrics Update(GtMetrics newMetric)
        {
            var ExistingMetric = _dbContext.GtMetrics
                                 .FirstOrDefault(M => M.CompanyId == newMetric.CompanyId);

            newMetric.Id = ExistingMetric.Id;
            if (ExistingMetric == null)
            {
                return(null);
            }
            _dbContext.Entry(ExistingMetric).CurrentValues
            .SetValues(newMetric);
            _dbContext.Update(ExistingMetric);
            _dbContext.SaveChanges();
            return(newMetric);
        }
        public async Task <GtMetrics> Test(string url, int companyId)
        {
            GtMetricsPostResponce Post = PostTest(url);

            if (Post == null)
            {
                throw new Exception("Error posting a url to External api");
            }

            GtMetrics Get = await GetTest(Post.poll_state_url, companyId);

            if (Get == null)
            {
                throw new Exception("Error getting gtmetric from external api");
            }

            return(Get);
        }
        public GtMetrics Add(GtMetrics gtMetric)
        {
            Company company = _companyServices.Get(gtMetric.CompanyId);

            if (company == null)
            {
                throw new Exception("Error getting company targeted by new metric. Are you sure the comapny Id you posted exists?");
            }

            company.GtMetrics = gtMetric;
            Company updateCompany = _companyServices.Update(company);

            //metric = _gtMetricsRepo.Add(gtMetric);
            if (updateCompany == null)
            {
                throw new Exception("Error new adding metric");
            }



            return(gtMetric);
        }
Exemple #9
0
        public async Task <IActionResult> Post(GtMetricsToApi metric)
        {
            try
            {
                GtMetrics results = await Task.Run(() =>
                {
                    return(_gtService.Test(metric.Url, metric.CompanyId));
                });

                if (results == null)
                {
                    return(NotFound(results.Error));
                }
                var AddMetric = _gtService.Add(results);
                return(Ok(results.Id));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("PostURL", ex.Message);
                ModelState.AddModelError("PostURLStackTrace", ex.StackTrace);
                return(BadRequest(ModelState));
            }
        }
Exemple #10
0
 public GtMetrics Add(GtMetrics newMetric)
 {
     _dbContext.GtMetrics.Add(newMetric);
     _dbContext.SaveChanges();
     return(newMetric);
 }