Skip to content

Commit

Permalink
Normalizing line endings. Version increment for release 0.0.43
Browse files Browse the repository at this point in the history
  • Loading branch information
NickSandelRWH committed Oct 3, 2023
1 parent 7a6d5b1 commit 86df10e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 97 deletions.
190 changes: 95 additions & 95 deletions Packer2.Library/DataModel/BimDataModelStore.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
using Microsoft.AnalysisServices.Tabular;
using Newtonsoft.Json.Linq;

namespace Packer2.Library.DataModel
{
public class BimDataModelStore : IModelStore<Database>
{
private readonly ITextStore file;

public static BimDataModelStore LoadFromText(string contents)
{
return new BimDataModelStore(new MemoryFile(contents));
}
public static BimDataModelStore LoadFromFile(string filePath)
{
return new BimDataModelStore(new TextFileStore(filePath));
}

public BimDataModelStore(ITextStore file)
{
this.file = file;
}

public Database Read()
{
return JsonSerializer.DeserializeDatabase(file.GetText());
}

public void Save(Database model)
{
var serialized = JsonSerializer.SerializeDatabase(model, new SerializeOptions() { IgnoreInferredObjects = true, IgnoreInferredProperties = true, IgnoreTimestamps = true });

// Git diffs were showing a bit of noise where order of some objects was inconsistent from one save to the next. Enforcing order of names.
serialized = OrderModelJSONSection(serialized, "tables");
serialized = OrderModelJSONSection(serialized, "relationships");
serialized = OrderModelJSONSection(serialized, "expressions");
serialized = OrderModelJSONSection(serialized, "annotations");

serialized = SetDefaultConnectionDetails(serialized);

file.SetText(serialized);
}

private string OrderModelJSONSection(string serialized, string sectionName, string orderByName = "name")
{
//Load the json into a jobject
JObject jObject = JObject.Parse(serialized);

//Find the tables jarray
JArray section = (JArray)jObject["model"][sectionName];

//If section is not null
if (section != null)
using Microsoft.AnalysisServices.Tabular;
using Newtonsoft.Json.Linq;

namespace Packer2.Library.DataModel
{
public class BimDataModelStore : IModelStore<Database>
{
private readonly ITextStore file;

public static BimDataModelStore LoadFromText(string contents)
{
return new BimDataModelStore(new MemoryFile(contents));
}
public static BimDataModelStore LoadFromFile(string filePath)
{
return new BimDataModelStore(new TextFileStore(filePath));
}

public BimDataModelStore(ITextStore file)
{
this.file = file;
}

public Database Read()
{
return JsonSerializer.DeserializeDatabase(file.GetText());
}

public void Save(Database model)
{
var serialized = JsonSerializer.SerializeDatabase(model, new SerializeOptions() { IgnoreInferredObjects = true, IgnoreInferredProperties = true, IgnoreTimestamps = true });

// Git diffs were showing a bit of noise where order of some objects was inconsistent from one save to the next. Enforcing order of names.
serialized = OrderModelJSONSection(serialized, "tables");
serialized = OrderModelJSONSection(serialized, "relationships");
serialized = OrderModelJSONSection(serialized, "expressions");
serialized = OrderModelJSONSection(serialized, "annotations");

serialized = SetDefaultConnectionDetails(serialized);

file.SetText(serialized);
}

private string OrderModelJSONSection(string serialized, string sectionName, string orderByName = "name")
{
//Load the json into a jobject
JObject jObject = JObject.Parse(serialized);

//Find the tables jarray
JArray section = (JArray)jObject["model"][sectionName];

//If section is not null
if (section != null)
{
//Sort it by name
JArray sortedSection = new JArray(section.OrderBy(obj => (string)obj[orderByName]));
Expand All @@ -60,45 +60,45 @@ private string OrderModelJSONSection(string serialized, string sectionName, stri

//Convert the sorted jObject back to a string
serialized = jObject.ToString();
}

return serialized;
}

private string SetDefaultConnectionDetails(string serialized)
{
//Load the json into a jobject
JObject jObject = JObject.Parse(serialized);

// Remove the line for model.defaultPowerBIDataSourceVersion
if (jObject["model"]["defaultPowerBIDataSourceVersion"] != null)
{
jObject["model"]["defaultPowerBIDataSourceVersion"].Parent.Remove();
}

// For any of the model.dataSources set connectionString to a default and set connectionDetails.database to a default
// These get overwritten at the proper build time anyway so they don't need real values stored for source control
JArray dataSources = (JArray)jObject["model"]["dataSources"];

if (!(dataSources is null))
{
foreach (JObject dataSource in dataSources)
{
// If the property exists, set it to the default
if (dataSource["connectionString"] != null)
{
dataSource["connectionString"] = "Data Source=.;Initial Catalog=Model;Integrated Security=True";
}
if (dataSource["connectionDetails"] != null)
{
dataSource["connectionDetails"]["address"]["database"] = "Model";
}
}
}
//Convert the sorted jObject back to a string
serialized = jObject.ToString();

return serialized;
}
}
}
}

return serialized;
}

private string SetDefaultConnectionDetails(string serialized)
{
//Load the json into a jobject
JObject jObject = JObject.Parse(serialized);

// Remove the line for model.defaultPowerBIDataSourceVersion
if (jObject["model"]["defaultPowerBIDataSourceVersion"] != null)
{
jObject["model"]["defaultPowerBIDataSourceVersion"].Parent.Remove();
}

// For any of the model.dataSources set connectionString to a default and set connectionDetails.database to a default
// These get overwritten at the proper build time anyway so they don't need real values stored for source control
JArray dataSources = (JArray)jObject["model"]["dataSources"];

if (!(dataSources is null))
{
foreach (JObject dataSource in dataSources)
{
// If the property exists, set it to the default
if (dataSource["connectionString"] != null)
{
dataSource["connectionString"] = "Data Source=.;Initial Catalog=Model;Integrated Security=True";
}
if (dataSource["connectionDetails"] != null)
{
dataSource["connectionDetails"]["address"]["database"] = "Model";
}
}
}
//Convert the sorted jObject back to a string
serialized = jObject.ToString();

return serialized;
}
}
}
2 changes: 1 addition & 1 deletion Packer2.PS/Packer2.PS.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Packer2.PS</id>
<version>0.0.40</version>
<version>0.0.43</version>
<authors>Antonio Nakic-Alfirev</authors>
<owners>Antonio Nakic-Alfirev</owners>
<projectUrl>https://github.com/anakic/packer</projectUrl>
Expand Down
2 changes: 1 addition & 1 deletion Packer2.PS/Packer2.Ps.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'packer2.ps.dll'

# Version number of this module.
ModuleVersion = '0.0.40'
ModuleVersion = '0.0.43'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down

0 comments on commit 86df10e

Please sign in to comment.