rework scheduled tasks in preparation of common project going portable

This commit is contained in:
Luke Pulverenti 2016-10-23 15:14:57 -04:00
parent 4829683402
commit 07791d46a5
78 changed files with 500 additions and 411 deletions

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Api.Dlna
{

View File

@ -198,17 +198,13 @@ namespace MediaBrowser.Api.ScheduledTasks
throw new ResourceNotFoundException("Task not found");
}
var hasKey = task.ScheduledTask as IHasKey;
if (hasKey != null)
if (string.Equals(task.ScheduledTask.Key, "SystemUpdateTask", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(hasKey.Key, "SystemUpdateTask", StringComparison.OrdinalIgnoreCase))
// This is a hack for now just to get the update application function to work when auto-update is disabled
if (!_config.Configuration.EnableAutoUpdate)
{
// This is a hack for now just to get the update application function to work when auto-update is disabled
if (!_config.Configuration.EnableAutoUpdate)
{
_config.Configuration.EnableAutoUpdate = true;
_config.SaveConfiguration();
}
_config.Configuration.EnableAutoUpdate = true;
_config.SaveConfiguration();
}
}
@ -252,7 +248,7 @@ namespace MediaBrowser.Api.ScheduledTasks
var triggerInfos = request;
task.Triggers = triggerInfos.Select(ScheduledTaskHelpers.GetTrigger);
task.Triggers = triggerInfos.ToArray();
}
}
}

View File

