/**************************************************************************/ private void BuildWorksheetSitemapsAudit( MacroscopeJobMaster JobMaster, XLWorkbook wb, string WorksheetLabel, MacroscopeDocumentList DocumentList, bool InOut ) { var ws = wb.Worksheets.Add(WorksheetLabel); int iRow = 1; int iCol = 1; int iColMax = 1; MacroscopeDocumentCollection DocCollection = JobMaster.GetDocCollection(); MacroscopeAllowedHosts AllowedHosts = JobMaster.GetAllowedHosts(); { ws.Cell(iRow, iCol).Value = "URL"; iCol++; ws.Cell(iRow, iCol).Value = "In Sitemap"; iCol++; ws.Cell(iRow, iCol).Value = "Status Code"; iCol++; ws.Cell(iRow, iCol).Value = "Is Redirect"; iCol++; ws.Cell(iRow, iCol).Value = "Robots"; iCol++; ws.Cell(iRow, iCol).Value = "Sitemap"; } iColMax = iCol; iRow++; foreach (MacroscopeDocument msDoc in DocumentList.IterateDocuments()) { string Url = null; string Robots = null; string SitemapUrl = null; int StatusCode; if (!msDoc.IsDocumentType(Type: MacroscopeConstants.DocumentType.HTML)) { continue; } if (msDoc.GetIsExternal()) { continue; } Url = msDoc.GetUrl(); StatusCode = (int)msDoc.GetStatusCode(); Robots = msDoc.GetAllowedByRobotsAsString(); SitemapUrl = DocumentList.GetDocumentNote(msDoc: msDoc); iCol = 1; this.InsertAndFormatUrlCell(ws, iRow, iCol, msDoc); if (msDoc.GetIsInternal()) { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green); } else { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Gray); } iCol++; this.InsertAndFormatContentCell(ws, iRow, iCol, InOut.ToString()); if (InOut) { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green); } else { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red); } iCol++; this.InsertAndFormatStatusCodeCell(ws, iRow, iCol, msDoc); iCol++; this.InsertAndFormatRedirectCell(ws, iRow, iCol, msDoc); iCol++; this.InsertAndFormatRobotsCell(ws, iRow, iCol, msDoc); iCol++; this.InsertAndFormatUrlCell(ws, iRow, iCol, SitemapUrl); if (AllowedHosts.IsInternalUrl(Url: SitemapUrl)) { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green); } else { ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Gray); } iRow++; } { var rangeData = ws.Range(1, 1, iRow - 1, iColMax); var excelTable = rangeData.CreateTable(); } }
/** -------------------------------------------------------------------- **/ private void _RenderListViewSitemapsAudit( MacroscopeDocumentCollection DocCollection, MacroscopeDocumentList DocumentList, bool InOut ) { List <ListViewItem> ListViewItems = new List <ListViewItem>(1); foreach (MacroscopeDocument msDoc in DocumentList.IterateDocuments()) { string Url = null; string Robots = null; string SitemapUrl = null; string PairKey = null; ListViewItem lvItem = null; int StatusCode; if (!msDoc.IsDocumentType(Type: MacroscopeConstants.DocumentType.HTML)) { continue; } if (msDoc.GetIsExternal()) { continue; } Url = msDoc.GetUrl(); StatusCode = (int)msDoc.GetStatusCode(); Robots = msDoc.GetAllowedByRobotsAsString(); SitemapUrl = DocumentList.GetDocumentNote(msDoc: msDoc); PairKey = string.Join("::::::::", Url); if (this.DisplayListView.Items.ContainsKey(PairKey)) { try { lvItem = this.DisplayListView.Items[PairKey]; lvItem.SubItems[COL_URL].Text = Url; lvItem.SubItems[COL_IN_SITEMAP].Text = InOut.ToString(); lvItem.SubItems[COL_STATUS_CODE].Text = msDoc.GetStatusCode().ToString(); lvItem.SubItems[COL_IS_REDIRECT].Text = msDoc.GetIsRedirect().ToString(); lvItem.SubItems[COL_ROBOTS].Text = Robots; lvItem.SubItems[COL_SITEMAP].Text = SitemapUrl; } catch (Exception ex) { DebugMsg(string.Format("_RenderListViewSitemapsAudit 1: {0}", ex.Message)); } } else { try { lvItem = new ListViewItem(PairKey); lvItem.UseItemStyleForSubItems = false; lvItem.Name = PairKey; lvItem.SubItems[COL_URL].Text = Url; lvItem.SubItems.Add(InOut.ToString()); lvItem.SubItems.Add(msDoc.GetStatusCode().ToString()); lvItem.SubItems.Add(msDoc.GetIsRedirect().ToString()); lvItem.SubItems.Add(Robots); lvItem.SubItems.Add(SitemapUrl); ListViewItems.Add(lvItem); } catch (Exception ex) { DebugMsg(string.Format("_RenderListViewSitemapsAudit 2: {0}", ex.Message)); } } try { if (lvItem != null) { lvItem.ForeColor = Color.Blue; if (msDoc.GetIsInternal()) { lvItem.SubItems[COL_URL].ForeColor = Color.Green; } else { lvItem.SubItems[COL_URL].ForeColor = Color.Gray; } if (InOut) { lvItem.SubItems[COL_IN_SITEMAP].ForeColor = Color.Green; } else { lvItem.SubItems[COL_IN_SITEMAP].ForeColor = Color.Red; } if ((StatusCode >= 200) && (StatusCode <= 299)) { lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Green; } else if ((StatusCode >= 300) && (StatusCode <= 399)) { lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Goldenrod; } else if ((StatusCode >= 400) && (StatusCode <= 599)) { lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Red; } else { lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Blue; } if (StatusCode == 410) { lvItem.SubItems[COL_STATUS_CODE].ForeColor = Color.Purple; } if (msDoc.GetIsRedirect()) { lvItem.SubItems[COL_IS_REDIRECT].ForeColor = Color.Goldenrod; } else { lvItem.SubItems[COL_IS_REDIRECT].ForeColor = Color.Gray; } if (!msDoc.GetAllowedByRobots()) { lvItem.SubItems[COL_ROBOTS].ForeColor = Color.Red; } else { lvItem.SubItems[COL_ROBOTS].ForeColor = Color.Green; } if (msDoc.GetIsInternal()) { lvItem.SubItems[COL_SITEMAP].ForeColor = Color.Green; } else { lvItem.SubItems[COL_SITEMAP].ForeColor = Color.Gray; } } else { lvItem.SubItems[3].ForeColor = Color.Gray; } } catch (Exception ex) { DebugMsg(string.Format("_RenderListViewSitemapsAudit 3: {0}", ex.Message)); } } this.DisplayListView.Items.AddRange(ListViewItems.ToArray()); return; }