Skip to content

Commit

Permalink
converted DataSourceProviders from a constant class to an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlagunas committed Aug 7, 2023
1 parent e0e22b8 commit 8d8a3d2
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
16 changes: 1 addition & 15 deletions e2e/Sandbox/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using Reveal.Sdk;
using Reveal.Sdk.Dom;
using Reveal.Sdk.Dom.Visualizations;
using Sandbox.Factories;
using Sandbox.Helpers;
using System;
using System.IO;
using System.Linq;
using System.Windows;

namespace Sandbox
Expand Down Expand Up @@ -84,25 +82,13 @@ 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 sourceDocument = RdashDocument.Load(_readFilePath);
//var document = new RdashDocument("Testing");

//document.Import(sourceDocument, sourceDocument.Visualizations[0]);

var sourceDocument = RdashDocument.Load(_readFilePath);
var dsi = sourceDocument.Visualizations[0].AsTabularVisualization().GetDataSourceItem();
var document = new RdashDocument("Testing");
var gridViz = new GridVisualization("My Grid", dsi)
.SetColumns("Territory");
document.Visualizations.Add(gridViz);

var json = document.ToJsonString();
//json.Save(_saveJsonToPath);
_revealView.Dashboard = await RVDashboard.LoadFromJsonAsync(json);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Reveal.Sdk.Dom.Core.Constants;
using Reveal.Sdk.Dom.Core.Utilities;
using Reveal.Sdk.Dom.Core.Utilities;
using Reveal.Sdk.Dom.Data;
using Reveal.Sdk.Dom.Visualizations;
using System.Collections.Generic;
Expand Down Expand Up @@ -40,7 +39,7 @@ public void DataSources_FromVisualizationsAreNotDuplicated()

RdashDocumentValidator.FixDocument(document);

var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProviders.JSON);
var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON);

Assert.Single(jsonDataSources);
}
Expand All @@ -63,7 +62,7 @@ public void DataSources_FromVisualizations_AndDataSources_AreNotDuplicated()

RdashDocumentValidator.FixDocument(document);

var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProviders.JSON);
var jsonDataSources = document.DataSources.Where(x => x.Provider == DataSourceProvider.JSON);

Assert.Single(jsonDataSources);
}
Expand Down
12 changes: 0 additions & 12 deletions src/Reveal.Sdk.Dom/Core/Constants/DataSourceProviders.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Reveal.Sdk.Dom/Data/Builders/RestServiceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Reveal.Sdk.Dom.Data
{
public sealed class RestServiceBuilder
{
readonly DataSource _dataSource = new DataSource() { Id = DataSourceIds.JSON, Provider = DataSourceProviders.JSON }; //data source
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 = DataSourceProviders.REST }; //rest 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)
Expand Down Expand Up @@ -94,7 +94,7 @@ public RestServiceBuilder UseCsv()
ClearJsonConfig();

_dataSource.Id = DataSourceIds.CSV;
_dataSource.Provider = DataSourceProviders.CsvProvider;
_dataSource.Provider = DataSourceProvider.CSV;
_resourceItemDataSource.Properties["Result-Type"] = ".csv";

_dataSourceItem.DataSourceId = _dataSource.Id;
Expand All @@ -107,7 +107,7 @@ public RestServiceBuilder UseExcel(string sheet = null, ExcelFileType fileType =
ClearJsonConfig();

_dataSource.Id = DataSourceIds.Excel;
_dataSource.Provider = DataSourceProviders.ExcelProvider;
_dataSource.Provider = DataSourceProvider.MicrosoftExcel;

var fileExt = fileType == ExcelFileType.Xlsx ? ".xlsx" : ".xls";
_resourceItemDataSource.Properties["Result-Type"] = fileExt;
Expand Down
2 changes: 1 addition & 1 deletion src/Reveal.Sdk.Dom/Data/Builders/SqlServerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Reveal.Sdk.Dom.Data
{
public sealed class SqlServerBuilder
{
readonly DataSource _dataSource = new DataSource() { Provider = DataSourceProviders.SqlServer }; //data source
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)
Expand Down
6 changes: 4 additions & 2 deletions src/Reveal.Sdk.Dom/Data/DataSource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Reveal.Sdk.Dom.Core;
using Reveal.Sdk.Dom.Core.Constants;
using System;
Expand All @@ -11,7 +12,8 @@ public sealed class DataSource : SchemaType, IEquatable<DataSource>
public string Id { get; set; } = Guid.NewGuid().ToString();

[JsonProperty]
public string Provider { get; internal set; }
[JsonConverter(typeof(StringEnumConverter))]
public DataSourceProvider Provider { get; internal set; }

[JsonProperty("Description")]
public string Title { get; set; }
Expand Down Expand Up @@ -42,7 +44,7 @@ public override int GetHashCode()
int hashCode = -258580624;
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(SchemaTypeName);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Id);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Provider);
hashCode = hashCode * -1521134295 + EqualityComparer<DataSourceProvider>.Default.GetHashCode(Provider);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Title);
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Subtitle);
return hashCode;
Expand Down
25 changes: 25 additions & 0 deletions src/Reveal.Sdk.Dom/Data/Enums/DataSourceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Runtime.Serialization;

namespace Reveal.Sdk.Dom.Data
{
public enum DataSourceProvider
{
[EnumMember(Value = "CSVLOCALFILEPROVIDER")]
CSV,

[EnumMember(Value = "JSON")]
JSON,

[EnumMember(Value = "REST")]
REST,

[EnumMember(Value = "EXCELLOCALFILEPROVIDER")]
MicrosoftExcel,

[EnumMember(Value = "SQLSERVER")]
MicrosoftSqlServer,

[EnumMember(Value = "WEBSERVICE")]
WebService
}
}

0 comments on commit 8d8a3d2

Please sign in to comment.