public ModuleResults GetResults(InstanceInfo instanceInfo, DatabaseService dbService)
        {
            var results = dbService.ExecuteAndGetPrintsFromFile("ScheduledTasksModule.sql");

            var res = new ModuleResults
            {
                Result = results,
            };

            if (results.Any(x => x.Contains("DISABLE SCHEDULED TASK!")
                || x.Contains("DON NOT RUN THE task as EXTERNAL")
                || x.Contains("RUN THE task as EXTERNAL")))
            {
                res.Status = Status.Warning;
            }

            return res;
        }
        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;
        }
        public ModuleResults GetResults(InstanceInfo instanceInfo, DatabaseService dbService)
        {
            var webPartsWithColumns = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-WebPartsWithColumns.sql");

            var templates = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-Templates.sql");

            DataSet results = new DataSet();
            bool duplicateTemplateCodeName = false;
            foreach (DataRow template in templates.Rows)
            {
                TemplateWebParts templateWP = GetTemplateWebPartsFromXML(template["PageTemplateWebParts"].ToString());
                string templateName = template["PageTemplateCodeName"].ToString();
                if (results.Tables.Contains(templateName))
                {
                    // Page template code names should be unique
                    templateName += " - DUPLICATE CODENAME (ID: " + template["PageTemplateID"] + ")";
                    duplicateTemplateCodeName = true;
                }
                DataTable result = GetTableForTemplateResult(templateName);

                if (templateWP.WebPartZones != null)
                {
                    foreach (var zone in templateWP.WebPartZones)
                    {
                        if (zone.WebParts == null || zone.WebParts.Length == 0)
                        {
                            continue;
                        }
                        foreach (var wp in zone.WebParts)
                        {
                            var row = result.NewRow();
                            row["WebPartTitle"] = GetWebPartPropertyValue(wp, "webparttitle");
                            row["WebPartType"] = wp.Type;
                            row["ID"] = wp.ControlID;
                            row["Zone"] = zone.ID;
                            row["ContentCache"] = GetWebPartPropertyValue(wp, "cacheminutes");
                            row["PartialCache"] = GetWebPartPropertyValue(wp, "partialcacheminutes");
                            row["ViewStateDisabled"] = GetWebPartPropertyValue(wp, "disableviewstate");

                            DataRow dr = webPartsWithColumns.Select("WebPartName = '" + wp.Type + "'").FirstOrDefault();
                            if (dr != null)
                            {
                                if ((int)dr["Columns"] == 1)
                                {
                                    string colsVal = GetWebPartPropertyValue(wp, "columns");
                                    row["Columns"] = String.IsNullOrEmpty(colsVal) ? "NOT SET" : colsVal;
                                }

                                if ((int)dr["TopN"] == 1)
                                {
                                    string topVal = GetWebPartPropertyValue(wp, "SelectTopN");
                                    if (String.IsNullOrEmpty(topVal))
                                    {
                                        topVal = GetWebPartPropertyValue(wp, "TopN");
                                    }

                                    row["TopN"] = String.IsNullOrEmpty(topVal) ? "NOT SET" : topVal;
                                }
                            }

                            result.Rows.Add(row);
                        }
                    }
                }

                results.Tables.Add(result);

                var documents = dbService.ExecuteAndGetTableFromFile("SiteTemplatesModule-Documents.sql",
                    new SqlParameter("PageTemplateID", template["PageTemplateID"]));
                documents.TableName = String.Format("{0} - Documents", templateName);
                results.Tables.Add(documents.Copy());
            }

            var moduleResults = new ModuleResults
            {
                Result = results,
            };

            if (duplicateTemplateCodeName)
            {
                moduleResults.Status = Status.Warning;
                moduleResults.ResultComment = "Duplicate template code name(s) found, incorrect item(s) are denoted by 'DUPLICATE CODENAME' in its name.";
            }

            return moduleResults;
        }