public ModuleResults GetResults(InstanceInfo instanceInfo, DatabaseService dbService) { var contactNumber = dbService.ExecuteAndGetScalar<int>(@"SELECT COUNT(*) FROM OM_Contact"); var results = dbService.ExecuteAndGetTableFromFile(@"OMInactiveContactsDeletion.sql"); return new ModuleResults { Result = results, ResultComment = @"Inactive contact deletion setting should be always set up, so that the database doesn't get too big over time. It is a business decision what contacts could be deleted. There are now " + (contactNumber < 10000 ? "only " : "") + contactNumber + " contacts in the database.", Status = (contactNumber > 100000 && results.Rows.Count > 0) ? Status.Error : (results.Rows.Count > 0) ? Status.Warning : Status.Good }; }
public ModuleResults GetResults(InstanceInfo instanceInfo, DatabaseService dbService) { List<string> responses = new List<string>(); var activityCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_Activity"); if (activityCount > 10000000) { responses.Add("There is over 10 000 000 (" + activityCount + " exactly) activities in the database. Consider using deleting old page visits or setting up the old contact's deletion"); } var contactsCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_Contact"); if (contactsCount > 1000000) { responses.Add("There is over 1 000 000 (" + contactsCount + " exactly) contacts in the database. Consider using old contact's deletion"); var anonymousCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_Contact WHERE ContactLastName LIKE 'Anonymous%'"); var mergedCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_Contact WHERE ContactMergedWithContactID NOT NULL"); responses.Add("Out of these " + contactsCount + " contacts, " + anonymousCount + " are anonymous and " + mergedCount + " are merged"); } var contactGroupCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_ContactGroup"); if (contactGroupCount > 50) { responses.Add("There is over 100 contact groups (" + contactGroupCount + " exactly). This might affect performance, are all of those really neccessary?"); } var scoringRuleCount = dbService.ExecuteAndGetScalar<int>("SELECT COUNT(*) FROM OM_Rule"); if (scoringRuleCount > 50) { responses.Add("There is over 100 scoring rules (" + scoringRuleCount + " exactly). This might affect performance, are all of those really neccessary?"); } if (responses.Any()) { return new ModuleResults { Result = responses, ResultComment = @"Check the counts in the result table. Exceeding the limits doesn't mean it must be wrong. It depends on other things like traffic, hardware and so on.", Status = Status.Error, }; } else { return new ModuleResults { ResultComment = "All of critical Online marketing are small enough to use Online marketing without affecting performance.", Status = Status.Good }; } }
public ModuleResults GetResults(InstanceInfo instanceInfo, DatabaseService dbService) { var siteID = dbService.ExecuteAndGetScalar<int>(string.Format(@"SELECT s.SiteID FROM CMS_Site AS s LEFT JOIN CMS_SiteDomainAlias AS sa ON s.SiteID = sa.SiteID WHERE ('{0}' LIKE '%' + s.SiteDomainName + '%' OR '{0}' LIKE '%' + sa.SiteDomainAliasName + '%') AND s.SiteStatus = N'RUNNING'", instanceInfo.Url)); var results = new ModuleResults(); var resultList = new List<string>(); var aliases = dbService.ExecuteAndGetTableFromFile("PagesAnalyzerModule.sql", new SqlParameter("SiteId", siteID)); var allLinks = new Dictionary<string, List<string>>(); Dictionary<string, string> faviconAvailabilityCache = new Dictionary<string, string>(); Dictionary<string, string> touchIconAvailabilityCache = new Dictionary<string, string>(); // Workaround to ignore invalid SSL certificates ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback((a, b, c, d) => { return true; }); foreach (DataRow alias in aliases.Rows) { var aliasPath = alias["AliasPath"].ToString().TrimStart('/'); var uri = new Uri(instanceInfo.Url, aliasPath + ".aspx"); var html = String.Empty; try { HttpWebRequest request = WebRequest.CreateHttp(uri); Stopwatch sw = Stopwatch.StartNew(); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { // Get size of the request using (StreamReader sr = new StreamReader(response.GetResponseStream())) { html = sr.ReadToEnd(); alias["Response"] = response.StatusCode.ToString(); } alias["Response type"] = response.ContentType; } sw.Stop(); alias["Response Time [ms]"] = sw.ElapsedMilliseconds; } catch (WebException e) { // Probably 404 alias["Response"] = e.Status.ToString(); } alias["HTML Size [KB]"] = html.Length / 1024; var viewState = Regex.Match(html, "(?<=__VIEWSTATE\" value=\")(?<val>.*?)(?=\")").Groups["val"].Value; alias["ViewState Size [KB]"] = viewState.Length / 1024; var linksRegex = new Regex("(href|src)=\"(/[^\"]+)|url\\('(/[^\']+)|url\\(\"(/[^\"]+)"); var links = linksRegex.Matches(html); // Evaluate favicon availability alias["Favicon"] = EvaluateFaviconAvailability(html, uri, faviconAvailabilityCache); // Evaluate Apple touch icon and precomposed icon availability alias["Apple Touch Icon"] = EvaluateAppleTouchIconAvailability(html, uri, touchIconAvailabilityCache); alias["Apple Touch Icon Precomposed"] = EvaluateAppleTouchIconAvailability(html, uri, touchIconAvailabilityCache, true); // Evaluate links count alias["Link count"] = links.Count; if (links.Count > 0) { foreach (Match match in links) { string link = match.Groups[2].ToString(); if (string.IsNullOrEmpty(link)) { link = match.Groups[3].ToString(); if (string.IsNullOrEmpty(link)) { link = match.Groups[4].ToString(); } } if (!link.ToLower().Contains("/webresource") && !link.ToLower().Contains("/scriptresource")) { if (allLinks.ContainsKey(link)) { allLinks[link].Add(aliasPath); } else { allLinks[link] = new List<string> { aliasPath }; } } } } } foreach (var linkList in allLinks) { // all the links are here, TODO: request them and get the response status } results.Result = aliases; return results; }
/// <summary> /// Gets the version of Kentico. /// </summary> private static Version GetKenticoVersion(DatabaseService dbService) { string version = dbService.ExecuteAndGetScalar<string>("SELECT KeyValue FROM CMS_SettingsKey WHERE KeyName = 'CMSDBVersion'"); return new Version(version); }