Esempio n. 1
0
        /**************************************************************************/

        private void BuildWorksheetKeywordsPresence(
            MacroscopeJobMaster JobMaster,
            XLWorkbook wb,
            string WorksheetLabel,
            MacroscopeDocumentCollection DocCollection
            )
        {
            var     ws       = wb.Worksheets.Add(WorksheetLabel);
            int     iRow     = 1;
            int     iCol     = 1;
            int     iColMax  = 1;
            decimal DocCount = 0;
            decimal DocTotal = (decimal)DocCollection.CountDocuments();

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

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

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

            iColMax = iCol;

            iRow++;

            foreach (MacroscopeDocument msDoc in DocCollection.IterateDocuments())
            {
                List <KeyValuePair <string, MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS> > KeywordPresence;

                KeywordPresence = DocCollection.GetIntenseKeywordAnalysis(msDoc: msDoc);

                if (DocCount > 0)
                {
                    this.ProgressForm.UpdatePercentages(
                        Title: null,
                        Message: null,
                        MajorPercentage: -1,
                        ProgressLabelMajor: null,
                        MinorPercentage: ((decimal)100 / DocTotal) * (decimal)DocCount,
                        ProgressLabelMinor: "Documents Processed"
                        );
                }

                if (KeywordPresence != null)
                {
                    foreach (KeyValuePair <string, MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS> Pair in KeywordPresence)
                    {
                        MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS Present = Pair.Value;
                        string Keyword = Pair.Key;

                        iCol = 1;

                        this.InsertAndFormatContentCell(ws, iRow, iCol, Pair.Value.ToString());

                        switch (Pair.Value)
                        {
                        case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.KEYWORDS_METATAG_EMPTY:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.MISSING_IN_BODY_TEXT:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.PRESENT_IN_BODY_TEXT:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green);
                            break;

                        default:
                            break;
                        }

                        iCol++;

                        this.InsertAndFormatContentCell(ws, iRow, iCol, Keyword);

                        iCol++;

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

                        iRow++;
                    }
                }

                DocCount++;
            }

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

        protected override void RenderListView(
            List <ListViewItem> ListViewItems,
            MacroscopeDocumentCollection DocCollection,
            MacroscopeDocument msDoc,
            string Url
            )
        {
            List <KeyValuePair <string, MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS> > KeywordPresence;
            bool Proceed = false;

            if (msDoc.GetIsExternal())
            {
                return;
            }

            if (msDoc.GetIsRedirect())
            {
                return;
            }

            switch (msDoc.GetDocumentType())
            {
            case MacroscopeConstants.DocumentType.HTML:
                Proceed = true;
                break;

            default:
                break;
            }

            if (Proceed)
            {
                ListViewItem lvItem = null;

                KeywordPresence = DocCollection.GetIntenseKeywordAnalysis(msDoc: msDoc);

                foreach (KeyValuePair <string, MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS> Pair in KeywordPresence)
                {
                    MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS Present = Pair.Value;
                    string Keyword = Pair.Key;
                    string PairKey = string.Join("", UrlToDigest(Url: Url).ToString(), Keyword);

                    if (this.DisplayListView.Items.ContainsKey(PairKey))
                    {
                        try
                        {
                            lvItem = this.DisplayListView.Items[PairKey];
                            lvItem.SubItems[0].Text = Url;
                            lvItem.SubItems[1].Text = Present.ToString();
                            lvItem.SubItems[2].Text = Keyword;
                        }
                        catch (Exception ex)
                        {
                            DebugMsg(string.Format("MacroscopeDisplayKeywordsPresence 1: {0}", ex.Message));
                        }
                    }
                    else
                    {
                        try
                        {
                            lvItem = new ListViewItem(PairKey);
                            lvItem.UseItemStyleForSubItems = false;
                            lvItem.Name = PairKey;

                            lvItem.SubItems[0].Text = Url;
                            lvItem.SubItems.Add(Present.ToString());
                            lvItem.SubItems.Add(Keyword);

                            ListViewItems.Add(lvItem);
                        }
                        catch (Exception ex)
                        {
                            DebugMsg(string.Format("MacroscopeDisplayKeywordsPresence 2: {0}", ex.Message));
                        }
                    }

                    if (lvItem != null)
                    {
                        lvItem.ForeColor = Color.Blue;

                        // URL -------------------------------------------------------------//

                        if (msDoc.GetIsInternal())
                        {
                            lvItem.SubItems[0].ForeColor = Color.Green;
                        }
                        else
                        {
                            lvItem.SubItems[0].ForeColor = Color.Gray;
                        }

                        // Check Missing Text ----------------------------------------------//

                        if (msDoc.GetIsInternal())
                        {
                            switch (Present)
                            {
                            case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.KEYWORDS_METATAG_EMPTY:
                                lvItem.SubItems[0].ForeColor = Color.Red;
                                lvItem.SubItems[1].ForeColor = Color.Red;
                                lvItem.SubItems[2].ForeColor = Color.Red;
                                break;

                            case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.MISSING_IN_BODY_TEXT:
                                lvItem.SubItems[0].ForeColor = Color.Red;
                                lvItem.SubItems[1].ForeColor = Color.Red;
                                lvItem.SubItems[2].ForeColor = Color.Red;
                                break;

                            case MacroscopeIntenseKeywordAnalysis.KEYWORD_STATUS.PRESENT_IN_BODY_TEXT:
                                lvItem.SubItems[0].ForeColor = Color.Green;
                                lvItem.SubItems[1].ForeColor = Color.Green;
                                lvItem.SubItems[2].ForeColor = Color.Green;
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            lvItem.SubItems[1].ForeColor = Color.Gray;
                            lvItem.SubItems[2].ForeColor = Color.Gray;
                        }
                    }
                }
            }
        }