mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-03 06:18:28 +01:00
Update to 3.5.2 and .net core 2.1
This commit is contained in:
@@ -19,6 +19,11 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using MediaBrowser.Model.Globalization;
|
||||
using MediaBrowser.Model.Extensions;
|
||||
using MediaBrowser.Model.Notifications;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Controller.Devices;
|
||||
using MediaBrowser.Controller.Authentication;
|
||||
|
||||
namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
@@ -26,7 +31,6 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
private readonly IInstallationManager _installationManager;
|
||||
|
||||
//private readonly ILogManager _logManager;
|
||||
//private readonly ILogger _logger;
|
||||
private readonly ISessionManager _sessionManager;
|
||||
private readonly ITaskManager _taskManager;
|
||||
@@ -38,10 +42,10 @@ namespace Emby.Server.Implementations.Activity
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IServerConfigurationManager _config;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
private readonly IDeviceManager _deviceManager;
|
||||
|
||||
public ActivityLogEntryPoint(ISessionManager sessionManager, ITaskManager taskManager, IActivityManager activityManager, ILocalizationManager localization, IInstallationManager installationManager, ILibraryManager libraryManager, ISubtitleManager subManager, IUserManager userManager, IServerConfigurationManager config, IServerApplicationHost appHost)
|
||||
public ActivityLogEntryPoint(ISessionManager sessionManager, IDeviceManager deviceManager, ITaskManager taskManager, IActivityManager activityManager, ILocalizationManager localization, IInstallationManager installationManager, ILibraryManager libraryManager, ISubtitleManager subManager, IUserManager userManager, IServerConfigurationManager config, IServerApplicationHost appHost)
|
||||
{
|
||||
//_logger = _logManager.GetLogger("ActivityLogEntryPoint");
|
||||
_sessionManager = sessionManager;
|
||||
_taskManager = taskManager;
|
||||
_activityManager = activityManager;
|
||||
@@ -51,21 +55,18 @@ namespace Emby.Server.Implementations.Activity
|
||||
_subManager = subManager;
|
||||
_userManager = userManager;
|
||||
_config = config;
|
||||
//_logManager = logManager;
|
||||
_appHost = appHost;
|
||||
_deviceManager = deviceManager;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
//_taskManager.TaskExecuting += _taskManager_TaskExecuting;
|
||||
//_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
||||
_taskManager.TaskCompleted += _taskManager_TaskCompleted;
|
||||
|
||||
//_installationManager.PluginInstalled += _installationManager_PluginInstalled;
|
||||
//_installationManager.PluginUninstalled += _installationManager_PluginUninstalled;
|
||||
//_installationManager.PluginUpdated += _installationManager_PluginUpdated;
|
||||
|
||||
//_libraryManager.ItemAdded += _libraryManager_ItemAdded;
|
||||
//_libraryManager.ItemRemoved += _libraryManager_ItemRemoved;
|
||||
_installationManager.PluginInstalled += _installationManager_PluginInstalled;
|
||||
_installationManager.PluginUninstalled += _installationManager_PluginUninstalled;
|
||||
_installationManager.PluginUpdated += _installationManager_PluginUpdated;
|
||||
_installationManager.PackageInstallationFailed += _installationManager_PackageInstallationFailed;
|
||||
|
||||
_sessionManager.SessionStarted += _sessionManager_SessionStarted;
|
||||
_sessionManager.AuthenticationFailed += _sessionManager_AuthenticationFailed;
|
||||
@@ -81,24 +82,33 @@ namespace Emby.Server.Implementations.Activity
|
||||
_userManager.UserCreated += _userManager_UserCreated;
|
||||
_userManager.UserPasswordChanged += _userManager_UserPasswordChanged;
|
||||
_userManager.UserDeleted += _userManager_UserDeleted;
|
||||
_userManager.UserConfigurationUpdated += _userManager_UserConfigurationUpdated;
|
||||
_userManager.UserPolicyUpdated += _userManager_UserPolicyUpdated;
|
||||
_userManager.UserLockedOut += _userManager_UserLockedOut;
|
||||
|
||||
//_config.ConfigurationUpdated += _config_ConfigurationUpdated;
|
||||
//_config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated;
|
||||
|
||||
//_logManager.LoggerLoaded += _logManager_LoggerLoaded;
|
||||
_deviceManager.CameraImageUploaded += _deviceManager_CameraImageUploaded;
|
||||
|
||||
_appHost.ApplicationUpdated += _appHost_ApplicationUpdated;
|
||||
}
|
||||
|
||||
void _deviceManager_CameraImageUploaded(object sender, GenericEventArgs<CameraImageUploadInfo> e)
|
||||
{
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("CameraImageUploadedFrom"), e.Argument.Device.Name),
|
||||
Type = NotificationType.CameraImageUploaded.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
void _userManager_UserLockedOut(object sender, GenericEventArgs<User> e)
|
||||
{
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserLockedOutWithName"), e.Argument.Name),
|
||||
Type = "UserLockedOut",
|
||||
UserId = e.Argument.Id.ToString("N")
|
||||
Type = NotificationType.UserLockedOut.ToString(),
|
||||
UserId = e.Argument.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -106,11 +116,10 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("SubtitleDownloadFailureForItem"), Notifications.Notifications.GetItemName(e.Item)),
|
||||
Name = string.Format(_localization.GetLocalizedString("SubtitleDownloadFailureFromForItem"), e.Provider, Notifications.Notifications.GetItemName(e.Item)),
|
||||
Type = "SubtitleDownloadFailure",
|
||||
ItemId = e.Item.Id.ToString("N"),
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("ProviderValue"), e.Provider),
|
||||
Overview = LogHelper.GetLogMessage(e.Exception).ToString()
|
||||
ShortOverview = e.Exception.Message
|
||||
});
|
||||
}
|
||||
|
||||
@@ -139,10 +148,9 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"), user.Name, Notifications.Notifications.GetItemName(item)),
|
||||
Type = "PlaybackStopped",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName),
|
||||
UserId = user.Id.ToString("N")
|
||||
Name = string.Format(_localization.GetLocalizedString("UserStoppedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName),
|
||||
Type = GetPlaybackStoppedNotificationType(item.MediaType),
|
||||
UserId = user.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -171,19 +179,71 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, Notifications.Notifications.GetItemName(item)),
|
||||
Type = "PlaybackStart",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("AppDeviceValues"), e.ClientName, e.DeviceName),
|
||||
UserId = user.Id.ToString("N")
|
||||
Name = string.Format(_localization.GetLocalizedString("UserStartedPlayingItemWithValues"), user.Name, GetItemName(item), e.DeviceName),
|
||||
Type = GetPlaybackNotificationType(item.MediaType),
|
||||
UserId = user.Id
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetItemName(BaseItemDto item)
|
||||
{
|
||||
var name = item.Name;
|
||||
|
||||
if (!string.IsNullOrEmpty(item.SeriesName))
|
||||
{
|
||||
name = item.SeriesName + " - " + name;
|
||||
}
|
||||
|
||||
if (item.Artists != null && item.Artists.Length > 0)
|
||||
{
|
||||
name = item.Artists[0] + " - " + name;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private string GetPlaybackNotificationType(string mediaType)
|
||||
{
|
||||
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.AudioPlayback.ToString();
|
||||
}
|
||||
if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.GamePlayback.ToString();
|
||||
}
|
||||
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.VideoPlayback.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetPlaybackStoppedNotificationType(string mediaType)
|
||||
{
|
||||
if (string.Equals(mediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.AudioPlaybackStopped.ToString();
|
||||
}
|
||||
if (string.Equals(mediaType, MediaType.Game, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.GamePlaybackStopped.ToString();
|
||||
}
|
||||
if (string.Equals(mediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return NotificationType.VideoPlaybackStopped.ToString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
void _sessionManager_SessionEnded(object sender, SessionEventArgs e)
|
||||
{
|
||||
string name;
|
||||
var session = e.SessionInfo;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(session.UserName))
|
||||
if (string.IsNullOrEmpty(session.UserName))
|
||||
{
|
||||
name = string.Format(_localization.GetLocalizedString("DeviceOfflineWithName"), session.DeviceName);
|
||||
|
||||
@@ -200,17 +260,20 @@ namespace Emby.Server.Implementations.Activity
|
||||
Name = name,
|
||||
Type = "SessionEnded",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), session.RemoteEndPoint),
|
||||
UserId = session.UserId.HasValue ? session.UserId.Value.ToString("N") : null
|
||||
UserId = session.UserId
|
||||
});
|
||||
}
|
||||
|
||||
void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationRequest> e)
|
||||
void _sessionManager_AuthenticationSucceeded(object sender, GenericEventArgs<AuthenticationResult> e)
|
||||
{
|
||||
var user = e.Argument.User;
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("AuthenticationSucceededWithUserName"), e.Argument.Username),
|
||||
Name = string.Format(_localization.GetLocalizedString("AuthenticationSucceededWithUserName"), user.Name),
|
||||
Type = "AuthenticationSucceeded",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), e.Argument.RemoteEndPoint)
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), e.Argument.SessionInfo.RemoteEndPoint),
|
||||
UserId = user.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -229,9 +292,8 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = _localization.GetLocalizedString("MessageApplicationUpdated"),
|
||||
Type = "ApplicationUpdated",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.versionStr),
|
||||
Name = string.Format(_localization.GetLocalizedString("MessageApplicationUpdatedTo"), e.Argument.versionStr),
|
||||
Type = NotificationType.ApplicationUpdateInstalled.ToString(),
|
||||
Overview = e.Argument.description
|
||||
});
|
||||
}
|
||||
@@ -254,13 +316,13 @@ namespace Emby.Server.Implementations.Activity
|
||||
});
|
||||
}
|
||||
|
||||
void _userManager_UserConfigurationUpdated(object sender, GenericEventArgs<User> e)
|
||||
void _userManager_UserPolicyUpdated(object sender, GenericEventArgs<User> e)
|
||||
{
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserConfigurationUpdatedWithName"), e.Argument.Name),
|
||||
Type = "UserConfigurationUpdated",
|
||||
UserId = e.Argument.Id.ToString("N")
|
||||
Name = string.Format(_localization.GetLocalizedString("UserPolicyUpdatedWithName"), e.Argument.Name),
|
||||
Type = "UserPolicyUpdated",
|
||||
UserId = e.Argument.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -279,7 +341,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserPasswordChangedWithName"), e.Argument.Name),
|
||||
Type = "UserPasswordChanged",
|
||||
UserId = e.Argument.Id.ToString("N")
|
||||
UserId = e.Argument.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -289,7 +351,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("UserCreatedWithName"), e.Argument.Name),
|
||||
Type = "UserCreated",
|
||||
UserId = e.Argument.Id.ToString("N")
|
||||
UserId = e.Argument.Id
|
||||
});
|
||||
}
|
||||
|
||||
@@ -309,7 +371,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
string name;
|
||||
var session = e.SessionInfo;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(session.UserName))
|
||||
if (string.IsNullOrEmpty(session.UserName))
|
||||
{
|
||||
name = string.Format(_localization.GetLocalizedString("DeviceOnlineWithName"), session.DeviceName);
|
||||
|
||||
@@ -326,36 +388,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
Name = name,
|
||||
Type = "SessionStarted",
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("LabelIpAddressValue"), session.RemoteEndPoint),
|
||||
UserId = session.UserId.HasValue ? session.UserId.Value.ToString("N") : null
|
||||
});
|
||||
}
|
||||
|
||||
void _libraryManager_ItemRemoved(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
if (e.Item.SourceType != SourceType.Library)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("ItemRemovedWithName"), Notifications.Notifications.GetItemName(e.Item)),
|
||||
Type = "ItemRemoved"
|
||||
});
|
||||
}
|
||||
|
||||
void _libraryManager_ItemAdded(object sender, ItemChangeEventArgs e)
|
||||
{
|
||||
if (e.Item.SourceType != SourceType.Library)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("ItemAddedWithName"), Notifications.Notifications.GetItemName(e.Item)),
|
||||
Type = "ItemAdded",
|
||||
ItemId = e.Item.Id.ToString("N")
|
||||
UserId = session.UserId
|
||||
});
|
||||
}
|
||||
|
||||
@@ -364,7 +397,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("PluginUpdatedWithName"), e.Argument.Item1.Name),
|
||||
Type = "PluginUpdated",
|
||||
Type = NotificationType.PluginUpdateInstalled.ToString(),
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.Item2.versionStr),
|
||||
Overview = e.Argument.Item2.description
|
||||
});
|
||||
@@ -375,7 +408,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("PluginUninstalledWithName"), e.Argument.Name),
|
||||
Type = "PluginUninstalled"
|
||||
Type = NotificationType.PluginUninstalled.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
@@ -384,25 +417,21 @@ namespace Emby.Server.Implementations.Activity
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("PluginInstalledWithName"), e.Argument.name),
|
||||
Type = "PluginInstalled",
|
||||
Type = NotificationType.PluginInstalled.ToString(),
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), e.Argument.versionStr)
|
||||
});
|
||||
}
|
||||
|
||||
void _taskManager_TaskExecuting(object sender, GenericEventArgs<IScheduledTaskWorker> e)
|
||||
void _installationManager_PackageInstallationFailed(object sender, InstallationFailedEventArgs e)
|
||||
{
|
||||
var task = e.Argument;
|
||||
|
||||
var activityTask = task.ScheduledTask as IConfigurableScheduledTask;
|
||||
if (activityTask != null && !activityTask.IsLogged)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var installationInfo = e.InstallationInfo;
|
||||
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("ScheduledTaskStartedWithName"), task.Name),
|
||||
Type = "ScheduledTaskStarted"
|
||||
Name = string.Format(_localization.GetLocalizedString("NameInstallFailed"), installationInfo.Name),
|
||||
Type = NotificationType.InstallationFailed.ToString(),
|
||||
ShortOverview = string.Format(_localization.GetLocalizedString("VersionNumber"), installationInfo.Version),
|
||||
Overview = e.Exception.Message
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,11 +453,11 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
var vals = new List<string>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(e.Result.ErrorMessage))
|
||||
if (!string.IsNullOrEmpty(e.Result.ErrorMessage))
|
||||
{
|
||||
vals.Add(e.Result.ErrorMessage);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(e.Result.LongErrorMessage))
|
||||
if (!string.IsNullOrEmpty(e.Result.LongErrorMessage))
|
||||
{
|
||||
vals.Add(e.Result.LongErrorMessage);
|
||||
}
|
||||
@@ -436,7 +465,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
CreateLogEntry(new ActivityLogEntry
|
||||
{
|
||||
Name = string.Format(_localization.GetLocalizedString("ScheduledTaskFailedWithName"), task.Name),
|
||||
Type = "ScheduledTaskFailed",
|
||||
Type = NotificationType.TaskFailed.ToString(),
|
||||
Overview = string.Join(Environment.NewLine, vals.ToArray(vals.Count)),
|
||||
ShortOverview = runningTime,
|
||||
Severity = LogSeverity.Error
|
||||
@@ -458,15 +487,12 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_taskManager.TaskExecuting -= _taskManager_TaskExecuting;
|
||||
_taskManager.TaskCompleted -= _taskManager_TaskCompleted;
|
||||
|
||||
_installationManager.PluginInstalled -= _installationManager_PluginInstalled;
|
||||
_installationManager.PluginUninstalled -= _installationManager_PluginUninstalled;
|
||||
_installationManager.PluginUpdated -= _installationManager_PluginUpdated;
|
||||
|
||||
_libraryManager.ItemAdded -= _libraryManager_ItemAdded;
|
||||
_libraryManager.ItemRemoved -= _libraryManager_ItemRemoved;
|
||||
_installationManager.PackageInstallationFailed -= _installationManager_PackageInstallationFailed;
|
||||
|
||||
_sessionManager.SessionStarted -= _sessionManager_SessionStarted;
|
||||
_sessionManager.AuthenticationFailed -= _sessionManager_AuthenticationFailed;
|
||||
@@ -482,16 +508,15 @@ namespace Emby.Server.Implementations.Activity
|
||||
_userManager.UserCreated -= _userManager_UserCreated;
|
||||
_userManager.UserPasswordChanged -= _userManager_UserPasswordChanged;
|
||||
_userManager.UserDeleted -= _userManager_UserDeleted;
|
||||
_userManager.UserConfigurationUpdated -= _userManager_UserConfigurationUpdated;
|
||||
_userManager.UserPolicyUpdated -= _userManager_UserPolicyUpdated;
|
||||
_userManager.UserLockedOut -= _userManager_UserLockedOut;
|
||||
|
||||
_config.ConfigurationUpdated -= _config_ConfigurationUpdated;
|
||||
_config.NamedConfigurationUpdated -= _config_NamedConfigurationUpdated;
|
||||
|
||||
//_logManager.LoggerLoaded -= _logManager_LoggerLoaded;
|
||||
_deviceManager.CameraImageUploaded -= _deviceManager_CameraImageUploaded;
|
||||
|
||||
_appHost.ApplicationUpdated -= _appHost_ApplicationUpdated;
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,7 +6,6 @@ using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
@@ -27,7 +26,6 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
public void Create(ActivityLogEntry entry)
|
||||
{
|
||||
entry.Id = Guid.NewGuid().ToString("N");
|
||||
entry.Date = DateTime.UtcNow;
|
||||
|
||||
_repo.Create(entry);
|
||||
@@ -35,11 +33,11 @@ namespace Emby.Server.Implementations.Activity
|
||||
EventHelper.FireEventIfNotNull(EntryCreated, this, new GenericEventArgs<ActivityLogEntry>(entry), _logger);
|
||||
}
|
||||
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
||||
{
|
||||
var result = _repo.GetActivityLogEntries(minDate, startIndex, limit);
|
||||
var result = _repo.GetActivityLogEntries(minDate, hasUserId, startIndex, limit);
|
||||
|
||||
foreach (var item in result.Items.Where(i => !string.IsNullOrWhiteSpace(i.UserId)))
|
||||
foreach (var item in result.Items.Where(i => !i.UserId.Equals(Guid.Empty)))
|
||||
{
|
||||
var user = _userManager.GetUserById(item.UserId);
|
||||
|
||||
@@ -52,5 +50,10 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
||||
{
|
||||
return GetActivityLogEntries(minDate, null, startIndex, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,20 +48,76 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
RunDefaultInitialization(connection);
|
||||
|
||||
string[] queries = {
|
||||
"create table if not exists ActivityLogEntries (Id GUID PRIMARY KEY NOT NULL, Name TEXT NOT NULL, Overview TEXT, ShortOverview TEXT, Type TEXT NOT NULL, ItemId TEXT, UserId TEXT, DateCreated DATETIME NOT NULL, LogSeverity TEXT NOT NULL)",
|
||||
"create index if not exists idx_ActivityLogEntries on ActivityLogEntries(Id)"
|
||||
};
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"create table if not exists ActivityLog (Id INTEGER PRIMARY KEY, Name TEXT NOT NULL, Overview TEXT, ShortOverview TEXT, Type TEXT NOT NULL, ItemId TEXT, UserId TEXT, DateCreated DATETIME NOT NULL, LogSeverity TEXT NOT NULL)",
|
||||
"drop index if exists idx_ActivityLogEntries"
|
||||
});
|
||||
|
||||
connection.RunQueries(queries);
|
||||
TryMigrate(connection);
|
||||
}
|
||||
}
|
||||
|
||||
private const string BaseActivitySelectText = "select Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity from ActivityLogEntries";
|
||||
private void TryMigrate(ManagedConnection connection)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (TableExists(connection, "ActivityLogEntries"))
|
||||
{
|
||||
connection.RunQueries(new[]
|
||||
{
|
||||
"INSERT INTO ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) SELECT Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity FROM ActivityLogEntries",
|
||||
"drop table if exists ActivityLogEntries"
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.ErrorException("Error migrating activity log database", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private const string BaseActivitySelectText = "select Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity from ActivityLog";
|
||||
|
||||
public void Create(ActivityLogEntry entry)
|
||||
{
|
||||
Update(entry);
|
||||
if (entry == null)
|
||||
{
|
||||
throw new ArgumentNullException("entry");
|
||||
}
|
||||
|
||||
using (WriteLock.Write())
|
||||
{
|
||||
using (var connection = CreateConnection())
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = db.PrepareStatement("insert into ActivityLog (Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"))
|
||||
{
|
||||
statement.TryBind("@Name", entry.Name);
|
||||
|
||||
statement.TryBind("@Overview", entry.Overview);
|
||||
statement.TryBind("@ShortOverview", entry.ShortOverview);
|
||||
statement.TryBind("@Type", entry.Type);
|
||||
statement.TryBind("@ItemId", entry.ItemId);
|
||||
|
||||
if (entry.UserId.Equals(Guid.Empty))
|
||||
{
|
||||
statement.TryBindNull("@UserId");
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
||||
}
|
||||
|
||||
statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
||||
statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
||||
|
||||
statement.MoveNext();
|
||||
}
|
||||
}, TransactionMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(ActivityLogEntry entry)
|
||||
@@ -77,16 +133,25 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = db.PrepareStatement("replace into ActivityLogEntries (Id, Name, Overview, ShortOverview, Type, ItemId, UserId, DateCreated, LogSeverity) values (@Id, @Name, @Overview, @ShortOverview, @Type, @ItemId, @UserId, @DateCreated, @LogSeverity)"))
|
||||
using (var statement = db.PrepareStatement("Update ActivityLog set Name=@Name,Overview=@Overview,ShortOverview=@ShortOverview,Type=@Type,ItemId=@ItemId,UserId=@UserId,DateCreated=@DateCreated,LogSeverity=@LogSeverity where Id=@Id"))
|
||||
{
|
||||
statement.TryBind("@Id", entry.Id.ToGuidBlob());
|
||||
statement.TryBind("@Name", entry.Name);
|
||||
statement.TryBind("@Id", entry.Id);
|
||||
|
||||
statement.TryBind("@Name", entry.Name);
|
||||
statement.TryBind("@Overview", entry.Overview);
|
||||
statement.TryBind("@ShortOverview", entry.ShortOverview);
|
||||
statement.TryBind("@Type", entry.Type);
|
||||
statement.TryBind("@ItemId", entry.ItemId);
|
||||
statement.TryBind("@UserId", entry.UserId);
|
||||
|
||||
if (entry.UserId.Equals(Guid.Empty))
|
||||
{
|
||||
statement.TryBindNull("@UserId");
|
||||
}
|
||||
else
|
||||
{
|
||||
statement.TryBind("@UserId", entry.UserId.ToString("N"));
|
||||
}
|
||||
|
||||
statement.TryBind("@DateCreated", entry.Date.ToDateTimeParamValue());
|
||||
statement.TryBind("@LogSeverity", entry.Severity.ToString());
|
||||
|
||||
@@ -97,7 +162,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
}
|
||||
}
|
||||
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, int? startIndex, int? limit)
|
||||
public QueryResult<ActivityLogEntry> GetActivityLogEntries(DateTime? minDate, bool? hasUserId, int? startIndex, int? limit)
|
||||
{
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
@@ -110,6 +175,17 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
whereClauses.Add("DateCreated>=@DateCreated");
|
||||
}
|
||||
if (hasUserId.HasValue)
|
||||
{
|
||||
if (hasUserId.Value)
|
||||
{
|
||||
whereClauses.Add("UserId not null");
|
||||
}
|
||||
else
|
||||
{
|
||||
whereClauses.Add("UserId is null");
|
||||
}
|
||||
}
|
||||
|
||||
var whereTextWithoutPaging = whereClauses.Count == 0 ?
|
||||
string.Empty :
|
||||
@@ -121,7 +197,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
string.Empty :
|
||||
" where " + string.Join(" AND ", whereClauses.ToArray(whereClauses.Count));
|
||||
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLogEntries {0} ORDER BY DateCreated DESC LIMIT {1})",
|
||||
whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM ActivityLog {0} ORDER BY DateCreated DESC LIMIT {1})",
|
||||
pagingWhereText,
|
||||
startIndex.Value.ToString(_usCulture)));
|
||||
}
|
||||
@@ -141,7 +217,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
var statementTexts = new List<string>();
|
||||
statementTexts.Add(commandText);
|
||||
statementTexts.Add("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging);
|
||||
statementTexts.Add("select count (Id) from ActivityLog" + whereTextWithoutPaging);
|
||||
|
||||
return connection.RunInTransaction(db =>
|
||||
{
|
||||
@@ -187,7 +263,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
|
||||
var info = new ActivityLogEntry
|
||||
{
|
||||
Id = reader[index].ReadGuidFromBlob().ToString("N")
|
||||
Id = reader[index].ToInt64()
|
||||
};
|
||||
|
||||
index++;
|
||||
@@ -223,7 +299,7 @@ namespace Emby.Server.Implementations.Activity
|
||||
index++;
|
||||
if (reader[index].SQLiteType != SQLiteType.Null)
|
||||
{
|
||||
info.UserId = reader[index].ToString();
|
||||
info.UserId = new Guid(reader[index].ToString());
|
||||
}
|
||||
|
||||
index++;
|
||||
|
||||
Reference in New Issue
Block a user