Example #1
0
 /// <summary>
 /// Create a command for the specified feature and additional arguments, If no argument is specified its default value will be an empty string.
 /// </summary>
 /// <param name="feature">Feature to use</param>
 /// <param name="arguments">Arguments to use</param>
 /// <param name="options">Command options to use</param>
 /// <returns>
 /// A reference to a new <see cref="FeatureCommand"/> associated with the specified feature.
 /// </returns>
 public static FeatureCommand Create(string feature, string arguments = null, CommandOptions options = null) =>
 new FeatureCommand
 {
     Arguments = arguments,
     Program   = OsProgram.Dism.GetDescription(),
     Options   = options ?? CommandOptions.SilentModeActivated,
     Feature   = (IISFeature)EnumHelper.CreateEnumTypeFromDescriptionAttribute <IISFeature>(feature)
 };
Example #2
0
        // Generates document
        public static void Generate(ILogger logger)
        {
            #region Retrieve report data

            //Informe reportData = BuildAverageByDaysReportData("EN");
            Informe reportData = BuildAverageByDaysReportData("ES");

            //Informe reportData = BuildSumByDaysReportData("EN");
            //Informe reportData = BuildSumByDaysReportData("ES");

            //Informe reportData = BuildAverageByMonthsReportData("EN");
            //Informe reportData = BuildAverageByMonthsReportData("ES");

            //Informe reportData = BuildSumByMonthsReportData("EN");
            //Informe reportData = BuildSumByMonthsReportData("ES");

            #endregion

            #region Add dynamic xlsx styles

            CellStylesTable.Add(
                "ShortDateValue",
                new XlsxCellStyle
            {
                Font =
                {
                    Bold = YesNo.Yes,
                },
                Borders =
                {
                    new XlsxStyleBorder
                    {
                        Show     = YesNo.Yes,
                        Position = KnownBorderPosition.Right
                    }
                },
                Content =
                {
                    DataType       = new DateTimeDataType
                    {
                        Locale     = (KnownCulture)EnumHelper.CreateEnumTypeFromDescriptionAttribute <KnownCulture>(reportData.ConfiguracionInforme.IdiomaInforme)
                    },
                    Alignment      =
                    {
                        Horizontal = KnownHorizontalAlignment.Right
                    }
                }
            });

            // Add dynamic xlsx styles
            CellStylesTable.Add(
                "MonthYearDateValue",
                new XlsxCellStyle
            {
                Font =
                {
                    Bold = YesNo.Yes,
                },
                Borders =
                {
                    new XlsxStyleBorder
                    {
                        Show     = YesNo.Yes,
                        Position = KnownBorderPosition.Right
                    }
                },
                Content =
                {
                    DataType       = new DateTimeDataType
                    {
                        Format = KnownDateTimeFormat.YearMonthShortPattern,
                        Locale = (KnownCulture)EnumHelper.CreateEnumTypeFromDescriptionAttribute <KnownCulture>(reportData.ConfiguracionInforme.IdiomaInforme),
                    },
                    Alignment      =
                    {
                        Horizontal = KnownHorizontalAlignment.Right
                    }
                }
            });

            CellStylesTable.Add(
                "SummaryDateValue",
                new XlsxCellStyle
            {
                Content =
                {
                    DataType       = new DateTimeDataType
                    {
                        Locale     = (KnownCulture)EnumHelper.CreateEnumTypeFromDescriptionAttribute <KnownCulture>(reportData.ConfiguracionInforme.IdiomaInforme)
                    },
                    Alignment      =
                    {
                        Horizontal = KnownHorizontalAlignment.Left
                    }
                }
            });

            #endregion

            #region Defines custom styles to use

            XlsxCellStyle dateAxisStyle =
                reportData.ConfiguracionInforme.ValoresPor.Equals("DIA", StringComparison.OrdinalIgnoreCase)
                    ? CellStylesTable["ShortDateValue"]
                    : CellStylesTable["MonthYearDateValue"];

            #endregion

            #region Defines localized literals

            bool isSpanishLanguage = reportData.ConfiguracionInforme.IdiomaInforme.Equals("ES", StringComparison.OrdinalIgnoreCase);

            #region Summary Sheet

            string summarySheetName = "Hoja1";
            if (!isSpanishLanguage)
            {
                summarySheetName = "Sheet1";
            }

            string summaryParameterLiteral = "ParĂ¡metro";
            if (!isSpanishLanguage)
            {
                summaryParameterLiteral = "Parameter";
            }

            string summaryTypeLiteral = "Tipo";
            if (!isSpanishLanguage)
            {
                summaryTypeLiteral = "Type";
            }

            string summaryValuesByLiteral = "Valores Por";
            if (!isSpanishLanguage)
            {
                summaryValuesByLiteral = "Values By";
            }

            string summaryInitialDateLiteral = "Fecha Inicio";
            if (!isSpanishLanguage)
            {
                summaryInitialDateLiteral = "Initial Date";
            }

            string summaryEndDateLiteral = "Fecha Fin";
            if (!isSpanishLanguage)
            {
                summaryEndDateLiteral = "End Date";
            }

            #endregion

            #region Rawdata Sheet

            string rawDataSheetName = "Hoja2";
            if (!isSpanishLanguage)
            {
                rawDataSheetName = "Sheet2";
            }

            string averageLiteral = "Media";
            if (!isSpanishLanguage)
            {
                averageLiteral = "Average";
            }

            string sumLiteral = "Suma";
            if (!isSpanishLanguage)
            {
                sumLiteral = "Sum";
            }

            #endregion

            #endregion

            #region Report type to generate

            bool generateSumReport = reportData.ConfiguracionInforme.Tipo.Equals("SUMA", StringComparison.OrdinalIgnoreCase);

            #endregion

            #region Determines locals to include in report

            IEnumerable <Local> localsToPrint = generateSumReport
                ? reportData.Locales.Where(local => local.Nombre.Equals("Suma", StringComparison.OrdinalIgnoreCase))
                : reportData.Locales;

            #endregion

            #region Creates xlsx file reference

            XlsxInput doc = XlsxInput.Create(new[] { summarySheetName, rawDataSheetName });

            #endregion

            #region Sheet 1

            #region Sheet 1 > Populates configuration data

            doc.Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["ReportTitle"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 1
                },
                Data = reportData.ConfiguracionInforme.TituloInforme
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryLabel"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 3
                },
                Data = summaryParameterLiteral
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryValue"],
                Location  = new XlsxPointRange {
                    Column = 3, Row = 3
                },
                Data = reportData.ConfiguracionInforme.Parametro
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryLabel"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 4
                },
                Data = summaryTypeLiteral
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryValue"],
                Location  = new XlsxPointRange {
                    Column = 3, Row = 4
                },
                Data = reportData.ConfiguracionInforme.Tipo
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryLabel"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 5
                },
                Data = summaryValuesByLiteral
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryValue"],
                Location  = new XlsxPointRange {
                    Column = 3, Row = 5
                },
                Data = reportData.ConfiguracionInforme.ValoresPor
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryLabel"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 6
                },
                Data = summaryInitialDateLiteral
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryDateValue"],
                Location  = new XlsxPointRange {
                    Column = 3, Row = 6
                },
                Data = reportData.ConfiguracionInforme.FechaInicioPeriodo
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryLabel"],
                Location  = new XlsxPointRange {
                    Column = 2, Row = 7
                },
                Data = summaryEndDateLiteral
            }).Insert(new InsertText
            {
                SheetName = summarySheetName,
                Style     = CellStylesTable["SummaryDateValue"],
                Location  = new XlsxPointRange {
                    Column = 3, Row = 7
                },
                Data = reportData.ConfiguracionInforme.FechaFinPeriodo
            });

            #endregion

            #endregion

            #region Sheet 2

            #region Sheet 2 > Populates data table

            var localId        = -1;
            var headerLocation = new XlsxPointRange {
                Column = 3, Row = 2
            };
            var dateAxisLocation = new XlsxPointRange {
                Column = 2, Row = 3
            };
            var parameterValueLocation = new XlsxPointRange {
                Column = 3, Row = 3
            };
            var localHeaderStyle = CellStylesTable["LocalHeader"];
            foreach (var local in localsToPrint)
            {
                // Defines local header text
                string localName = local.Nombre;
                if (localName.Equals("Suma", StringComparison.OrdinalIgnoreCase))
                {
                    localName = sumLiteral;
                }
                else if (localName.Equals("Media", StringComparison.OrdinalIgnoreCase))
                {
                    localName = averageLiteral;
                }

                // Defines local style
                localHeaderStyle.Name          = $"LocalHeader{localId}";
                localHeaderStyle.Content.Color = local.Color;

                doc.Insert(new InsertText
                {
                    SheetName = rawDataSheetName,
                    Data      = localName,
                    Location  = headerLocation,
                    Style     = localHeaderStyle
                });

                headerLocation.Offset(1, 0);

                localId++;
                var series = local.Series;
                foreach (var serie in series)
                {
                    if (localId == 0)
                    {
                        doc.Insert(new InsertText
                        {
                            SheetName = rawDataSheetName,
                            Data      = serie.Fecha,
                            Location  = dateAxisLocation,
                            Style     = dateAxisStyle
                        });
                    }

                    doc.Insert(new InsertText
                    {
                        SheetName = rawDataSheetName,
                        Data      = serie.Valor,
                        Location  = parameterValueLocation,
                        Style     = CellStylesTable["ParameterValue"]
                    });

                    dateAxisLocation.Offset(0, 1);
                    parameterValueLocation.Offset(0, 1);
                }

                parameterValueLocation = new XlsxPointRange {
                    Column = parameterValueLocation.Column + 1, Row = 3
                };
            }

            #endregion

            #region Sheet 2 > Insert autofilter

            doc.Insert(new InsertAutoFilter
            {
                SheetName = rawDataSheetName,
                Location  = new XlsxStringRange {
                    Address = "C2:E2"
                }
            });

            #endregion

            #region Sheet 2 > Insert Mini-Charts

            doc.Insert(new InsertMiniChart
            {
                SheetName = rawDataSheetName,
                Location  = new XlsxPointRange {
                    Column = 3, Row = 33
                },                                                     // B3:B33
                MiniChart = new XlsxMiniChart
                {
                    Name         = "MiniChart1",
                    EmptyValueAs = MiniChartEmptyValuesAs.Gap,
                    ChartAxes    =
                    {
                        Horizontal = { Type = MiniChartHorizontalAxisType.Date }
                    },
                    ChartSize =
                    {
                        VerticalCells   = 3,
                        HorizontalCells = 3
                    },
                    ChartRanges =
                    {
                        Axis        = new XlsxRange       {
                            Start   =                     { Column= 2, Row = 3 }, End = { Column = 2, Row = 32 }
                        },                                                                                   //B3:B32
                        Data        = new XlsxStringRange {
                            Address = "C3:C32"
                        }
                    },
                    ChartType =
                    {
                        Active = MiniChartType.Line,
                        Column =
                        {
                            Serie  = { Color = "#FF5733" },
                            Points =
                            {
                                First    = { Color = "Yellow"  },
                                Last     = { Color = "Black"   },
                                High     = { Color = "Blue"    },
                                Low      = { Color = "Green"   },
                                Negative = { Color = "Red"     }
                            }
                        },
                        Line             =
                        {
                            Serie  = { Color = "#FF5733" },
                            Points =
                            {
                                First    = { Color = "Yellow"  },
                                Last     = { Color = "Black"   },
                                High     = { Color = "Blue"    },
                                Low      = { Color = "Green"   },
                                Negative = { Color = "Red"     }
                            }
                        },
                        WinLoss          =
                        {
                            Serie  = { Color = "#FF5733" },
                            Points =
                            {
                                First    = { Color = "Yellow"  },
                                Last     = { Color = "Black"   },
                                High     = { Color = "Blue"    },
                                Low      = { Color = "Green"   },
                                Negative = { Color = "Red"     }
                            }
                        }
                    }
                }
            });

            #endregion

            #endregion

            #region Create output result

            var result = doc.CreateResult(new OutputResultConfig {
                AutoFitColumns = true
            });
            if (!result.Success)
            {
                logger.Info("   > Error creating output result");
                logger.Info($"     > Error: {result.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            #endregion

            #region Saves output result

            var saveResult = result.Result.Action(new SaveToFile {
                OutputPath = "~/Output/Sample05/Sample-05"
            });
            if (!saveResult.Success)
            {
                logger.Info("   > Error while saving to disk");
                logger.Info($"     > Error: {saveResult.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            logger.Info("   > Saved to disk correctly");
            logger.Info("     > Path: ~/Output/Sample05/Sample-05.xlsx");

            #endregion
        }