Skip to content

Commit d33863d

Browse files
authored
Merge pull request #35 from ricaun-io/develop
Version 1.2.0
2 parents 55cd69c + fcb7a19 commit d33863d

File tree

11 files changed

+157
-51
lines changed

11 files changed

+157
-51
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [1.2.0] / 2023-10-28
8+
### Features
9+
- Application works offline.
10+
- Application force Revit Login.
11+
### Application
12+
- Update `ricaun.Auth.Aps.UI` to 1.0.4
13+
- Update scope to `OpenId`.
14+
- Update only with `IsLoggedIn` and same `UserId`.
15+
716
## [1.1.3] / 2023-10-16
817
### Features
918
- Application show error in log if fail.
@@ -321,6 +330,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
321330
- [x] TestsFail
322331

323332
[vNext]: ../../compare/1.0.0...HEAD
333+
[1.2.0]: ../../compare/1.1.3...1.2.0
324334
[1.1.3]: ../../compare/1.1.2...1.1.3
325335
[1.1.2]: ../../compare/1.1.1...1.1.2
326336
[1.1.1]: ../../compare/1.1.0...1.1.1

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>1.1.3</Version>
3+
<Version>1.2.0</Version>
44
</PropertyGroup>
55
</Project>

ricaun.RevitTest.Application/Revit/App.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,16 @@ private static void PipeTestServer_Initialize()
126126
response.Tests = null;
127127
});
128128

129-
TestAssemblyModel ApsApplicationCheckTest()
129+
TestAssemblyModel ApsApplicationCheckTest(UIApplication uiapp)
130130
{
131131
try
132132
{
133+
if (Autodesk.Revit.ApplicationServices.Application.IsLoggedIn == false)
134+
{
135+
var exceptionNeedLoggedIn = new Exception("There is no user connected to Revit.");
136+
return TestEngine.Fail(message.TestPathFile, exceptionNeedLoggedIn, testFilterNames);
137+
}
138+
133139
if (ApsApplication.ApsApplication.IsConnected == false)
134140
{
135141
PipeTestServer.Update((response) =>
@@ -153,23 +159,33 @@ TestAssemblyModel ApsApplicationCheckTest()
153159
return await ApsApplicationCheck.Check();
154160
});
155161
var apsResponse = task.GetAwaiter().GetResult();
156-
if (apsResponse is null || apsResponse.isValid == false)
162+
if (apsResponse is not null && apsResponse.isValid == false)
157163
{
158-
var exceptionNotValid = new Exception($"The user is not valid, {apsResponse.message}");
164+
var exceptionNotValid = new Exception($"The user is not valid, {apsResponse?.message}");
159165
return TestEngine.Fail(message.TestPathFile, exceptionNotValid, testFilterNames);
160166
}
161167
}
168+
169+
if (ApsApplication.ApsApplication.IsConnected == true)
170+
{
171+
var revitLoginUserId = uiapp.Application.LoginUserId;
172+
var apsLoginUserId = ApsApplication.ApsApplication.LoginUserId;
173+
var isSameUserId = apsLoginUserId.Equals(revitLoginUserId);
174+
175+
if (isSameUserId == false)
176+
{
177+
var exceptionDifferentLoginUserId = new Exception($"The user connected to Revit is different from the user connected to 'ricaun.Auth'.");
178+
return TestEngine.Fail(message.TestPathFile, exceptionDifferentLoginUserId, testFilterNames);
179+
}
180+
}
162181
}
163182
catch (Exception ex)
164183
{
165184
Debug.WriteLine(ex);
166185
}
167186
return null;
168187
}
169-
var testAssemblyModel = await RevitTask.Run((uiapp) =>
170-
{
171-
return ApsApplicationCheckTest();
172-
});
188+
var testAssemblyModel = await RevitTask.Run(ApsApplicationCheckTest);
173189

