mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-19 21:03:17 -07:00
commit
16a03240c2
12 changed files with 354 additions and 195 deletions
|
@ -4,6 +4,7 @@ using System.Data.Common;
|
|||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Ninject;
|
||||
using NLog;
|
||||
using PlexRequests.Store;
|
||||
|
||||
namespace PlexRequests.Core.Migration
|
||||
|
@ -18,6 +19,7 @@ namespace PlexRequests.Core.Migration
|
|||
|
||||
private IKernel Kernel { get; }
|
||||
private ISqliteConfiguration Db { get; }
|
||||
private static Logger _log = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public void MigrateToLatest()
|
||||
{
|
||||
|
@ -25,25 +27,34 @@ namespace PlexRequests.Core.Migration
|
|||
var versions = GetMigrations();
|
||||
|
||||
var dbVersion = con.GetVersionInfo().OrderByDescending(x => x.Version).FirstOrDefault() ??
|
||||
new TableCreation.VersionInfo { Version = 0 };
|
||||
new TableCreation.VersionInfo {Version = 0};
|
||||
foreach (var v in versions)
|
||||
{
|
||||
#if !DEBUG
|
||||
if (v.Value.Version > dbVersion.Version)
|
||||
{
|
||||
#endif
|
||||
// Assuming only one constructor
|
||||
var ctor = v.Key.GetConstructors().FirstOrDefault();
|
||||
var dependencies = ctor.GetParameters().Select(param => Kernel.Get(param.ParameterType)).ToList();
|
||||
|
||||
var method = v.Key.GetMethod("Start");
|
||||
if (method != null)
|
||||
try
|
||||
{
|
||||
var classInstance = Activator.CreateInstance(v.Key, dependencies.Any() ? dependencies.ToArray() : null);
|
||||
var parametersArray = new object[] { Db.DbConnection() };
|
||||
// Assuming only one constructor
|
||||
var ctor = v.Key.GetConstructors().FirstOrDefault();
|
||||
var dependencies = ctor.GetParameters().Select(param => Kernel.Get(param.ParameterType)).ToList();
|
||||
|
||||
method.Invoke(classInstance, parametersArray);
|
||||
var method = v.Key.GetMethod("Start");
|
||||
if (method != null)
|
||||
{
|
||||
var classInstance = Activator.CreateInstance(v.Key, dependencies.Any() ? dependencies.ToArray() : null);
|
||||
var parametersArray = new object[] { Db.DbConnection() };
|
||||
|
||||
method.Invoke(classInstance, parametersArray);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.Fatal("Error when migrating version : {0}", v.Value.Version);
|
||||
_log.Fatal(e);
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#region Copyright
|
||||
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: Version1100.cs
|
||||
|
@ -23,16 +24,15 @@
|
|||
// 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.Collections.Generic;
|
||||
using System.Data;
|
||||
using NLog;
|
||||
using System.Linq;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Core.Users;
|
||||
using PlexRequests.Helpers;
|
||||
using PlexRequests.Helpers.Permissions;
|
||||
using PlexRequests.Store;
|
||||
|
@ -44,8 +44,10 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
[Migration(11000, "v1.10.0.0")]
|
||||
public class Version1100 : BaseMigration, IMigration
|
||||
{
|
||||
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log, IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
||||
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings, ISettingsService<UserManagementSettings> umSettings,
|
||||
public Version1100(IUserRepository userRepo, IRequestService requestService, ISettingsService<LogSettings> log,
|
||||
IPlexApi plexApi, ISettingsService<PlexSettings> plexService,
|
||||
IPlexUserRepository plexusers, ISettingsService<PlexRequestSettings> prSettings,
|
||||
ISettingsService<UserManagementSettings> umSettings,
|
||||
ISettingsService<ScheduledJobsSettings> sjs, IRepository<UsersToNotify> usersToNotify)
|
||||
{
|
||||
UserRepo = userRepo;
|
||||
|
@ -59,7 +61,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
ScheduledJobSettings = sjs;
|
||||
UserNotifyRepo = usersToNotify;
|
||||
}
|
||||
|
||||
public int Version => 11000;
|
||||
|
||||
private IUserRepository UserRepo { get; }
|
||||
private IRequestService RequestService { get; }
|
||||
private ISettingsService<LogSettings> Log { get; }
|
||||
|
@ -71,6 +75,9 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
private ISettingsService<ScheduledJobsSettings> ScheduledJobSettings { get; }
|
||||
private IRepository<UsersToNotify> UserNotifyRepo { get; }
|
||||
|
||||
|
||||
private static Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public void Start(IDbConnection con)
|
||||
{
|
||||
UpdateDb(con);
|
||||
|
@ -89,190 +96,250 @@ namespace PlexRequests.Core.Migration.Migrations
|
|||
|
||||
private void MigrateUserNotifications()
|
||||
{
|
||||
var usersToNotify = UserNotifyRepo.GetAll();
|
||||
var plexUsers = PlexUsers.GetAll().ToList();
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
if (usersToNotify == null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
var usersToNotify = UserNotifyRepo.GetAll();
|
||||
var plexUsers = PlexUsers.GetAll().ToList();
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
if (usersToNotify == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var u in usersToNotify)
|
||||
{
|
||||
var selectedPlexUser =
|
||||
plexUsers.FirstOrDefault(
|
||||
x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedPlexUser != null)
|
||||
{
|
||||
selectedPlexUser.Features += (int)Features.RequestAddedNotification;
|
||||
PlexUsers.Update(selectedPlexUser);
|
||||
}
|
||||
|
||||
var selectedLocalUser =
|
||||
users.FirstOrDefault(x => x.UserName.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedLocalUser != null)
|
||||
{
|
||||
selectedLocalUser.Features += (int)Features.RequestAddedNotification;
|
||||
UserRepo.Update(selectedLocalUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var u in usersToNotify)
|
||||
catch (Exception e)
|
||||
{
|
||||
var selectedPlexUser = plexUsers.FirstOrDefault(x => x.Username.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedPlexUser != null)
|
||||
{
|
||||
selectedPlexUser.Features += (int)Features.RequestAddedNotification;
|
||||
PlexUsers.Update(selectedPlexUser);
|
||||
}
|
||||
|
||||
var selectedLocalUser =
|
||||
users.FirstOrDefault(x => x.UserName.Equals(u.Username, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (selectedLocalUser != null)
|
||||
{
|
||||
selectedLocalUser.Features += (int)Features.RequestAddedNotification;
|
||||
UserRepo.Update(selectedLocalUser);
|
||||
}
|
||||
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScheduledJobs()
|
||||
{
|
||||
var settings = ScheduledJobSettings.GetSettings();
|
||||
try
|
||||
{
|
||||
var settings = ScheduledJobSettings.GetSettings();
|
||||
|
||||
settings.PlexUserChecker = 24;
|
||||
settings.PlexContentCacher = 60;
|
||||
settings.PlexUserChecker = 24;
|
||||
settings.PlexContentCacher = 60;
|
||||
|
||||
ScheduledJobSettings.SaveSettings(settings);
|
||||
ScheduledJobSettings.SaveSettings(settings);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateScheduledJobs)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateDefaultUserManagementSettings()
|
||||
{
|
||||
var plexRequestSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
UserManagementSettings.SaveSettings(new UserManagementSettings
|
||||
try
|
||||
{
|
||||
AutoApproveMovies = !plexRequestSettings.RequireMovieApproval,
|
||||
RequestTvShows = plexRequestSettings.SearchForTvShows,
|
||||
RequestMusic = plexRequestSettings.SearchForMusic,
|
||||
RequestMovies = plexRequestSettings.SearchForMovies,
|
||||
AutoApproveMusic = !plexRequestSettings.RequireMusicApproval,
|
||||
AutoApproveTvShows = !plexRequestSettings.RequireTvShowApproval
|
||||
});
|
||||
var plexRequestSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
UserManagementSettings.SaveSettings(new UserManagementSettings
|
||||
{
|
||||
AutoApproveMovies = !plexRequestSettings.RequireMovieApproval,
|
||||
RequestTvShows = plexRequestSettings.SearchForTvShows,
|
||||
RequestMusic = plexRequestSettings.SearchForMusic,
|
||||
RequestMovies = plexRequestSettings.SearchForMovies,
|
||||
AutoApproveMusic = !plexRequestSettings.RequireMusicApproval,
|
||||
AutoApproveTvShows = !plexRequestSettings.RequireTvShowApproval
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (PopulateDefaultUserMngmentSettings)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePlexUsers()
|
||||
{
|
||||
var settings = PlexSettings.GetSettings();
|
||||
if (string.IsNullOrEmpty(settings.PlexAuthToken))
|
||||
try
|
||||
{
|
||||
return;
|
||||
}
|
||||
var plexUsers = PlexApi.GetUsers(settings.PlexAuthToken);
|
||||
var settings = PlexSettings.GetSettings();
|
||||
if (string.IsNullOrEmpty(settings.PlexAuthToken))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var plexUsers = PlexApi.GetUsers(settings.PlexAuthToken);
|
||||
|
||||
if (plexUsers?.User == null)
|
||||
if (plexUsers?.User == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var prSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
var dbUsers = PlexUsers.GetAll().ToList();
|
||||
foreach (var user in plexUsers.User)
|
||||
{
|
||||
if (dbUsers.FirstOrDefault(x => x.PlexUserId == user.Id) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int permissions = 0;
|
||||
if (prSettings.SearchForMovies)
|
||||
{
|
||||
permissions = (int)Permissions.RequestMovie;
|
||||
}
|
||||
if (prSettings.SearchForTvShows)
|
||||
{
|
||||
permissions += (int)Permissions.RequestTvShow;
|
||||
}
|
||||
if (prSettings.SearchForMusic)
|
||||
{
|
||||
permissions += (int)Permissions.RequestMusic;
|
||||
}
|
||||
if (!prSettings.RequireMovieApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveMovie;
|
||||
}
|
||||
if (!prSettings.RequireTvShowApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveTv;
|
||||
}
|
||||
if (!prSettings.RequireMusicApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveAlbum;
|
||||
}
|
||||
|
||||
// Add report Issues
|
||||
|
||||
permissions += (int)Permissions.ReportIssue;
|
||||
|
||||
var m = new PlexUsers
|
||||
{
|
||||
PlexUserId = user.Id,
|
||||
Permissions = permissions,
|
||||
Features = 0,
|
||||
UserAlias = string.Empty,
|
||||
EmailAddress = user.Email,
|
||||
Username = user.Username,
|
||||
LoginId = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
PlexUsers.Insert(m);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return;
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdatePlexUsers)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
|
||||
var prSettings = PlexRequestSettings.GetSettings();
|
||||
|
||||
var dbUsers = PlexUsers.GetAll().ToList();
|
||||
foreach (var user in plexUsers.User)
|
||||
{
|
||||
if (dbUsers.FirstOrDefault(x => x.PlexUserId == user.Id) != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int permissions = 0;
|
||||
if (prSettings.SearchForMovies)
|
||||
{
|
||||
permissions = (int)Permissions.RequestMovie;
|
||||
}
|
||||
if (prSettings.SearchForTvShows)
|
||||
{
|
||||
permissions += (int)Permissions.RequestTvShow;
|
||||
}
|
||||
if (prSettings.SearchForMusic)
|
||||
{
|
||||
permissions += (int)Permissions.RequestMusic;
|
||||
}
|
||||
if (!prSettings.RequireMovieApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveMovie;
|
||||
}
|
||||
if (!prSettings.RequireTvShowApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveTv;
|
||||
}
|
||||
if (!prSettings.RequireMusicApproval)
|
||||
{
|
||||
permissions += (int)Permissions.AutoApproveAlbum;
|
||||
}
|
||||
|
||||
// Add report Issues
|
||||
|
||||
permissions += (int)Permissions.ReportIssue;
|
||||
|
||||
var m = new PlexUsers
|
||||
{
|
||||
PlexUserId = user.Id,
|
||||
Permissions = permissions,
|
||||
Features = 0,
|
||||
UserAlias = string.Empty,
|
||||
EmailAddress = user.Email,
|
||||
Username = user.Username,
|
||||
LoginId = Guid.NewGuid().ToString()
|
||||
};
|
||||
|
||||
PlexUsers.Insert(m);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ResetLogLevel()
|
||||
{
|
||||
var logSettings = Log.GetSettings();
|
||||
logSettings.Level = LogLevel.Error.Ordinal;
|
||||
Log.SaveSettings(logSettings);
|
||||
try
|
||||
{
|
||||
var logSettings = Log.GetSettings();
|
||||
logSettings.Level = LogLevel.Error.Ordinal;
|
||||
Log.SaveSettings(logSettings);
|
||||
|
||||
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
|
||||
LoggingHelper.ReconfigureLogLevel(LogLevel.FromOrdinal(logSettings.Level));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (ResetLogLvl)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDb(IDbConnection con)
|
||||
{
|
||||
// Create the two new columns
|
||||
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("Users", "ADD", "Features", true, "INTEGER");
|
||||
|
||||
con.AlterTable("PlexUsers", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Features", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Username", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "EmailAddress", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "LoginId", true, "VARCHAR(100)");
|
||||
|
||||
//https://image.tmdb.org/t/p/w150/https://image.tmdb.org/t/p/w150//aqhAqttDq7zgsTaBHtCD8wmTk6k.jpg
|
||||
|
||||
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}
|
||||
// Update old invalid posters
|
||||
var allRequests = RequestService.GetAll();
|
||||
if (allRequests == null)
|
||||
try
|
||||
{
|
||||
return;
|
||||
}
|
||||
var requestedModels = allRequests as RequestedModel[] ?? allRequests.ToArray();
|
||||
foreach (var req in requestedModels)
|
||||
{
|
||||
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))
|
||||
// Create the two new columns
|
||||
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("Users", "ADD", "Features", true, "INTEGER");
|
||||
|
||||
con.AlterTable("PlexUsers", "ADD", "Permissions", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Features", true, "INTEGER");
|
||||
con.AlterTable("PlexUsers", "ADD", "Username", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "EmailAddress", true, "VARCHAR(100)");
|
||||
con.AlterTable("PlexUsers", "ADD", "LoginId", true, "VARCHAR(100)");
|
||||
|
||||
//https://image.tmdb.org/t/p/w150/https://image.tmdb.org/t/p/w150//aqhAqttDq7zgsTaBHtCD8wmTk6k.jpg
|
||||
|
||||
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}
|
||||
// Update old invalid posters
|
||||
var allRequests = RequestService.GetAll();
|
||||
if (allRequests == null)
|
||||
{
|
||||
var newImg = req.PosterPath.Replace("https://image.tmdb.org/t/p/w150/", string.Empty);
|
||||
req.PosterPath = newImg;
|
||||
return;
|
||||
}
|
||||
var requestedModels = allRequests.ToList();
|
||||
foreach (var req in requestedModels)
|
||||
{
|
||||
if (string.IsNullOrEmpty(req.PosterPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))
|
||||
{
|
||||
var newImg = req.PosterPath.Replace("https://image.tmdb.org/t/p/w150/", string.Empty);
|
||||
req.PosterPath = newImg;
|
||||
}
|
||||
}
|
||||
RequestService.BatchUpdate(requestedModels);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateDb)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
RequestService.BatchUpdate(requestedModels);
|
||||
}
|
||||
|
||||
private void UpdateAdmin()
|
||||
{
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
foreach (var user in users)
|
||||
try
|
||||
{
|
||||
user.Permissions = (int)
|
||||
(Permissions.Administrator
|
||||
| Permissions.ReportIssue
|
||||
| Permissions.RequestMusic
|
||||
| Permissions.RequestTvShow
|
||||
| Permissions.RequestMovie
|
||||
| Permissions.AutoApproveAlbum
|
||||
| Permissions.AutoApproveMovie
|
||||
| Permissions.AutoApproveTv);
|
||||
}
|
||||
var users = UserRepo.GetAll().ToList();
|
||||
|
||||
UserRepo.UpdateAll(users);
|
||||
foreach (var user in users)
|
||||
{
|
||||
user.Permissions = (int)
|
||||
(Permissions.Administrator
|
||||
| Permissions.ReportIssue
|
||||
| Permissions.RequestMusic
|
||||
| Permissions.RequestTvShow
|
||||
| Permissions.RequestMovie
|
||||
| Permissions.AutoApproveAlbum
|
||||
| Permissions.AutoApproveMovie
|
||||
| Permissions.AutoApproveTv);
|
||||
}
|
||||
|
||||
UserRepo.UpdateAll(users);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Fatal("Exception when migrating Version 1.10.0 (UpdateAdmin)");
|
||||
Logger.Fatal(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -511,7 +511,7 @@ namespace PlexRequests.Services.Jobs
|
|||
|
||||
private void EndLoopHtml(StringBuilder sb)
|
||||
{
|
||||
sb.Append("<td");
|
||||
sb.Append("</td>");
|
||||
sb.Append("<hr>");
|
||||
sb.Append("<br>");
|
||||
sb.Append("<br>");
|
||||
|
|
|
@ -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}");
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
<button id="clearLogs" type="submit" class="btn btn-danger-outline ">Clear Logs</button>
|
||||
</form>
|
||||
|
||||
<table id="example" class="table table-striped table-hover table-responsive">
|
||||
<table id="logDatatable" class="table table-striped table-hover table-responsive">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Message</th>
|
||||
|
@ -63,7 +63,7 @@
|
|||
|
||||
var logsUrl = "/admin/loadlogs";
|
||||
var url = createBaseUrl(baseUrl, logsUrl);
|
||||
$('#example').DataTable({
|
||||
$('#logDatatable').DataTable({
|
||||
"ajax": url,
|
||||
"columns": [
|
||||
{ "data": "message" },
|
||||
|
@ -147,5 +147,8 @@
|
|||
});
|
||||
|
||||
|
||||
$('body .dropdown-toggle').dropdown();
|
||||
|
||||
|
||||
});
|
||||
</script>
|
|
@ -57,7 +57,6 @@
|
|||
<div class="form-group">
|
||||
<label for="ApiKey" class="control-label">Api Key</label>
|
||||
<div class="input-group">
|
||||
<input type="text" hidden="hidden" name="ApiKey" value="@Model.ApiKey"/>
|
||||
<input type="text" readonly="readonly" class="form-control form-control-custom" id="ApiKey" name="ApiKey" value="@Model.ApiKey">
|
||||
|
||||
<div class="input-group-addon">
|
||||
|
|
|
@ -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 @@ ____
|
|||
[](https://github.com/tidusjar/PlexRequests.Net)
|
||||
[](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…
Add table
Add a link
Reference in a new issue