PBIT
This commit is contained in:
parent
bfcc869d19
commit
353bab30c5
@ -194,18 +194,10 @@ namespace AlmToolkit
|
|||||||
btnGenerateScript.Enabled = true;
|
btnGenerateScript.Enabled = true;
|
||||||
|
|
||||||
_compareState = CompareState.Validated;
|
_compareState = CompareState.Validated;
|
||||||
// This method needs to be moved out of comparison control during clean up
|
|
||||||
//ComparisonCtrl.SetValidatedState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShowConnectionsForm()
|
private bool ShowConnectionsForm()
|
||||||
{
|
{
|
||||||
//if (ComparisonCtrl.CompareState != CompareState.NotCompared)
|
|
||||||
//{
|
|
||||||
//
|
|
||||||
// ComparisonCtrl.RefreshSkipSelections();
|
|
||||||
//}
|
|
||||||
|
|
||||||
if (_compareState != CompareState.NotCompared)
|
if (_compareState != CompareState.NotCompared)
|
||||||
{
|
{
|
||||||
//just in case user has some selections, store them to the SkipSelections collection
|
//just in case user has some selections, store them to the SkipSelections collection
|
||||||
@ -672,7 +664,7 @@ namespace AlmToolkit
|
|||||||
|
|
||||||
private void btnUpdate_Click(object sender, EventArgs e)
|
private void btnUpdate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show($"Are you sure you want to update target?", Utils.AssemblyProduct, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
if (MessageBox.Show($"Are you sure you want to update the target?", Utils.AssemblyProduct, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,7 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System.DirectoryServices.AccountManagement" />
|
<Reference Include="System.DirectoryServices.AccountManagement" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.IO.Compression" />
|
||||||
<Reference Include="System.Management" />
|
<Reference Include="System.Management" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Runtime.Caching" />
|
<Reference Include="System.Runtime.Caching" />
|
||||||
@ -230,6 +231,7 @@
|
|||||||
<Compile Include="TabularCompare\Enums.cs" />
|
<Compile Include="TabularCompare\Enums.cs" />
|
||||||
<Compile Include="TabularCompare\BlobKeyEventArgs.cs" />
|
<Compile Include="TabularCompare\BlobKeyEventArgs.cs" />
|
||||||
<Compile Include="TabularCompare\PasswordPromptEventArgs.cs" />
|
<Compile Include="TabularCompare\PasswordPromptEventArgs.cs" />
|
||||||
|
<Compile Include="TabularCompare\PowerBiTemplate.cs" />
|
||||||
<Compile Include="TabularCompare\TabularMetadata\CalculationItem.cs" />
|
<Compile Include="TabularCompare\TabularMetadata\CalculationItem.cs" />
|
||||||
<Compile Include="TabularCompare\TabularMetadata\CalculationItemCollection.cs" />
|
<Compile Include="TabularCompare\TabularMetadata\CalculationItemCollection.cs" />
|
||||||
<Compile Include="TabularCompare\TabularMetadata\Model.cs" />
|
<Compile Include="TabularCompare\TabularMetadata\Model.cs" />
|
||||||
@ -250,10 +252,10 @@
|
|||||||
<Compile Include="TabularCompare\UI\Connections.Designer.cs">
|
<Compile Include="TabularCompare\UI\Connections.Designer.cs">
|
||||||
<DependentUpon>Connections.cs</DependentUpon>
|
<DependentUpon>Connections.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="TabularCompare\UI\DesktopInstances\ManagedIpHelper.cs" />
|
<Compile Include="TabularCompare\DesktopInstances\ManagedIpHelper.cs" />
|
||||||
<Compile Include="TabularCompare\UI\DesktopInstances\PowerBIHelper.cs" />
|
<Compile Include="TabularCompare\DesktopInstances\PowerBIHelper.cs" />
|
||||||
<Compile Include="TabularCompare\UI\DesktopInstances\ProcessExtensions.cs" />
|
<Compile Include="TabularCompare\DesktopInstances\ProcessExtensions.cs" />
|
||||||
<Compile Include="TabularCompare\UI\DesktopInstances\WindowTitle.cs" />
|
<Compile Include="TabularCompare\DesktopInstances\WindowTitle.cs" />
|
||||||
<Compile Include="TabularCompare\UI\Utils.cs" />
|
<Compile Include="TabularCompare\UI\Utils.cs" />
|
||||||
<Compile Include="TabularCompare\UI\BlobCredentials.cs">
|
<Compile Include="TabularCompare\UI\BlobCredentials.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
|
@ -451,7 +451,7 @@ namespace BismNormalizer.TabularCompare
|
|||||||
bool exceptionLoadingFile = false;
|
bool exceptionLoadingFile = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
tomDatabase = TOM.JsonSerializer.DeserializeDatabase(File.ReadAllText(_bimFile));
|
tomDatabase = OpenDatabaseFromFile();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@ -497,7 +497,7 @@ namespace BismNormalizer.TabularCompare
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Server amoServer = new Server();
|
Microsoft.AnalysisServices.Server amoServer = new Microsoft.AnalysisServices.Server();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
amoServer.Connect(BuildConnectionString());
|
amoServer.Connect(BuildConnectionString());
|
||||||
@ -546,7 +546,7 @@ namespace BismNormalizer.TabularCompare
|
|||||||
throw new ConnectionException($"Analysis Server {this.ServerName} is not running in Tabular mode");
|
throw new ConnectionException($"Analysis Server {this.ServerName} is not running in Tabular mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
Database amoDatabase = null;
|
Microsoft.AnalysisServices.Database amoDatabase = null;
|
||||||
if (this.DatabaseName == "" && this.ServerName.ToUpper().StartsWith("localhost:".ToUpper()))
|
if (this.DatabaseName == "" && this.ServerName.ToUpper().StartsWith("localhost:".ToUpper()))
|
||||||
{
|
{
|
||||||
//PBI Desktop doesn't have db name yet
|
//PBI Desktop doesn't have db name yet
|
||||||
@ -700,6 +700,27 @@ $@"{{
|
|||||||
amoDatabase.DirectQueryMode == DirectQueryMode.DirectQuery || amoDatabase.DirectQueryMode == DirectQueryMode.InMemoryWithDirectQuery || amoDatabase.DirectQueryMode == DirectQueryMode.DirectQueryWithInMemory);
|
amoDatabase.DirectQueryMode == DirectQueryMode.DirectQuery || amoDatabase.DirectQueryMode == DirectQueryMode.InMemoryWithDirectQuery || amoDatabase.DirectQueryMode == DirectQueryMode.DirectQueryWithInMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if file is PBIT and return instantiated TOM database.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TOM.Database OpenDatabaseFromFile()
|
||||||
|
{
|
||||||
|
TOM.Database tomDatabase;
|
||||||
|
string modelJson;
|
||||||
|
if (_bimFile.ToUpper().EndsWith(".PBIT"))
|
||||||
|
{
|
||||||
|
PowerBiTemplate pbit = new PowerBiTemplate(_bimFile);
|
||||||
|
modelJson = pbit.ModelJson;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modelJson = File.ReadAllText(_bimFile);
|
||||||
|
}
|
||||||
|
tomDatabase = TOM.JsonSerializer.DeserializeDatabase(modelJson);
|
||||||
|
return tomDatabase;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Build connection string.
|
/// Build connection string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -6,6 +6,7 @@ using System.Net;
|
|||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
//namespace DaxStudio.UI.Utils
|
||||||
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
||||||
{
|
{
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
|||||||
//using Serilog;
|
//using Serilog;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
|
|
||||||
|
//namespace DaxStudio.UI.Utils
|
||||||
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
||||||
{
|
{
|
||||||
public enum EmbeddedSSASIcon
|
public enum EmbeddedSSASIcon
|
@ -2,6 +2,7 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Management;
|
using System.Management;
|
||||||
|
|
||||||
|
//namespace DaxStudio.UI.Extensions
|
||||||
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
||||||
{
|
{
|
||||||
public static class ProcessExtensions
|
public static class ProcessExtensions
|
@ -6,6 +6,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
//namespace DaxStudio.Common
|
||||||
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
namespace BismNormalizer.TabularCompare.UI.DesktopInstances
|
||||||
{
|
{
|
||||||
public class WindowTitle
|
public class WindowTitle
|
101
BismNormalizer/BismNormalizer/TabularCompare/PowerBiTemplate.cs
Normal file
101
BismNormalizer/BismNormalizer/TabularCompare/PowerBiTemplate.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
//namespace TabularEditor.TOMWrapper.PowerBI
|
||||||
|
namespace BismNormalizer.TabularCompare
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a Power BI Template (.pbit) file. Constructor loads the file into memory. Provides properties for
|
||||||
|
/// getting and setting the data model json, as well as saving the content back to a .pbit file.
|
||||||
|
/// </summary>
|
||||||
|
internal class PowerBiTemplate
|
||||||
|
{
|
||||||
|
MemoryStream fileData = new MemoryStream();
|
||||||
|
public PowerBiTemplate(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var fs = new FileStream(path, FileMode.Open))
|
||||||
|
{
|
||||||
|
fs.CopyTo(fileData);
|
||||||
|
fileData.Seek(0, SeekOrigin.Begin);
|
||||||
|
using (var za = new ZipArchive(fileData, ZipArchiveMode.Read, true))
|
||||||
|
{
|
||||||
|
var modelEntry = za.Entries.FirstOrDefault(e => e.Name == "DataModelSchema");
|
||||||
|
if (modelEntry != null)
|
||||||
|
{
|
||||||
|
using (var sr = new StreamReader(modelEntry.Open(), Encoding.Unicode, true, 1024, true))
|
||||||
|
{
|
||||||
|
_modelJson = sr.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("This file is not a valid PBIX / PBIT file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string _modelJson;
|
||||||
|
public string ModelJson
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _modelJson;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
SetModelJson(value);
|
||||||
|
_modelJson = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetModelJson(string modelJson)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fileData.Seek(0, SeekOrigin.Begin);
|
||||||
|
using (var za = new ZipArchive(fileData, ZipArchiveMode.Update, true))
|
||||||
|
{
|
||||||
|
var modelEntry = za.Entries.FirstOrDefault(e => e.Name == "DataModelSchema");
|
||||||
|
if (modelEntry != null)
|
||||||
|
{
|
||||||
|
var modelEntryName = modelEntry.FullName;
|
||||||
|
modelEntry.Delete();
|
||||||
|
modelEntry = za.CreateEntry(modelEntryName);
|
||||||
|
var unicodeNoBom = new UnicodeEncoding(false, false);
|
||||||
|
using (var sw = new StreamWriter(modelEntry.Open(), unicodeNoBom, 1024, true))
|
||||||
|
{
|
||||||
|
sw.Write(modelJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("This file is not a valid PBIX / PBIT file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveAs(string path)
|
||||||
|
{
|
||||||
|
fileData.Seek(0, SeekOrigin.Begin);
|
||||||
|
using (var fs = File.Open(path, FileMode.OpenOrCreate, FileAccess.Write))
|
||||||
|
{
|
||||||
|
fs.SetLength(0);
|
||||||
|
fileData.CopyTo(fs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -59,7 +59,7 @@ namespace BismNormalizer.TabularCompare.TabularMetadata
|
|||||||
|
|
||||||
if (_connectionInfo.UseBimFile)
|
if (_connectionInfo.UseBimFile)
|
||||||
{
|
{
|
||||||
_database = JsonSerializer.DeserializeDatabase(File.ReadAllText(_connectionInfo.BimFile));
|
_database = _connectionInfo.OpenDatabaseFromFile();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1767,22 +1767,45 @@ namespace BismNormalizer.TabularCompare.TabularMetadata
|
|||||||
|
|
||||||
//serialize db to json
|
//serialize db to json
|
||||||
SerializeOptions options = new SerializeOptions();
|
SerializeOptions options = new SerializeOptions();
|
||||||
|
bool isPbit = (_connectionInfo.UseBimFile && _connectionInfo.BimFile.ToUpper().EndsWith(".PBIT"));
|
||||||
|
|
||||||
|
if (isPbit)
|
||||||
|
{
|
||||||
|
options.IgnoreInferredProperties = false;
|
||||||
|
options.IgnoreInferredObjects = false;
|
||||||
|
options.IgnoreTimestamps = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
options.IgnoreInferredProperties = true;
|
options.IgnoreInferredProperties = true;
|
||||||
options.IgnoreInferredObjects = true;
|
options.IgnoreInferredObjects = true;
|
||||||
options.IgnoreTimestamps = true;
|
options.IgnoreTimestamps = true;
|
||||||
|
}
|
||||||
options.SplitMultilineStrings = true;
|
options.SplitMultilineStrings = true;
|
||||||
string json = JsonSerializer.SerializeDatabase(_database, options);
|
string json = JsonSerializer.SerializeDatabase(_database, options);
|
||||||
|
|
||||||
//replace db name with "SemanticModel"
|
//replace db name with "SemanticModel"
|
||||||
|
if (!isPbit)
|
||||||
|
{
|
||||||
JObject jDb = JObject.Parse(json);
|
JObject jDb = JObject.Parse(json);
|
||||||
jDb["name"] = "SemanticModel";
|
jDb["name"] = "SemanticModel";
|
||||||
jDb["id"] = "SemanticModel";
|
jDb["id"] = "SemanticModel";
|
||||||
json = jDb.ToString();
|
json = jDb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
if (_connectionInfo.UseBimFile)
|
if (_connectionInfo.UseBimFile)
|
||||||
|
{
|
||||||
|
if (isPbit)
|
||||||
|
{
|
||||||
|
PowerBiTemplate pbit = new PowerBiTemplate(_connectionInfo.BimFile);
|
||||||
|
pbit.ModelJson = json;
|
||||||
|
pbit.SaveAs(_connectionInfo.BimFile);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
File.WriteAllText(_connectionInfo.BimFile, json);
|
File.WriteAllText(_connectionInfo.BimFile, json);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.WriteAllText(_connectionInfo.SsdtBimFile, json);
|
File.WriteAllText(_connectionInfo.SsdtBimFile, json);
|
||||||
@ -2153,7 +2176,7 @@ namespace BismNormalizer.TabularCompare.TabularMetadata
|
|||||||
//script db to json
|
//script db to json
|
||||||
string json = JsonScripter.ScriptCreateOrReplace(_database);
|
string json = JsonScripter.ScriptCreateOrReplace(_database);
|
||||||
|
|
||||||
if (_connectionInfo.UseProject)
|
if (_connectionInfo.UseProject || _connectionInfo.UseBimFile)
|
||||||
{
|
{
|
||||||
//replace db/cube name/id with name of deploymnet db from the project file
|
//replace db/cube name/id with name of deploymnet db from the project file
|
||||||
JObject jScript = JObject.Parse(json);
|
JObject jScript = JObject.Parse(json);
|
||||||
@ -2164,6 +2187,16 @@ namespace BismNormalizer.TabularCompare.TabularMetadata
|
|||||||
((JObject)createOrReplace["database"])["name"] = _connectionInfo.DeploymentServerDatabase;
|
((JObject)createOrReplace["database"])["name"] = _connectionInfo.DeploymentServerDatabase;
|
||||||
((JObject)createOrReplace["database"])["id"] = _connectionInfo.DeploymentServerDatabase;
|
((JObject)createOrReplace["database"])["id"] = _connectionInfo.DeploymentServerDatabase;
|
||||||
}
|
}
|
||||||
|
else if (_connectionInfo.UseBimFile)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileNameWithoutExtension(_connectionInfo.BimFile);
|
||||||
|
((JObject)createOrReplace["object"])["database"] = fileName;
|
||||||
|
((JObject)createOrReplace["database"])["name"] = fileName;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
json = jScript.ToString();
|
json = jScript.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +492,7 @@ namespace BismNormalizer.TabularCompare.UI
|
|||||||
{
|
{
|
||||||
OpenFileDialog ofd = new OpenFileDialog();
|
OpenFileDialog ofd = new OpenFileDialog();
|
||||||
ofd.InitialDirectory = (String.IsNullOrEmpty(Settings.Default.LastBimFileLocation) ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) : Settings.Default.LastBimFileLocation);
|
ofd.InitialDirectory = (String.IsNullOrEmpty(Settings.Default.LastBimFileLocation) ? Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) : Settings.Default.LastBimFileLocation);
|
||||||
ofd.Filter = "BIM Files (.bim)|*.bim|All files (*.*)|*.*";
|
ofd.Filter = "PBIT files (.pbit)|*.pbit|BIM files (.bim)|*.bim|All files (*.*)|*.*";
|
||||||
ofd.Title = "Open";
|
ofd.Title = "Open";
|
||||||
return ofd;
|
return ofd;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user