174190
if (testAssemblyModel is null)
175191
{

ricaun.RevitTest.Application/Revit/ApsApplication/ApsApplication.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,46 @@ public static class ApsApplication
1010
public static string ClientId = "Ko1ABEYpRPL7K8ju1JYUAUzG5pkguxVQ";
1111
public static int ClientPort = 52000;
1212
public static string[] ClientScopes = new string[] {
13-
ApsScope.UserProfileRead,
13+
ApsScope.Openid,
1414
};
1515

1616
public static ApsService ApsService;
1717
public static bool IsConnected => ApsService?.IsConnected ?? false;
18+
public static string LoginUserId => GetLoginUserId();
19+
public static string GetLoginUserId()
20+
{
21+
if (IsConnected == false)
22+
return string.Empty;
23+
24+
var data = ApsService.ApsClient?.GetAccessToken()?.GetDataBase();
25+
26+
if (data is null)
27+
return string.Empty;
28+
29+
return data.UserId;
30+
}
1831
public static async Task Initialize()
1932
{
2033
ApsService = new ApsService(ClientId, ClientScopes) { ClientPort = ClientPort };
2134
await ApsService.Initialize();
2235
//System.Console.WriteLine($"ApsService: {ApsService.IsConnected}");
2336
}
37+
38+
/// <summary>
39+
/// Login
40+
/// </summary>
41+
/// <returns></returns>
42+
public static async Task<bool> Login()
43+
{
44+
return await ApsService.Login();
45+
}
46+
/// <summary>
47+
/// Logout
48+
/// </summary>
49+
/// <returns></returns>
50+
public static async Task Logout()
51+
{
52+
await ApsService.Logout();
53+
}
2454
}
2555
}

ricaun.RevitTest.Application/Revit/ApsApplication/ApsApplicationCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static class ApsApplicationCheck
1212
public static async Task<ApsResponse> Check()
1313
{
1414
ApsResponse result = null;
15-
Debug.WriteLine($"Check[{ApsApplication.IsConnected}]: check/{AppApsUtils.AppId}/{AppApsUtils.AppVersion}");
15+
Debug.WriteLine($"Aps Check[{ApsApplication.IsConnected}]: check/{AppApsUtils.AppId}/{AppApsUtils.AppVersion}");
1616
if (ApsApplication.IsConnected)
1717
{
1818
try
@@ -26,7 +26,7 @@ public static async Task<ApsResponse> Check()
2626
}
2727
catch (Exception ex)
2828
{
29-
Debug.WriteLine(ex);
29+
Debug.WriteLine($"Aps Check: {ex.GetType()}");
3030
}
3131
}
3232
return result;

ricaun.RevitTest.Application/Revit/ApsApplication/ApsApplicationLogger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class ApsApplicationLogger
1313
public static async Task<string> Log(string type, string message, int appCount = 1)
1414
{
1515
string result = null;
16-
Debug.WriteLine($"Log[{ApsApplication.IsConnected}]: {type} {message} | {appCount}");
16+
Debug.WriteLine($"Aps Log[{ApsApplication.IsConnected}]: {type} {message} | {appCount}");
1717
if (ApsApplication.IsConnected)
1818
{
1919
try
@@ -28,7 +28,7 @@ public static async Task<string> Log(string type, string message, int appCount =
2828
}
2929
catch (Exception ex)
3030
{
31-
Debug.WriteLine(ex);
31+
Debug.WriteLine($"Aps Log: {ex.GetType()}");
3232
}
3333
}
3434
return result;

ricaun.RevitTest.Application/Revit/ApsApplication/ApsApplicationView.cs

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,79 @@ public static class ApsApplicationView
1919
/// </summary>
2020
public static void OpenApsView(bool showDialog = false)
2121
{
22-
if (apsView is null)
22+
try
2323
{
24-
var apsService = new ApsService(ApsApplication.ClientId, ApsApplication.ClientScopes)
24+
if (apsView is null)
2525
{
26-
ClientPort = ApsApplication.ClientPort,
27-
};
28-
var isConnected = ApsApplication.IsConnected;
29-
Debug.WriteLine($"ApsView: {typeof(ApsView).Assembly}");
30-
31-
apsView = new ApsView(Autodesk.Windows.ComponentManager.ApplicationWindow);
32-
apsView.SetApsConfiguration(apsService);
33-
apsView.Closed += (s, e) => { apsService?.Dispose(); };
34-
apsView.Closed += (s, e) => { apsView = null; };
35-
apsView.Closed += async (s, e) =>
36-
{
37-
if (isConnected == false)
26+
var apsService = new ApsService(ApsApplication.ClientId, ApsApplication.ClientScopes)
3827
{
39-
var result = await ApsApplicationLogger.Log("Login", $"Login with ApsView {typeof(ApsView).Assembly.GetName().Version.ToString(3)}");
40-
Debug.WriteLine($"Login: {result}");
41-
}
42-
};
28+
ClientPort = ApsApplication.ClientPort,
29+
};
30+
var isConnected = ApsApplication.IsConnected;
31+
Debug.WriteLine($"ApsView: {typeof(ApsView).Assembly}");
4332

44-
if (showDialog)
45-
{
46-
apsService.Connected += async (client) =>
33+
apsView = new ApsView(Autodesk.Windows.ComponentManager.ApplicationWindow);
34+
apsView.SetApsConfiguration(apsService);
35+
apsView.Closed += (s, e) => { apsService?.Dispose(); };
36+
apsView.Closed += (s, e) => { apsView = null; };
37+
apsView.Closed += async (s, e) =>
4738
{
48-
Debug.WriteLine($"ApsView: [Connected] was conencted = {isConnected}");
4939
if (isConnected == false)
5040
{
51-
await Task.Delay(MillisecondsDelayCloseAfterConnected);
52-
apsView?.Close();
41+
var result = await ApsApplicationLogger.Log("Login", $"Login with ApsView {typeof(ApsView).Assembly.GetName().Version.ToString(3)}");
42+
Debug.WriteLine($"Login: {result}");
5343
}
5444
};
5545

56-
Task.Run(async () =>
46+
if (showDialog)
5747
{
58-
await Task.Delay(MillisecondsDelayAutoClose);
59-
if (apsView != null)
48+
apsService.Connected += async (client) =>
6049
{
61-
Debug.WriteLine($"ApsView: [AutoClose] {MillisecondsDelayAutoClose}");
62-
try
50+
Debug.WriteLine($"ApsView: [Connected] was conencted = {isConnected}");
51+
if (isConnected == false)
6352
{
64-
apsView?.Dispatcher?.Invoke(() => { apsView?.Close(); });
53+
await Task.Delay(MillisecondsDelayCloseAfterConnected);
54+
apsView?.Close();
6555
}
66-
catch (System.Exception ex)
56+
};
57+
58+
Task.Run(async () =>
59+
{
60+
await Task.Delay(MillisecondsDelayAutoClose);
61+
if (apsView != null)
6762
{
68-
System.Console.WriteLine(ex);
63+
Debug.WriteLine($"ApsView: [AutoClose] {MillisecondsDelayAutoClose}");
64+
try
65+
{
66+
apsView?.Dispatcher?.Invoke(() => { apsView?.Close(); });
67+
}
68+
catch (System.Exception ex)
69+
{
70+
System.Console.WriteLine(ex);
71+
}
6972
}
70-
}
71-
});
73+
});
7274

73-
apsView.ShowDialog();
75+
apsView.ShowDialog();
76+
}
77+
apsView?.Show();
7478
}
75-
apsView?.Show();
79+
apsView?.Activate();
80+
}
81+
catch (System.Exception)
82+
{
83+
Task.Run(async () =>
84+
{
85+
if (ApsApplication.IsConnected)
86+
{
87+
await ApsApplication.Logout();
88+
}
89+
else
90+
{
91+
await ApsApplication.Login();
92+
}
93+
});
7694
}
77-
apsView?.Activate();
7895
}
7996
}
8097
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Autodesk.Revit.Attributes;
2+
using Autodesk.Revit.DB;
3+
using Autodesk.Revit.UI;
4+
5+
namespace ricaun.RevitTest.Application.Revit.ApsApplication
6+
{
7+
[Transaction(TransactionMode.Manual)]
8+
public class CommandApsLogin : IExternalCommand
9+
{
10+
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
11+
{
12+
UIApplication uiapp = commandData.Application;
13+
14+
ApsApplication.Login();
15+
16+
return Result.Succeeded;
17+
}
18+
}
19+
20+
[Transaction(TransactionMode.Manual)]
21+
public class CommandApsLogout : IExternalCommand
22+
{
23+
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
24+
{
25+
UIApplication uiapp = commandData.Application;
26+
27+
ApsApplication.Logout();
28+
29+
return Result.Succeeded;
30+
}
31+
}
32+
33+
}

ricaun.RevitTest.Application/ricaun.RevitTest.Application.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133

134134
<ItemGroup>
135135
<PackageReference Include="Revit.Busy" Version="*" />
136-
<PackageReference Include="ricaun.Auth.Aps.UI" Version="*" />
136+
<PackageReference Include="ricaun.Auth.Aps.UI" Version="1.0.3" />
137137
<PackageReference Include="ricaun.Revit.UI" Version="0.5.2" />
138138
<PackageReference Include="ricaun.Revit.Async" Version="1.0.4" />
139139
<PackageReference Include="ricaun.NUnit" Version="*" />
1.28 KB
Binary file not shown.

0 commit comments

Comments
 (0)