添加项目文件。

This commit is contained in:
GG Z
2024-01-08 09:30:50 +08:00
commit 1ccc4b3047
85 changed files with 5904 additions and 0 deletions

View File

@@ -0,0 +1,482 @@
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Net.Http;
using System.Security.Cryptography;
using KGdev.BI3D.Revit.Common;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json.Linq;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultAuthProvider : IAuthProvider
{
public DefaultAuthProvider(
string productId,
IMuidProvider muidProvider,
IGlobalStore globalStore
)
{
this.productId = productId;
this.muidProvider = muidProvider;
this.globalStore = globalStore;
}
public bool IsTrial(string token)
{
JwtSecurityToken securityToken = this.GetSecurityToken(token);
bool flag = !securityToken.Payload.ContainsKey("META_LICENSE_TYPE");
bool flag2;
if (flag)
{
flag2 = false;
}
else
{
string text = securityToken.Payload["META_LICENSE_TYPE"].ToString();
flag2 = text == "TRIAL";
}
return flag2;
}
public int LicenseTypeInt(string token)
{
int num = 1;
JwtSecurityToken securityToken = this.GetSecurityToken(token);
bool flag = securityToken.Payload.ContainsKey("META_LICENSE_TYPE");
if (flag)
{
string text = securityToken.Payload["META_LICENSE_TYPE"].ToString();
bool flag2 = text == "TRIAL";
if (flag2)
{
num = 0;
}
else
{
bool flag3 = text == "PERSONAL";
if (flag3)
{
num = 1;
}
else
{
bool flag4 = text == "REVIEW";
if (flag4)
{
num = 2;
}
else
{
bool flag5 = text == "ENTERPRISE";
if (flag5)
{
num = 3;
}
else
{
bool flag6 = text == "ROYALTY_FREE";
if (flag6)
{
num = 4;
}
}
}
}
}
}
return num;
}
public bool TryUpdateToken(string key)
{
bool flag2;
try
{
string muid = this.muidProvider.GetMuid();
string text = string.Concat(
new string[]
{
"https://consumer.licensing.kg-dev.be/api/LicenseToken?key=",
key,
"&client=",
muid,
"&productreference=",
this.productId
}
);
HttpClient httpClient = new HttpClient();
HttpResponseMessage result = httpClient.GetAsync(text).Result;
string result2 = result.Content.ReadAsStringAsync().Result;
JObject jobject = null;
try
{
jobject = JObject.Parse(result2);
}
catch
{
throw new Exception("Failed to parse: " + result2);
}
JToken jtoken = null;
jobject.TryGetValue("token", out jtoken);
bool flag = jtoken == null;
if (flag)
{
throw new Exception("Response does not contain a token.");
}
string text2 = jtoken.Value<string>();
this.globalStore.SetToken(text2);
flag2 = true;
}
catch (Exception ex)
{
string token = this.globalStore.GetToken();
bool flag3 = this.ValidateToken(token);
bool flag4 = !flag3;
if (flag4)
{
this.globalStore.SetToken(
(ex.InnerException != null) ? ex.InnerException.Message : ex.Message
);
}
flag2 = false;
}
return flag2;
}
public bool ValidateToken(string token)
{
bool flag3;
try
{
JwtSecurityToken securityToken = this.GetSecurityToken(token);
bool flag = !securityToken.Payload.ContainsKey("certserialnumber");
if (flag)
{
throw new Exception("No certserialnumber given.");
}
string text = securityToken.Payload["certserialnumber"].ToString();
string muid = this.muidProvider.GetMuid();
bool flag2 =
string.IsNullOrWhiteSpace(muid)
|| string.IsNullOrWhiteSpace(text)
|| muid != text;
if (flag2)
{
throw new Exception("Not Licensed.");
}
flag3 = true;
}
catch (Exception ex)
{
flag3 = false;
}
return flag3;
}
private JwtSecurityToken GetSecurityToken(string token)
{
RSAParameters rsaparameters = new RSAParameters
{
Modulus = new byte[]
{
158,
172,
231,
226,
231,
91,
212,
107,
240,
26,
173,
150,
233,
20,
187,
54,
239,
143,
195,
143,
77,
126,
138,
22,
181,
236,
24,
20,
3,
224,
189,
11,
236,
47,
58,
114,
141,
189,
239,
40,
208,
181,
43,
209,
40,
144,
218,
84,
117,
207,
2,
190,
103,
137,
213,
129,
224,
241,
173,
144,
242,
6,
86,
156,
183,
160,
59,
192,
96,
122,
33,
215,
20,
8,
55,
189,
92,
8,
165,
48,
126,
0,
64,
161,
240,
3,
79,
196,
238,
226,
193,
246,
133,
181,
43,
214,
147,
31,
132,
157,
19,
22,
43,
246,
5,
40,
172,
79,
98,
121,
66,
46,
99,
251,
194,
237,
108,
235,
179,
75,
225,
166,
206,
215,
115,
17,
145,
188,
36,
129,
49,
216,
240,
177,
91,
216,
59,
200,
166,
108,
195,
105,
248,
137,
61,
159,
167,
40,
18,
154,
190,
40,
136,
32,
59,
239,
40,
239,
130,
32,
223,
81,
167,
30,
201,
151,
86,
95,
128,
35,
1,
215,
128,
178,
21,
169,
28,
71,
154,
139,
91,
52,
27,
87,
31,
58,
21,
169,
159,
156,
189,
84,
79,
185,
120,
109,
24,
83,
220,
122,
68,
213,
220,
50,
56,
188,
176,
52,
140,
54,
64,
161,
31,
55,
246,
32,
246,
141,
186,
183,
107,
102,
235,
139,
147,
81,
15,
231,
44,
193,
7,
117,
251,
byte.MaxValue,
53,
98,
187,
41,
213,
157,
92,
byte.MaxValue,
222,
71,
7,
69,
85,
225,
237,
117,
142,
164,
48,
96,
220,
191
},
Exponent = new byte[] { 1, 0, 1 }
};
RSACryptoServiceProvider rsacryptoServiceProvider = new RSACryptoServiceProvider(2048);
rsacryptoServiceProvider.ImportParameters(rsaparameters);
RsaSecurityKey rsaSecurityKey = new RsaSecurityKey(rsacryptoServiceProvider);
TokenValidationParameters tokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = rsaSecurityKey,
RequireSignedTokens = true,
RequireExpirationTime = true,
ValidateLifetime = true,
ValidateAudience = true,
ValidAudiences = new string[] { this.productId },
ValidateIssuer = false
};
JwtSecurityTokenHandler jwtSecurityTokenHandler = new JwtSecurityTokenHandler();
SecurityToken securityToken;
jwtSecurityTokenHandler.ValidateToken(
token,
tokenValidationParameters,
out securityToken
);
return (JwtSecurityToken)securityToken;
}
private const string LICENSE_TYPE_CLAIM_NAME = "META_LICENSE_TYPE";
private const string TRIAL = "TRIAL";
private const string PERSONAL = "PERSONAL";
private const string REVIEW = "REVIEW";
private const string ENTERPRISE = "ENTERPRISE";
private const string ROYALTY_FREE = "ROYALTY_FREE";
private readonly string productId;
private readonly IMuidProvider muidProvider;
private readonly IGlobalStore globalStore;
}
}

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using KGdev.BI3D.Revit.Common;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultBI3DViewsProvider : IBI3DViewsProvider
{
public View3D GetContextView3D(Document document)
{
Element element2 = (
from element in new FilteredElementCollector(document)
.WhereElementIsNotElementType()
.OfCategory(BuiltInCategory.OST_Views)
.OfClass(typeof(View3D))
where element.Name == "3DBI-Context"
select element
).FirstOrDefault<Element>();
return element2 as View3D;
}
public List<View3D> GetScenes(Document document)
{
return new FilteredElementCollector(document)
.OfCategory(BuiltInCategory.OST_Views)
.WhereElementIsNotElementType()
.OfClass(typeof(View3D))
.Cast<View3D>()
.Where(
delegate(View3D v)
{
bool flag;
try
{
flag = v.IsPerspective && v.Name.StartsWith("3DBI_");
}
catch
{
flag = false;
}
return flag;
}
)
.ToList<View3D>();
}
public string GetSceneName(View3D view)
{
return view.Name.StartsWith("3DBI_") ? view.Name.Substring("3DBI_".Length) : view.Name;
}
private const string CONTEXT_VIEW_NAME = "3DBI-Context";
private const string VIEW_IS_SCENE_PREFIX = "3DBI_";
}
}

