Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kharonus committed Nov 4, 2021
2 parents 6cf0101 + 2778700 commit 93e117a
Show file tree
Hide file tree
Showing 70 changed files with 1,071 additions and 2,085 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/continuous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v1
- name: Run tests
run: ./build.cmd Test
- name: Run './build.cmd PublishGitHubRelease'
run: ./build.cmd PublishGitHubRelease
env:
Expand Down
33 changes: 32 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,37 @@
This is the Changelog for the OpenProject Revit Add-in. It follows the guidelines described
in https://keepachangelog.com/en/1.0.0/. The versions follow [semantic versioning](https://semver.org/).

## Unreleased

### Added

- Amended README with information about reporting bugs and other useful information

### Changed

- Viewpoint snapshot data is given in an improper state to the OpenProject instance frontend. The current hack has to be
maintained until the related
[work package](https://community.openproject.org/projects/bcfier/work_packages/39135/activity) is resolved and the
solution deployed.

### Fixed

- Section boxes with infinity values, which can exist after importing viewpoints with less then 6 clipping planes, no
longer create invalid viewpoint data when generating a new viewpoint.
- If there is a newer version of the AddIn released at GitHub, a notification dialog is displayed again
- When exporting a viewpoint from a Revit view, elements hidden by category are interpreted as hidden. However, applying
this viewpoint does not apply the category visibility, but sets all contained elements to hidden, as BCF viewpoints
are not aware of Revit categories.

## [2.3.1] - 2021-10-04

### Fixed

- Fixed an issue that led to an exception when installing the Revit Add-In for the very first time
- Made the loading of the `OpenProject.Configuration.json` more robust, so that missing or outdated keys no longer lead
to errors
- Improved logging and error dialog communication

## [2.3.0] - 2021-09-21

### Added
Expand Down Expand Up @@ -35,7 +66,7 @@ in https://keepachangelog.com/en/1.0.0/. The versions follow [semantic versionin
- Loading times for viewpoints were slightly improved, on machines without enough capability the asynchronous zoom for
orthogonal viewpoints can take several seconds (see this
[official issue](https://thebuildingcoder.typepad.com/blog/2020/10/save-and-restore-3d-view-camera-settings.html)).
- An issue was fixed, causing the cursor in input fields in the embedded browser vanishing occasionally.
- An issue was fixed, causing the cursor in input fields in the embedded browser vanishing occasionally.

## [2.2.5] - 2021-04-16

Expand Down
25 changes: 20 additions & 5 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
using Nuke.Common.Utilities.Collections;
using Nuke.GitHub;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using Nuke.Common.Tools.Git;
using Octokit;
using static Nuke.Common.IO.CompressionTasks;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
Expand Down Expand Up @@ -221,7 +224,7 @@ public static class RepositoryInfo
.Executes(() =>
{
DotNetTest(c => c
.SetConfiguration("Debug")
.SetConfiguration("Debug-2022")
.SetProjectFile(RootDirectory / "test" / "OpenProject.Tests" / "OpenProject.Tests.csproj")
.SetTestAdapterPath(".")
.SetLoggers($"xunit;LogFilePath={OutputDirectory / "testresults.xml"}"));
Expand Down Expand Up @@ -281,7 +284,19 @@ public static class RepositoryInfo
SignFilesIfRequirementsMet(OutputDirectory / "OpenProject.Revit.exe");
});

static bool ShouldBuildRelease()
{
const string flag = "[release skip]";

var message = GitTasks.Git("log -1 --pretty=format:%B", logOutput: false)
.Select(output => output.Text)
.Aggregate((s, s1) => $"{s}\n{s1}");

return !message.Contains(flag);
}

Target PublishGitHubRelease => _ => _
.OnlyWhenDynamic(() => ShouldBuildRelease())
.DependsOn(CreateSetup)
.DependsOn(BuildDocumentation)
.Requires(() => GitHubAuthenticationToken)
Expand All @@ -290,10 +305,10 @@ public static class RepositoryInfo
var releaseTag = $"v{GitVersion.SemVer}";
var isStableRelease = GitVersion.BranchName.Equals("master") || GitVersion.BranchName.Equals("origin/master") || GitVersion.BranchName.Equals("main") || GitVersion.BranchName.Equals("origin/main");
var repositoryInfo = GetGitHubRepositoryInfo(GitRepository);
var (gitHubOwner, repositoryName) = GetGitHubRepositoryInfo(GitRepository);
var installationFile = GlobFiles(OutputDirectory, "OpenProject.Revit.exe").NotEmpty().Single();
var artifactPaths = new string[]
var artifactPaths = new[]
{
installationFile,
OutputDirectory / "InstallationInstructions.pdf",
Expand All @@ -304,8 +319,8 @@ await PublishRelease(x => x
.SetPrerelease(!isStableRelease)
.SetArtifactPaths(artifactPaths)
.SetCommitSha(GitVersion.Sha)
.SetRepositoryName(repositoryInfo.repositoryName)
.SetRepositoryOwner(repositoryInfo.gitHubOwner)
.SetRepositoryName(repositoryName)
.SetRepositoryOwner(gitHubOwner)
.SetTag(releaseTag)
.SetToken(GitHubAuthenticationToken));
});
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "5.0.301"
"version": "5.0.402"
}
}
}
25 changes: 25 additions & 0 deletions src/OpenProject.Browser/Models/Release.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable InconsistentNaming

