Skip to content

Commit

Permalink
Support net7.0-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Nov 21, 2023
1 parent 26387ad commit 2b27453
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using ricaun.Nuke;
using ricaun.Nuke.Components;

class Build : NukeBuild, IPublishRevit, IBuildConsole, IBuildLocalTests, IBuildCommand, IPrePack // IPackRelease,
class Build : NukeBuild, IPublishRevit, IBuildConsole, IBuildCommand, IPrePack, IBuildLocalTests
{
string IHazRevitPackageBuilder.Application => "Revit.App";
bool IHazPackageBuilderProject.ReleasePackageBuilder => false;
Expand Down
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.1] / 2023-11-21
### Features
- Support `net7.0-windows` for Revit 2025.
### Application
- Add `EnsureApsUserHaveOpenId` to make sure `OpenId` has data.
- Update `net7.0-windows` for Revit 2025.
### Shared
- Update `net6.0-windows` framework.

## [1.2.0] / 2023-10-28
### Features
- Application works offline.
Expand Down Expand Up @@ -330,6 +339,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.1]: ../../compare/1.2.0...1.2.1
[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
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.2.0</Version>
<Version>1.2.1</Version>
</PropertyGroup>
</Project>
4 changes: 4 additions & 0 deletions ricaun.RevitTest.Application/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace ricaun.RevitTest.Application
{
class Module
{
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
[ModuleInitializer]
#pragma warning restore CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
internal static void Initialize()
{
//Debug.WriteLine($"Module: {typeof(Module).Assembly}");
Expand All @@ -21,8 +23,10 @@ internal static void Initialize()
}
}

#if NETFRAMEWORK
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
internal sealed class ModuleInitializerAttribute : Attribute { }
}
#endif
13 changes: 12 additions & 1 deletion ricaun.RevitTest.Application/Revit/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,23 @@ TestAssemblyModel ApsApplicationCheckTest(UIApplication uiapp)

if (ApsApplication.ApsApplication.IsConnected == true)
{
var task = Task.Run(async () =>
{
return await ApsApplication.ApsApplication.EnsureApsUserHaveOpenId();
});
var userHaveOpenId = task.GetAwaiter().GetResult();
if (userHaveOpenId == false)
{
var exceptionUserWithoutOpenId = new Exception($"The user was disconnected, reconnect the user to 'ricaun.Auth' and Autodesk Platform Service.");
return TestEngine.Fail(message.TestPathFile, exceptionUserWithoutOpenId, testFilterNames);
}

var revitLoginUserId = uiapp.Application.LoginUserId;
var apsLoginUserId = ApsApplication.ApsApplication.LoginUserId;
var isSameUserId = apsLoginUserId.Equals(revitLoginUserId);

if (isSameUserId == false)
{
Log.WriteLine($"ApsApplication: '{revitLoginUserId}' != '{apsLoginUserId}'");
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ricaun.Aps;
using ricaun.Aps.Extensions;
using ricaun.Auth.Aps;
using System.Diagnostics;
using System.Threading.Tasks;

namespace ricaun.RevitTest.Application.Revit.ApsApplication
Expand All @@ -21,13 +22,44 @@ public static string GetLoginUserId()
if (IsConnected == false)
return string.Empty;

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

var data = ApsService.ApsClient?.GetOpenIdData();
if (data is null)
{
return string.Empty;
}

return data.UserId;
}

public static async Task<bool> EnsureApsUserHaveOpenId()
{
if (IsConnected == false)
return false;

async Task DisconnectUser()
{
Debug.WriteLine($"EnsureApsUserHaveOpenId: Force to disconnect User.");
await Logout();
}

var tokenData = ApsService.ApsClient?.GetAccessToken()?.GetAccessTokenData();
if (tokenData is null)
{
Debug.WriteLine($"EnsureApsUserHaveOpenId: AccessTokenData is empty.");
await DisconnectUser();
return false;
}

var data = ApsService.ApsClient?.GetOpenIdData();
if (data is null)
{
Debug.WriteLine($"EnsureApsUserHaveOpenId: OpenIdData is empty.");
await DisconnectUser();
return false;
}

return true;
}
public static async Task Initialize()
{
ApsService = new ApsService(ClientId, ClientScopes) { ClientPort = ClientPort };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Threading.Tasks;

namespace ricaun.RevitTest.Application.Revit.ApsApplication
{
Expand All @@ -11,7 +12,7 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
UIApplication uiapp = commandData.Application;

ApsApplication.Login();
ApsApplication.Login().RunAndForget();

return Result.Succeeded;
}
Expand All @@ -24,10 +25,9 @@ public Result Execute(ExternalCommandData commandData, ref string message, Eleme
{
UIApplication uiapp = commandData.Application;

ApsApplication.Logout();
ApsApplication.Logout().RunAndForget();

return Result.Succeeded;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading.Tasks;

namespace ricaun.RevitTest.Application.Revit.ApsApplication
{
public static class TaskExtension
{
public static async void RunAndForget(this Task task)
{
try
{
await task;
}
catch { }
}
}
}
62 changes: 10 additions & 52 deletions ricaun.RevitTest.Application/ricaun.RevitTest.Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,34 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<UseWPF>true</UseWPF>
<LangVersion>latest</LangVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<Configurations>
Debug; Release;
</Configurations>
</PropertyGroup>

<!-- RevitVersion -->
<PropertyGroup>
<TargetFrameworks>net46;net7.0-windows</TargetFrameworks>
</PropertyGroup>
<Choose>
<When Condition="$(Configuration.Contains('2017'))">
<When Condition="$(TargetFramework.StartsWith('net4'))">
<PropertyGroup>
<RevitVersion>2017</RevitVersion>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2018'))">
<PropertyGroup>
<RevitVersion>2018</RevitVersion>
<TargetFramework>net46</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2019'))">
<PropertyGroup>
<RevitVersion>2019</RevitVersion>
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2020'))">
<PropertyGroup>
<RevitVersion>2020</RevitVersion>
<TargetFramework>net47</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2021'))">
<PropertyGroup>
<RevitVersion>2021</RevitVersion>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2022'))">
<PropertyGroup>
<RevitVersion>2022</RevitVersion>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
</When>
<When Condition="$(Configuration.Contains('2023'))">
<PropertyGroup>
<RevitVersion>2023</RevitVersion>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup>
<RevitVersion>2017</RevitVersion>
<TargetFramework>net46</TargetFramework>
<RevitVersion>2025</RevitVersion>
</PropertyGroup>
</Otherwise>
</Choose>

<!-- Release -->
<PropertyGroup Condition="!$(Configuration.Contains('Debug'))">
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<OutputPath>bin\Release\$(RevitVersion)</OutputPath>
<DefineConstants>REVIT$(RevitVersion)</DefineConstants>
<NoWarn>MSB3052</NoWarn>
<DebugType>None</DebugType>
Expand Down Expand Up @@ -117,13 +82,6 @@
<Copyright>Copyright © $(Company) $(CopyrightYears)</Copyright>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Revit\ApsApplication\Services\**" />
<EmbeddedResource Remove="Revit\ApsApplication\Services\**" />
<None Remove="Revit\ApsApplication\Services\**" />
<Page Remove="Revit\ApsApplication\Services\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Images\test-fail.png" />
<None Remove="Images\test-pass.png" />
Expand All @@ -133,9 +91,9 @@

<ItemGroup>
<PackageReference Include="Revit.Busy" 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.Auth.Aps.UI" Version="*" />
<PackageReference Include="ricaun.Revit.UI" Version="0.6.0-alpha" />
<PackageReference Include="ricaun.Revit.Async" Version="*" />
<PackageReference Include="ricaun.NUnit" Version="*" />
<PackageReference Include="NamedPipeWrapper.Json" Version="*" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions ricaun.RevitTest.Shared/ricaun.RevitTest.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<UseWPF>true</UseWPF>
<LangVersion>latest</LangVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<Configurations>Debug; Release</Configurations>
<TargetFramework>net46</TargetFramework>
<TargetFrameworks>net46;net6.0-windows</TargetFrameworks>
</PropertyGroup>

<!-- Release -->
Expand Down

0 comments on commit 2b27453

Please sign in to comment.