-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathPBICloudDataset.cs
230 lines (187 loc) · 8.38 KB
/
PBICloudDataset.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
namespace Sqlbi.Bravo.Models
{
using Sqlbi.Bravo.Infrastructure;
using Sqlbi.Bravo.Infrastructure.Contracts.PBICloud;
using Sqlbi.Bravo.Infrastructure.Extensions;
using Sqlbi.Bravo.Infrastructure.Helpers;
using Sqlbi.Bravo.Infrastructure.Models;
using Sqlbi.Bravo.Infrastructure.Models.PBICloud;
using Sqlbi.Bravo.Infrastructure.Services.PowerBI;
using System;
using System.Diagnostics;
using System.Text.Json.Serialization;
[DebuggerDisplay("{WorkspaceName} - {DisplayName} - {ConnectionMode}")]
public class PBICloudDataset : IDataModel<PBICloudDataset>
{
[JsonPropertyName("workspaceId")]
public string? WorkspaceId { get; set; }
[JsonPropertyName("workspaceName")]
public string? WorkspaceName { get; set; }
[JsonPropertyName("workspaceObjectId")]
public string? WorkspaceObjectId { get; set; }
[JsonPropertyName("id")]
public long? Id { get; set; }
[JsonPropertyName("serverName")]
public string? ServerName { get; set; }
[JsonPropertyName("databaseName")]
public string? DatabaseName { get; set; }
[JsonPropertyName("externalServerName")]
public string? ExternalServerName { get; set; }
[JsonPropertyName("externalDatabaseName")]
public string? ExternalDatabaseName { get; set; }
[JsonPropertyName("name")]
public string? DisplayName { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
[JsonPropertyName("owner")]
public string? Owner { get; set; }
[JsonPropertyName("refreshed")]
public DateTime? Refreshed { get; set; }
[JsonPropertyName("onPremModelConnectionString")]
public string? OnPremModelConnectionString { get; set; }
[JsonPropertyName("endorsement")]
public PBICloudDatasetEndorsement? Endorsement { get; set; }
[JsonPropertyName("workspaceType")]
public PBICloudDatasetWorkspaceType? WorkspaceType { get; set; }
[JsonPropertyName("capacitySkuType")]
public PBICloudDatasetCapacitySkuType? CapacitySkuType { get; set; }
[JsonPropertyName("isPushDataEnabled")]
public bool? IsPushDataEnabled { get; set; }
[JsonPropertyName("isExcelWorkbook")]
public bool? IsExcelWorkbook { get; set; }
[JsonPropertyName("isOnPremModel")]
public bool? IsOnPremModel { get; set; }
[JsonPropertyName("isPremiumCapacity")]
public bool? IsPremiumCapacity { get; set; }
[JsonPropertyName("isXmlaEndPointSupported")]
public bool IsXmlaEndPointSupported
{
get
{
if (IsPremiumCapacity is null || IsPremiumCapacity == false)
return false;
// Exclude unsupported datasets - a.k.a. datasets not accessible by the XMLA endpoint
// see https://docs.microsoft.com/en-us/power-bi/admin/service-premium-connect-tools#unsupported-datasets
// Datasets in 'My Workspace' are unsupported
if (WorkspaceType == PBICloudDatasetWorkspaceType.PersonalGroup)
return false;
// Datasets based on a live connection to an Azure Analysis Services or SQL Server Analysis Services model are unsupported
if (IsOnPremModel ?? false)
return false;
// TODO: Exclude datasets based on a live connection to a Power BI dataset in another workspace
// if ( ... )
// return false;
// Datasets with Push data by using the REST API are unsupported
if (IsPushDataEnabled ?? false)
return false;
// Excel workbook datasets are unsupported
if (IsExcelWorkbook ?? false)
return false;
return true;
}
}
[JsonPropertyName("connectionMode")]
public PBICloudDatasetConnectionMode ConnectionMode { get; set; } = PBICloudDatasetConnectionMode.Unknown;
public override bool Equals(object? obj)
{
return Equals(obj as PBICloudDataset);
}
public bool Equals(PBICloudDataset? other)
{
return other != null &&
WorkspaceId == other.WorkspaceId &&
Id == other.Id;
}
public override int GetHashCode()
{
HashCode hash = new();
hash.Add(WorkspaceId);
hash.Add(Id);
return hash.ToHashCode();
}
internal static PBICloudDataset CreateFrom(IPBICloudEnvironment environment, CloudWorkspace cloudWorkspace, CloudSharedModel cloudSharedModel)
{
BravoUnexpectedException.ThrowIfNull(cloudWorkspace);
BravoUnexpectedException.ThrowIfNull(cloudSharedModel);
BravoUnexpectedException.ThrowIfNull(cloudSharedModel.Model);
var cloudModel = cloudSharedModel.Model;
var dataset = new PBICloudDataset
{
WorkspaceId = cloudWorkspace.Id,
WorkspaceName = cloudWorkspace.Name.NullIfEmpty() ?? cloudSharedModel.WorkspaceName,
WorkspaceObjectId = cloudWorkspace.ObjectId,
Id = cloudModel.Id,
ServerName = CommonHelper.ChangeUriScheme(environment.ServiceEndpoint, PBICloudService.PBIDatasetProtocolScheme, ignorePort: true),
DatabaseName = cloudModel.DBName,
ExternalServerName = null,
ExternalDatabaseName = null,
DisplayName = cloudModel.DisplayName,
Description = cloudModel.Description,
Owner = $"{ cloudModel.CreatorUser?.GivenName } { cloudModel.CreatorUser?.FamilyName }",
Refreshed = cloudModel.LastRefreshTime,
OnPremModelConnectionString = cloudModel.OnPremModelConnectionString,
Endorsement = cloudSharedModel.GalleryItem?.Stage.TryParseTo<PBICloudDatasetEndorsement>(),
WorkspaceType = cloudSharedModel.WorkspaceType.TryParseTo<PBICloudDatasetWorkspaceType>(),
CapacitySkuType = cloudWorkspace.CapacitySkuType.TryParseTo<PBICloudDatasetCapacitySkuType>(),
IsPremiumCapacity = cloudWorkspace.IsPremiumCapacity,
IsPushDataEnabled = cloudModel.IsPushDataEnabled,
IsExcelWorkbook = cloudModel.IsExcelWorkbook,
IsOnPremModel = cloudModel.IsOnPremModel,
ConnectionMode = PBICloudDatasetConnectionMode.Supported,
};
if (dataset.IsXmlaEndPointSupported)
{
dataset.ExternalServerName = CommonHelper.ChangeUriScheme(environment.ClusterEndpoint, PBICloudService.PBIPremiumXmlaEndpointProtocolScheme, ignorePort: true);
dataset.ExternalDatabaseName = cloudModel.DisplayName;
}
else if (dataset.IsOnPremModel == true)
{
var properties = ConnectionStringHelper.GetConnectionStringProperties(dataset.OnPremModelConnectionString);
dataset.ExternalServerName = dataset.ServerName = properties.ServerName;
dataset.ExternalDatabaseName = dataset.DatabaseName = properties.DatabaseName;
}
else
{
dataset.ExternalServerName = dataset.ServerName;
dataset.ExternalDatabaseName = $"{ cloudModel.VSName }-{ cloudModel.DBName }";
}
return dataset;
}
}
/// <summary>
/// Re-mapping <see cref="CloudPromotionalStage"/>
/// </summary>
public enum PBICloudDatasetEndorsement
{
[JsonPropertyName("None")]
None = 0,
[JsonPropertyName("Promoted")]
Promoted = 1,
[JsonPropertyName("Certified")]
Certified = 2,
}
/// <summary>
/// Re-mapping <see cref="CloudSharedModelWorkspaceType"/>
/// </summary>
public enum PBICloudDatasetWorkspaceType
{
Personal = 0,
Workspace = 1,
Group = 2,
PersonalGroup = 3
}
/// <summary>
/// Re-mapping <see cref="CloudWorkspaceCapacitySkuType"/>
/// </summary>
public enum PBICloudDatasetCapacitySkuType
{
Unknown = 0,
Premium,
Shared,
}
public enum PBICloudDatasetConnectionMode
{
Unknown = 0,
Supported = 1,
}
}