From 231d8b8fbb320feeda46325bd4fd7d4ad910c375 Mon Sep 17 00:00:00 2001 From: Brian Lagunas <835562+brianlagunas@users.noreply.github.com> Date: Thu, 28 Mar 2024 19:41:29 -0600 Subject: [PATCH] working on adding a datasource factory --- e2e/Sandbox/Factories/CampaignsDashboard.cs | 1 + e2e/Sandbox/Factories/CustomDashboard.cs | 1 + e2e/Sandbox/Factories/HealthcareDashboard.cs | 1 + .../Factories/ManufacturingDashboard.cs | 673 +++++++++--------- e2e/Sandbox/Factories/MarketingDashboard.cs | 1 + .../Factories/RestDataSourceDashboards.cs | 1 + e2e/Sandbox/Factories/SalesDashboard.cs | 385 +++++----- e2e/Sandbox/MainWindow.xaml.cs | 102 ++- .../Data/Builders/DataSourceBuilder.cs | 61 ++ .../Data/Builders/Enums/DataSourceType.cs | 9 + .../Builders/Interfaces/IDataSourceBuilder.cs | 15 + .../Data/Builders/Interfaces/IRestBuilder.cs | 11 + .../Data/Builders/RemoteFileBuilder.cs | 68 ++ .../Data/Builders/RestBuilder.cs | 107 +++ .../Data/Builders/RestServiceBuilder.cs | 348 ++++----- .../Data/Builders/SqlServerBuilder.cs | 158 ++-- src/Reveal.Sdk.Dom/Data/DataSource.cs | 106 +-- src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs | 18 + .../Data/Enums/DataSourceProvider.cs | 242 +++---- src/Reveal.Sdk.Dom/Reveal.Sdk.Dom.csproj | 58 +- 20 files changed, 1379 insertions(+), 987 deletions(-) create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs create mode 100644 src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs create mode 100644 src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs diff --git a/e2e/Sandbox/Factories/CampaignsDashboard.cs b/e2e/Sandbox/Factories/CampaignsDashboard.cs index a71bac8d..d6ee0cd0 100644 --- a/e2e/Sandbox/Factories/CampaignsDashboard.cs +++ b/e2e/Sandbox/Factories/CampaignsDashboard.cs @@ -3,6 +3,7 @@ using Reveal.Sdk.Dom.Filters; using Reveal.Sdk.Dom.Visualizations; using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; namespace Sandbox.Factories { diff --git a/e2e/Sandbox/Factories/CustomDashboard.cs b/e2e/Sandbox/Factories/CustomDashboard.cs index 9781f1a2..c29d651a 100644 --- a/e2e/Sandbox/Factories/CustomDashboard.cs +++ b/e2e/Sandbox/Factories/CustomDashboard.cs @@ -2,6 +2,7 @@ using Reveal.Sdk.Dom.Data; using Reveal.Sdk.Dom.Visualizations; using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; namespace Sandbox.Factories { diff --git a/e2e/Sandbox/Factories/HealthcareDashboard.cs b/e2e/Sandbox/Factories/HealthcareDashboard.cs index 4d529d24..3ecd2f8a 100644 --- a/e2e/Sandbox/Factories/HealthcareDashboard.cs +++ b/e2e/Sandbox/Factories/HealthcareDashboard.cs @@ -3,6 +3,7 @@ using Reveal.Sdk.Dom.Filters; using Reveal.Sdk.Dom.Visualizations; using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; namespace Sandbox.Factories { diff --git a/e2e/Sandbox/Factories/ManufacturingDashboard.cs b/e2e/Sandbox/Factories/ManufacturingDashboard.cs index f4559d6b..5ffbc432 100644 --- a/e2e/Sandbox/Factories/ManufacturingDashboard.cs +++ b/e2e/Sandbox/Factories/ManufacturingDashboard.cs @@ -1,336 +1,337 @@ -using Reveal.Sdk.Dom; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Filters; -using Reveal.Sdk.Dom.Visualizations; -using Sandbox.Helpers; -using System.Linq; - -namespace Sandbox.Factories -{ - internal class ManufacturingDashboard - { - internal static RdashDocument CreateDashboard() - { - var excelDataSourceItem = DataSourceFactory.GetManufacturingDataSourceItem(); - - var document = new RdashDocument("Manufacturing") - { - Title = "Manufacturing", - Theme = Theme.RockyMountain, - Description = "I created this in code", - UseAutoLayout = false, - }; - - document.Visualizations.Add(CreateIndicatorVisualization("Productivity", "Overall Plant Productivity ", excelDataSourceItem, true)); - document.Visualizations.Add(CreateIndicatorVisualization("Units Lost", "Units Lost", excelDataSourceItem)); - document.Visualizations.Add(CreateLineChartVisualization(excelDataSourceItem)); - document.Visualizations.Add(CreateColumnChartVisualization(excelDataSourceItem)); - document.Visualizations.Add(CreateDoughnutChartVisualization(excelDataSourceItem)); - document.Visualizations.Add(CreateCircularGaugeVisualization(excelDataSourceItem)); - document.Visualizations.Add(CreateCircularGaugeVisualization2(excelDataSourceItem)); - document.Visualizations.Add(CreateColumnChartVisualization2(excelDataSourceItem)); - - return document; - } - - private static Visualization CreateIndicatorVisualization(string title, string field, DataSourceItem excelDataSourceItem, bool avg = false) - { - var visualization = new KpiTimeVisualization(excelDataSourceItem) - { - Title = title, - ColumnSpan = 10, - RowSpan = 22, - }; - - visualization.Date = new DimensionColumn() - { - DataField = new DateDataField("Date") - }; - - NumberDataField dataField = new NumberDataField(field); - if (avg) - { - dataField.AggregationType = AggregationType.Avg; - dataField.Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Percent, - DecimalDigits = 0, - ShowGroupingSeparator = true, - ApplyMkFormat = true - }; - } - - visualization.Values.Add(new MeasureColumn() - { - DataField = dataField - }); - - return visualization; - } - - private static Visualization CreateLineChartVisualization(DataSourceItem excelDataSourceItem) - { - var visualization = new LineChartVisualization(excelDataSourceItem) - { - Title = "Cost of Labor vs Revenue", - ColumnSpan = 40, - RowSpan = 22, - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; - field.DataFilter = new DateTimeFilter() - { - FilterType = FilterType.FilterByRule, - DateFiscalYearStartMonth = 0, - DisplayInLocalTimeZone = false, - RuleType = DateRuleType.LastYear - }; - - visualization.Labels.Add(new DimensionColumn() - { - DataField = new DateDataField("Date") - { - AggregationType = DateAggregationType.Month - } - }); - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Cost of Labor ") - { - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Currency, - DecimalDigits = 0, - ShowGroupingSeparator = true, - } - } - }); - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Revenue") - { - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Currency, - DecimalDigits = 0, - ShowGroupingSeparator = true, - } - } - }); - - return visualization; - } - - private static Visualization CreateColumnChartVisualization(DataSourceItem excelDataSourceItem) - { - var visualization = new ColumnChartVisualization(excelDataSourceItem) - { - Title = "Units Produced By Line", - ColumnSpan = 19, - RowSpan = 38 - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; - field.DataFilter = new DateTimeFilter() - { - FilterType = FilterType.FilterByRule, - DateFiscalYearStartMonth = 0, - DisplayInLocalTimeZone = false, - RuleType = DateRuleType.LastMonth - }; - - visualization.Labels.Add(new DimensionColumn() - { - DataField = new TextDataField("Line") - }); - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Units Produced") - { - Sorting = SortingType.Desc, - Formatting = new NumberFormatting() - { - DecimalDigits = 0, - ShowGroupingSeparator = true, - } - } - }); - - return visualization; - } - - private static Visualization CreateDoughnutChartVisualization(DataSourceItem excelDataSourceItem) - { - var visualization = new DoughnutChartVisualization(excelDataSourceItem) - { - Title = "Operators Available by Function", - ColumnSpan = 21, - RowSpan = 38, - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; - field.DataFilter = new DateTimeFilter() - { - FilterType = FilterType.FilterByRule, - DateFiscalYearStartMonth = 0, - DisplayInLocalTimeZone = false, - RuleType = DateRuleType.LastMonth - }; - - visualization.Labels.Add(new DimensionColumn() - { - DataField = new TextDataField("Operators by Function") - }); - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Operators Available ") - { - Sorting = SortingType.Asc, - Formatting = new NumberFormatting() - { - DecimalDigits = 0, - ShowGroupingSeparator = true - } - } - }); - - return visualization; - } - - private static Visualization CreateCircularGaugeVisualization(DataSourceItem excelDataSourceItem) - { - var visualization = new CircularGaugeVisualization(excelDataSourceItem) - { - Title = "Line 2 Efficiency", - ColumnSpan = 20, - RowSpan = 19 - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Line").First() as TextField; - field.DataFilter = new TextFilter() - { - FilterType = FilterType.SelectedValues, - SelectedValues = new System.Collections.Generic.List() - { - new FilterValue() { Name = "Line 5", Value = "Line 5"}, - new FilterValue() { Name = "Line 2", Value = "Line 2"} - } - }; - - visualization.Settings.Minimum = new Bound() { Value = 0.0, ValueType = BoundValueType.NumberValue }; - visualization.Settings.Maximum = new Bound() { Value = 1.0, ValueType = BoundValueType.NumberValue }; - visualization.Settings.UpperBand.Value = 100.0; - visualization.Settings.MiddleBand.Value = 0.0; - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Efficiency") - { - AggregationType = AggregationType.Avg, - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Percent, - DecimalDigits = 2, - ShowGroupingSeparator = false, - ApplyMkFormat = true, - } - } - }); - - visualization.Label = new DimensionColumn() - { - DataField = new TextDataField("Line") - }; - - return visualization; - } - - private static Visualization CreateCircularGaugeVisualization2(DataSourceItem excelDataSourceItem) - { - var visualization = new CircularGaugeVisualization(excelDataSourceItem) - { - Title = "Line 1 Efficiency", - ColumnSpan = 20, - RowSpan = 19 - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Line").First() as TextField; - field.DataFilter = new TextFilter() - { - FilterType = FilterType.SelectedValues, - SelectedValues = new System.Collections.Generic.List() - { - new FilterValue() { Name = "Line 1", Value = "Line 1"} - } - }; - - visualization.Settings.Minimum = new Bound() { Value = 0.0, ValueType = BoundValueType.NumberValue }; - visualization.Settings.Maximum = new Bound() { Value = 1.0, ValueType = BoundValueType.NumberValue }; - visualization.Settings.UpperBand.Value = 100.0; - visualization.Settings.MiddleBand.Value = 0.0; - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Efficiency") - { - AggregationType = AggregationType.Max, - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Percent, - DecimalDigits = 2, - ShowGroupingSeparator = false, - ApplyMkFormat = true, - } - } - }); - - visualization.Label = new DimensionColumn() - { - DataField = new TextDataField("Line") - }; - - return visualization; - } - - private static Visualization CreateColumnChartVisualization2(DataSourceItem excelDataSourceItem) - { - var visualization = new ColumnChartVisualization(excelDataSourceItem) - { - Title = "Orders In vs Orders Shipped", - ColumnSpan = 60, - RowSpan = 32 - }; - - var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; - field.DataFilter = new DateTimeFilter() - { - FilterType = FilterType.FilterByRule, - DateFiscalYearStartMonth = 0, - DisplayInLocalTimeZone = false, - RuleType = DateRuleType.LastYear - }; - - visualization.Labels.Add(new DimensionColumn() - { - DataField = new DateDataField("Date") - { - AggregationType = DateAggregationType.Month - } - }); - - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Orders In") - }); - visualization.Values.Add(new MeasureColumn() - { - DataField = new NumberDataField("Orders Shipped ") - }); - - return visualization; - } - } -} +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Filters; +using Reveal.Sdk.Dom.Visualizations; +using Sandbox.Helpers; +using System.Linq; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; + +namespace Sandbox.Factories +{ + internal class ManufacturingDashboard + { + internal static RdashDocument CreateDashboard() + { + var excelDataSourceItem = DataSourceFactory.GetManufacturingDataSourceItem(); + + var document = new RdashDocument("Manufacturing") + { + Title = "Manufacturing", + Theme = Theme.RockyMountain, + Description = "I created this in code", + UseAutoLayout = false, + }; + + document.Visualizations.Add(CreateIndicatorVisualization("Productivity", "Overall Plant Productivity ", excelDataSourceItem, true)); + document.Visualizations.Add(CreateIndicatorVisualization("Units Lost", "Units Lost", excelDataSourceItem)); + document.Visualizations.Add(CreateLineChartVisualization(excelDataSourceItem)); + document.Visualizations.Add(CreateColumnChartVisualization(excelDataSourceItem)); + document.Visualizations.Add(CreateDoughnutChartVisualization(excelDataSourceItem)); + document.Visualizations.Add(CreateCircularGaugeVisualization(excelDataSourceItem)); + document.Visualizations.Add(CreateCircularGaugeVisualization2(excelDataSourceItem)); + document.Visualizations.Add(CreateColumnChartVisualization2(excelDataSourceItem)); + + return document; + } + + private static Visualization CreateIndicatorVisualization(string title, string field, DataSourceItem excelDataSourceItem, bool avg = false) + { + var visualization = new KpiTimeVisualization(excelDataSourceItem) + { + Title = title, + ColumnSpan = 10, + RowSpan = 22, + }; + + visualization.Date = new DimensionColumn() + { + DataField = new DateDataField("Date") + }; + + NumberDataField dataField = new NumberDataField(field); + if (avg) + { + dataField.AggregationType = AggregationType.Avg; + dataField.Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Percent, + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = true + }; + } + + visualization.Values.Add(new MeasureColumn() + { + DataField = dataField + }); + + return visualization; + } + + private static Visualization CreateLineChartVisualization(DataSourceItem excelDataSourceItem) + { + var visualization = new LineChartVisualization(excelDataSourceItem) + { + Title = "Cost of Labor vs Revenue", + ColumnSpan = 40, + RowSpan = 22, + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; + field.DataFilter = new DateTimeFilter() + { + FilterType = FilterType.FilterByRule, + DateFiscalYearStartMonth = 0, + DisplayInLocalTimeZone = false, + RuleType = DateRuleType.LastYear + }; + + visualization.Labels.Add(new DimensionColumn() + { + DataField = new DateDataField("Date") + { + AggregationType = DateAggregationType.Month + } + }); + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Cost of Labor ") + { + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Currency, + DecimalDigits = 0, + ShowGroupingSeparator = true, + } + } + }); + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Revenue") + { + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Currency, + DecimalDigits = 0, + ShowGroupingSeparator = true, + } + } + }); + + return visualization; + } + + private static Visualization CreateColumnChartVisualization(DataSourceItem excelDataSourceItem) + { + var visualization = new ColumnChartVisualization(excelDataSourceItem) + { + Title = "Units Produced By Line", + ColumnSpan = 19, + RowSpan = 38 + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; + field.DataFilter = new DateTimeFilter() + { + FilterType = FilterType.FilterByRule, + DateFiscalYearStartMonth = 0, + DisplayInLocalTimeZone = false, + RuleType = DateRuleType.LastMonth + }; + + visualization.Labels.Add(new DimensionColumn() + { + DataField = new TextDataField("Line") + }); + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Units Produced") + { + Sorting = SortingType.Desc, + Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true, + } + } + }); + + return visualization; + } + + private static Visualization CreateDoughnutChartVisualization(DataSourceItem excelDataSourceItem) + { + var visualization = new DoughnutChartVisualization(excelDataSourceItem) + { + Title = "Operators Available by Function", + ColumnSpan = 21, + RowSpan = 38, + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; + field.DataFilter = new DateTimeFilter() + { + FilterType = FilterType.FilterByRule, + DateFiscalYearStartMonth = 0, + DisplayInLocalTimeZone = false, + RuleType = DateRuleType.LastMonth + }; + + visualization.Labels.Add(new DimensionColumn() + { + DataField = new TextDataField("Operators by Function") + }); + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Operators Available ") + { + Sorting = SortingType.Asc, + Formatting = new NumberFormatting() + { + DecimalDigits = 0, + ShowGroupingSeparator = true + } + } + }); + + return visualization; + } + + private static Visualization CreateCircularGaugeVisualization(DataSourceItem excelDataSourceItem) + { + var visualization = new CircularGaugeVisualization(excelDataSourceItem) + { + Title = "Line 2 Efficiency", + ColumnSpan = 20, + RowSpan = 19 + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Line").First() as TextField; + field.DataFilter = new TextFilter() + { + FilterType = FilterType.SelectedValues, + SelectedValues = new System.Collections.Generic.List() + { + new FilterValue() { Name = "Line 5", Value = "Line 5"}, + new FilterValue() { Name = "Line 2", Value = "Line 2"} + } + }; + + visualization.Settings.Minimum = new Bound() { Value = 0.0, ValueType = BoundValueType.NumberValue }; + visualization.Settings.Maximum = new Bound() { Value = 1.0, ValueType = BoundValueType.NumberValue }; + visualization.Settings.UpperBand.Value = 100.0; + visualization.Settings.MiddleBand.Value = 0.0; + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Efficiency") + { + AggregationType = AggregationType.Avg, + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Percent, + DecimalDigits = 2, + ShowGroupingSeparator = false, + ApplyMkFormat = true, + } + } + }); + + visualization.Label = new DimensionColumn() + { + DataField = new TextDataField("Line") + }; + + return visualization; + } + + private static Visualization CreateCircularGaugeVisualization2(DataSourceItem excelDataSourceItem) + { + var visualization = new CircularGaugeVisualization(excelDataSourceItem) + { + Title = "Line 1 Efficiency", + ColumnSpan = 20, + RowSpan = 19 + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Line").First() as TextField; + field.DataFilter = new TextFilter() + { + FilterType = FilterType.SelectedValues, + SelectedValues = new System.Collections.Generic.List() + { + new FilterValue() { Name = "Line 1", Value = "Line 1"} + } + }; + + visualization.Settings.Minimum = new Bound() { Value = 0.0, ValueType = BoundValueType.NumberValue }; + visualization.Settings.Maximum = new Bound() { Value = 1.0, ValueType = BoundValueType.NumberValue }; + visualization.Settings.UpperBand.Value = 100.0; + visualization.Settings.MiddleBand.Value = 0.0; + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Efficiency") + { + AggregationType = AggregationType.Max, + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Percent, + DecimalDigits = 2, + ShowGroupingSeparator = false, + ApplyMkFormat = true, + } + } + }); + + visualization.Label = new DimensionColumn() + { + DataField = new TextDataField("Line") + }; + + return visualization; + } + + private static Visualization CreateColumnChartVisualization2(DataSourceItem excelDataSourceItem) + { + var visualization = new ColumnChartVisualization(excelDataSourceItem) + { + Title = "Orders In vs Orders Shipped", + ColumnSpan = 60, + RowSpan = 32 + }; + + var field = visualization.DataDefinition.AsTabular().Fields.Where(x => x.FieldName == "Date").First() as DateField; + field.DataFilter = new DateTimeFilter() + { + FilterType = FilterType.FilterByRule, + DateFiscalYearStartMonth = 0, + DisplayInLocalTimeZone = false, + RuleType = DateRuleType.LastYear + }; + + visualization.Labels.Add(new DimensionColumn() + { + DataField = new DateDataField("Date") + { + AggregationType = DateAggregationType.Month + } + }); + + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Orders In") + }); + visualization.Values.Add(new MeasureColumn() + { + DataField = new NumberDataField("Orders Shipped ") + }); + + return visualization; + } + } +} diff --git a/e2e/Sandbox/Factories/MarketingDashboard.cs b/e2e/Sandbox/Factories/MarketingDashboard.cs index e8816c19..f16839e7 100644 --- a/e2e/Sandbox/Factories/MarketingDashboard.cs +++ b/e2e/Sandbox/Factories/MarketingDashboard.cs @@ -4,6 +4,7 @@ using Reveal.Sdk.Dom.Visualizations; using Reveal.Sdk.Dom.Visualizations.Settings; using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; namespace Sandbox.Factories { diff --git a/e2e/Sandbox/Factories/RestDataSourceDashboards.cs b/e2e/Sandbox/Factories/RestDataSourceDashboards.cs index 51107281..1db4d5f9 100644 --- a/e2e/Sandbox/Factories/RestDataSourceDashboards.cs +++ b/e2e/Sandbox/Factories/RestDataSourceDashboards.cs @@ -2,6 +2,7 @@ using Reveal.Sdk.Dom.Data; using Reveal.Sdk.Dom.Visualizations; using Sandbox.Helpers; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; namespace Sandbox.Factories { diff --git a/e2e/Sandbox/Factories/SalesDashboard.cs b/e2e/Sandbox/Factories/SalesDashboard.cs index 841f3f0d..bd7aec53 100644 --- a/e2e/Sandbox/Factories/SalesDashboard.cs +++ b/e2e/Sandbox/Factories/SalesDashboard.cs @@ -1,193 +1,194 @@ -using Reveal.Sdk.Dom; -using Reveal.Sdk.Dom.Data; -using Reveal.Sdk.Dom.Filters; -using Reveal.Sdk.Dom.Visualizations; -using Sandbox.Helpers; -using System.Linq; - -namespace Sandbox.Factories -{ - internal class SalesDashboard - { - internal static RdashDocument CreateDashboard() - { - var excelDataSourceItem = DataSourceFactory.GetSalesDataSourceItem(); - - var document = new RdashDocument() - { - Title = "Sales", - Description = "I created this in code", - UseAutoLayout = false, - }; - - document.Filters.Add(new DashboardDateFilter() - { - Title = "My Date Filter" - }); - - var territoryFilter = new DashboardDataFilter(excelDataSourceItem) - { - Title = "Territory", - SelectedFieldName = "Territory", - AllowMultipleSelection = true, - AllowEmptySelection = true - }; - document.Filters.Add(territoryFilter); - - var globalDateFilterBinding = new DashboardDateFilterBinding("Date"); - var territoryFilterBinding = new DashboardDataFilterBinding(territoryFilter); - - document.Visualizations.Add(CreateKpiTargetVisualization(excelDataSourceItem, territoryFilterBinding)); - document.Visualizations.Add(CreateSplineAreaChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - document.Visualizations.Add(CreateStackedColumnChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - document.Visualizations.Add(CreateIndicatorVisualization(excelDataSourceItem, territoryFilterBinding)); - document.Visualizations.Add(CreateSparklineVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - document.Visualizations.Add(CreateBarChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - document.Visualizations.Add(CreateColumnChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - document.Visualizations.Add(CreateGaugeVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); - - return document; - } - - private static Visualization CreateKpiTargetVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new KpiTargetVisualization("Sales", excelDataSourceItem) - .SetDate("Date") - .SetValue(new NumberDataField("Pipepline") - { - FieldLabel = "Actual Sales", - AggregationType = AggregationType.Sum, - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Currency, - DecimalDigits = 0, - ShowGroupingSeparator = true, - CurrencySymbol = "$", - NegativeFormat = NegativeFormatType.MinusSign, - ApplyMkFormat = true, - } - }) - .SetTarget("Forecasted") - .AddFilterBindings(filterBindings) - .SetPosition(20, 11); - } - - private static Visualization CreateSplineAreaChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new SplineAreaChartVisualization("New vs Renewal Sales", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("New Sales", "Renewal Sales ") - .AddFilterBindings(filterBindings) - .SetPosition(39, 31); - } - - private static Visualization CreateStackedColumnChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new StackedColumnChartVisualization("Sales by Product", excelDataSourceItem) - .SetLabel("Product") - .SetValues("New Sales", "Renewal Sales ") - .AddFilterBindings(filterBindings) - .SetPosition(39, 18); - } - - private static Visualization CreateIndicatorVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new KpiTimeVisualization("Total Opportunities", excelDataSourceItem) - .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Year }) - .SetValue("Total Opportunites") - .AddFilterBindings(filterBindings) - .SetPosition(19, 11); - } - - private static Visualization CreateSparklineVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new SparklineVisualization("New Seats by Product", excelDataSourceItem) - .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValue(new NumberDataField("New Seats") - { - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Number, - DecimalDigits = 0, - ShowGroupingSeparator = true, - CurrencySymbol = "$", - NegativeFormat = NegativeFormatType.MinusSign, - ApplyMkFormat = false, - } - }) - .SetCategory("Product") - .ConfigureSettings(settings => - { - settings.TextFieldAlignment = Alignment.Left; - settings.NumericFieldAlignment = Alignment.Left; - settings.DateFieldAlignment = Alignment.Left; - settings.AggregationType = SparklineAggregationType.Months; - }) - .AddFilterBindings(filterBindings) - .SetPosition(30, 31); - } - - private static Visualization CreateBarChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new BarChartVisualization("Sales", excelDataSourceItem) - .SetLabel("Employee") - .SetValue(new NumberDataField("Pipepline") - { - Sorting = SortingType.Asc, - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Currency, - DecimalDigits = 0, - ShowGroupingSeparator = true, - ApplyMkFormat = true, - } - }) - .AddFilterBindings(filterBindings) - .SetPosition(43, 29); - } - - private static Visualization CreateColumnChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - return new ColumnChartVisualization("", excelDataSourceItem) - .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) - .SetValues("Leads", "Hot Leads") - .AddFilterBindings(filterBindings) - .SetPosition(46, 31); - } - - private static Visualization CreateGaugeVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) - { - var visualization = new BulletGraphVisualization("Quotas by Sales Rep", excelDataSourceItem) - .SetLabel("Employee") - .SetValue(new NumberDataField("Quota") - { - Formatting = new NumberFormatting() - { - FormatType = NumberFormattingType.Percent, - DecimalDigits = 2, - ShowGroupingSeparator = false, - ApplyMkFormat = true, - } - }) - .ConfigureSettings(settings => - { - settings.Minimum = new Bound() { Value = 0.8 }; - settings.Maximum = new Bound() { Value = 2.0 }; - - settings.ValueComparisonType = ValueComparisonType.Number; - settings.UpperBand.Value = 100.0; - settings.MiddleBand.Value = 80.0; - }) - .AddDataFilter("Quota", new NumberFilter() - { - FilterType = FilterType.FilterByRule, - RuleType = NumberRuleType.TopItems, - Value = 10.0 - }) - .AddFilterBindings(filterBindings) - .SetPosition(33, 29); - - return visualization; - } - } +using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Filters; +using Reveal.Sdk.Dom.Visualizations; +using Sandbox.Helpers; +using System.Linq; +using DataSourceFactory = Sandbox.Helpers.DataSourceFactory; + +namespace Sandbox.Factories +{ + internal class SalesDashboard + { + internal static RdashDocument CreateDashboard() + { + var excelDataSourceItem = DataSourceFactory.GetSalesDataSourceItem(); + + var document = new RdashDocument() + { + Title = "Sales", + Description = "I created this in code", + UseAutoLayout = false, + }; + + document.Filters.Add(new DashboardDateFilter() + { + Title = "My Date Filter" + }); + + var territoryFilter = new DashboardDataFilter(excelDataSourceItem) + { + Title = "Territory", + SelectedFieldName = "Territory", + AllowMultipleSelection = true, + AllowEmptySelection = true + }; + document.Filters.Add(territoryFilter); + + var globalDateFilterBinding = new DashboardDateFilterBinding("Date"); + var territoryFilterBinding = new DashboardDataFilterBinding(territoryFilter); + + document.Visualizations.Add(CreateKpiTargetVisualization(excelDataSourceItem, territoryFilterBinding)); + document.Visualizations.Add(CreateSplineAreaChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + document.Visualizations.Add(CreateStackedColumnChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + document.Visualizations.Add(CreateIndicatorVisualization(excelDataSourceItem, territoryFilterBinding)); + document.Visualizations.Add(CreateSparklineVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + document.Visualizations.Add(CreateBarChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + document.Visualizations.Add(CreateColumnChartVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + document.Visualizations.Add(CreateGaugeVisualization(excelDataSourceItem, globalDateFilterBinding, territoryFilterBinding)); + + return document; + } + + private static Visualization CreateKpiTargetVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new KpiTargetVisualization("Sales", excelDataSourceItem) + .SetDate("Date") + .SetValue(new NumberDataField("Pipepline") + { + FieldLabel = "Actual Sales", + AggregationType = AggregationType.Sum, + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Currency, + DecimalDigits = 0, + ShowGroupingSeparator = true, + CurrencySymbol = "$", + NegativeFormat = NegativeFormatType.MinusSign, + ApplyMkFormat = true, + } + }) + .SetTarget("Forecasted") + .AddFilterBindings(filterBindings) + .SetPosition(20, 11); + } + + private static Visualization CreateSplineAreaChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new SplineAreaChartVisualization("New vs Renewal Sales", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("New Sales", "Renewal Sales ") + .AddFilterBindings(filterBindings) + .SetPosition(39, 31); + } + + private static Visualization CreateStackedColumnChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new StackedColumnChartVisualization("Sales by Product", excelDataSourceItem) + .SetLabel("Product") + .SetValues("New Sales", "Renewal Sales ") + .AddFilterBindings(filterBindings) + .SetPosition(39, 18); + } + + private static Visualization CreateIndicatorVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new KpiTimeVisualization("Total Opportunities", excelDataSourceItem) + .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Year }) + .SetValue("Total Opportunites") + .AddFilterBindings(filterBindings) + .SetPosition(19, 11); + } + + private static Visualization CreateSparklineVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new SparklineVisualization("New Seats by Product", excelDataSourceItem) + .SetDate(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValue(new NumberDataField("New Seats") + { + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Number, + DecimalDigits = 0, + ShowGroupingSeparator = true, + CurrencySymbol = "$", + NegativeFormat = NegativeFormatType.MinusSign, + ApplyMkFormat = false, + } + }) + .SetCategory("Product") + .ConfigureSettings(settings => + { + settings.TextFieldAlignment = Alignment.Left; + settings.NumericFieldAlignment = Alignment.Left; + settings.DateFieldAlignment = Alignment.Left; + settings.AggregationType = SparklineAggregationType.Months; + }) + .AddFilterBindings(filterBindings) + .SetPosition(30, 31); + } + + private static Visualization CreateBarChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new BarChartVisualization("Sales", excelDataSourceItem) + .SetLabel("Employee") + .SetValue(new NumberDataField("Pipepline") + { + Sorting = SortingType.Asc, + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Currency, + DecimalDigits = 0, + ShowGroupingSeparator = true, + ApplyMkFormat = true, + } + }) + .AddFilterBindings(filterBindings) + .SetPosition(43, 29); + } + + private static Visualization CreateColumnChartVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + return new ColumnChartVisualization("", excelDataSourceItem) + .SetLabel(new DateDataField("Date") { AggregationType = DateAggregationType.Month }) + .SetValues("Leads", "Hot Leads") + .AddFilterBindings(filterBindings) + .SetPosition(46, 31); + } + + private static Visualization CreateGaugeVisualization(DataSourceItem excelDataSourceItem, params Binding[] filterBindings) + { + var visualization = new BulletGraphVisualization("Quotas by Sales Rep", excelDataSourceItem) + .SetLabel("Employee") + .SetValue(new NumberDataField("Quota") + { + Formatting = new NumberFormatting() + { + FormatType = NumberFormattingType.Percent, + DecimalDigits = 2, + ShowGroupingSeparator = false, + ApplyMkFormat = true, + } + }) + .ConfigureSettings(settings => + { + settings.Minimum = new Bound() { Value = 0.8 }; + settings.Maximum = new Bound() { Value = 2.0 }; + + settings.ValueComparisonType = ValueComparisonType.Number; + settings.UpperBand.Value = 100.0; + settings.MiddleBand.Value = 80.0; + }) + .AddDataFilter("Quota", new NumberFilter() + { + FilterType = FilterType.FilterByRule, + RuleType = NumberRuleType.TopItems, + Value = 10.0 + }) + .AddFilterBindings(filterBindings) + .SetPosition(33, 29); + + return visualization; + } + } } \ No newline at end of file diff --git a/e2e/Sandbox/MainWindow.xaml.cs b/e2e/Sandbox/MainWindow.xaml.cs index 8880eb54..e439f3b6 100644 --- a/e2e/Sandbox/MainWindow.xaml.cs +++ b/e2e/Sandbox/MainWindow.xaml.cs @@ -1,11 +1,16 @@ -using Reveal.Sdk; +using Reveal.Sdk; using Reveal.Sdk.Data; using Reveal.Sdk.Dom; +using Reveal.Sdk.Dom.Data; +using Reveal.Sdk.Dom.Visualizations; using Sandbox.Factories; using Sandbox.Helpers; using System; +using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using System.Windows; +using System.Windows.Documents; namespace Sandbox { @@ -29,6 +34,7 @@ public MainWindow() //RevealSdkSettings.EnableNewCharts = true; RevealSdkSettings.AuthenticationProvider = new AuthenticationProvider(); RevealSdkSettings.DataSources.RegisterMicrosoftSqlServer().RegisterMicrosoftAnalysisServices(); + RevealSdkSettings.DataSourceProvider = new DataSourceProvider(); _revealView.LinkedDashboardProvider = (string dashboardId, string linkTitle) => { @@ -39,9 +45,36 @@ public MainWindow() return null; }; + _revealView.DataSourcesRequested += RevealView_DataSourcesRequested; + _revealView.DashboardSelectorRequested += RevealView_DashboardSelectorRequested; } + private void RevealView_DataSourcesRequested(object sender, DataSourcesRequestedEventArgs e) + { + var ds = new List(); + var dsi = new List(); + + var restDS = new RVRESTDataSource(); + restDS.Title = "Excel to JSON"; + restDS.UseAnonymousAuthentication = true; + restDS.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; + ds.Add(restDS); + + var sqlDS = new RVSqlServerDataSource(); + sqlDS.Title = "SQL Server"; + sqlDS.Host = "Brian-Desktop\\SQLEXPRESS"; + ds.Add(sqlDS); + + var webDS = new RVWebResourceDataSource(); + webDS.UseAnonymousAuthentication = true; + webDS.Title = "Web Resource"; + webDS.Url = "http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx"; + ds.Add(webDS); + + e.Callback(new RevealDataSources(ds, dsi, false)); + } + private void RevealView_DashboardSelectorRequested(object sender, DashboardSelectorRequestedEventArgs e) { e.Callback("Campaigns"); @@ -53,7 +86,7 @@ private async void RevealView_SaveDashboard(object sender, DashboardSaveEventArg var path = Path.Combine(Environment.CurrentDirectory, $"Dashboards/{e.Name}.rdash"); var data = await e.Serialize(); var json = _revealView.Dashboard.ExportToJson(); - using (var output = File.Open(path, FileMode.Open)) + using (var output = File.Open(path, FileMode.OpenOrCreate)) { output.Write(data, 0, data.Length); } @@ -85,16 +118,79 @@ private async void Create_Dashboard(object sender, RoutedEventArgs e) //var document = CampaignsDashboard.CreateDashboard(); //var document = HealthcareDashboard.CreateDashboard(); //var document = ManufacturingDashboard.CreateDashboard(); - var document = CustomDashboard.CreateDashboard(); + //var document = CustomDashboard.CreateDashboard(); //var document = RestDataSourceDashboards.CreateDashboard(); //var document = SqlServerDataSourceDashboards.CreateDashboard(); //var document = DashboardLinkingDashboard.CreateDashboard(); //document.Save(_saveRdashToPath); + //var dsi = new RestBuilder("Excel Data Source", "Marketing Sheet") + // .SetUrl("https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9") + // .SetFields( + // new TextField("CategoryName"), + // new TextField("ProductName"), + // new NumberField("ProductSales") + // ).Build(); + + //var dsi = Reveal.Sdk.Dom.Data.DataSourceFactory.Create(DataSourceType.REST, "Excel Data Source", "Marketing Sheet") + // .SetFields(new List + // { + // new TextField("CategoryName"), + // new TextField("ProductName"), + // new NumberField("ProductSales") + // }).Build(); + + var dsi = new RemoteFileBuilder("Excel Data Source", "Marketing Sheet") + .SetUrl("http://dl.infragistics.com/reportplus/reveal/samples/Samples.xlsx") + .UseExcel("Marketing") + .SetFields(new List + { + new DateField("Date"), + new NumberField("Spend"), + new NumberField("Budget"), + new NumberField("CTR"), + new NumberField("Avg. CPC"), + new NumberField("Traffic"), + new NumberField("Paid Traffic"), + new NumberField("Other Traffic"), + new NumberField("Conversions"), + new TextField("Territory"), + new TextField("CampaignID"), + new NumberField("New Seats"), + new NumberField("Paid %"), + new NumberField("Organic %") + }).Build(); + + + var document = new RdashDocument() + { + Title = "My Dashboard", + Description = "I created" + }; + + //var gridViz = new GridVisualization(dsi).SetColumns("CategoryName", "ProductName", "ProductSales"); + var gridViz = new GridVisualization(dsi).SetColumns("Spend", "Budget", "CTR"); + document.Visualizations.Add(gridViz); + var json = document.ToJsonString(); //json.Save(_saveJsonToPath); _revealView.Dashboard = await RVDashboard.LoadFromJsonAsync(json); } } + + public class DataSourceProvider : IRVDataSourceProvider + { + public Task ChangeDataSourceItemAsync(RVDataSourceItem dataSourceItem) + { + if (dataSourceItem is RVJsonDataSourceItem jsonDataSourceItem) + { + var restDataSourceItem = jsonDataSourceItem.ResourceItem as RVRESTDataSourceItem; + restDataSourceItem.Url = "https://excel2json.io/api/share/6e0f06b3-72d3-4fec-7984-08da43f56bb9"; + } + return Task.FromResult(dataSourceItem); + } + + + } } diff --git a/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs new file mode 100644 index 00000000..d480fd51 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/DataSourceBuilder.cs @@ -0,0 +1,61 @@ +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public class DataSourceBuilder : IDataSourceBuilder + { + protected DataSource DataSource { get; } = new DataSource(); + protected DataSourceItem DataSourceItem { get; } = new DataSourceItem(); + + public DataSourceBuilder(DataSourceProvider provider, string title, string subtitle) + { + DataSource.Provider = provider; + DataSourceItem.DataSource = DataSource; + DataSourceItem.DataSourceId = DataSource.Id; + SetTitle(title); + SetSubtitle(subtitle); + } + + public DataSourceItem Build() + { + if (DataSourceItem.Fields.Count == 0) + throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); + + return DataSourceItem; + } + + public IDataSourceBuilder SetId(string id) + { + DataSource.Id = id; + DataSourceItem.DataSourceId = id; + return this; + } + + public virtual IDataSourceBuilder SetFields(IEnumerable fields) + { + DataSourceItem.Fields.Clear(); + DataSourceItem.Fields.AddRange(fields); + return this; + } + + public virtual IDataSourceBuilder SetFields(params IField[] fields) + { + return SetFields((IEnumerable)fields); + } + + public IDataSourceBuilder SetSubtitle(string subtitle) + { + DataSourceItem.Subtitle = subtitle; + return this; + } + + public IDataSourceBuilder SetTitle(string title) + { + DataSourceItem.Title = title; + return this; + } + } + +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs b/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs new file mode 100644 index 00000000..cc9a067f --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Enums/DataSourceType.cs @@ -0,0 +1,9 @@ +namespace Reveal.Sdk.Dom.Data +{ + public enum DataSourceType + { + RemoteFile, + REST, + MicrosoftSqlServer + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs new file mode 100644 index 00000000..683e774c --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IDataSourceBuilder.cs @@ -0,0 +1,15 @@ +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public interface IDataSourceBuilder + { + IDataSourceBuilder SetFields(IEnumerable fields); + IDataSourceBuilder SetFields(params IField[] fields); + IDataSourceBuilder SetTitle(string title); + IDataSourceBuilder SetSubtitle(string subtitle); + DataSourceItem Build(); + } + +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs new file mode 100644 index 00000000..38e6d17f --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/Interfaces/IRestBuilder.cs @@ -0,0 +1,11 @@ +namespace Reveal.Sdk.Dom.Data +{ + public interface IRestBuilder : IDataSourceBuilder + { + IRestBuilder AddHeader(HeaderType headerType, string value); + IRestBuilder SetUrl(string url); + IRestBuilder SetMethod(string method); + IRestBuilder SetAnonymous(bool isAnonymous); + } + +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs new file mode 100644 index 00000000..bd61fbfa --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/RemoteFileBuilder.cs @@ -0,0 +1,68 @@ +using Reveal.Sdk.Dom.Core.Constants; + +namespace Reveal.Sdk.Dom.Data +{ + public class RemoteFileBuilder : DataSourceBuilder, IRemoteFileBuilder + { + readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.WebService }; //data source + readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the data source + + public RemoteFileBuilder(string title, string subtitle) : base(DataSourceProvider.WebService, title, subtitle) + { + DataSourceItem.ResourceItemDataSource = _resourceItemDataSource; + _resourceItem.DataSourceId = _resourceItemDataSource.Id; + DataSourceItem.ResourceItem = _resourceItem; + + SetAnonymous(true); + } + + public IRemoteFileBuilder SetAnonymous(bool isAnonymous) + { + _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; + return this; + } + + public IRemoteFileBuilder SetUrl(string url) + { + _resourceItemDataSource.Properties.Add("Url", url); + _resourceItem.Properties.Add("Url", url); + return this; + } + + public IRemoteFileBuilder UseCsv() + { + DataSource.Id = DataSourceIds.CSV; + DataSource.Provider = DataSourceProvider.CSV; + _resourceItemDataSource.Properties["Result-Type"] = ".csv"; + DataSourceItem.DataSourceId = DataSource.Id; + return this; + } + + public IRemoteFileBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) + { + DataSource.Id = DataSourceIds.Excel; + DataSource.Provider = DataSourceProvider.MicrosoftExcel; + + if (sheet != null) + { + DataSourceItem.Subtitle = sheet; + + if (DataSourceItem.Properties.ContainsKey("Sheet")) + DataSourceItem.Properties["Sheet"] = sheet; + else + DataSourceItem.Properties.Add("Sheet", sheet); + } + + DataSourceItem.DataSourceId = DataSource.Id; + + return this; + } + + } + + public interface IRemoteFileBuilder : IDataSourceBuilder + { + IRemoteFileBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx); + IRemoteFileBuilder UseCsv(); + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs new file mode 100644 index 00000000..cf0633d1 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/Builders/RestBuilder.cs @@ -0,0 +1,107 @@ +using Reveal.Sdk.Dom.Visualizations; +using System.Collections.Generic; +using System.Linq; + +namespace Reveal.Sdk.Dom.Data +{ + public class RestBuilder : DataSourceBuilder, IRestBuilder + { + readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.REST }; //rest data source + readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the rest data source + + public RestBuilder(string title, string subtitle) : + base(DataSourceProvider.JSON, title, subtitle) + { + DataSourceItem.HasTabularData = true; + DataSourceItem.ResourceItemDataSource = _resourceItemDataSource; + _resourceItem.DataSourceId = _resourceItemDataSource.Id; + DataSourceItem.ResourceItem = _resourceItem; + + SetAnonymous(true); + SetMethod("GET"); + _resourceItemDataSource.Properties.Add("Result-Type", ".json"); + } + + public IRestBuilder AddHeader(HeaderType headerType, string value) + { + var propertyKey = "Headers"; + + var headerValue = $"{AddDashesToEnumName(headerType.ToString())}={value}"; + + if (!_resourceItemDataSource.Properties.ContainsKey(propertyKey)) + { + _resourceItemDataSource.Properties.Add(propertyKey, new List { headerValue }); + } + else + { + var headers = (List)_resourceItemDataSource.Properties[propertyKey]; + headers.Add(headerValue); + } + + return this; + } + + public IRestBuilder SetAnonymous(bool isAnonymous) + { + _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; + return this; + } + + public IRestBuilder SetMethod(string method) + { + _resourceItemDataSource.Properties.Add("Method", method); + return this; + } + + public IRestBuilder SetUrl(string url) + { + _resourceItemDataSource.Properties.Add("Url", url); + return this; + } + + public override IDataSourceBuilder SetFields(IEnumerable fields) + { + DataSourceItem.Parameters.Add("config", BuildConfig(fields)); + return base.SetFields(fields); + } + + string AddDashesToEnumName(string name) + { + return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); + } + + Dictionary BuildConfig(IEnumerable fields) + { + Dictionary config = new Dictionary(); + List columnConfigs = new List(); + foreach (var field in fields) + { + if (field == null) + continue; + + var columnConfig = new ColumnConfig + { + Key = field.FieldName + }; + + + int type = ((IFieldDataType)field).DataType switch + { + DataType.Number => 1, + DataType.Date => 2, + DataType.DateTime => 3, + DataType.Time => 4, + _ => 0 + }; + + columnConfig.Type = type; + columnConfigs.Add(columnConfig); + } + + config.Add("iterationDepth", 0); + config.Add("columnsConfig", columnConfigs); + return config; + } + } + +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs index 0266594e..833f7f9b 100644 --- a/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs +++ b/src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs @@ -1,174 +1,174 @@ -using Reveal.Sdk.Dom.Core.Constants; -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Reveal.Sdk.Dom.Data -{ - public sealed class RestServiceBuilder - { - readonly DataSource _dataSource = new DataSource() { Id = DataSourceIds.JSON, Provider = DataSourceProvider.JSON }; //data source - readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source - readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.REST }; //rest data source - readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the rest data source - - public RestServiceBuilder(string uri) - { - _dataSourceItem.DataSource = _dataSource; - _dataSourceItem.DataSourceId = _dataSource.Id; - _dataSourceItem.HasTabularData = true; - - _resourceItemDataSource.Properties.Add("_rpUseAnonymousAuthentication", true); - _resourceItemDataSource.Properties.Add("Url", uri); - _resourceItemDataSource.Properties.Add("Method", "GET"); - _resourceItemDataSource.Properties.Add("Result-Type", ".json"); - - _dataSourceItem.ResourceItemDataSource = _resourceItemDataSource; - _resourceItem.DataSourceId = _resourceItemDataSource.Id; - - _resourceItem.Properties.Add("Url", uri); - _dataSourceItem.ResourceItem = _resourceItem; - } - - - public RestServiceBuilder IsAnonymous(bool isAnonymous) - { - _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; - return this; - } - - public RestServiceBuilder SetFields(IEnumerable fields) - { - _dataSourceItem.Fields.Clear(); - _dataSourceItem.Fields.AddRange(fields); - - _dataSourceItem.Parameters.Add("config", BuildConfig(fields)); - - return this; - } - - public RestServiceBuilder SetTitle(string title) - { - _dataSourceItem.Title = title; - _resourceItem.Title = title; - _resourceItemDataSource.Title = title; - return this; - } - - public RestServiceBuilder SetSubtitle(string subtitle) - { - _dataSourceItem.Subtitle = subtitle; - return this; - } - - public DataSourceItem Build() - { - if (_dataSourceItem.Fields.Count == 0) - throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); - - return _dataSourceItem; - } - - public RestServiceBuilder AddHeader(HeaderType headerType, string value) - { - var propertyKey = "Headers"; - - var headerValue = $"{AddDashesToEnumName(headerType.ToString())}={value}"; - - if (!_resourceItemDataSource.Properties.ContainsKey(propertyKey)) - { - _resourceItemDataSource.Properties.Add(propertyKey, new List { headerValue }); - } - else - { - var headers = (List)_resourceItemDataSource.Properties[propertyKey]; - headers.Add(headerValue); - } - - return this; - } - - public RestServiceBuilder UseCsv() - { - ClearJsonConfig(); - - _dataSource.Id = DataSourceIds.CSV; - _dataSource.Provider = DataSourceProvider.CSV; - _resourceItemDataSource.Properties["Result-Type"] = ".csv"; - - _dataSourceItem.DataSourceId = _dataSource.Id; - - return this; - } - - public RestServiceBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) - { - ClearJsonConfig(); - - _dataSource.Id = DataSourceIds.Excel; - _dataSource.Provider = DataSourceProvider.MicrosoftExcel; - - var fileExt = fileType == ExcelFileType.Xlsx ? ".xlsx" : ".xls"; - _resourceItemDataSource.Properties["Result-Type"] = fileExt; - - if (sheet != null) - { - _dataSourceItem.Subtitle = sheet; - - if (_dataSourceItem.Properties.ContainsKey("Sheet")) - _dataSourceItem.Properties["Sheet"] = sheet; - else - _dataSourceItem.Properties.Add("Sheet", sheet); - } - - _dataSourceItem.DataSourceId = _dataSource.Id; - - return this; - } - - Dictionary BuildConfig(IEnumerable fields) - { - Dictionary config = new Dictionary(); - List columnConfigs = new List(); - foreach (var field in fields) - { - if (field == null) - continue; - - var columnConfig = new ColumnConfig - { - Key = field.FieldName - }; - - - int type = ((IFieldDataType)field).DataType switch - { - DataType.Number => 1, - DataType.Date => 2, - DataType.DateTime => 3, - DataType.Time => 4, - _ => 0 - }; - - columnConfig.Type = type; - columnConfigs.Add(columnConfig); - } - - config.Add("iterationDepth", 0); - config.Add("columnsConfig", columnConfigs); - return config; - } - - void ClearJsonConfig() - { - if (_dataSourceItem.Parameters.ContainsKey("config")) - _dataSourceItem.Parameters.Remove("config"); - } - - string AddDashesToEnumName(string name) - { - return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); - } - } -} +using Reveal.Sdk.Dom.Core.Constants; +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Reveal.Sdk.Dom.Data +{ + public sealed class RestServiceBuilder + { + readonly DataSource _dataSource = new DataSource() { Id = DataSourceIds.JSON, Provider = DataSourceProvider.JSON }; //data source + readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source + readonly DataSource _resourceItemDataSource = new DataSource() { Provider = DataSourceProvider.REST }; //rest data source + readonly DataSourceItem _resourceItem = new DataSourceItem(); //resource item that points to the rest data source + + public RestServiceBuilder(string uri) + { + _dataSourceItem.DataSource = _dataSource; + _dataSourceItem.DataSourceId = _dataSource.Id; + _dataSourceItem.HasTabularData = true; + + _resourceItemDataSource.Properties.Add("_rpUseAnonymousAuthentication", true); + _resourceItemDataSource.Properties.Add("Url", uri); + _resourceItemDataSource.Properties.Add("Method", "GET"); + _resourceItemDataSource.Properties.Add("Result-Type", ".json"); + + _dataSourceItem.ResourceItemDataSource = _resourceItemDataSource; + _resourceItem.DataSourceId = _resourceItemDataSource.Id; + + _resourceItem.Properties.Add("Url", uri); + _dataSourceItem.ResourceItem = _resourceItem; + } + + + public RestServiceBuilder IsAnonymous(bool isAnonymous) + { + _resourceItemDataSource.Properties["_rpUseAnonymousAuthentication"] = isAnonymous; + return this; + } + + public RestServiceBuilder SetFields(IEnumerable fields) + { + _dataSourceItem.Fields.Clear(); + _dataSourceItem.Fields.AddRange(fields); + + _dataSourceItem.Parameters.Add("config", BuildConfig(fields)); + + return this; + } + + public RestServiceBuilder SetTitle(string title) + { + _dataSourceItem.Title = title; + _resourceItem.Title = title; + _resourceItemDataSource.Title = title; + return this; + } + + public RestServiceBuilder SetSubtitle(string subtitle) + { + _dataSourceItem.Subtitle = subtitle; + return this; + } + + public DataSourceItem Build() + { + if (_dataSourceItem.Fields.Count == 0) + throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); + + return _dataSourceItem; + } + + public RestServiceBuilder AddHeader(HeaderType headerType, string value) + { + var propertyKey = "Headers"; + + var headerValue = $"{AddDashesToEnumName(headerType.ToString())}={value}"; + + if (!_resourceItemDataSource.Properties.ContainsKey(propertyKey)) + { + _resourceItemDataSource.Properties.Add(propertyKey, new List { headerValue }); + } + else + { + var headers = (List)_resourceItemDataSource.Properties[propertyKey]; + headers.Add(headerValue); + } + + return this; + } + + public RestServiceBuilder UseCsv() + { + ClearJsonConfig(); + + _dataSource.Id = DataSourceIds.CSV; + _dataSource.Provider = DataSourceProvider.CSV; + _resourceItemDataSource.Properties["Result-Type"] = ".csv"; + + _dataSourceItem.DataSourceId = _dataSource.Id; + + return this; + } + + public RestServiceBuilder UseExcel(string sheet = null, ExcelFileType fileType = ExcelFileType.Xlsx) + { + ClearJsonConfig(); + + _dataSource.Id = DataSourceIds.Excel; + _dataSource.Provider = DataSourceProvider.MicrosoftExcel; + + var fileExt = fileType == ExcelFileType.Xlsx ? ".xlsx" : ".xls"; + _resourceItemDataSource.Properties["Result-Type"] = fileExt; + + if (sheet != null) + { + _dataSourceItem.Subtitle = sheet; + + if (_dataSourceItem.Properties.ContainsKey("Sheet")) + _dataSourceItem.Properties["Sheet"] = sheet; + else + _dataSourceItem.Properties.Add("Sheet", sheet); + } + + _dataSourceItem.DataSourceId = _dataSource.Id; + + return this; + } + + Dictionary BuildConfig(IEnumerable fields) + { + Dictionary config = new Dictionary(); + List columnConfigs = new List(); + foreach (var field in fields) + { + if (field == null) + continue; + + var columnConfig = new ColumnConfig + { + Key = field.FieldName + }; + + + int type = ((IFieldDataType)field).DataType switch + { + DataType.Number => 1, + DataType.Date => 2, + DataType.DateTime => 3, + DataType.Time => 4, + _ => 0 + }; + + columnConfig.Type = type; + columnConfigs.Add(columnConfig); + } + + config.Add("iterationDepth", 0); + config.Add("columnsConfig", columnConfigs); + return config; + } + + void ClearJsonConfig() + { + if (_dataSourceItem.Parameters.ContainsKey("config")) + _dataSourceItem.Parameters.Remove("config"); + } + + string AddDashesToEnumName(string name) + { + return string.Concat(name.Select(x => char.IsUpper(x) ? "-" + x : x.ToString())).TrimStart('-'); + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs b/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs index f30526d3..da2f1eb8 100644 --- a/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs +++ b/src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs @@ -1,79 +1,79 @@ -using Reveal.Sdk.Dom.Core.Constants; -using Reveal.Sdk.Dom.Core.Extensions; -using Reveal.Sdk.Dom.Visualizations; -using System; -using System.Collections.Generic; - -namespace Reveal.Sdk.Dom.Data -{ - public sealed class SqlServerBuilder - { - readonly DataSource _dataSource = new DataSource() { Provider = DataSourceProvider.MicrosoftSqlServer }; //data source - readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source - - public SqlServerBuilder(string host, string database, string table) - { - _dataSourceItem.DataSource = _dataSource; - _dataSourceItem.DataSourceId = _dataSource.Id; - - SetHost(host); - SetDatabase(database); - SetTable(table); - SetSchema("dbo"); - } - - public SqlServerBuilder SetDatabase(string database) - { - _dataSource.Properties.SetItem("Database", database); - _dataSourceItem.Properties.SetItem("Database", database); - return this; - } - - public SqlServerBuilder SetFields(IEnumerable fields) - { - _dataSourceItem.Fields.Clear(); - _dataSourceItem.Fields.AddRange(fields); - return this; - } - - public SqlServerBuilder SetHost(string host) - { - _dataSource.Properties.SetItem("Host", host); - return this; - } - - public SqlServerBuilder SetSchema(string schema) - { - _dataSourceItem.Properties.SetItem("Schema", schema); - return this; - } - - public SqlServerBuilder SetTable(string table) - { - _dataSourceItem.Properties.SetItem("Table", table); - return this; - } - - public SqlServerBuilder SetTitle(string title) - { - _dataSource.Title = title; - _dataSourceItem.Title = title; - return this; - } - - public SqlServerBuilder SetSubtitle(string subtitle) - { - _dataSource.Subtitle = subtitle; - _dataSourceItem.Subtitle = subtitle; - return this; - } - - public DataSourceItem Build() - { - if (_dataSourceItem.Fields.Count == 0) - throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); - - return _dataSourceItem; - } - } -} +using Reveal.Sdk.Dom.Core.Constants; +using Reveal.Sdk.Dom.Core.Extensions; +using Reveal.Sdk.Dom.Visualizations; +using System; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public sealed class SqlServerBuilder + { + readonly DataSource _dataSource = new DataSource() { Provider = DataSourceProvider.MicrosoftSqlServer }; //data source + readonly DataSourceItem _dataSourceItem = new DataSourceItem(); //data source item that points to the data source + + public SqlServerBuilder(string host, string database, string table) + { + _dataSourceItem.DataSource = _dataSource; + _dataSourceItem.DataSourceId = _dataSource.Id; + + SetHost(host); + SetDatabase(database); + SetTable(table); + SetSchema("dbo"); + } + + public SqlServerBuilder SetDatabase(string database) + { + _dataSource.Properties.SetItem("Database", database); + _dataSourceItem.Properties.SetItem("Database", database); + return this; + } + + public SqlServerBuilder SetFields(IEnumerable fields) + { + _dataSourceItem.Fields.Clear(); + _dataSourceItem.Fields.AddRange(fields); + return this; + } + + public SqlServerBuilder SetHost(string host) + { + _dataSource.Properties.SetItem("Host", host); + return this; + } + + public SqlServerBuilder SetSchema(string schema) + { + _dataSourceItem.Properties.SetItem("Schema", schema); + return this; + } + + public SqlServerBuilder SetTable(string table) + { + _dataSourceItem.Properties.SetItem("Table", table); + return this; + } + + public SqlServerBuilder SetTitle(string title) + { + _dataSource.Title = title; + _dataSourceItem.Title = title; + return this; + } + + public SqlServerBuilder SetSubtitle(string subtitle) + { + _dataSource.Subtitle = subtitle; + _dataSourceItem.Subtitle = subtitle; + return this; + } + + public DataSourceItem Build() + { + if (_dataSourceItem.Fields.Count == 0) + throw new ArgumentException("You must provide the field definitions for the data source item. Call the SetFields method and provide the fields."); + + return _dataSourceItem; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/DataSource.cs b/src/Reveal.Sdk.Dom/Data/DataSource.cs index 35c4562c..4f1c6092 100644 --- a/src/Reveal.Sdk.Dom/Data/DataSource.cs +++ b/src/Reveal.Sdk.Dom/Data/DataSource.cs @@ -1,53 +1,53 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Reveal.Sdk.Dom.Core; -using Reveal.Sdk.Dom.Core.Constants; -using System; -using System.Collections.Generic; - -namespace Reveal.Sdk.Dom.Data -{ - public sealed class DataSource : SchemaType, IEquatable - { - public string Id { get; set; } = Guid.NewGuid().ToString(); - - [JsonProperty] - [JsonConverter(typeof(StringEnumConverter))] - public DataSourceProvider Provider { get; internal set; } - - [JsonProperty("Description")] - public string Title { get; set; } - - public string Subtitle { get; set; } - - - public Dictionary Properties { get; internal set; } - - public DataSource() - { - SchemaTypeName = SchemaTypeNames.DataSourceType; - Properties = new Dictionary(); - } - - public override bool Equals(object obj) - { - return Equals(obj as DataSource); - } - - public bool Equals(DataSource other) - { - return other != null && other.Id == Id; - } - - public override int GetHashCode() - { - int hashCode = -258580624; - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(SchemaTypeName); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Id); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Provider); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Title); - hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Subtitle); - return hashCode; - } - } -} +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Reveal.Sdk.Dom.Core; +using Reveal.Sdk.Dom.Core.Constants; +using System; +using System.Collections.Generic; + +namespace Reveal.Sdk.Dom.Data +{ + public sealed class DataSource : SchemaType, IEquatable + { + public string Id { get; set; } = Guid.NewGuid().ToString(); + + [JsonProperty] + [JsonConverter(typeof(StringEnumConverter))] + public DataSourceProvider Provider { get; internal set; } + + [JsonProperty("Description")] + public string Title { get; set; } + + public string Subtitle { get; set; } + + + public Dictionary Properties { get; internal set; } + + public DataSource() + { + SchemaTypeName = SchemaTypeNames.DataSourceType; + Properties = new Dictionary(); + } + + public override bool Equals(object obj) + { + return Equals(obj as DataSource); + } + + public bool Equals(DataSource other) + { + return other != null && other.Id == Id; + } + + public override int GetHashCode() + { + int hashCode = -258580624; + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(SchemaTypeName); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Id); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Provider); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Title); + hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(Subtitle); + return hashCode; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs b/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs new file mode 100644 index 00000000..030fe591 --- /dev/null +++ b/src/Reveal.Sdk.Dom/Data/DataSourceFactory.cs @@ -0,0 +1,18 @@ +using System; + +namespace Reveal.Sdk.Dom.Data +{ + public class DataSourceFactory + { + public static IDataSourceBuilder Create(DataSourceType type, string title, string subtitle) + { + return type switch + { + DataSourceType.RemoteFile => new RemoteFileBuilder(title, subtitle), + DataSourceType.REST => new RestBuilder(title, subtitle), + //DataSourceType.MicrosoftSqlServer => new SqlServerBuilder("", "", ""), + _ => throw new NotImplementedException($"No builder implemented for provider: {type}") + }; + } + } +} diff --git a/src/Reveal.Sdk.Dom/Data/Enums/DataSourceProvider.cs b/src/Reveal.Sdk.Dom/Data/Enums/DataSourceProvider.cs index 80e13033..97190fa8 100644 --- a/src/Reveal.Sdk.Dom/Data/Enums/DataSourceProvider.cs +++ b/src/Reveal.Sdk.Dom/Data/Enums/DataSourceProvider.cs @@ -1,121 +1,121 @@ -using System.Runtime.Serialization; - -namespace Reveal.Sdk.Dom.Data -{ - public enum DataSourceProvider - { - [EnumMember(Value = "AMAZON_ATHENA")] - AmazonAthena, - - [EnumMember(Value = "AMAZON_REDSHIFT")] - AmazonRedshift, - - [EnumMember(Value = "AMAZON_S3")] - AmazonS3, - - [EnumMember(Value = "ASSET_PROVIDER")] - Asset, - - [EnumMember(Value = "BOXPROVIDER")] - Box, - - [EnumMember(Value = "CSVLOCALFILEPROVIDER")] - CSV, - - [EnumMember(Value = "DROPBOXPROVIDER")] - DropBox, - - [EnumMember(Value = "GOOGLE_ANALYTICS")] - GoogleAnalytics, - - [EnumMember(Value = "GOOGLE_ANALYTICS_4")] - GoogleAnalytics4, - - [EnumMember(Value = "BIG_QUERY")] - GoogleBigQuery, - - [EnumMember(Value = "GOOGLEDRIVEPROVIDER")] - GoogleDrive, - - [EnumMember(Value = "GOOGLESHEETLOCALFILEPROVIDER")] - GoogleSheets, - - [EnumMember(Value = "HUBSPOT")] - HubSpot, - - [EnumMember(Value = "InMemory")] - InMemory, - - [EnumMember(Value = "JSON")] - JSON, - - [EnumMember(Value = "LOCALFILE")] - LocalFile, - - [EnumMember(Value = "REST")] - REST, - - [EnumMember(Value = "MARKETO")] - Marketo, - - [EnumMember(Value = "ANALYSISSERVICES")] - MicrosoftAnalysisServices, - - [EnumMember(Value = "AZURE_ANALYSIS_SERVICES")] - MicrosoftAzureAnalysisServices, - - [EnumMember(Value = "AZURE_SQL")] - MicrosoftAzureSqlServer, - - [EnumMember(Value = "AZURE_SYNAPSE")] - MicrosoftAzureSynapseAnalytics, - - [EnumMember(Value = "DYNAMICS_CRM")] - MicrosoftDynamics, - - [EnumMember(Value = "EXCELLOCALFILEPROVIDER")] - MicrosoftExcel, - - [EnumMember(Value = "ONEDRIVEPROVIDER")] - MicrosoftOneDrive, - - [EnumMember(Value = "SQLSERVER")] - MicrosoftSqlServer, - - [EnumMember(Value = "SSRS")] - MicrosoftSqlServerReportingServices, - - [EnumMember(Value = "MYSQL")] - MySql, - - [EnumMember(Value = "ODATAPROVIDER")] - OData, - - [EnumMember(Value = "ORACLE")] - Oracle, - - [EnumMember(Value = "POSTGRES")] - PostgreSql, - - [EnumMember(Value = "QUICK_BOOKS")] - QuickBooks, - - [EnumMember(Value = "QUICK_BOOKS_DESKTOP")] - QuickBooksDesktop, - - [EnumMember(Value = "SALESFORCE")] - Salesforce, - - [EnumMember(Value = "SHAREPOINT")] - SharePoint, - - [EnumMember(Value = "SNOWFLAKE")] - Snowflake, - - [EnumMember(Value = "SYBASE")] - Sybase, - - [EnumMember(Value = "WEBSERVICE")] - WebService, - } -} +using System.Runtime.Serialization; + +namespace Reveal.Sdk.Dom.Data +{ + public enum DataSourceProvider + { + [EnumMember(Value = "AMAZON_ATHENA")] + AmazonAthena, + + [EnumMember(Value = "AMAZON_REDSHIFT")] + AmazonRedshift, + + [EnumMember(Value = "AMAZON_S3")] + AmazonS3, + + [EnumMember(Value = "ASSET_PROVIDER")] + Asset, + + [EnumMember(Value = "BOXPROVIDER")] + Box, + + [EnumMember(Value = "CSVLOCALFILEPROVIDER")] + CSV, + + [EnumMember(Value = "DROPBOXPROVIDER")] + DropBox, + + [EnumMember(Value = "GOOGLE_ANALYTICS")] + GoogleAnalytics, + + [EnumMember(Value = "GOOGLE_ANALYTICS_4")] + GoogleAnalytics4, + + [EnumMember(Value = "BIG_QUERY")] + GoogleBigQuery, + + [EnumMember(Value = "GOOGLEDRIVEPROVIDER")] + GoogleDrive, + + [EnumMember(Value = "GOOGLESHEETLOCALFILEPROVIDER")] + GoogleSheets, + + [EnumMember(Value = "HUBSPOT")] + HubSpot, + + [EnumMember(Value = "InMemory")] + InMemory, + + [EnumMember(Value = "JSON")] + JSON, + + [EnumMember(Value = "LOCALFILE")] + LocalFile, + + [EnumMember(Value = "REST")] + REST, + + [EnumMember(Value = "MARKETO")] + Marketo, + + [EnumMember(Value = "ANALYSISSERVICES")] + MicrosoftAnalysisServices, + + [EnumMember(Value = "AZURE_ANALYSIS_SERVICES")] + MicrosoftAzureAnalysisServices, + + [EnumMember(Value = "AZURE_SQL")] + MicrosoftAzureSqlServer, + + [EnumMember(Value = "AZURE_SYNAPSE")] + MicrosoftAzureSynapseAnalytics, + + [EnumMember(Value = "DYNAMICS_CRM")] + MicrosoftDynamics, + + [EnumMember(Value = "EXCELLOCALFILEPROVIDER")] + MicrosoftExcel, + + [EnumMember(Value = "ONEDRIVEPROVIDER")] + MicrosoftOneDrive, + + [EnumMember(Value = "SQLSERVER")] + MicrosoftSqlServer, + + [EnumMember(Value = "SSRS")] + MicrosoftSqlServerReportingServices, + + [EnumMember(Value = "MYSQL")] + MySql, + + [EnumMember(Value = "ODATAPROVIDER")] + OData, + + [EnumMember(Value = "ORACLE")] + Oracle, + + [EnumMember(Value = "POSTGRES")] + PostgreSql, + + [EnumMember(Value = "QUICK_BOOKS")] + QuickBooks, + + [EnumMember(Value = "QUICK_BOOKS_DESKTOP")] + QuickBooksDesktop, + + [EnumMember(Value = "SALESFORCE")] + Salesforce, + + [EnumMember(Value = "SHAREPOINT")] + SharePoint, + + [EnumMember(Value = "SNOWFLAKE")] + Snowflake, + + [EnumMember(Value = "SYBASE")] + Sybase, + + [EnumMember(Value = "WEBSERVICE")] + WebService, + } +} diff --git a/src/Reveal.Sdk.Dom/Reveal.Sdk.Dom.csproj b/src/Reveal.Sdk.Dom/Reveal.Sdk.Dom.csproj index 5eeab046..258d8a0a 100644 --- a/src/Reveal.Sdk.Dom/Reveal.Sdk.Dom.csproj +++ b/src/Reveal.Sdk.Dom/Reveal.Sdk.Dom.csproj @@ -1,29 +1,29 @@ - - - - net462;net6.0 - true - true - True - - - - - - all - runtime; build; native; contentfiles; analyzers - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + + + net462;net6.0 + true + true + True + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + +