Skip to content

Commit

Permalink
Merge pull request #35 from ricaun-io/develop
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
ricaun authored Oct 30, 2023
2 parents 55cd69c + fcb7a19 commit d33863d
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 51 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.2.0] / 2023-10-28
### Features
- Application works offline.
- Application force Revit Login.
### Application
- Update `ricaun.Auth.Aps.UI` to 1.0.4
- Update scope to `OpenId`.
- Update only with `IsLoggedIn` and same `UserId`.

## [1.1.3] / 2023-10-16
### Features
- Application show error in log if fail.
Expand Down Expand Up @@ -321,6 +330,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [x] TestsFail

[vNext]: ../../compare/1.0.0...HEAD
[1.2.0]: ../../compare/1.1.3...1.2.0
[1.1.3]: ../../compare/1.1.2...1.1.3
[1.1.2]: ../../compare/1.1.1...1.1.2
[1.1.1]: ../../compare/1.1.0...1.1.1
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.1.3</Version>
<Version>1.2.0</Version>
</PropertyGroup>
</Project>
30 changes: 23 additions & 7 deletions ricaun.RevitTest.Application/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,16 @@ private static void PipeTestServer_Initialize()
response.Tests = null;
});

TestAssemblyModel ApsApplicationCheckTest()
TestAssemblyModel ApsApplicationCheckTest(UIApplication uiapp)
{
try
{
if (Autodesk.Revit.ApplicationServices.Application.IsLoggedIn == false)
{
var exceptionNeedLoggedIn = new Exception("There is no user connected to Revit.");
return TestEngine.Fail(message.TestPathFile, exceptionNeedLoggedIn, testFilterNames);
}

if (ApsApplication.ApsApplication.IsConnected == false)
{
PipeTestServer.Update((response) =>
Expand All @@ -153,23 +159,33 @@ TestAssemblyModel ApsApplicationCheckTest()
return await ApsApplicationCheck.Check();
});
var apsResponse = task.GetAwaiter().GetResult();
if (apsResponse is null || apsResponse.isValid == false)
if (apsResponse is not null && apsResponse.isValid == false)
{
var exceptionNotValid = new Exception($"The user is not valid, {apsResponse.message}");
var exceptionNotValid = new Exception($"The user is not valid, {apsResponse?.message}");
return TestEngine.Fail(message.TestPathFile, exceptionNotValid, testFilterNames);
}
}

if (ApsApplication.ApsApplication.IsConnected == true)
{
var revitLoginUserId = uiapp.Application.LoginUserId;
var apsLoginUserId = ApsApplication.ApsApplication.LoginUserId;
var isSameUserId = apsLoginUserId.Equals(revitLoginUserId);

if (isSameUserId == false)
{
var exceptionDifferentLoginUserId = new Exception($"The user connected to Revit is different from the user connected to 'ricaun.Auth'.");
return TestEngine.Fail(message.TestPathFile, exceptionDifferentLoginUserId, testFilterNames);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
return null;
}
var testAssemblyModel = await RevitTask.Run((uiapp) =>
{
return ApsApplicationCheckTest();
});
var testAssemblyModel = await RevitTask.Run(ApsApplicationCheckTest);

if (testAssemblyModel is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,46 @@ public static class ApsApplication
public static string ClientId = "Ko1ABEYpRPL7K8ju1JYUAUzG5pkguxVQ";
public static int ClientPort = 52000;
public static string[] ClientScopes = new string[] {
ApsScope.UserProfileRead,
ApsScope.Openid,
};

public static ApsService ApsService;
public static bool IsConnected => ApsService?.IsConnected ?? false;
public static string LoginUserId => GetLoginUserId();
public static string GetLoginUserId()
{
if (IsConnected == false)
return string.Empty;

var data = ApsService.ApsClient?.GetAccessToken()?.GetDataBase();

if (data is null)
return string.Empty;

return data.UserId;
}
public static async Task Initialize()
{
ApsService = new ApsService(ClientId, ClientScopes) { ClientPort = ClientPort };
await ApsService.Initialize();
//System.Console.WriteLine($"ApsService: {ApsService.IsConnected}");
}

/// <summary>
/// Login
/// </summary>
/// <returns></returns>
public static async Task<bool> Login()
{
return await ApsService.Login();
}
/// <summary>
/// Logout
/// </summary>
/// <returns></returns>
public static async Task Logout()
{
await ApsService.Logout();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static class ApsApplicationCheck
public static async Task<ApsResponse> Check()
{
ApsResponse result = null;
Debug.WriteLine($"Check[{ApsApplication.IsConnected}]: check/{AppApsUtils.AppId}/{AppApsUtils.AppVersion}");
Debug.WriteLine($"Aps Check[{ApsApplication.IsConnected}]: check/{AppApsUtils.AppId}/{AppApsUtils.AppVersion}");
if (ApsApplication.IsConnected)
{
try
Expand All @@ -26,7 +26,7 @@ public static async Task<ApsResponse> Check()
}
catch (Exception ex)
{
Debug.WriteLine(ex);
Debug.WriteLine($"Aps Check: {ex.GetType()}");
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class ApsApplicationLogger
public static async Task<string> Log(string type, string message, int appCount = 1)
{
string result = null;
Debug.WriteLine($"Log[{ApsApplication.IsConnected}]: {type} {message} | {appCount}");
Debug.WriteLine($"Aps Log[{ApsApplication.IsConnected}]: {type} {message} | {appCount}");
if (ApsApplication.IsConnected)
{
try
Expand All @@ -28,7 +28,7 @@ public static async Task<string> Log(string type, string message, int appCount =
}
catch (Exception ex)
{
Debug.WriteLine(ex);
Debug.WriteLine($"Aps Log: {ex.GetType()}");
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,62 +19,79 @@ public static class ApsApplicationView
/// </summary>
public static void OpenApsView(bool showDialog = false)
{
if (apsView is null)
try
{
var apsService = new ApsService(ApsApplication.ClientId, ApsApplication.ClientScopes)
if (apsView is null)
{
ClientPort = ApsApplication.ClientPort,
};
var isConnected = ApsApplication.IsConnected;
Debug.WriteLine($"ApsView: {typeof(ApsView).Assembly}");

apsView = new ApsView(Autodesk.Windows.ComponentManager.ApplicationWindow);
apsView.SetApsConfiguration(apsService);
apsView.Closed += (s, e) => { apsService?.Dispose(); };
apsView.Closed += (s, e) => { apsView = null; };
apsView.Closed += async (s, e) =>
{
if (isConnected == false)
var apsService = new ApsService(ApsApplication.ClientId, ApsApplication.ClientScopes)
{
var result = await ApsApplicationLogger.Log("Login", $"Login with ApsView {typeof(ApsView).Assembly.GetName().Version.ToString(3)}");
Debug.WriteLine($"Login: {result}");
}
};
ClientPort = ApsApplication.ClientPort,
};
var isConnected = ApsApplication.IsConnected;
Debug.WriteLine($"ApsView: {typeof(ApsView).Assembly}");

if (showDialog)
{
apsService.Connected += async (client) =>
apsView = new ApsView(Autodesk.Windows.ComponentManager.ApplicationWindow);
apsView.SetApsConfiguration(apsService);
apsView.Closed += (s, e) => { apsService?.Dispose(); };
apsView.Closed += (s, e) => { apsView = null; };
apsView.Closed += async (s, e) =>
{
Debug.WriteLine($"ApsView: [Connected] was conencted = {isConnected}");
if (isConnected == false)
{
await Task.Delay(MillisecondsDelayCloseAfterConnected);
apsView?.Close();
var result = await ApsApplicationLogger.Log("Login", $"Login with ApsView {typeof(ApsView).Assembly.GetName().Version.ToString(3)}");
Debug.WriteLine($"Login: {result}");
}
};

Task.Run(async () =>
if (showDialog)
{
await Task.Delay(MillisecondsDelayAutoClose);
if (apsView != null)
apsService.Connected += async (client) =>
{
Debug.WriteLine($"ApsView: [AutoClose] {MillisecondsDelayAutoClose}");
try
Debug.WriteLine($"ApsView: [Connected] was conencted = {isConnected}");
if (isConnected == false)
{
apsView?.Dispatcher?.Invoke(() => { apsView?.Close(); });
await Task.Delay(MillisecondsDelayCloseAfterConnected);
apsView?.Close();
}
catch (System.Exception ex)
};

Task.Run(async () =>
{
await Task.Delay(MillisecondsDelayAutoClose);
if (apsView != null)
{
System.Console.WriteLine(ex);
Debug.WriteLine($"ApsView: [AutoClose] {MillisecondsDelayAutoClose}");
try
{
apsView?.Dispatcher?.Invoke(() => { apsView?.Close(); });
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex);
}
}
}
});
});

apsView.ShowDialog();
apsView.ShowDialog();
}
apsView?.Show();
}
apsView?.Show();
apsView?.Activate();
}
catch (System.Exception)
{
Task.Run(async () =>
{
if (ApsApplication.IsConnected)
{
await ApsApplication.Logout();
}
else
{
await ApsApplication.Login();
}
});
}
apsView?.Activate();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace ricaun.RevitTest.Application.Revit.ApsApplication
{
[Transaction(TransactionMode.Manual)]
public class CommandApsLogin : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

ApsApplication.Login();

return Result.Succeeded;
}
}

[Transaction(TransactionMode.Manual)]
public class CommandApsLogout : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
{
UIApplication uiapp = commandData.Application;

ApsApplication.Logout();

return Result.Succeeded;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@

<ItemGroup>
<PackageReference Include="Revit.Busy" Version="*" />
<PackageReference Include="ricaun.Auth.Aps.UI" Version="*" />
<PackageReference Include="ricaun.Auth.Aps.UI" Version="1.0.3" />
<PackageReference Include="ricaun.Revit.UI" Version="0.5.2" />
<PackageReference Include="ricaun.Revit.Async" Version="1.0.4" />
<PackageReference Include="ricaun.NUnit" Version="*" />
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit d33863d

Please sign in to comment.