View File

@@ -0,0 +1,16 @@
using System;
using KGdev.BI3D.Revit.Common;
namespace KGdev.BI3D.Revit.Implementations
{
public class DefaultConstantsProvider : IConstantsProvider
{
public string ProductId { get; } = "3DBI_REVIT";
public string PurchaseUrl { get; } = "https://kg-dev.be/project/3dbi-for-revit";
public string ViewerAndExamplesFolderName { get; } = "3dbi_viewer_and_examples";
public string TrialKey { get; } = "3DBI-REVIT-TRIAL-14DAYS";
}
}

View File

@@ -0,0 +1,17 @@
using System;
using Autodesk.Revit.DB;
using KGdev.BI3D.Revit.Common;
using KGdev.BI3D.Revit.Common.Models;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultElementIdProvider : IElementIdProvider
{
public string GetElementId(LinkedElementIdPath elementIdPath)
{
return string.Join<ElementId>("-", elementIdPath.ElementIds);
}
private const string SEPARATOR = "-";
}
}

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.IO;
using KGdev.BI3D.Revit.Common;
using Newtonsoft.Json;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultGlobalStore : IGlobalStore
{
public string GetKey()
{
return this.Read("key");
}
public string GetToken()
{
return this.Read("token");
}
public void SetKey(string key)
{
this.Write("key", key);
}
public void SetToken(string token)
{
this.Write("token", token);
}
public string GetAppTempDirectoryPath()
{
return this.BuildFolderPath();
}
public Dictionary<string, object> GetDefaultExporterChosenOptionValues()
{
Dictionary<string, object> dictionary = new Dictionary<string, object>();
string text = this.Read("defaultOptionValues");
try
{
dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(text);
}
catch { }
return dictionary;
}
public void SetDefaultExporterChosenOptionValues(
Dictionary<string, object> valuesDictionary
)
{
string text = JsonConvert.SerializeObject(valuesDictionary);
this.Write("defaultOptionValues", text);
}
private string Read(string key)
{
string text = this.BuildPath(key);
bool flag = !File.Exists(text);
string text2;
if (flag)
{
text2 = null;
}
else
{
text2 = File.ReadAllText(text);
}
return text2;
}
private void Write(string key, string value)
{
string text = this.BuildPath(key);
File.WriteAllText(text, value);
}
private string BuildFolderPath()
{
string folderPath = Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData
);
string text = Path.Combine(folderPath, ".3dbi-for-revit");
Directory.CreateDirectory(text);
return text;
}
private string BuildPath(string key)
{
string text = this.BuildFolderPath();
return Path.Combine(text, key + ".setting");
}
private const string DIRECTORY_NAME = ".3dbi-for-revit";
private const string SETTINGS_FILE_EXTENSION = ".setting";
private const string KEY_KEY = "key";
private const string KEY_TOKEN = "token";
private const string KEY_DEFAULT_OPTION_VALUES = "defaultOptionValues";
}
}

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using KGdev.BI3D.Revit.Common;
using KGdev.BI3D.Revit.Common.Models;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultLinkedDocumentUtilities : ILinkedDocumentsUtilities
{
public Element GetElement(Document rootDocument, LinkedElementIdPath path)
{
Document document = rootDocument;
Queue<ElementId> queue = new Queue<ElementId>(path.ElementIds);
Element element = null;
while (queue.Count > 0)
{
ElementId elementId = queue.Dequeue();
bool flag = queue.Count == 0;
if (flag)
{
element = document.GetElement(elementId);
}
else
{
RevitLinkInstance revitLinkInstance =
document.GetElement(elementId) as RevitLinkInstance;
document = revitLinkInstance.GetLinkDocument();
}
}
return element;
}
public IList<LinkedDocumentInformation> GetLinkedDocuments(
Document rootDocument,
Transform baseTransform,
bool includeThis,
List<ElementId> passedLinkInstanceIds
)
{
List<LinkedDocumentInformation> list = new List<LinkedDocumentInformation>();
if (includeThis)
{
list.Add(
new LinkedDocumentInformation
{
Document = rootDocument,
TransformToRoot = baseTransform,
PassedLinkInstanceIds = passedLinkInstanceIds
}
);
}
IEnumerable<RevitLinkInstance> enumerable = new FilteredElementCollector(rootDocument)
.OfCategory(BuiltInCategory.OST_RvtLinks)
.OfClass(typeof(RevitLinkInstance))
.Cast<RevitLinkInstance>();
foreach (RevitLinkInstance revitLinkInstance in enumerable)
{
bool flag = !revitLinkInstance.IsValidObject;
if (!flag)
{
Document linkDocument = revitLinkInstance.GetLinkDocument();
bool flag2 = linkDocument == null || !linkDocument.IsValidObject;
if (!flag2)
{
Transform transform = baseTransform.Multiply(
revitLinkInstance.GetTransform()
);
List<ElementId> list2 = new List<ElementId>();
list2.AddRange(passedLinkInstanceIds);
list2.Add(revitLinkInstance.Id);
IList<LinkedDocumentInformation> linkedDocuments = this.GetLinkedDocuments(
linkDocument,
transform,
true,
list2
);
list.AddRange(linkedDocuments);
}
}
}
return list;
}
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using KGdev.BI3D.Revit.Common;
namespace KGdev.BI3D.Revit.Implementations
{
internal class DefaultMuidProvider : IMuidProvider
{
public string GetMuid()
{
string text = "wmic";
bool flag = File.Exists("C:\\Windows\\System32\\wbem\\WMIC.exe");
if (flag)
{
text = "C:\\Windows\\System32\\wbem\\WMIC.exe";
}
else
{
bool flag2 = File.Exists("C:\\Windows\\System32\\WMIC.exe");
if (flag2)
{
text = "C:\\Windows\\System32\\WMIC.exe";
}
}
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = text,
Arguments = "path win32_computersystemproduct get uuid /Value",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
}
};
process.Start();
string text2 = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return text2.Trim().Split(new char[] { '=' }).Last<string>();
}
}
}