namespace OpenProject.Browser.Models
{
/// <summary>
/// Class model for deserialization of github release JSON data from the github rest API.
/// </summary>
// ReSharper disable once ClassNeverInstantiated.Global
public sealed class Release
{
public string tag_name { private get; set; }
public DateTime published_at { private get; set; }
public string html_url { private get; set; }

public Version Version() => Models.Version.Parse(tag_name);

public DateTime PublishedAt() => published_at;

public string DownloadUrl() => html_url;
}
}
92 changes: 92 additions & 0 deletions src/OpenProject.Browser/Models/Version.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using Serilog;

namespace OpenProject.Browser.Models
{
/// <summary>
/// Immutable class representing semantic versions.
/// </summary>
public sealed class Version : IComparable<Version>
{
private readonly int _major;
private readonly int _minor;
private readonly int _patch;
private readonly string _suffix;

private Version(int major, int minor, int patch, string suffix)
{
_major = major;
_minor = minor;
_patch = patch;
_suffix = suffix;
}

/// <summary>
/// Parses a string into a semantic version. Returns 'v0.0.0' if an invalid string is given.
/// </summary>
/// <param name="versionString">The input string</param>
/// <returns>A semantic version object</returns>
public static Version Parse(string versionString)
{
var separators = new[] { '.', '-' };
var split = versionString.Split(separators);

var major = 0;
var minor = 0;
var patch = 0;
var suffix = "";

try
{
if (split.Length >= 1)
{
var str = split[0].StartsWith("v", StringComparison.InvariantCultureIgnoreCase) ? split[0][1..] : split[0];
major = int.Parse(str);
}

if (split.Length >= 2)
minor = int.Parse(split[1]);
if (split.Length >= 3)
patch = int.Parse(split[2]);
if (split.Length >= 4)
suffix = split[3];
}
catch (FormatException)
{
Log.Error("{version} is no valid version string.", versionString);
return new Version(0, 0, 0, "");
}

return new Version(major, minor, patch, suffix);
}

/// <inheritdoc />
public int CompareTo(Version other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;

if (_major > other._major)
return 1;
if (_major < other._major)
return -1;

if (_minor > other._minor)
return 1;
if (_minor < other._minor)
return -1;

if (_patch > other._patch)
return 1;
if (_patch < other._patch)
return -1;

var stringComparison = string.CompareOrdinal(_suffix, other._suffix);
return stringComparison > 0 ? 1 : stringComparison < 0 ? -1 : 0;
}

/// <inheritdoc />
public override string ToString() =>
_suffix.Length > 0 ? $"v{_major}.{_minor}.{_patch}-{_suffix}" : $"v{_major}.{_minor}.{_patch}";
}
}
7 changes: 1 addition & 6 deletions src/OpenProject.Browser/Services/ConfigurationHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using Config.Net;
using Newtonsoft.Json;
Expand All @@ -25,11 +24,7 @@ static ConfigurationHandler()
}
}

private static IOpenProjectSettings Settings { get; }

