/**************************************************************************/

        private void RenderListView(
            MacroscopeDocumentCollection DocCollection,
            Dictionary <string, string> LocalesList
            )
        {
            MacroscopeAllowedHosts AllowedHosts = this.MainForm.GetJobMaster().GetAllowedHosts();

            SortedDictionary <string, int> LocaleColsTable = new SortedDictionary <string, int> ();

            if (DocCollection.CountDocuments() == 0)
            {
                return;
            }

            List <ListViewItem> ListViewItems = new List <ListViewItem> ();

            MacroscopeSinglePercentageProgressForm ProgressForm = new MacroscopeSinglePercentageProgressForm(this.MainForm);
            decimal Count           = 0;
            decimal TotalDocs       = ( decimal )DocCollection.CountDocuments();
            decimal MajorPercentage = (( decimal )100 / TotalDocs) * Count;

            if (MacroscopePreferencesManager.GetShowProgressDialogues())
            {
                ProgressForm.UpdatePercentages(
                    Title: "Preparing Display",
                    Message: "Processing document collection for display:",
                    MajorPercentage: MajorPercentage,
                    ProgressLabelMajor: string.Format("Document {0} / {1}", Count, TotalDocs)
                    );
            }

            this.DisplayListView.Items.Clear();
            this.DisplayListView.Columns.Clear();

            {
                int LocaleColCount = 5;

                this.DisplayListView.Columns.Add("URL", "URL");
                this.DisplayListView.Columns.Add("Status Code", "Status Code");
                this.DisplayListView.Columns.Add("Site Locale", "Site Locale");
                this.DisplayListView.Columns.Add("HrefLang Present", "HrefLang Present");
                this.DisplayListView.Columns.Add("Title", "Title");

                foreach (string Locale in LocalesList.Keys)
                {
                    string LocaleLabel       = Locale.ToUpper();
                    string DateServerLabel   = string.Format("{0} Date Server", Locale.ToUpper());
                    string DateModifiedLabel = string.Format("{0} Date Modified", Locale.ToUpper());

                    this.DisplayListView.Columns.Add(LocaleLabel, LocaleLabel);
                    this.DisplayListView.Columns.Add(DateServerLabel, DateServerLabel);
                    this.DisplayListView.Columns.Add(DateModifiedLabel, DateModifiedLabel);

                    LocaleColsTable[Locale] = LocaleColCount;
                    LocaleColCount++;

                    LocaleColsTable[DateServerLabel] = LocaleColCount;
                    LocaleColCount++;

                    LocaleColsTable[DateModifiedLabel] = LocaleColCount;
                    LocaleColCount++;
                }
            }

            foreach (MacroscopeDocument msDoc in DocCollection.IterateDocuments())
            {
                bool Proceed = false;

                if (msDoc.GetIsInternal())
                {
                    Proceed = true;

                    if (msDoc.GetIsRedirect())
                    {
                        Proceed = false;
                    }

                    if (!msDoc.IsDocumentType(Type: MacroscopeConstants.DocumentType.HTML))
                    {
                        Proceed = false;
                    }
                }

                if (Proceed)
                {
                    Dictionary <string, MacroscopeHrefLang> HrefLangsTable = msDoc.GetHrefLangs();
                    string         DocUrl        = msDoc.GetUrl();
                    string         PairKey       = UrlToDigest(DocUrl).ToString();
                    HttpStatusCode StatusCode    = msDoc.GetStatusCode();
                    int            StatusCodeNum = ( int )StatusCode;
                    MacroscopeConstants.Specifiers HrefLangPresent = MacroscopeConstants.Specifiers.UNSPECIFIED;
                    string       DocLocale = msDoc.GetLocale();
                    string       DocTitle  = msDoc.GetTitle();
                    ListViewItem lvItem    = null;

                    if (
                        (HrefLangsTable != null) &&
                        (HrefLangsTable.Count > 1))
                    {
                        HrefLangPresent = MacroscopeConstants.Specifiers.SPECIFIED;
                    }
                    else
                    {
                        HrefLangPresent = MacroscopeConstants.Specifiers.UNSPECIFIED;
                    }

                    if (this.DisplayListView.Items.ContainsKey(PairKey))
                    {
                        lvItem = this.DisplayListView.Items[PairKey];
                    }
                    else
                    {
                        lvItem = new ListViewItem(PairKey);
                        lvItem.UseItemStyleForSubItems = false;
                        lvItem.Name = PairKey;

                        lvItem.SubItems.Add("");
                        lvItem.SubItems.Add("");
                        lvItem.SubItems.Add("");
                        lvItem.SubItems.Add("");
                        lvItem.SubItems.Add("");

                        for (int i = 0; i < LocalesList.Keys.Count; i++)
                        {
                            lvItem.SubItems.Add("");
                            lvItem.SubItems.Add("");
                            lvItem.SubItems.Add("");
                        }

                        ListViewItems.Add(lvItem);
                    }

                    if (lvItem != null)
                    {
                        try
                        {
                            lvItem.SubItems[ColUrl].Text             = DocUrl;
                            lvItem.SubItems[ColStatusCode].Text      = StatusCode.ToString();
                            lvItem.SubItems[ColSiteLocale].Text      = DocLocale;
                            lvItem.SubItems[ColHrefLangPresent].Text = "";
                            lvItem.SubItems[ColTitle].Text           = DocTitle;

                            switch (HrefLangPresent)
                            {
                            case MacroscopeConstants.Specifiers.SPECIFIED:
                                lvItem.SubItems[ColHrefLangPresent].ForeColor = Color.Green;
                                lvItem.SubItems[ColHrefLangPresent].Text      = "SPECIFIED";
                                break;

                            default:
                                lvItem.SubItems[ColHrefLangPresent].ForeColor = Color.Red;
                                lvItem.SubItems[ColHrefLangPresent].Text      = "UNSPECIFIED";
                                break;
                            }

                            if (AllowedHosts.IsInternalUrl(DocUrl))
                            {
                                lvItem.SubItems[ColUrl].ForeColor = Color.Green;
                            }
                            else
                            {
                                lvItem.SubItems[ColUrl].ForeColor = Color.Gray;
                            }

                            if ((StatusCodeNum >= 100) && (StatusCodeNum <= 299))
                            {
                                lvItem.SubItems[ColStatusCode].ForeColor = Color.Green;
                            }
                            else
                            if ((StatusCodeNum >= 300) && (StatusCodeNum <= 399))
                            {
                                lvItem.SubItems[ColStatusCode].ForeColor = Color.Orange;
                            }
                            else
                            if ((StatusCodeNum >= 400) && (StatusCodeNum <= 599))
                            {
                                lvItem.SubItems[ColStatusCode].ForeColor = Color.Red;
                            }
                            else
                            {
                                lvItem.SubItems[ColSiteLocale].ForeColor = Color.Gray;
                            }

                            foreach (string Locale in LocalesList.Keys)
                            {
                                if (!string.IsNullOrEmpty(Locale))
                                {
                                    string   HrefLangUrl          = null;
                                    DateTime HrefLangDateServer   = new DateTime();
                                    DateTime HrefLangDateModified = new DateTime();
                                    int      LocaleCol            = LocaleColsTable[Locale];

                                    if (
                                        (HrefLangsTable != null) &&
                                        (HrefLangsTable.Count > 0))
                                    {
                                        if (HrefLangsTable.ContainsKey(Locale))
                                        {
                                            MacroscopeHrefLang HrefLangAlternate = HrefLangsTable[Locale];

                                            if (HrefLangAlternate != null)
                                            {
                                                HrefLangUrl          = HrefLangAlternate.GetUrl();
                                                HrefLangDateServer   = HrefLangAlternate.GetDateServer();
                                                HrefLangDateModified = HrefLangAlternate.GetDateModified();
                                            }
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(HrefLangUrl))
                                    {
                                        lvItem.SubItems[LocaleCol].ForeColor = Color.Blue;

                                        lvItem.SubItems[LocaleCol].Text = HrefLangUrl;

                                        lvItem.SubItems[LocaleCol + 1].Text = HrefLangDateServer.ToString();
                                        lvItem.SubItems[LocaleCol + 2].Text = HrefLangDateModified.ToString();
                                    }
                                    else
                                    {
                                        lvItem.SubItems[LocaleCol].ForeColor = Color.Red;

                                        lvItem.SubItems[LocaleCol].Text     = "NOT SPECIFIED";
                                        lvItem.SubItems[LocaleCol + 1].Text = "NOT SPECIFIED";
                                        lvItem.SubItems[LocaleCol + 2].Text = "NOT SPECIFIED";
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            DebugMsg(string.Format("MacroscopeDisplayHrefLang: {0}", ex.Message));
                            DebugMsg(string.Format("MacroscopeDisplayHrefLang: {0}", ex.StackTrace));
                        }
                    }
                    else
                    {
                        DebugMsg(string.Format("MacroscopeDisplayHrefLang NOT SPECIFIED: {0}", PairKey));
                    }
                }

                if (MacroscopePreferencesManager.GetShowProgressDialogues())
                {
                    Count++;

                    MajorPercentage = (( decimal )100 / TotalDocs) * Count;

                    ProgressForm.UpdatePercentages(
                        Title: null,
                        Message: null,
                        MajorPercentage: MajorPercentage,
                        ProgressLabelMajor: string.Format("Document {0} / {1}", Count, TotalDocs)
                        );
                }
            }

            this.DisplayListView.Items.AddRange(ListViewItems.ToArray());

            this.DisplayListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);

            this.DisplayListView.Columns[ColUrl].Width        = 300;
            this.DisplayListView.Columns[ColStatusCode].Width = 80;
            this.DisplayListView.Columns[ColSiteLocale].Width = 100;
            this.DisplayListView.Columns[ColTitle].Width      = 100;

            if (MacroscopePreferencesManager.GetShowProgressDialogues())
            {
                ProgressForm.DoClose();
            }

            if (ProgressForm != null)
            {
                ProgressForm.Dispose();
            }
        }
示例#2
0
        /**************************************************************************/

        private void BuildWorksheetHrefLangMatrix(
            MacroscopeJobMaster JobMaster,
            XLWorkbook wb,
            string WorksheetLabel
            )
        {
            var ws = wb.Worksheets.Add(WorksheetLabel);

            int iRow    = 1;
            int iCol    = 1;
            int iColMax = 1;

            Dictionary <string, string>  LocalesTable  = JobMaster.GetLocales();
            MacroscopeDocumentCollection DocCollection = JobMaster.GetDocCollection();
            Dictionary <string, int>     LocaleCols    = new Dictionary <string, int> ();

            {
                ws.Cell(iRow, iCol).Value = "URL";
                iCol++;

                ws.Cell(iRow, iCol).Value = "Status Code";
                iCol++;

                ws.Cell(iRow, iCol).Value = "Site Locale";
                iCol++;

                ws.Cell(iRow, iCol).Value = "Title";
                iCol++;

                foreach (string LocaleKey in LocalesTable.Keys)
                {
                    DebugMsg(string.Format("EXCEL Locale: {0}", LocaleKey));

                    string LocaleLabel       = LocaleKey.ToUpper();
                    string DateServerLabel   = string.Format("{0} Date Server", LocaleKey.ToUpper());
                    string DateModifiedLabel = string.Format("{0} Date Modified", LocaleKey.ToUpper());

                    LocaleCols[LocaleKey] = iCol;

                    ws.Cell(iRow, iCol).Value = LocaleLabel;
                    iCol++;

                    ws.Cell(iRow, iCol).Value = DateServerLabel;
                    iCol++;

                    ws.Cell(iRow, iCol).Value = DateModifiedLabel;
                    iCol++;
                }

                for (int i = 1; i <= iCol; i++)
                {
                    ws.Cell(iRow, i).Style.Font.SetBold();
                }
            }

            iColMax = iCol;

            iRow++;

            foreach (MacroscopeDocument msDoc in DocCollection.IterateDocuments())
            {
                Dictionary <string, MacroscopeHrefLang> HrefLangsTable = msDoc.GetHrefLangs();

                string SiteLocale = this.FormatIfMissing(msDoc.GetLocale());
                string Title      = this.FormatIfMissing(msDoc.GetTitle());
                string LocaleCol  = msDoc.GetLocale();

                iCol = 1;

                this.InsertAndFormatUrlCell(ws, iRow, iCol, msDoc);
                iCol++;

                this.InsertAndFormatStatusCodeCell(ws, iRow, iCol, msDoc);
                iCol++;

                ws.Cell(iRow, iCol).Value = SiteLocale;
                if (SiteLocale == "MISSING")
                {
                    ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                }
                iCol++;

                ws.Cell(iRow, iCol).Value = Title;
                if (Title == "MISSING")
                {
                    ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                }
                iCol++;

                if (LocaleCol != null)
                {
                    this.InsertAndFormatUrlCell(ws, iRow, LocaleCols[LocaleCol], msDoc.GetUrl());
                }
                else
                {
                    ;
                }

                foreach (string LocaleKey in LocalesTable.Keys)
                {
                    if (!string.IsNullOrEmpty(LocaleKey))
                    {
                        if (HrefLangsTable.ContainsKey(LocaleKey))
                        {
                            MacroscopeHrefLang HrefLangAlternate = HrefLangsTable[LocaleKey];

                            string   HrefLangUrl          = HrefLangAlternate.GetUrl();
                            DateTime HrefLangDateServer   = HrefLangAlternate.GetDateServer();
                            DateTime HrefLangDateModified = HrefLangAlternate.GetDateModified();

                            this.InsertAndFormatUrlCell(ws, iRow, LocaleCols[LocaleKey], HrefLangUrl);

                            if (JobMaster.GetAllowedHosts().IsInternalUrl(HrefLangUrl))
                            {
                                ws.Cell(iRow, LocaleCols[LocaleKey]).Style.Font.SetFontColor(XLColor.Green);
                            }
                            else
                            {
                                ws.Cell(iRow, LocaleCols[LocaleKey]).Style.Font.SetFontColor(XLColor.Blue);
                            }

                            this.InsertAndFormatDateCell(ws, iRow, LocaleCols[LocaleKey] + 1, HrefLangDateServer.ToString());

                            this.InsertAndFormatDateCell(ws, iRow, LocaleCols[LocaleKey] + 2, HrefLangDateModified.ToString());
                        }
                        else
                        {
                            ws.Cell(iRow, LocaleCols[LocaleKey]).Style.Font.SetFontColor(XLColor.Red);
                            ws.Cell(iRow, LocaleCols[LocaleKey]).Value     = "NOT SPECIFIED";
                            ws.Cell(iRow, LocaleCols[LocaleKey] + 1).Value = "";
                            ws.Cell(iRow, LocaleCols[LocaleKey] + 2).Value = "";
                        }
                    }
                }

                iRow++;
            }

            {
                var rangeData  = ws.Range(1, 1, iRow - 1, iColMax - 1);
                var excelTable = rangeData.CreateTable();
            }
        }