forked from teocomi/BCFier
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
1,071 additions
and
2,085 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"sdk": { | ||
"version": "5.0.301" | ||
"version": "5.0.402" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
src/OpenProject.Browser/Services/Interfaces/IGitHubService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/OpenProject.Browser/Settings/OpenProject.Configuration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"EnableDevelopmentTools": false, | ||
"OpenProjectInstances": [] | ||
"OpenProjectInstances": [], | ||
"CheckForUpdates": true | ||
} |
Oops, something went wrong.