public static bool ShouldEnableDevelopmentTools() => Settings.EnableDevelopmentTools;

public static List<string> LoadAllInstances() => Settings.GetOpenProjectInstances();
public static IOpenProjectSettings Settings { get; }

public static void RemoveSavedInstance(string instanceUrl)
{
Expand Down
39 changes: 39 additions & 0 deletions src/OpenProject.Browser/Services/GitHubService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Net;
using OpenProject.Browser.Models;
using OpenProject.Shared;
using Optional;
using RestSharp;

namespace OpenProject.Browser.Services
{
public sealed class GitHubService : IGitHubService
{
private RestClient _client;

private RestClient Client
{
get
{
if (_client != null)
return _client;

_client = new RestClient(@"https://api.github.com/");
return _client;
}
}

/// <inheritdoc />
public Option<Release> GetLatestRelease()
{
var request =
new RestRequest($"repos/{RepositoryInfo.GitHubOwner}/{RepositoryInfo.GitHubRepository}/releases/latest", Method.GET);
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = DataFormat.Json;
request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

var response = Client.Execute<Release>(request);

return response.StatusCode == HttpStatusCode.OK ? response.Data.SomeNotNull() : Option.None<Release>();
}
}
}
17 changes: 17 additions & 0 deletions src/OpenProject.Browser/Services/Interfaces/IGitHubService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using OpenProject.Browser.Models;
using Optional;

namespace OpenProject.Browser.Services
{
/// <summary>
/// A service for communication to the repository on github.
/// </summary>
public interface IGitHubService
{
/// <summary>
/// Get the latest published released of the OpenProject Revit AddIn.
/// </summary>
/// <returns>A release object.</returns>
Option<Release> GetLatestRelease();
}
}
27 changes: 27 additions & 0 deletions src/OpenProject.Browser/Services/MessageHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Windows;
using Serilog;

Expand All @@ -17,5 +18,31 @@ public static void ShowError(Exception exception, string message)
Log.Error(exception, message);
MessageBox.Show(message, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
}

/// <summary>
/// Displays an update dialog, which indicates that a newer add-in version is available for download.
/// User can decide whether to download update or not.
/// </summary>
/// <param name="oldVersion">The string representation of the currently installed version.</param>
/// <param name="newVersion">The string representation of the new version.</param>
/// <param name="releaseDate">The release date of the new version.</param>
/// <param name="downloadUrl">The URL where the new version can be downloaded from.</param>
public static void ShowUpdateDialog(string oldVersion, string newVersion, DateTime releaseDate, string downloadUrl)
{
Log.Information("New version {new} available. Currently installed: {old}", newVersion, oldVersion);
var messageBoxText = $"A new release '{newVersion}' was released at {releaseDate.ToLongDateString()}. " +
$"'{oldVersion}' is currently installed.\nDo you want to download the new version?";
MessageBoxResult messageBoxResult = MessageBox.Show(
messageBoxText,
"New version available",
MessageBoxButton.YesNo,
MessageBoxImage.Information
);

if (messageBoxResult != MessageBoxResult.Yes) return;

Process.Start(new ProcessStartInfo("cmd", $"/c start {downloadUrl}") { CreateNoWindow = true });
Log.Information("Download of new version {new} started.", newVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ internal static IServiceCollection ConfigureIoCContainer()
services.AddSingleton<ChromiumWebBrowser>();

// Interface implementations
services.AddSingleton<IGitHubService, GitHubService>();
services.AddSingleton<IDownloadHandler, OpenProjectBrowserDownloadHandler>();
services.AddSingleton<IRequestHandler, OpenProjectBrowserRequestHandler>();
services.AddSingleton<ILifeSpanHandler, OpenProjectBrowserLifeSpanHandler>();
Expand Down
1 change: 1 addition & 0 deletions src/OpenProject.Browser/Settings/IOpenProjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public interface IOpenProjectSettings
public bool EnableDevelopmentTools { get; set; }
public string OpenProjectInstances { get; set; }
public string LastVisitedPage { get; set; }
public bool CheckForUpdates { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"EnableDevelopmentTools": false,
"OpenProjectInstances": []
"OpenProjectInstances": [],
"CheckForUpdates": true
}
Loading

0 comments on commit 93e117a

Please sign in to comment.