@ -26,11 +26,16 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Implementations.Cryptography;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Common.Implementations
{
@ -67,7 +72,7 @@ namespace MediaBrowser.Common.Implementations
/// Gets or sets the plugins.
/// </summary>
/// <value>The plugins.</value>
public IEnumerable<IPlugin> Plugins { get; protected set; }
public IPlugin[] Plugins { get; protected set; }
/// <summary>
/// Gets or sets the log manager.
@ -174,6 +179,8 @@ namespace MediaBrowser.Common.Implementations
/// <value><c>true</c> if this instance is running as service; otherwise, <c>false</c>.</value>
public abstract bool IsRunningAsService { get; }
protected ICryptographyProvider CryptographyProvider = new CryptographyProvider();
private DeviceId _deviceId;
public string SystemId
{
@ -202,7 +209,10 @@ namespace MediaBrowser.Common.Implementations
ILogManager logManager,
IFileSystem fileSystem)
{
XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer"));
// hack alert, until common can target .net core
BaseExtensions.CryptographyProvider = CryptographyProvider;
XmlSerializer = new XmlSerializer (fileSystem, logManager.GetLogger("XmlSerializer"));
FailedAssemblies = new List<string>();
ApplicationPaths = applicationPaths;
@ -430,7 +440,28 @@ namespace MediaBrowser.Common.Implementations
RegisterModules();
ConfigurationManager.AddParts(GetExports<IConfigurationFactory>());
Plugins = GetExports<IPlugin>();
Plugins = GetExports<IPlugin>().Select(LoadPlugin).Where(i => i != null).ToArray();
}
private IPlugin LoadPlugin(IPlugin plugin)
{
var assemblyPlugin = plugin as IPluginAssembly;
if (assemblyPlugin != null)
{
var assembly = plugin.GetType().Assembly;
var assemblyName = assembly.GetName();
var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var assemblyId = new Guid(attribute.Value);
var assemblyFileName = assemblyName.Name + ".dll";
var assemblyFilePath = Path.Combine(ApplicationPaths.PluginsPath, assemblyFileName);
assemblyPlugin.SetAttributes(assemblyFilePath, assemblyFileName, assemblyName.Version, assemblyId);
}
return plugin;
}
/// <summary>
@ -747,7 +778,7 @@ namespace MediaBrowser.Common.Implementations
{
var list = Plugins.ToList();
list.Remove(plugin);
Plugins = list;
Plugins = list.ToArray();
}
/// <summary>

View File

@ -0,0 +1,18 @@
using System;
using System.Security.Cryptography;
using System.Text;
using MediaBrowser.Model.Cryptography;
namespace MediaBrowser.Common.Implementations.Cryptography
{
public class CryptographyProvider : ICryptographyProvider
{
public Guid GetMD5(string str)
{
using (var provider = MD5.Create())
{
return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
}
}
}
}

View File

@ -18,6 +18,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Common.Implementations.HttpClientManager
{

View File

@ -1,5 +1,6 @@
using System.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
using Microsoft.IO;
namespace MediaBrowser.Common.Implementations.IO

View File

@ -91,6 +91,7 @@
<Compile Include="BaseApplicationPaths.cs" />
<Compile Include="Configuration\BaseConfigurationManager.cs" />
<Compile Include="Configuration\ConfigurationHelper.cs" />
<Compile Include="Cryptography\CryptographyProvider.cs" />
<Compile Include="Devices\DeviceId.cs" />
<Compile Include="HttpClientManager\HttpClientInfo.cs" />
<Compile Include="HttpClientManager\HttpClientManager.cs" />
@ -101,11 +102,16 @@
<Compile Include="Logging\NlogManager.cs" />
<Compile Include="Networking\BaseNetworkManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScheduledTasks\DailyTrigger.cs" />
<Compile Include="ScheduledTasks\IntervalTrigger.cs" />
<Compile Include="ScheduledTasks\ScheduledTaskWorker.cs" />
<Compile Include="ScheduledTasks\StartupTrigger.cs" />
<Compile Include="ScheduledTasks\SystemEventTrigger.cs" />
<Compile Include="ScheduledTasks\TaskManager.cs" />
<Compile Include="ScheduledTasks\Tasks\DeleteCacheFileTask.cs" />
<Compile Include="ScheduledTasks\Tasks\DeleteLogFileTask.cs" />
<Compile Include="ScheduledTasks\Tasks\ReloadLoggerFileTask.cs" />
<Compile Include="ScheduledTasks\WeeklyTrigger.cs" />
<Compile Include="Security\MbAdmin.cs" />
<Compile Include="Security\MBLicenseFile.cs" />
<Compile Include="Security\PluginSecurityManager.cs" />

View File

@ -232,13 +232,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <summary>
/// The _triggers
/// </summary>
private List<ITaskTrigger> _triggers;
private Tuple<TaskTriggerInfo,ITaskTrigger>[] _triggers;
/// <summary>
/// Gets the triggers that define when the task will run
/// </summary>
/// <value>The triggers.</value>
/// <exception cref="System.ArgumentNullException">value</exception>
public IEnumerable<ITaskTrigger> Triggers
private Tuple<TaskTriggerInfo, ITaskTrigger>[] InternalTriggers
{
get
{
@ -257,11 +256,33 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
DisposeTriggers();
}
_triggers = value.ToList();
_triggers = value.ToArray();
ReloadTriggerEvents(false);
}
}
SaveTriggers(_triggers);
/// <summary>
/// Gets the triggers that define when the task will run
/// </summary>
/// <value>The triggers.</value>
/// <exception cref="System.ArgumentNullException">value</exception>
public TaskTriggerInfo[] Triggers
{
get
{
return InternalTriggers.Select(i => i.Item1).ToArray();
}
set
{
if (value == null)
{
throw new ArgumentNullException("value");
}
SaveTriggers(value);
InternalTriggers = value.Select(i => new Tuple<TaskTriggerInfo, ITaskTrigger>(i, GetTrigger(i))).ToArray();
}
}
@ -304,8 +325,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
private void ReloadTriggerEvents(bool isApplicationStartup)
{
foreach (var trigger in Triggers)
foreach (var triggerInfo in InternalTriggers)
{
var trigger = triggerInfo.Item2;
trigger.Stop();
trigger.Triggered -= trigger_Triggered;
@ -507,23 +530,29 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// Loads the triggers.
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
private List<ITaskTrigger> LoadTriggers()
private Tuple<TaskTriggerInfo, ITaskTrigger>[] LoadTriggers()
{
var settings = LoadTriggerSettings();
return settings.Select(i => new Tuple<TaskTriggerInfo, ITaskTrigger>(i, GetTrigger(i))).ToArray();
}
private TaskTriggerInfo[] LoadTriggerSettings()
{
try
{
return JsonSerializer.DeserializeFromFile<IEnumerable<TaskTriggerInfo>>(GetConfigurationFilePath())
.Select(ScheduledTaskHelpers.GetTrigger)
.ToList();
.ToArray();
}
catch (FileNotFoundException)
{
// File doesn't exist. No biggie. Return defaults.
return ScheduledTask.GetDefaultTriggers().ToList();
return ScheduledTask.GetDefaultTriggers().ToArray();
}
catch (DirectoryNotFoundException)
{
// File doesn't exist. No biggie. Return defaults.
return ScheduledTask.GetDefaultTriggers().ToList();
return ScheduledTask.GetDefaultTriggers().ToArray();
}
}
@ -531,13 +560,13 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
/// Saves the triggers.
/// </summary>
/// <param name="triggers">The triggers.</param>
private void SaveTriggers(IEnumerable<ITaskTrigger> triggers)
private void SaveTriggers(TaskTriggerInfo[] triggers)
{
var path = GetConfigurationFilePath();
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
JsonSerializer.SerializeToFile(triggers.Select(ScheduledTaskHelpers.GetTriggerInfo), path);
JsonSerializer.SerializeToFile(triggers, path);
}
/// <summary>
@ -561,11 +590,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
Id = Id
};
var hasKey = ScheduledTask as IHasKey;
if (hasKey != null)
{
result.Key = hasKey.Key;
}
result.Key = ScheduledTask.Key;
if (ex != null)
{
@ -655,13 +680,98 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks
}
}
/// <summary>
/// Converts a TaskTriggerInfo into a concrete BaseTaskTrigger
/// </summary>
/// <param name="info">The info.</param>
/// <returns>BaseTaskTrigger.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
/// <exception cref="System.ArgumentException">Invalid trigger type: + info.Type</exception>
public static ITaskTrigger GetTrigger(TaskTriggerInfo info)
{
var options = new TaskExecutionOptions
{
MaxRuntimeMs = info.MaxRuntimeMs
};
if (info.Type.Equals(typeof(DailyTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.TimeOfDayTicks.HasValue)
{
throw new ArgumentNullException();
}
return new DailyTrigger
{
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
TaskOptions = options
};
}
if (info.Type.Equals(typeof(WeeklyTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.TimeOfDayTicks.HasValue)
{
throw new ArgumentNullException();
}
if (!info.DayOfWeek.HasValue)
{
throw new ArgumentNullException();
}
return new WeeklyTrigger
{
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
DayOfWeek = info.DayOfWeek.Value,
TaskOptions = options
};
}
if (info.Type.Equals(typeof(IntervalTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.IntervalTicks.HasValue)
{
throw new ArgumentNullException();
}
return new IntervalTrigger
{
Interval = TimeSpan.FromTicks(info.IntervalTicks.Value),
TaskOptions = options
};
}
if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.SystemEvent.HasValue)
{
throw new ArgumentNullException();
}
return new SystemEventTrigger
{
SystemEvent = info.SystemEvent.Value,
TaskOptions = options
};
}
if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
return new StartupTrigger();
}
throw new ArgumentException("Unrecognized trigger type: " + info.Type);
}
/// <summary>
/// Disposes each trigger
/// </summary>
private void DisposeTriggers()
{
foreach (var trigger in Triggers)
foreach (var triggerInfo in InternalTriggers)
{
var trigger = triggerInfo.Item2;
trigger.Triggered -= trigger_Triggered;
trigger.Stop();
}

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
@ -40,13 +41,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Until we can vary these default triggers per server and MBT, we need something that makes sense for both
return new ITaskTrigger[] {
return new[] {
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
@ -95,7 +95,7 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// <param name="progress">The progress.</param>
private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress<double> progress)
{
var filesToDelete = _fileSystem.GetFiles(directory, true)
var filesToDelete = _fileSystem.GetFiles(directory, true)
.Where(f => _fileSystem.GetLastWriteTimeUtc(f) < minDateModified)
.ToList();
@ -168,6 +168,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
get { return "Cache file cleanup"; }
}
public string Key
{
get { return "DeleteCacheFiles"; }
}
/// <summary>
/// Gets the description.
/// </summary>
@ -202,5 +207,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
get { return true; }
}
public bool IsLogged
{
get { return true; }
}
}
}

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
@ -36,13 +37,12 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Until we can vary these default triggers per server and MBT, we need something that makes sense for both
return new ITaskTrigger[] {
return new[] {
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
@ -82,6 +82,11 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
return Task.FromResult(true);
}
public string Key
{
get { return "CleanLogFiles"; }
}
/// <summary>
/// Gets the name of the task
/// </summary>
@ -125,5 +130,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
get { return true; }
}
public bool IsLogged
{
get { return true; }
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
@ -39,9 +40,9 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
/// Gets the default triggers.
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
var trigger = new DailyTrigger { TimeOfDay = TimeSpan.FromHours(0) }; //12am
var trigger = new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(0).Ticks }; //12am
return new[] { trigger };
}
@ -74,6 +75,8 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
get { return "Start new log file"; }
}
public string Key { get; }
/// <summary>
/// Gets the description.
/// </summary>
@ -101,5 +104,10 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
{
get { return true; }
}
public bool IsLogged
{
get { return true; }
}
}
}

View File

@ -1,9 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using MediaBrowser.Model.Cryptography;
namespace MediaBrowser.Common.Extensions
{
@ -12,6 +10,7 @@ namespace MediaBrowser.Common.Extensions
/// </summary>
public static class BaseExtensions
{
public static ICryptographyProvider CryptographyProvider { get; set; }
/// <summary>
/// Strips the HTML.
@ -26,15 +25,6 @@ namespace MediaBrowser.Common.Extensions
return Regex.Replace(htmlString, pattern, string.Empty).Trim();
}
public static string RemoveDiacritics(this string text)
{
return String.Concat(
text.Normalize(NormalizationForm.FormD)
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) !=
UnicodeCategory.NonSpacingMark)
).Normalize(NormalizationForm.FormC);
}
/// <summary>
/// Gets the M d5.
/// </summary>
@ -42,10 +32,7 @@ namespace MediaBrowser.Common.Extensions
/// <returns>Guid.</returns>
public static Guid GetMD5(this string str)
{
using (var provider = MD5.Create())
{
return new Guid(provider.ComputeHash(Encoding.Unicode.GetBytes(str)));
}
return CryptographyProvider.GetMD5(str);
}
/// <summary>

View File

@ -142,7 +142,7 @@ namespace MediaBrowser.Common
/// Gets the plugins.
/// </summary>
/// <value>The plugins.</value>
IEnumerable<IPlugin> Plugins { get; }
IPlugin[] Plugins { get; }
/// <summary>
/// Removes the plugin.

View File

@ -57,9 +57,7 @@
<Compile Include="Extensions\BaseExtensions.cs" />
<Compile Include="Extensions\ResourceNotFoundException.cs" />
<Compile Include="IDependencyContainer.cs" />
<Compile Include="IO\IMemoryStreamProvider.cs" />
<Compile Include="IO\ProgressStream.cs" />
<Compile Include="IO\StreamDefaults.cs" />
<Compile Include="Configuration\IApplicationPaths.cs" />
<Compile Include="Net\HttpRequestOptions.cs" />
<Compile Include="Net\HttpResponseInfo.cs" />
@ -69,22 +67,13 @@
<Compile Include="Plugins\IDependencyModule.cs" />
<Compile Include="Plugins\IPlugin.cs" />
<Compile Include="Progress\ActionableProgress.cs" />
<Compile Include="ScheduledTasks\IConfigurableScheduledTask.cs" />
<Compile Include="ScheduledTasks\IHasKey.cs" />
<Compile Include="ScheduledTasks\IScheduledTask.cs" />
<Compile Include="ScheduledTasks\IScheduledTaskWorker.cs" />
<Compile Include="ScheduledTasks\ITaskManager.cs" />
<Compile Include="ScheduledTasks\ITaskTrigger.cs" />
<Compile Include="ScheduledTasks\ScheduledTaskHelpers.cs" />
<Compile Include="ScheduledTasks\StartupTrigger.cs" />
<Compile Include="ScheduledTasks\SystemEventTrigger.cs" />
<Compile Include="Plugins\BasePlugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ScheduledTasks\DailyTrigger.cs" />
<Compile Include="ScheduledTasks\IntervalTrigger.cs" />
<Compile Include="ScheduledTasks\TaskCompletionEventArgs.cs" />
<Compile Include="ScheduledTasks\TaskExecutionOptions.cs" />
<Compile Include="ScheduledTasks\WeeklyTrigger.cs" />
<Compile Include="Security\IRequiresRegistration.cs" />
<Compile Include="Security\ISecurityManager.cs" />
<Compile Include="Security\PaymentRequiredException.cs" />

View File

@ -3,8 +3,6 @@ using MediaBrowser.Model.Plugins;
using MediaBrowser.Model.Serialization;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace MediaBrowser.Common.Plugins
{
@ -12,7 +10,7 @@ namespace MediaBrowser.Common.Plugins
/// Provides a common base class for all plugins
/// </summary>
/// <typeparam name="TConfigurationType">The type of the T configuration type.</typeparam>
public abstract class BasePlugin<TConfigurationType> : IPlugin
public abstract class BasePlugin<TConfigurationType> : IPlugin, IPluginAssembly
where TConfigurationType : BasePluginConfiguration
{
/// <summary>
@ -57,69 +55,33 @@ namespace MediaBrowser.Common.Plugins
get { return typeof(TConfigurationType); }
}
/// <summary>
/// The _assembly name
/// </summary>
private AssemblyName _assemblyName;
/// <summary>
/// Gets the name of the assembly.
/// </summary>
/// <value>The name of the assembly.</value>
protected AssemblyName AssemblyName
public void SetAttributes(string assemblyFilePath, string assemblyFileName, Version assemblyVersion, Guid assemblyId)
{
get
{
return _assemblyName ?? (_assemblyName = GetType().Assembly.GetName());
}
}
AssemblyFilePath = assemblyFilePath;
AssemblyFileName = assemblyFileName;
Version = assemblyVersion;
Id = assemblyId;
/// <summary>
/// The _unique id
/// </summary>
private Guid? _uniqueId;
IsFirstRun = !File.Exists(ConfigurationFilePath);
}
/// <summary>
/// Gets the unique id.
/// </summary>
/// <value>The unique id.</value>
public Guid Id
{
get
{
if (!_uniqueId.HasValue)
{
var attribute = (GuidAttribute)GetType().Assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
_uniqueId = new Guid(attribute.Value);
}
return _uniqueId.Value;
}
}
public Guid Id { get; private set; }
/// <summary>
/// Gets the plugin version
/// </summary>
/// <value>The version.</value>
public Version Version
{
get
{
return AssemblyName.Version;
}
}
public Version Version { get; private set; }
/// <summary>
/// Gets the name the assembly file
/// </summary>
/// <value>The name of the assembly file.</value>
public string AssemblyFileName
{
get
{
return AssemblyName.Name + ".dll";
}
}
protected string AssemblyFileName { get; private set; }
/// <summary>
/// Gets the last date modified of the configuration
@ -136,29 +98,11 @@ namespace MediaBrowser.Common.Plugins
}
}
/// <summary>
/// Gets the last date modified of the plugin
/// </summary>
/// <value>The assembly date last modified.</value>
public DateTime AssemblyDateLastModified
{
get
{
return File.GetLastWriteTimeUtc(AssemblyFilePath);
}
}
/// <summary>
/// Gets the path to the assembly file
/// </summary>
/// <value>The assembly file path.</value>
public string AssemblyFilePath
{
get
{
return Path.Combine(ApplicationPaths.PluginsPath, AssemblyFileName);
}
}
public string AssemblyFilePath { get; private set; }
/// <summary>
/// The _configuration sync lock
@ -272,8 +216,6 @@ namespace MediaBrowser.Common.Plugins
{
ApplicationPaths = applicationPaths;
XmlSerializer = xmlSerializer;
IsFirstRun = !File.Exists(ConfigurationFilePath);
}
/// <summary>
@ -349,4 +291,9 @@ namespace MediaBrowser.Common.Plugins
get { return Configuration; }
}
}
public interface IPluginAssembly
{
void SetAttributes(string assemblyFilePath, string assemblyFileName, Version assemblyVersion, Guid assemblyId);
}
}

View File

@ -38,12 +38,6 @@ namespace MediaBrowser.Common.Plugins
/// <value>The version.</value>
Version Version { get; }
/// <summary>
/// Gets the name the assembly file
/// </summary>
/// <value>The name of the assembly file.</value>
string AssemblyFileName { get; }
/// <summary>
/// Gets a value indicating whether this instance is first run.
/// </summary>
@ -56,12 +50,6 @@ namespace MediaBrowser.Common.Plugins
/// <value>The configuration date last modified.</value>
DateTime ConfigurationDateLastModified { get; }
/// <summary>
/// Gets the last date modified of the plugin
/// </summary>
/// <value>The assembly date last modified.</value>
DateTime AssemblyDateLastModified { get; }
/// <summary>
/// Gets the path to the assembly file
/// </summary>

View File

@ -1,7 +0,0 @@
namespace MediaBrowser.Common.ScheduledTasks
{
public interface IHasKey
{
string Key { get; }
}
}

View File

@ -1,7 +1,6 @@
using MediaBrowser.Model.Events;
using MediaBrowser.Model.Tasks;
using System;
using System.Collections.Generic;
namespace MediaBrowser.Common.ScheduledTasks
{
@ -62,7 +61,7 @@ namespace MediaBrowser.Common.ScheduledTasks
/// </summary>
/// <value>The triggers.</value>
/// <exception cref="System.ArgumentNullException">value</exception>
IEnumerable<ITaskTrigger> Triggers { get; set; }
TaskTriggerInfo[] Triggers { get; set; }
/// <summary>
/// Gets the unique id.

View File

@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Common.ScheduledTasks
{

View File

@ -18,8 +18,6 @@ namespace MediaBrowser.Common.ScheduledTasks
/// <summary>
/// Stars waiting for the trigger action
/// </summary>
/// <param name="lastResult">The last result.</param>
/// <param name="isApplicationStartup">if set to <c>true</c> [is application startup].</param>
void Start(TaskResult lastResult, ILogger logger, string taskName, bool isApplicationStartup);
/// <summary>

View File

@ -25,17 +25,9 @@ namespace MediaBrowser.Common.ScheduledTasks
isHidden = configurableTask.IsHidden;
}
string key = null;
var hasKey = task.ScheduledTask as IHasKey;
if (hasKey != null)
{
key = hasKey.Key;
}
string key = task.ScheduledTask.Key;
var triggers = task.Triggers
.Select(GetTriggerInfo)
.OrderBy(i => i.Type)
.ThenBy(i => i.DayOfWeek ?? DayOfWeek.Sunday)
.ThenBy(i => i.TimeOfDayTicks ?? 0)
@ -57,138 +49,5 @@ namespace MediaBrowser.Common.ScheduledTasks
Key = key
};
}
/// <summary>
/// Gets the trigger info.
/// </summary>
/// <param name="trigger">The trigger.</param>
/// <returns>TaskTriggerInfo.</returns>
public static TaskTriggerInfo GetTriggerInfo(ITaskTrigger trigger)
{
var info = new TaskTriggerInfo
{
Type = trigger.GetType().Name
};
var dailyTrigger = trigger as DailyTrigger;
if (dailyTrigger != null)
{
info.TimeOfDayTicks = dailyTrigger.TimeOfDay.Ticks;
}
var weeklyTaskTrigger = trigger as WeeklyTrigger;
if (weeklyTaskTrigger != null)
{
info.TimeOfDayTicks = weeklyTaskTrigger.TimeOfDay.Ticks;
info.DayOfWeek = weeklyTaskTrigger.DayOfWeek;
}
var intervalTaskTrigger = trigger as IntervalTrigger;
if (intervalTaskTrigger != null)
{
info.IntervalTicks = intervalTaskTrigger.Interval.Ticks;
}
var systemEventTrigger = trigger as SystemEventTrigger;
if (systemEventTrigger != null)
{
info.SystemEvent = systemEventTrigger.SystemEvent;
}
if (trigger.TaskOptions != null)
{
info.MaxRuntimeMs = trigger.TaskOptions.MaxRuntimeMs;
}
return info;
}
/// <summary>
/// Converts a TaskTriggerInfo into a concrete BaseTaskTrigger
/// </summary>
/// <param name="info">The info.</param>
/// <returns>BaseTaskTrigger.</returns>
/// <exception cref="System.ArgumentNullException"></exception>
/// <exception cref="System.ArgumentException">Invalid trigger type: + info.Type</exception>
public static ITaskTrigger GetTrigger(TaskTriggerInfo info)
{
var options = new TaskExecutionOptions
{
MaxRuntimeMs = info.MaxRuntimeMs
};
if (info.Type.Equals(typeof(DailyTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.TimeOfDayTicks.HasValue)
{
throw new ArgumentNullException();
}
return new DailyTrigger
{
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
TaskOptions = options
};
}
if (info.Type.Equals(typeof(WeeklyTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.TimeOfDayTicks.HasValue)
{
throw new ArgumentNullException();
}
if (!info.DayOfWeek.HasValue)
{
throw new ArgumentNullException();
}
return new WeeklyTrigger
{
TimeOfDay = TimeSpan.FromTicks(info.TimeOfDayTicks.Value),
DayOfWeek = info.DayOfWeek.Value,
TaskOptions = options
};
}
if (info.Type.Equals(typeof(IntervalTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.IntervalTicks.HasValue)
{
throw new ArgumentNullException();
}
return new IntervalTrigger
{
Interval = TimeSpan.FromTicks(info.IntervalTicks.Value),
TaskOptions = options
};
}
if (info.Type.Equals(typeof(SystemEventTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
if (!info.SystemEvent.HasValue)
{
throw new ArgumentNullException();
}
return new SystemEventTrigger
{
SystemEvent = info.SystemEvent.Value,
TaskOptions = options
};
}
if (info.Type.Equals(typeof(StartupTrigger).Name, StringComparison.OrdinalIgnoreCase))
{
return new StartupTrigger();
}
throw new ArgumentException("Unrecognized trigger type: " + info.Type);
}
}
}

View File

@ -10,6 +10,7 @@ using System.Runtime.Serialization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Controller.Entities.Audio
{

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Controller.Entities.Audio
{

View File

@ -24,6 +24,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Providers;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Controller.Entities
{

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Controller.Entities
{

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Entities

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Controller.Entities
{

View File

@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Linq;
using System.Text;
using MediaBrowser.Model.Cryptography;
namespace MediaBrowser.Controller.Extensions
{
/// <summary>
/// Class BaseExtensions
/// </summary>
public static class BaseExtensions
{
public static ICryptographyProvider CryptographyProvider { get; set; }
public static string RemoveDiacritics(this string text)
{
return String.Concat(
text.Normalize(NormalizationForm.FormD)
.Where(ch => CharUnicodeInfo.GetUnicodeCategory(ch) !=
UnicodeCategory.NonSpacingMark)
).Normalize(NormalizationForm.FormC);
}
}
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Model.Extensions;
namespace MediaBrowser.Controller.Library

View File

@ -165,6 +165,7 @@
<Compile Include="Entities\TagExtensions.cs" />
<Compile Include="Entities\UserView.cs" />
<Compile Include="Entities\UserViewBuilder.cs" />
<Compile Include="Extensions\BaseExtensions.cs" />
<Compile Include="FileOrganization\IFileOrganizationService.cs" />
<Compile Include="IO\ThrottledStream.cs" />
<Compile Include="Library\DeleteOptions.cs" />

View File

@ -12,6 +12,7 @@ using CommonIO;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.MediaInfo;

View File

@ -20,6 +20,7 @@ using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
using UniversalDetector;
namespace MediaBrowser.MediaEncoding.Subtitles

View File

@ -0,0 +1,9 @@
using System;
namespace MediaBrowser.Model.Cryptography
{
public interface ICryptographyProvider
{
Guid GetMD5(string str);
}
}

View File

@ -118,7 +118,7 @@ namespace MediaBrowser.Model.Entities
private string AddLanguageIfNeeded(string title)
{
if (!string.IsNullOrEmpty(Language) && title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) == -1)
if (!string.IsNullOrEmpty(Language) && !string.Equals(Language, "und", StringComparison.OrdinalIgnoreCase) && title.IndexOf(Language, StringComparison.OrdinalIgnoreCase) == -1)
{
title = StringHelper.FirstToUpper(Language) + " " + title;
}

View File

@ -1,6 +1,6 @@
using System.IO;
namespace MediaBrowser.Common.IO
namespace MediaBrowser.Model.IO
{
public interface IMemoryStreamProvider
{

View File

@ -1,5 +1,5 @@

namespace MediaBrowser.Common.IO
namespace MediaBrowser.Model.IO
{
/// <summary>
/// Class StreamDefaults

View File

@ -98,6 +98,7 @@
<Compile Include="Connect\PinExchangeResult.cs" />
<Compile Include="Connect\PinStatusResult.cs" />
<Compile Include="Connect\UserLinkType.cs" />
<Compile Include="Cryptography\ICryptographyProvider.cs" />
<Compile Include="Devices\DeviceOptions.cs" />
<Compile Include="Devices\DeviceQuery.cs" />
<Compile Include="Devices\LocalFileInfo.cs" />
@ -133,6 +134,8 @@
<Compile Include="Extensions\LinqExtensions.cs" />
<Compile Include="FileOrganization\SmartMatchInfo.cs" />
<Compile Include="Health\IHealthMonitor.cs" />
<Compile Include="IO\IMemoryStreamProvider.cs" />
<Compile Include="IO\StreamDefaults.cs" />
<Compile Include="MediaInfo\LiveStreamRequest.cs" />
<Compile Include="MediaInfo\LiveStreamResponse.cs" />
<Compile Include="MediaInfo\PlaybackInfoRequest.cs" />
@ -384,6 +387,9 @@
<Compile Include="System\Architecture.cs" />
<Compile Include="System\LogFile.cs" />
<Compile Include="System\PublicSystemInfo.cs" />
<Compile Include="Tasks\IConfigurableScheduledTask.cs" />
<Compile Include="Tasks\IScheduledTask.cs" />
<Compile Include="Tasks\TaskExecutionOptions.cs" />
<Compile Include="Updates\CheckForUpdateResult.cs" />
<Compile Include="Updates\PackageTargetSystem.cs" />
<Compile Include="Updates\InstallationInfo.cs" />

View File

@ -1,4 +1,4 @@
namespace MediaBrowser.Common.ScheduledTasks
namespace MediaBrowser.Model.Tasks
{
public interface IConfigurableScheduledTask
{
@ -12,10 +12,7 @@
/// </summary>
/// <value><c>true</c> if this instance is enabled; otherwise, <c>false</c>.</value>
bool IsEnabled { get; }
}
public interface IScheduledTaskActivityLog
{
bool IsActivityLogged { get; }
bool IsLogged { get; }
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Common.ScheduledTasks
namespace MediaBrowser.Model.Tasks
{
/// <summary>
/// Interface IScheduledTaskWorker
@ -16,6 +16,8 @@ namespace MediaBrowser.Common.ScheduledTasks
/// <value>The name.</value>
string Name { get; }
string Key { get; }
/// <summary>
/// Gets the description.
/// </summary>
@ -40,6 +42,6 @@ namespace MediaBrowser.Common.ScheduledTasks
/// Gets the default triggers.
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
IEnumerable<ITaskTrigger> GetDefaultTriggers();
IEnumerable<TaskTriggerInfo> GetDefaultTriggers();
}
}

View File

@ -1,5 +1,5 @@

namespace MediaBrowser.Common.ScheduledTasks
namespace MediaBrowser.Model.Tasks
{
/// <summary>
/// A class that encomposases all common task run properties.

View File

@ -42,5 +42,11 @@ namespace MediaBrowser.Model.Tasks
/// </summary>
/// <value>The maximum runtime ms.</value>
public int? MaxRuntimeMs { get; set; }
public const string TriggerDaily = "DailyTrigger";
public const string TriggerWeekly = "WeeklyTrigger";
public const string TriggerInterval = "IntervalTrigger";
public const string TriggerSystemEvent = "SystemEventTrigger";
public const string TriggerStartup = "StartupTrigger";
}
}

View File

@ -17,6 +17,7 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Providers.Manager
{

View File

@ -21,6 +21,7 @@ using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Serialization;
namespace MediaBrowser.Providers.Manager

View File

@ -139,7 +139,7 @@ namespace MediaBrowser.Providers.MediaInfo
request.IndexNumberEnd = episode.IndexNumberEnd;
request.SeriesName = episode.SeriesName;
}
try
{
var searchResults = await _subtitleManager.SearchSubtitles(request, cancellationToken).ConfigureAwait(false);

View File

@ -16,6 +16,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.IO;
using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Providers.MediaInfo
{
@ -184,12 +185,18 @@ namespace MediaBrowser.Providers.MediaInfo
return false;
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromHours(8)}
};
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
public string Key
{
get { return "DownloadSubtitles"; }
}
}
}

View File

@ -5,10 +5,11 @@ using MediaBrowser.Model.Logging;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.Channels
{
class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
class RefreshChannelsScheduledTask : IScheduledTask
{
private readonly IChannelManager _channelManager;
private readonly IUserManager _userManager;
@ -48,14 +49,23 @@ namespace MediaBrowser.Server.Implementations.Channels
.ConfigureAwait(false);
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromHours(24)}
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
public string Key
{
get { return "RefreshInternetChannels"; }
}
public bool IsHidden
{
get { return false; }

View File

@ -401,8 +401,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
{
var task = e.Argument;
var activityTask = task.ScheduledTask as IScheduledTaskActivityLog;
if (activityTask != null && !activityTask.IsActivityLogged)
var activityTask = task.ScheduledTask as IConfigurableScheduledTask;
if (activityTask != null && !activityTask.IsLogged)
{
return;
}
@ -419,8 +419,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
var result = e.Result;
var task = e.Task;
var activityTask = task.ScheduledTask as IScheduledTaskActivityLog;
if (activityTask != null && !activityTask.IsActivityLogged)
var activityTask = task.ScheduledTask as IConfigurableScheduledTask;
if (activityTask != null && !activityTask.IsLogged)
{
return;
}

View File

@ -10,10 +10,11 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.FileOrganization
{
public class OrganizerScheduledTask : IScheduledTask, IConfigurableScheduledTask, IScheduledTaskActivityLog, IHasKey
public class OrganizerScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly ILibraryMonitor _libraryMonitor;
private readonly ILibraryManager _libraryManager;
@ -63,12 +64,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
}
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromMinutes(5)}
};
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromMinutes(5).Ticks}
};
}
public bool IsHidden
@ -81,7 +87,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
get { return GetAutoOrganizeOptions().TvOptions.IsEnabled; }
}
public bool IsActivityLogged
public bool IsLogged
{
get { return false; }
}

View File

@ -23,6 +23,7 @@ using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Security;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.HttpServer
{

View File

@ -3,6 +3,7 @@ using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using ServiceStack.Logging;

View File

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.HttpServer.SocketSharp
{

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Text;
using Funq;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using ServiceStack;
using ServiceStack.Host;

View File

@ -10,6 +10,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Controller.Extensions;
namespace MediaBrowser.Server.Implementations.Library
{

View File

@ -6,10 +6,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.LiveTv
{
public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask, IHasKey
public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly ILiveTvManager _liveTvManager;
private readonly IConfigurationManager _config;
@ -42,11 +43,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return manager.RefreshChannels(progress, cancellationToken);
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromHours(12)}
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(12).Ticks}
};
}
@ -65,6 +71,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
get { return true; }
}
public bool IsLogged
{
get { return true; }
}
public string Key
{
get { return "RefreshGuide"; }

View File

@ -18,6 +18,7 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Server.Implementations.ScheduledTasks;
namespace MediaBrowser.Server.Implementations.Persistence
@ -337,12 +338,22 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger{ Interval = TimeSpan.FromHours(24)}
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
public string Key
{
get { return "CleanDatabase"; }
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Data;
using System.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Persistence
{

View File

@ -11,6 +11,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Persistence
{

View File

@ -23,8 +23,10 @@ using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Collections;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Server.Implementations.Devices;
using MediaBrowser.Server.Implementations.Playlists;

View File

@ -10,6 +10,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Persistence
{

View File

@ -13,6 +13,7 @@ using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
@ -62,20 +63,22 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
return new[] {
new TaskTriggerInfo
{
new DailyTrigger
{
TimeOfDay = TimeSpan.FromHours(1),
TaskOptions = new TaskExecutionOptions
{
MaxRuntimeMs = Convert.ToInt32(TimeSpan.FromHours(4).TotalMilliseconds)
}
}
};
Type = TaskTriggerInfo.TriggerDaily,
TimeOfDayTicks = TimeSpan.FromHours(1).Ticks,
MaxRuntimeMs = Convert.ToInt32(TimeSpan.FromHours(4).TotalMilliseconds)
}
};
}
public string Key
{
get { return "RefreshChapterImages"; }
}
/// <summary>

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
@ -33,16 +34,21 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Randomize the default start hour because this operation can really hammer internet metadata providers
var startHour = new Random(_appHost.SystemId.GetHashCode()).Next(0, 8);
return new ITaskTrigger[]
{
new DailyTrigger { TimeOfDay = TimeSpan.FromHours(startHour) },
};
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerDaily, TimeOfDayTicks = TimeSpan.FromHours(startHour).Ticks}
};
}
public string Key
{
get { return "RefreshPeople"; }
}
/// <summary>

View File

@ -9,6 +9,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
@ -37,18 +38,23 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[] {
return new[] {
// At startup
new StartupTrigger(),
new TaskTriggerInfo {Type = TaskTriggerInfo.TriggerStartup},
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}
public string Key
{
get { return "PluginUpdates"; }
}
/// <summary>
/// Update installed plugins
/// </summary>

View File

@ -7,13 +7,14 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
/// <summary>
/// Class RefreshMediaLibraryTask
/// </summary>
public class RefreshMediaLibraryTask : IScheduledTask, IHasKey
public class RefreshMediaLibraryTask : IScheduledTask
{
/// <summary>
/// The _library manager
@ -32,18 +33,16 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
}
/// <summary>
/// Gets the default triggers.
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
var list = new ITaskTrigger[] {
new IntervalTrigger{ Interval = TimeSpan.FromHours(12)}
}.ToList();
return list;
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(12).Ticks}
};
}
/// <summary>

View File

@ -6,13 +6,14 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.ScheduledTasks
{
/// <summary>
/// Plugin Update Task
/// </summary>
public class SystemUpdateTask : IScheduledTask, IHasKey
public class SystemUpdateTask : IScheduledTask
{
/// <summary>
/// The _app host
@ -47,16 +48,15 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
// Until we can vary these default triggers per server and MBT, we need something that makes sense for both
return new ITaskTrigger[] {
return new[] {
// At startup
new StartupTrigger(),
new TaskTriggerInfo {Type = TaskTriggerInfo.TriggerStartup},
// Every so often
new IntervalTrigger { Interval = TimeSpan.FromHours(24)}
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(24).Ticks}
};
}

View File

@ -14,6 +14,7 @@ using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.ServerManager
{

View File

@ -10,6 +10,7 @@ using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
using UniversalDetector;
namespace MediaBrowser.Server.Implementations.ServerManager

View File

@ -9,10 +9,11 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.Sync
{
class ServerSyncScheduledTask : IScheduledTask, IConfigurableScheduledTask, IHasKey
class ServerSyncScheduledTask : IScheduledTask, IConfigurableScheduledTask
{
private readonly ISyncManager _syncManager;
private readonly ILogger _logger;
@ -58,14 +59,17 @@ namespace MediaBrowser.Server.Implementations.Sync
get { return ((SyncManager)_syncManager).ServerSyncProviders; }
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger { Interval = TimeSpan.FromHours(3) }
};
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(3).Ticks}
};
}
public bool IsHidden
{
get { return !IsEnabled; }
@ -76,6 +80,11 @@ namespace MediaBrowser.Server.Implementations.Sync
get { return ServerSyncProviders.Any(); }
}
public bool IsLogged
{
get { return true; }
}
public string Key
{
get { return "ServerSync"; }

View File

@ -10,10 +10,11 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Tasks;
namespace MediaBrowser.Server.Implementations.Sync
{
public class SyncConvertScheduledTask : IScheduledTask, IConfigurableScheduledTask, IHasKey
public class SyncConvertScheduledTask : IScheduledTask
{
private readonly ILibraryManager _libraryManager;
private readonly ISyncRepository _syncRepo;
@ -66,22 +67,17 @@ namespace MediaBrowser.Server.Implementations.Sync
.Sync(progress, cancellationToken);
}
public IEnumerable<ITaskTrigger> GetDefaultTriggers()
/// <summary>
/// Creates the triggers that define when the task will run
/// </summary>
/// <returns>IEnumerable{BaseTaskTrigger}.</returns>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new ITaskTrigger[]
{
new IntervalTrigger { Interval = TimeSpan.FromHours(3) }
};
}
public bool IsHidden
{
get { return false; }
}
public bool IsEnabled
{
get { return true; }
return new[] {
// Every so often
new TaskTriggerInfo { Type = TaskTriggerInfo.TriggerInterval, IntervalTicks = TimeSpan.FromHours(3).Ticks}
};
}
public string Key

View File

@ -25,6 +25,7 @@ using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Sync
{

View File

@ -30,6 +30,7 @@ using System.Threading;
using System.Threading.Tasks;
using CommonIO;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Sync
{

View File

@ -13,6 +13,7 @@ using System.Threading.Tasks;
using CommonIO;
using Interfaces.IO;
using MediaBrowser.Common.IO;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Server.Implementations.Sync
{

View File

@ -13,7 +13,6 @@
<copyright>Copyright © Emby 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.665" />
<dependency id="Interfaces.IO" version="1.0.0.5" />
</dependencies>
</metadata>
<files>