Merge pull request #771 from tidusjar/dev

Small fixes and error handling
pull/780/head
Jamie 8 years ago committed by GitHub
commit 1fcb318c27

@ -243,7 +243,7 @@ namespace PlexRequests.Core.Migration.Migrations
{
return;
}
var requestedModels = allRequests as RequestedModel[] ?? allRequests.ToArray();
var requestedModels = allRequests.ToList();
foreach (var req in requestedModels)
{
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))

@ -49,41 +49,89 @@ namespace PlexRequests.Helpers.Analytics
public void TrackEvent(Category category, Action action, string label, string username, string clientId, int? value = null)
{
var cat = category.ToString();
var act = action.ToString();
Track(HitType.@event, username, cat, act, label, clientId, value);
try
{
var cat = category.ToString();
var act = action.ToString();
Track(HitType.@event, username, cat, act, label, clientId, value);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
public async void TrackEventAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
{
var cat = category.ToString();
var act = action.ToString();
await TrackAsync(HitType.@event, username, cat, act, clientId, label, value);
try
{
var cat = category.ToString();
var act = action.ToString();
await TrackAsync(HitType.@event, username, cat, act, clientId, label, value);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
public void TrackPageview(Category category, Action action, string label, string username, string clientId, int? value = null)
{
var cat = category.ToString();
var act = action.ToString();
Track(HitType.@pageview, username, cat, act, clientId, label, value);
try
{
var cat = category.ToString();
var act = action.ToString();
Track(HitType.@pageview, username, cat, act, clientId, label, value);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
public async Task TrackPageviewAsync(Category category, Action action, string label, string username, string clientId, int? value = null)
{
var cat = category.ToString();
var act = action.ToString();
await TrackAsync(HitType.@pageview, username, cat, act, clientId, label, value);
try
{
var cat = category.ToString();
var act = action.ToString();
await TrackAsync(HitType.@pageview, username, cat, act, clientId, label, value);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
public void TrackException(string message, string username, string clientId, bool fatal)
{
var fatalInt = fatal ? 1 : 0;
Track(HitType.exception, message, fatalInt, username, clientId);
try
{
var fatalInt = fatal ? 1 : 0;
Track(HitType.exception, message, fatalInt, username, clientId);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
public async Task TrackExceptionAsync(string message, string username, string clientId, bool fatal)
{
var fatalInt = fatal ? 1 : 0;
await TrackAsync(HitType.exception, message, fatalInt, username, clientId);
try
{
var fatalInt = fatal ? 1 : 0;
await TrackAsync(HitType.exception, message, fatalInt, username, clientId);
}
catch (Exception ex)
{
Log.Error(ex);
}
}
private void Track(HitType type, string username, string category, string action, string clientId, string label, int? value = null)

@ -28,6 +28,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using MarkdownSharp;
using Nancy;
@ -118,10 +120,23 @@ namespace PlexRequests.UI.Modules.Admin
Analytics.TrackEventAsync(Category.Admin, PlexRequests.Helpers.Analytics.Action.Update, "AutoUpdate", Username, CookieHelper.GetAnalyticClientId(Cookies));
var url = Request.Form["url"];
var args = (string)Request.Form["args"].ToString();
var lowered = args.ToLower();
var appPath = Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(SystemStatusModule)).Location ?? string.Empty) ?? string.Empty, "PlexRequests.Updater.exe");
if (!string.IsNullOrEmpty(lowered))
{
if (lowered.Contains("plexrequests.exe"))
{
lowered = lowered.Replace("plexrequests.exe", "");
}
}
var startArgs = string.IsNullOrEmpty(lowered) ? appPath : $"{lowered} Plexrequests.Updater.exe";
var startInfo = Type.GetType("Mono.Runtime") != null
? new ProcessStartInfo("mono PlexRequests.Updater.exe") { Arguments = url }
: new ProcessStartInfo("PlexRequests.Updater.exe") { Arguments = url };
? new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}", }
: new ProcessStartInfo(startArgs) { Arguments = $"{url} {lowered}" };
Process.Start(startInfo);

@ -128,7 +128,7 @@ namespace PlexRequests.UI
private static void WriteOutVersion()
{
var assemblyVer = AssemblyHelper.GetProductVersion();
var assemblyVer = AssemblyHelper.GetFileVersion();
Log.Info($"Version: {assemblyVer}");
Console.WriteLine($"Version: {assemblyVer}");
}

@ -11,7 +11,7 @@
<label class="control-label">Current Version: </label>
<label class="control-label">@Model.Status.CurrentVersion</label>
</div>
@if (Model.Status.UpdateAvailable)
{
<div class="form-group">
@ -50,6 +50,8 @@
{
<label class="control-label"><a href="@Model.Status.UpdateUri" target="_blank"><i class="fa fa-check"></i></a></label>
<br />
<input id="args" class="form-control form-control-custom " placeholder="optional launch arguments e.g. /etc/mono /opt/PlexRequests.exe">
<br/>
<button id="autoUpdate" class="btn btn-success-outline">Automatic Update (beta) <i class="fa fa-download"></i></button>
}
else
@ -92,7 +94,10 @@
$.ajax({
type: "Post",
url: "autoupdate",
data: { url: "@Model.Status.DownloadUri" },
data: {
url: "@Model.Status.DownloadUri",
args: $('#args').val()
},
dataType: "json",
error: function () {
setTimeout(

@ -8,7 +8,14 @@ namespace PlexRequests.Updater
{
Console.WriteLine ("Starting PlexRequests .Net updater");
var s = new Updater();
s.Start(args[0]);
if (args.Length >= 2)
{
s.Start(args[0], args[1]);
}
else
{
s.Start(args[0], string.Empty);
}
}
}
}

@ -29,6 +29,7 @@ using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Reflection;
using System.Windows.Forms;
namespace PlexRequests.Updater
@ -67,7 +68,7 @@ namespace PlexRequests.Updater
}
}
public void Start(string downloadPath)
public void Start(string downloadPath, string launchOptions)
{
try
{
@ -79,6 +80,10 @@ namespace PlexRequests.Updater
Console.WriteLine("Downloading new version");
using (var client = new WebClient())
{
client.DownloadProgressChanged += (s, e) =>
{
Console.WriteLine($"{e.ProgressPercentage}%");
};
client.DownloadFile(downloadPath, TempPath);
}
Console.WriteLine("Downloaded!");
@ -130,7 +135,7 @@ namespace PlexRequests.Updater
RestoreBackup();
}
FinishUpdate();
FinishUpdate(launchOptions);
}
}
@ -139,8 +144,9 @@ namespace PlexRequests.Updater
Console.WriteLine("Backing up the current version");
try
{
var dir = Directory.CreateDirectory("BackupSystem");
var applicationPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath));
var applicationPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty) ?? string.Empty;
var dir = Directory.CreateDirectory(Path.Combine(applicationPath, "BackupSystem"));
var allfiles = Directory.GetFiles(applicationPath, "*.*", SearchOption.AllDirectories);
BackupPath = Path.Combine(dir.FullName, "PlexRequestsBackup.zip");
@ -179,7 +185,9 @@ namespace PlexRequests.Updater
{
try
{
return Directory.CreateDirectory("UpdateTemp");
var location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(Updater)).Location ?? string.Empty);
var path = Path.Combine(location, "UpdateTemp");
return Directory.CreateDirectory(path);
}
catch (Exception e)
{
@ -190,15 +198,13 @@ namespace PlexRequests.Updater
}
}
private void FinishUpdate()
private void FinishUpdate(string launchOptions)
{
ProcessStartInfo startInfo;
startInfo = Type.GetType("Mono.Runtime") != null
? new ProcessStartInfo("mono PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" }
: new ProcessStartInfo("PlexRequests.exe") { Arguments = Error ? "-u 2" : "-u 1" };
var args = Error ? "-u 2" : "-u 1";
var startInfo = new ProcessStartInfo($"{launchOptions}PlexRequests.exe") { Arguments = args, UseShellExecute = true };
Process.Start(startInfo);
Environment.Exit(0);
}
}

@ -9,8 +9,6 @@ ____
[![Github All Releases](https://img.shields.io/github/downloads/tidusjar/PlexRequests.net/total.svg)](https://github.com/tidusjar/PlexRequests.Net)
[![Stories in Progress](https://badge.waffle.io/tidusjar/PlexRequests.Net.svg?label=in progress&title=In Progress)](http://waffle.io/tidusjar/PlexRequests.Net)
This is based off [Plex Requests by lokenx](https://github.com/lokenx/plexrequests-meteor) so big props to that guy!
I wanted to write a similar application in .Net!
# Features
Here some of the features Plex Requests.Net has:

Loading…
Cancel
Save