Exemplo n.º 1
0
        /**************************************************************************/

        private void BuildWorksheetCustomFilter(
            MacroscopeJobMaster JobMaster,
            CsvWriter ws
            )
        {
            MacroscopeDocumentCollection DocCollection = JobMaster.GetDocCollection();
            MacroscopeAllowedHosts       AllowedHosts  = JobMaster.GetAllowedHosts();

            Dictionary <string, int> FilterColsTable = new Dictionary <string, int> (CustomFilter.GetSize());

            const int FilterColOffset = 3;

            {
                ws.WriteField(MacroscopeConstants.Url);
                ws.WriteField(MacroscopeConstants.StatusCode);
                ws.WriteField(MacroscopeConstants.Status);
                ws.WriteField(MacroscopeConstants.ContentType);

                for (int Slot = 0; Slot < CustomFilter.GetSize(); Slot++)
                {
                    string FilterPattern = CustomFilter.GetPattern(Slot).Key;

                    if (FilterColsTable.ContainsKey(FilterPattern) || string.IsNullOrEmpty(FilterPattern))
                    {
                        FilterColsTable.Add(string.Format("EMPTY{0}", Slot + 1), Slot + FilterColOffset);

                        ws.WriteField(string.Format("EMPTY{0}", Slot + 1));
                    }
                    else
                    {
                        FilterColsTable.Add(FilterPattern, Slot + FilterColOffset);

                        ws.WriteField(FilterPattern);
                    }
                }

                ws.NextRecord();
            }

            foreach (MacroscopeDocument msDoc in DocCollection.IterateDocuments())
            {
                string DocUrl     = msDoc.GetUrl();
                string StatusCode = (( int )msDoc.GetStatusCode()).ToString();
                string Status     = msDoc.GetStatusCode().ToString();
                string MimeType   = msDoc.GetMimeType();

                if (!this.CustomFilter.CanApplyCustomFiltersToDocument(msDoc: msDoc))
                {
                    continue;
                }

                this.InsertAndFormatUrlCell(ws, msDoc);

                this.InsertAndFormatStatusCodeCell(ws, msDoc);

                this.InsertAndFormatContentCell(ws, this.FormatIfMissing(msDoc.GetStatusCode().ToString()));

                this.InsertAndFormatContentCell(ws, this.FormatIfMissing(MimeType));

                for (int Slot = 0; Slot < this.CustomFilter.GetSize(); Slot++)
                {
                    string FilterPattern = this.CustomFilter.GetPattern(Slot: Slot).Key;
                    KeyValuePair <string,  MacroscopeConstants.TextPresence> Pair = msDoc.GetCustomFilteredItem(Text: FilterPattern);

                    if ((Pair.Key != null) && (Pair.Value != MacroscopeConstants.TextPresence.UNDEFINED))
                    {
                        string CustomFilterItemValue = MacroscopeConstants.TextPresenceLabels[Pair.Value];

                        this.InsertAndFormatContentCell(ws, CustomFilterItemValue);
                    }
                    else
                    {
                        this.InsertAndFormatContentCell(ws, "");
                    }

                    ws.NextRecord();
                }
            }
        }
        /**************************************************************************/

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

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

            MacroscopeDocumentCollection DocCollection = JobMaster.GetDocCollection();
            MacroscopeAllowedHosts       AllowedHosts  = JobMaster.GetAllowedHosts();

            Dictionary <string, int> FilterColsTable = new Dictionary <string, int>(CustomFilter.GetSize());

            const int FilterColOffset = 4;

            {
                ws.Cell(iRow, iCol).Value = MacroscopeConstants.Url;
                iCol++;

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

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

                ws.Cell(iRow, iCol).Value = MacroscopeConstants.ContentType;

                for (int Slot = 0; Slot < CustomFilter.GetSize(); Slot++)
                {
                    string FilterPattern = CustomFilter.GetPattern(Slot).Key;

                    iCol++;

                    if (FilterColsTable.ContainsKey(FilterPattern) || string.IsNullOrEmpty(FilterPattern))
                    {
                        FilterColsTable.Add(string.Format("EMPTY{0}", Slot + 1), Slot + FilterColOffset);
                        ws.Cell(iRow, iCol).Value = string.Format("EMPTY{0}", Slot + 1);
                    }
                    else
                    {
                        FilterColsTable.Add(FilterPattern, Slot + FilterColOffset);
                        ws.Cell(iRow, iCol).Value = FilterPattern;
                    }
                }
            }

            iColMax = iCol;

            iRow++;

            foreach (MacroscopeDocument msDoc in DocCollection.IterateDocuments())
            {
                string DocUrl     = msDoc.GetUrl();
                string StatusCode = ((int)msDoc.GetStatusCode()).ToString();
                string Status     = msDoc.GetStatusCode().ToString();
                string MimeType   = msDoc.GetMimeType();

                if (!CustomFilter.CanApplyCustomFiltersToDocument(msDoc: msDoc))
                {
                    continue;
                }

                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.InsertAndFormatStatusCodeCell(ws, iRow, iCol, msDoc);

                iCol++;

                this.InsertAndFormatContentCell(ws, iRow, iCol, this.FormatIfMissing(msDoc.GetStatusCode().ToString()));

                iCol++;

                this.InsertAndFormatContentCell(ws, iRow, iCol, this.FormatIfMissing(MimeType));

                iCol++;

                for (int Slot = 0; Slot < this.CustomFilter.GetSize(); Slot++)
                {
                    string FilterPattern = this.CustomFilter.GetPattern(Slot: Slot).Key;
                    KeyValuePair <string, MacroscopeConstants.TextPresence> Pair = msDoc.GetCustomFilteredItem(Text: FilterPattern);

                    if ((Pair.Key != null) && (Pair.Value != MacroscopeConstants.TextPresence.UNDEFINED))
                    {
                        string CustomFilterItemValue = MacroscopeConstants.TextPresenceLabels[Pair.Value];

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

                        switch (Pair.Value)
                        {
                        case MacroscopeConstants.TextPresence.CONTAINS_STRING:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green);
                            break;

                        case MacroscopeConstants.TextPresence.NOT_CONTAINS_STRING:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green);
                            break;

                        case MacroscopeConstants.TextPresence.MUST_CONTAIN_STRING:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        case MacroscopeConstants.TextPresence.SHOULD_NOT_CONTAIN_STRING:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        case MacroscopeConstants.TextPresence.CONTAINS_REGEX:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green);
                            break;

                        case MacroscopeConstants.TextPresence.NOT_CONTAINS_REGEX:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Green);
                            break;

                        case MacroscopeConstants.TextPresence.MUST_CONTAIN_REGEX:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        case MacroscopeConstants.TextPresence.SHOULD_NOT_CONTAIN_REGEX:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Red);
                            break;

                        default:
                            ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Gray);
                            break;
                        }
                    }
                    else
                    {
                        this.InsertAndFormatContentCell(ws, iRow, iCol, "");
                        ws.Cell(iRow, iCol).Style.Font.SetFontColor(XLColor.Gray);
                    }

                    iCol++;
                }

                iRow++;
            }

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