mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -07:00
Async async async improvements.
This commit is contained in:
parent
236024e4ae
commit
b3e90c7a7f
19 changed files with 785 additions and 755 deletions
|
@ -1,83 +1,83 @@
|
|||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: StatusChecker.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Octokit;
|
||||
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Helpers;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class StatusChecker
|
||||
{
|
||||
public StatusChecker()
|
||||
{
|
||||
Git = new GitHubClient(new ProductHeaderValue("PlexRequests-StatusChecker"));
|
||||
}
|
||||
private IGitHubClient Git { get; }
|
||||
private const string Owner = "tidusjar";
|
||||
private const string RepoName = "PlexRequests.Net";
|
||||
|
||||
public async Task<Release> GetLatestRelease()
|
||||
{
|
||||
var releases = await Git.Repository.Release.GetAll(Owner, RepoName);
|
||||
return releases.FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task<StatusModel> GetStatus()
|
||||
{
|
||||
var assemblyVersion = AssemblyHelper.GetProductVersion();
|
||||
var model = new StatusModel
|
||||
{
|
||||
Version = assemblyVersion,
|
||||
};
|
||||
|
||||
var latestRelease = await GetLatestRelease();
|
||||
if (latestRelease == null)
|
||||
{
|
||||
return new StatusModel { Version = "Unknown" };
|
||||
}
|
||||
var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty;
|
||||
|
||||
if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
model.UpdateAvailable = true;
|
||||
model.UpdateUri = latestRelease.HtmlUrl;
|
||||
}
|
||||
|
||||
model.ReleaseNotes = latestRelease.Body;
|
||||
model.DownloadUri = latestRelease.Assets[0].BrowserDownloadUrl;
|
||||
model.ReleaseTitle = latestRelease.Name;
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: StatusChecker.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Octokit;
|
||||
|
||||
using PlexRequests.Core.Models;
|
||||
using PlexRequests.Helpers;
|
||||
|
||||
namespace PlexRequests.Core
|
||||
{
|
||||
public class StatusChecker
|
||||
{
|
||||
public StatusChecker()
|
||||
{
|
||||
Git = new GitHubClient(new ProductHeaderValue("PlexRequests-StatusChecker"));
|
||||
}
|
||||
private IGitHubClient Git { get; }
|
||||
private const string Owner = "tidusjar";
|
||||
private const string RepoName = "PlexRequests.Net";
|
||||
|
||||
public async Task<Release> GetLatestRelease()
|
||||
{
|
||||
var releases = await Git.Repository.Release.GetAll(Owner, RepoName);
|
||||
return releases.FirstOrDefault();
|
||||
}
|
||||
|
||||
public async Task<StatusModel> GetStatus()
|
||||
{
|
||||
var assemblyVersion = AssemblyHelper.GetProductVersion();
|
||||
var model = new StatusModel
|
||||
{
|
||||
Version = assemblyVersion,
|
||||
};
|
||||
|
||||
var latestRelease = await GetLatestRelease();
|
||||
if (latestRelease == null)
|
||||
{
|
||||
return new StatusModel { Version = "Unknown" };
|
||||
}
|
||||
var latestVersionArray = latestRelease.Name.Split(new[] { 'v' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var latestVersion = latestVersionArray.Length > 1 ? latestVersionArray[1] : string.Empty;
|
||||
|
||||
if (!latestVersion.Equals(assemblyVersion, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
model.UpdateAvailable = true;
|
||||
model.UpdateUri = latestRelease.HtmlUrl;
|
||||
}
|
||||
|
||||
model.ReleaseNotes = latestRelease.Body;
|
||||
model.DownloadUri = latestRelease.Assets[0].BrowserDownloadUrl;
|
||||
model.ReleaseTitle = latestRelease.Name;
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue