diff --git a/MediaBrowser.Api/EnvironmentService.cs b/MediaBrowser.Api/EnvironmentService.cs index e552c7f1d..db768d0e8 100644 --- a/MediaBrowser.Api/EnvironmentService.cs +++ b/MediaBrowser.Api/EnvironmentService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using ServiceStack.ServiceHost; using System; diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index 546cf4492..220101de5 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -66,14 +66,11 @@ - - - - + @@ -87,6 +84,8 @@ + + @@ -108,6 +107,8 @@ + + diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index 64c5d6cbc..924c33937 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -1,8 +1,7 @@ using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Net; -using MediaBrowser.Common.Updates; using MediaBrowser.Controller; -using MediaBrowser.Model.Tasks; using MediaBrowser.Model.Updates; using ServiceStack.ServiceHost; using System; @@ -97,6 +96,12 @@ namespace MediaBrowser.Api [Export(typeof(IRestfulService))] public class PackageService : BaseRestService { + /// + /// Gets or sets the application host. + /// + /// The application host. + public IApplicationHost ApplicationHost { get; set; } + /// /// Gets the specified request. /// @@ -116,9 +121,9 @@ namespace MediaBrowser.Api else if (request.PackageType == PackageType.System || request.PackageType == PackageType.All) { - var updateCheckResult = new ApplicationUpdateCheck().CheckForApplicationUpdate(CancellationToken.None, new Progress { }).Result; + var updateCheckResult = ApplicationHost.CheckForApplicationUpdate(CancellationToken.None, new Progress { }).Result; - if (updateCheckResult.UpdateAvailable) + if (updateCheckResult.IsUpdateAvailable) { result.Add(new PackageVersionInfo { diff --git a/MediaBrowser.Common/Api/ScheduledTasks/ScheduledTaskService.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs similarity index 99% rename from MediaBrowser.Common/Api/ScheduledTasks/ScheduledTaskService.cs rename to MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs index 1df24dcd2..bd12454a0 100644 --- a/MediaBrowser.Common/Api/ScheduledTasks/ScheduledTaskService.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs @@ -11,7 +11,7 @@ using System.IO; using System.Linq; using ServiceStack.Text.Controller; -namespace MediaBrowser.Common.Api.ScheduledTasks +namespace MediaBrowser.Api.ScheduledTasks { /// /// Class GetScheduledTask diff --git a/MediaBrowser.Common/Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs similarity index 96% rename from MediaBrowser.Common/Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs rename to MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs index 7e4596d9d..7fa47735e 100644 --- a/MediaBrowser.Common/Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs @@ -7,7 +7,7 @@ using System.ComponentModel.Composition; using System.Linq; using System.Threading.Tasks; -namespace MediaBrowser.Common.Api.ScheduledTasks +namespace MediaBrowser.Api.ScheduledTasks { /// /// Class ScheduledTasksWebSocketListener diff --git a/MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs b/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs similarity index 99% rename from MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs rename to MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs index e873facb1..f725b0222 100644 --- a/MediaBrowser.Common/Api/Logging/LogFileWebSocketListener.cs +++ b/MediaBrowser.Api/WebSocket/LogFileWebSocketListener.cs @@ -8,7 +8,7 @@ using System.Linq; using System.Threading.Tasks; using MediaBrowser.Model.Logging; -namespace MediaBrowser.Common.Api.Logging +namespace MediaBrowser.Api.WebSocket { /// /// Class ScheduledTasksWebSocketListener diff --git a/MediaBrowser.Common/Api/SystemInfoWebSocketListener.cs b/MediaBrowser.Api/WebSocket/SystemInfoWebSocketListener.cs similarity index 86% rename from MediaBrowser.Common/Api/SystemInfoWebSocketListener.cs rename to MediaBrowser.Api/WebSocket/SystemInfoWebSocketListener.cs index a216937ed..51d9f2fcd 100644 --- a/MediaBrowser.Common/Api/SystemInfoWebSocketListener.cs +++ b/MediaBrowser.Api/WebSocket/SystemInfoWebSocketListener.cs @@ -1,15 +1,16 @@ using MediaBrowser.Common.Kernel; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.System; using System.ComponentModel.Composition; using System.Threading.Tasks; -namespace MediaBrowser.Common.Api +namespace MediaBrowser.Api.WebSocket { /// /// Class SystemInfoWebSocketListener /// [Export(typeof(IWebSocketListener))] - public class SystemInfoWebSocketListener : BasePeriodicWebSocketListener + public class SystemInfoWebSocketListener : BasePeriodicWebSocketListener { /// /// Gets the name. @@ -36,7 +37,7 @@ namespace MediaBrowser.Common.Api /// /// The state. /// Task{SystemInfo}. - protected override Task GetDataToSend(object state) + protected override Task GetDataToSend(object state) { return Task.FromResult(Kernel.GetSystemInfo()); } diff --git a/MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs b/MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs similarity index 74% rename from MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs rename to MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs index 7501d7321..72c42f586 100644 --- a/MediaBrowser.Common/Updates/ApplicationUpdateCheck.cs +++ b/MediaBrowser.ClickOnce/ApplicationUpdateCheck.cs @@ -1,10 +1,10 @@ -using MediaBrowser.Model.Tasks; +using MediaBrowser.Model.Updates; using System; using System.Deployment.Application; using System.Threading; using System.Threading.Tasks; -namespace MediaBrowser.Common.Updates +namespace MediaBrowser.ClickOnce { /// /// Class ApplicationUpdateCheck @@ -14,12 +14,12 @@ namespace MediaBrowser.Common.Updates /// /// The _task completion source /// - private TaskCompletionSource _taskCompletionSource; + private TaskCompletionSource _taskCompletionSource; /// /// The _progress /// - private IProgress _progress; + private IProgress _progress; /// /// Checks for application update. @@ -28,7 +28,7 @@ namespace MediaBrowser.Common.Updates /// The progress. /// Task{CheckForUpdateCompletedEventArgs}. /// Current deployment is not a ClickOnce deployment - public Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) + public Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) { if (!ApplicationDeployment.IsNetworkDeployed) { @@ -36,8 +36,8 @@ namespace MediaBrowser.Common.Updates } _progress = progress; - - _taskCompletionSource = new TaskCompletionSource(); + + _taskCompletionSource = new TaskCompletionSource(); var deployment = ApplicationDeployment.CurrentDeployment; @@ -53,6 +53,20 @@ namespace MediaBrowser.Common.Updates return _taskCompletionSource.Task; } + /// + /// To the result. + /// + /// The instance containing the event data. + /// CheckForUpdateResult. + private CheckForUpdateResult ToResult(CheckForUpdateCompletedEventArgs args) + { + return new CheckForUpdateResult + { + AvailableVersion = args.AvailableVersion, + IsUpdateAvailable = args.UpdateAvailable + }; + } + /// /// Handles the CheckForUpdateCompleted event of the deployment control. /// @@ -75,7 +89,7 @@ namespace MediaBrowser.Common.Updates } else { - _taskCompletionSource.SetResult(e); + _taskCompletionSource.SetResult(ToResult(e)); } } @@ -86,7 +100,7 @@ namespace MediaBrowser.Common.Updates /// The instance containing the event data. void deployment_CheckForUpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) { - _progress.Report(new TaskProgress { PercentComplete = e.ProgressPercentage }); + _progress.Report(e.ProgressPercentage); } } } diff --git a/MediaBrowser.Common/Updates/ApplicationUpdater.cs b/MediaBrowser.ClickOnce/ApplicationUpdater.cs similarity index 91% rename from MediaBrowser.Common/Updates/ApplicationUpdater.cs rename to MediaBrowser.ClickOnce/ApplicationUpdater.cs index d8ae87b37..29af406f1 100644 --- a/MediaBrowser.Common/Updates/ApplicationUpdater.cs +++ b/MediaBrowser.ClickOnce/ApplicationUpdater.cs @@ -1,11 +1,10 @@ -using MediaBrowser.Model.Tasks; -using System; +using System; using System.ComponentModel; using System.Deployment.Application; using System.Threading; using System.Threading.Tasks; -namespace MediaBrowser.Common.Updates +namespace MediaBrowser.ClickOnce { /// /// Class ApplicationUpdater @@ -20,7 +19,7 @@ namespace MediaBrowser.Common.Updates /// /// The _progress /// - private IProgress _progress; + private IProgress _progress; /// /// Updates the application @@ -29,7 +28,7 @@ namespace MediaBrowser.Common.Updates /// The progress. /// Task{AsyncCompletedEventArgs}. /// Current deployment is not network deployed. - public Task UpdateApplication(CancellationToken cancellationToken, IProgress progress) + public Task UpdateApplication(CancellationToken cancellationToken, IProgress progress) { if (!ApplicationDeployment.IsNetworkDeployed) { @@ -87,7 +86,7 @@ namespace MediaBrowser.Common.Updates /// The instance containing the event data. void deployment_UpdateProgressChanged(object sender, DeploymentProgressChangedEventArgs e) { - _progress.Report(new TaskProgress { PercentComplete = e.ProgressPercentage }); + _progress.Report(e.ProgressPercentage); } } } diff --git a/MediaBrowser.Common/Updates/ClickOnceHelper.cs b/MediaBrowser.ClickOnce/ClickOnceHelper.cs similarity index 82% rename from MediaBrowser.Common/Updates/ClickOnceHelper.cs rename to MediaBrowser.ClickOnce/ClickOnceHelper.cs index 7dd0cf9c5..c86332ccf 100644 --- a/MediaBrowser.Common/Updates/ClickOnceHelper.cs +++ b/MediaBrowser.ClickOnce/ClickOnceHelper.cs @@ -1,4 +1,5 @@ -using Microsoft.Win32; +using System.Deployment.Application; +using Microsoft.Win32; using System; using System.Diagnostics; using System.IO; @@ -6,7 +7,7 @@ using System.Linq; using System.Reflection; using System.Security.AccessControl; -namespace MediaBrowser.Common.Updates +namespace MediaBrowser.ClickOnce { /// /// Class ClickOnceHelper @@ -43,6 +44,15 @@ namespace MediaBrowser.Common.Updates get { return Assembly.GetExecutingAssembly().Location; } } + /// + /// Gets a value indicating whether this instance is network deployed. + /// + /// true if this instance is network deployed; otherwise, false. + public static bool IsNetworkDeployed + { + get { return ApplicationDeployment.IsNetworkDeployed; } + } + /// /// Gets the name of the publisher. /// @@ -213,5 +223,33 @@ namespace MediaBrowser.Common.Updates }.Start(); } + + /// + /// Configures the click once startup. + /// + /// Name of the publisher. + /// Name of the product. + /// Name of the suite. + /// if set to true [run at startup]. + /// The uninstaller filename. + public static void ConfigureClickOnceStartupIfInstalled(string publisherName, string productName, string suiteName, bool runAtStartup, string uninstallerFilename) + { + if (!ApplicationDeployment.IsNetworkDeployed) + { + return; + } + + var clickOnceHelper = new ClickOnceHelper(publisherName, productName, suiteName); + + if (runAtStartup) + { + clickOnceHelper.UpdateUninstallParameters(uninstallerFilename); + clickOnceHelper.AddShortcutToStartup(); + } + else + { + clickOnceHelper.RemoveShortcutFromStartup(); + } + } } } diff --git a/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj b/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj new file mode 100644 index 000000000..00370bfcd --- /dev/null +++ b/MediaBrowser.ClickOnce/MediaBrowser.ClickOnce.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {CC96BF3E-0BDA-4809-BC4B-BB6D418F4A84} + Library + Properties + MediaBrowser.ClickOnce + MediaBrowser.ClickOnce + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} + MediaBrowser.Model + + + + + \ No newline at end of file diff --git a/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs b/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1faa44e01 --- /dev/null +++ b/MediaBrowser.ClickOnce/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MediaBrowser.ClickOnce")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MediaBrowser.ClickOnce")] +[assembly: AssemblyCopyright("Copyright © 2013")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("16e62c11-5009-4212-8c96-fd692479fc5d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MediaBrowser.Common/Extensions/BaseExtensions.cs b/MediaBrowser.Common/Extensions/BaseExtensions.cs index e6b9d8ee6..6abe6d4e0 100644 --- a/MediaBrowser.Common/Extensions/BaseExtensions.cs +++ b/MediaBrowser.Common/Extensions/BaseExtensions.cs @@ -5,7 +5,6 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; -using System.Windows.Threading; namespace MediaBrowser.Common.Extensions { @@ -46,24 +45,6 @@ namespace MediaBrowser.Common.Extensions return val.Split(new[] { separator }, options); } - /// - /// Invokes an action after a specified delay - /// - /// The dispatcher. - /// The action. - /// The delay ms. - public static void InvokeWithDelay(this Dispatcher dispatcher, Action action, long delayMs) - { - var timer = new DispatcherTimer(DispatcherPriority.Normal, dispatcher); - timer.Interval = TimeSpan.FromMilliseconds(delayMs); - timer.Tick += (sender, args) => - { - timer.Stop(); - action(); - }; - timer.Start(); - } - /// /// Provides a non-blocking method to start a process and wait asynchronously for it to exit /// diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index a4ac70749..d172d0a0d 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -13,7 +13,6 @@ using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; -using System.Deployment.Application; using System.Diagnostics; using System.IO; using System.Linq; @@ -155,12 +154,6 @@ namespace MediaBrowser.Common.Kernel /// true if this instance is first run; otherwise, false. public bool IsFirstRun { get; private set; } - /// - /// The version of the application to display - /// - /// The display version. - public string DisplayVersion { get { return ApplicationVersion.ToString(); } } - /// /// Gets or sets a value indicating whether this instance has changes that require the entire application to restart. /// @@ -325,7 +318,10 @@ namespace MediaBrowser.Common.Kernel /// Gets the log file path. /// /// The log file path. - public string LogFilePath { get; private set; } + public string LogFilePath + { + get { return ApplicationHost.LogFilePath; } + } /// /// Gets the logger. @@ -429,7 +425,7 @@ namespace MediaBrowser.Common.Kernel await ReloadComposableParts().ConfigureAwait(false); DisposeTcpManager(); - TcpManager = new TcpManager(this, Logger); + TcpManager = new TcpManager(ApplicationHost, this, Logger); } /// @@ -482,6 +478,7 @@ namespace MediaBrowser.Common.Kernel protected virtual void ComposeExportedValues(CompositionContainer container) { container.ComposeExportedValue("logger", Logger); + container.ComposeExportedValue("appHost", ApplicationHost); } /// @@ -729,8 +726,8 @@ namespace MediaBrowser.Common.Kernel return new SystemInfo { HasPendingRestart = HasPendingRestart, - Version = DisplayVersion, - IsNetworkDeployed = ApplicationDeployment.IsNetworkDeployed, + Version = ApplicationVersion.ToString(), + IsNetworkDeployed = ApplicationHost.CanSelfUpdate, WebSocketPortNumber = TcpManager.WebSocketPortNumber, SupportsNativeWebSocket = TcpManager.SupportsNativeWebSocket, FailedPluginAssemblies = FailedPluginAssemblies.ToArray() diff --git a/MediaBrowser.Common/Kernel/IApplicationHost.cs b/MediaBrowser.Common/Kernel/IApplicationHost.cs index c1b63c261..63c63eb3d 100644 --- a/MediaBrowser.Common/Kernel/IApplicationHost.cs +++ b/MediaBrowser.Common/Kernel/IApplicationHost.cs @@ -1,4 +1,8 @@ - +using MediaBrowser.Model.Updates; +using System; +using System.Threading; +using System.Threading.Tasks; + namespace MediaBrowser.Common.Kernel { /// @@ -15,5 +19,29 @@ namespace MediaBrowser.Common.Kernel /// Reloads the logger. /// void ReloadLogger(); + + /// + /// Gets the log file path. + /// + /// The log file path. + string LogFilePath { get; } + + /// + /// Gets or sets a value indicating whether this instance can self update. + /// + /// true if this instance can self update; otherwise, false. + bool CanSelfUpdate { get; } + + /// + /// Checks for update. + /// + /// Task{CheckForUpdateResult}. + Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress); + + /// + /// Updates the application. + /// + /// Task. + Task UpdateApplication(CancellationToken cancellationToken, IProgress progress); } } diff --git a/MediaBrowser.Common/Kernel/TcpManager.cs b/MediaBrowser.Common/Kernel/TcpManager.cs index 7fb624f73..086815cbf 100644 --- a/MediaBrowser.Common/Kernel/TcpManager.cs +++ b/MediaBrowser.Common/Kernel/TcpManager.cs @@ -64,6 +64,11 @@ namespace MediaBrowser.Common.Kernel /// The _logger /// private readonly ILogger _logger; + + /// + /// The _application host + /// + private readonly IApplicationHost _applicationHost; /// /// The _supports native web socket @@ -108,12 +113,14 @@ namespace MediaBrowser.Common.Kernel /// /// Initializes a new instance of the class. /// + /// The application host. /// The kernel. /// The logger. - public TcpManager(IKernel kernel, ILogger logger) + public TcpManager(IApplicationHost applicationHost, IKernel kernel, ILogger logger) : base(kernel) { _logger = logger; + _applicationHost = applicationHost; if (kernel.IsFirstRun) { @@ -182,7 +189,7 @@ namespace MediaBrowser.Common.Kernel try { - HttpServer = new HttpServer(Kernel.HttpServerUrlPrefix, "Media Browser", Kernel, _logger); + HttpServer = new HttpServer(Kernel.HttpServerUrlPrefix, "Media Browser", _applicationHost, Kernel, _logger); } catch (HttpListenerException ex) { diff --git a/MediaBrowser.Common/MediaBrowser.Common.csproj b/MediaBrowser.Common/MediaBrowser.Common.csproj index b806df856..c7b162dee 100644 --- a/MediaBrowser.Common/MediaBrowser.Common.csproj +++ b/MediaBrowser.Common/MediaBrowser.Common.csproj @@ -34,7 +34,8 @@ 4 - Resources\Images\Icon.ico + + @@ -94,7 +95,6 @@ - @@ -118,13 +118,8 @@ - - - - - @@ -156,8 +151,6 @@ - - @@ -193,9 +186,6 @@ - - - @@ -216,9 +206,6 @@ Designer - - - diff --git a/MediaBrowser.Common/Net/HttpServer.cs b/MediaBrowser.Common/Net/HttpServer.cs index 184b82c16..b09c95da0 100644 --- a/MediaBrowser.Common/Net/HttpServer.cs +++ b/MediaBrowser.Common/Net/HttpServer.cs @@ -45,6 +45,12 @@ namespace MediaBrowser.Common.Net /// The kernel. private IKernel Kernel { get; set; } + /// + /// Gets or sets the application host. + /// + /// The application host. + private IApplicationHost ApplicationHost { get; set; } + /// /// This subscribes to HttpListener requests and finds the appropriate BaseHandler to process it /// @@ -67,11 +73,12 @@ namespace MediaBrowser.Common.Net /// /// The URL. /// Name of the product. + /// The application host. /// The kernel. /// The logger. /// The default redirectpath. /// urlPrefix - public HttpServer(string urlPrefix, string serverName, IKernel kernel, ILogger logger, string defaultRedirectpath = null) + public HttpServer(string urlPrefix, string serverName, IApplicationHost applicationHost, IKernel kernel, ILogger logger, string defaultRedirectpath = null) : base() { if (string.IsNullOrEmpty(urlPrefix)) @@ -86,9 +93,14 @@ namespace MediaBrowser.Common.Net { throw new ArgumentNullException("logger"); } + if (applicationHost == null) + { + throw new ArgumentNullException("applicationHost"); + } DefaultRedirectPath = defaultRedirectpath; _logger = logger; + ApplicationHost = applicationHost; EndpointHostConfig.Instance.ServiceStackHandlerFactoryPath = null; EndpointHostConfig.Instance.MetadataRedirectPath = "metadata"; @@ -144,6 +156,7 @@ namespace MediaBrowser.Common.Net container.Register(Kernel); container.Register(_logger); + container.Register(ApplicationHost); foreach (var service in Kernel.RestServices) { diff --git a/MediaBrowser.Common/Net/StaticResult.cs b/MediaBrowser.Common/Net/StaticResult.cs deleted file mode 100644 index 0dd6372cf..000000000 --- a/MediaBrowser.Common/Net/StaticResult.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MediaBrowser.Common.Net -{ - public class StaticResult - { - public Stream Stream { get; set; } - } -} diff --git a/MediaBrowser.Common/Resources/Images/Icon.ico b/MediaBrowser.Common/Resources/Images/Icon.ico deleted file mode 100644 index bea939de4..000000000 Binary files a/MediaBrowser.Common/Resources/Images/Icon.ico and /dev/null differ diff --git a/MediaBrowser.Common/ScheduledTasks/BaseScheduledTask.cs b/MediaBrowser.Common/ScheduledTasks/BaseScheduledTask.cs index 99dd7ab01..395c73a84 100644 --- a/MediaBrowser.Common/ScheduledTasks/BaseScheduledTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/BaseScheduledTask.cs @@ -171,7 +171,7 @@ namespace MediaBrowser.Common.ScheduledTasks /// Gets the current progress. /// /// The current progress. - public TaskProgress CurrentProgress { get; private set; } + public double? CurrentProgress { get; private set; } /// /// The _triggers @@ -246,7 +246,7 @@ namespace MediaBrowser.Common.ScheduledTasks /// The cancellation token. /// The progress. /// Task. - protected abstract Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress); + protected abstract Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress); /// /// Gets the name of the task @@ -355,7 +355,7 @@ namespace MediaBrowser.Common.ScheduledTasks Logger.Info("Executing {0}", Name); - var progress = new Progress(); + var progress = new Progress(); progress.ProgressChanged += progress_ProgressChanged; @@ -426,7 +426,7 @@ namespace MediaBrowser.Common.ScheduledTasks /// /// The sender. /// The e. - void progress_ProgressChanged(object sender, TaskProgress e) + void progress_ProgressChanged(object sender, double e) { CurrentProgress = e; } diff --git a/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs b/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs index a3809c4b9..95d1edf63 100644 --- a/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/IScheduledTask.cs @@ -34,7 +34,7 @@ namespace MediaBrowser.Common.ScheduledTasks /// Gets the current progress. /// /// The current progress. - TaskProgress CurrentProgress { get; } + double? CurrentProgress { get; } /// /// Gets the name of the task diff --git a/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs b/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs index 34421ca1f..95c4c6a66 100644 --- a/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs +++ b/MediaBrowser.Common/ScheduledTasks/ScheduledTaskHelpers.cs @@ -20,7 +20,7 @@ namespace MediaBrowser.Common.ScheduledTasks return new TaskInfo { Name = task.Name, - CurrentProgress = task.CurrentProgress, + CurrentProgressPercentage = task.CurrentProgress, State = task.State, Id = task.Id, LastExecutionResult = task.LastExecutionResult, diff --git a/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index 98c6d672a..2a9bc4a0d 100644 --- a/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks /// The cancellation token. /// The progress. /// Task. - protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) + protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) { return Task.Run(() => { @@ -51,7 +51,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks /// The directory. /// The min date modified. /// The progress. - private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress progress) + private void DeleteCacheFilesFromDirectory(CancellationToken cancellationToken, string directory, DateTime minDateModified, IProgress progress) { var filesToDelete = new DirectoryInfo(directory).EnumerateFileSystemInfos("*", SearchOption.AllDirectories) .Where(f => !f.Attributes.HasFlag(FileAttributes.Directory) && f.LastWriteTimeUtc < minDateModified) @@ -64,7 +64,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks double percent = index; percent /= filesToDelete.Count; - progress.Report(new TaskProgress { Description = file.FullName, PercentComplete = 100 * percent }); + progress.Report(100 * percent); cancellationToken.ThrowIfCancellationRequested(); @@ -73,7 +73,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks index++; } - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); } /// diff --git a/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteLogFileTask.cs b/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteLogFileTask.cs index afb21187c..a1068a263 100644 --- a/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteLogFileTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/Tasks/DeleteLogFileTask.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks /// The cancellation token. /// The progress. /// Task. - protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) + protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) { return Task.Run(() => { @@ -51,7 +51,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks double percent = index; percent /= filesToDelete.Count; - progress.Report(new TaskProgress { Description = file.FullName, PercentComplete = 100 * percent }); + progress.Report(100 * percent); cancellationToken.ThrowIfCancellationRequested(); @@ -60,7 +60,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks index++; } - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); }); } diff --git a/MediaBrowser.Common/ScheduledTasks/Tasks/ReloadLoggerTask.cs b/MediaBrowser.Common/ScheduledTasks/Tasks/ReloadLoggerTask.cs index 24aaad57f..a4f06f205 100644 --- a/MediaBrowser.Common/ScheduledTasks/Tasks/ReloadLoggerTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/Tasks/ReloadLoggerTask.cs @@ -31,11 +31,11 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks /// The cancellation token. /// The progress. /// Task. - protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) + protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) { cancellationToken.ThrowIfCancellationRequested(); - progress.Report(new TaskProgress { PercentComplete = 0 }); + progress.Report(0); return Task.Run(() => Kernel.ReloadLogger()); } diff --git a/MediaBrowser.Common/ScheduledTasks/Tasks/SystemUpdateTask.cs b/MediaBrowser.Common/ScheduledTasks/Tasks/SystemUpdateTask.cs index a7e3f90a0..f9950424f 100644 --- a/MediaBrowser.Common/ScheduledTasks/Tasks/SystemUpdateTask.cs +++ b/MediaBrowser.Common/ScheduledTasks/Tasks/SystemUpdateTask.cs @@ -1,10 +1,7 @@ using MediaBrowser.Common.Kernel; -using MediaBrowser.Common.Updates; -using MediaBrowser.Model.Tasks; using System; using System.Collections.Generic; using System.ComponentModel.Composition; -using System.Deployment.Application; using System.Threading; using System.Threading.Tasks; @@ -16,6 +13,21 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks [Export(typeof(IScheduledTask))] public class SystemUpdateTask : BaseScheduledTask { + /// + /// The _app host + /// + private readonly IApplicationHost _appHost; + + /// + /// Initializes a new instance of the class. + /// + /// The app host. + [ImportingConstructor] + public SystemUpdateTask([Import("appHost")] IApplicationHost appHost) + { + _appHost = appHost; + } + /// /// Creates the triggers that define when the task will run /// @@ -37,26 +49,26 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks /// The cancellation token. /// The progress. /// Task. - protected override async Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) + protected override async Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) { - if (!ApplicationDeployment.IsNetworkDeployed) return; + if (!_appHost.CanSelfUpdate) return; - EventHandler innerProgressHandler = (sender, e) => progress.Report(new TaskProgress { PercentComplete = e.PercentComplete * .1 }); + EventHandler innerProgressHandler = (sender, e) => progress.Report(e * .1); // Create a progress object for the update check - var innerProgress = new Progress(); + var innerProgress = new Progress(); innerProgress.ProgressChanged += innerProgressHandler; - var updateInfo = await new ApplicationUpdateCheck().CheckForApplicationUpdate(cancellationToken, innerProgress).ConfigureAwait(false); + var updateInfo = await _appHost.CheckForApplicationUpdate(cancellationToken, innerProgress).ConfigureAwait(false); // Release the event handler innerProgress.ProgressChanged -= innerProgressHandler; - progress.Report(new TaskProgress { PercentComplete = 10 }); + progress.Report(10); - if (!updateInfo.UpdateAvailable) + if (!updateInfo.IsUpdateAvailable) { - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); return; } @@ -66,12 +78,12 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks { Logger.Info("Update Revision {0} available. Updating...", updateInfo.AvailableVersion); - innerProgressHandler = (sender, e) => progress.Report(new TaskProgress { PercentComplete = (e.PercentComplete * .9) + .1 }); + innerProgressHandler = (sender, e) => progress.Report((e * .9) + .1); - innerProgress = new Progress(); + innerProgress = new Progress(); innerProgress.ProgressChanged += innerProgressHandler; - await new ApplicationUpdater().UpdateApplication(cancellationToken, innerProgress).ConfigureAwait(false); + await _appHost.UpdateApplication(cancellationToken, innerProgress).ConfigureAwait(false); // Release the event handler innerProgress.ProgressChanged -= innerProgressHandler; @@ -83,7 +95,7 @@ namespace MediaBrowser.Common.ScheduledTasks.Tasks Logger.Info("A new version of Media Browser is available."); } - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); } /// diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 33e9f291d..fbcd2f589 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -56,7 +56,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// if set to true [recursive]. /// Task. - protected override Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) + protected override Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) { //we don't directly validate our children //but we do need to clear out the index cache... diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index f67934f5d..bcb0b26be 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -612,7 +612,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// if set to true [recursive]. /// Task. - public async Task ValidateChildren(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) + public async Task ValidateChildren(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) { cancellationToken.ThrowIfCancellationRequested(); @@ -664,7 +664,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// if set to true [recursive]. /// Task. - protected async virtual Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) + protected async virtual Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool? recursive = null) { // Nothing to do here if (LocationType != LocationType.FileSystem) @@ -681,7 +681,7 @@ namespace MediaBrowser.Controller.Entities if (nonCachedChildren == null) return; //nothing to validate - progress.Report(new TaskProgress { PercentComplete = 5 }); + progress.Report(5); //build a dictionary of the current children we have now by Id so we can compare quickly and easily var currentChildren = ActualChildren.ToDictionary(i => i.Id); @@ -772,13 +772,13 @@ namespace MediaBrowser.Controller.Entities Kernel.Instance.LibraryManager.OnLibraryChanged(changedArgs); } - progress.Report(new TaskProgress { PercentComplete = 15 }); + progress.Report(15); cancellationToken.ThrowIfCancellationRequested(); await RefreshChildren(validChildren, progress, cancellationToken, recursive).ConfigureAwait(false); - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); } /// @@ -789,7 +789,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// if set to true [recursive]. /// Task. - private Task RefreshChildren(IEnumerable> children, IProgress progress, CancellationToken cancellationToken, bool? recursive) + private Task RefreshChildren(IEnumerable> children, IProgress progress, CancellationToken cancellationToken, bool? recursive) { var numComplete = 0; @@ -824,7 +824,7 @@ namespace MediaBrowser.Controller.Entities { cancellationToken.ThrowIfCancellationRequested(); - await ((Folder)child).ValidateChildren(new Progress { }, cancellationToken, recursive: recursive).ConfigureAwait(false); + await ((Folder)child).ValidateChildren(new Progress { }, cancellationToken, recursive: recursive).ConfigureAwait(false); } lock (progress) @@ -834,7 +834,7 @@ namespace MediaBrowser.Controller.Entities double percent = numComplete; percent /= list.Count; - progress.Report(new TaskProgress { PercentComplete = (85 * percent) + 15 }); + progress.Report((85 * percent) + 15); } })); @@ -952,7 +952,7 @@ namespace MediaBrowser.Controller.Entities { await base.ChangedExternally().ConfigureAwait(false); - var progress = new Progress { }; + var progress = new Progress { }; await ValidateChildren(progress, CancellationToken.None).ConfigureAwait(false); } diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index ee9815e62..f27e8c689 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -205,7 +205,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// The progress. /// Task. - public async Task ValidateMediaLibrary(IProgress progress, CancellationToken cancellationToken) + public async Task ValidateMediaLibrary(IProgress progress, CancellationToken cancellationToken) { Logger.Info("Validating media library for {0}", Name); await RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false); @@ -221,7 +221,7 @@ namespace MediaBrowser.Controller.Entities /// The cancellation token. /// The progress. /// Task. - public async Task ValidateCollectionFolders(IProgress progress, CancellationToken cancellationToken) + public async Task ValidateCollectionFolders(IProgress progress, CancellationToken cancellationToken) { Logger.Info("Validating collection folders for {0}", Name); await RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false); @@ -279,7 +279,7 @@ namespace MediaBrowser.Controller.Entities RootFolder = null; // Kick off a task to validate the media library - Task.Run(() => ValidateMediaLibrary(new Progress { }, CancellationToken.None)); + Task.Run(() => ValidateMediaLibrary(new Progress { }, CancellationToken.None)); return RefreshMetadata(CancellationToken.None, forceSave: true, forceRefresh: true); } diff --git a/MediaBrowser.Common/Net/NetworkShares.cs b/MediaBrowser.Controller/IO/NetworkShares.cs similarity index 99% rename from MediaBrowser.Common/Net/NetworkShares.cs rename to MediaBrowser.Controller/IO/NetworkShares.cs index 202865b4c..93edc6447 100644 --- a/MediaBrowser.Common/Net/NetworkShares.cs +++ b/MediaBrowser.Controller/IO/NetworkShares.cs @@ -3,7 +3,7 @@ using System.IO; using System.Collections; using System.Runtime.InteropServices; -namespace MediaBrowser.Common.Net +namespace MediaBrowser.Controller.IO { /// /// Type of share diff --git a/MediaBrowser.Controller/Library/LibraryManager.cs b/MediaBrowser.Controller/Library/LibraryManager.cs index 95a11e8fe..4087f9ef8 100644 --- a/MediaBrowser.Controller/Library/LibraryManager.cs +++ b/MediaBrowser.Controller/Library/LibraryManager.cs @@ -369,7 +369,7 @@ namespace MediaBrowser.Controller.Library /// The cancellation token. /// The progress. /// Task. - internal async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) + internal async Task ValidatePeople(CancellationToken cancellationToken, IProgress progress) { // Clear the IBN cache ImagesByNameItemCache.Clear(); @@ -422,14 +422,14 @@ namespace MediaBrowser.Controller.Library double percent = numComplete; percent /= people.Count; - progress.Report(new TaskProgress { PercentComplete = 100 * percent }); + progress.Report(100 * percent); } })); } await Task.WhenAll(tasks).ConfigureAwait(false); - progress.Report(new TaskProgress { PercentComplete = 100 }); + progress.Report(100); _logger.Info("People validation complete"); } @@ -440,17 +440,17 @@ namespace MediaBrowser.Controller.Library /// The progress. /// The cancellation token. /// Task. - internal async Task ValidateMediaLibrary(IProgress progress, CancellationToken cancellationToken) + internal async Task ValidateMediaLibrary(IProgress progress, CancellationToken cancellationToken) { _logger.Info("Validating media library"); await Kernel.RootFolder.RefreshMetadata(cancellationToken).ConfigureAwait(false); // Start by just validating the children of the root, but go no further - await Kernel.RootFolder.ValidateChildren(new Progress { }, cancellationToken, recursive: false); + await Kernel.RootFolder.ValidateChildren(new Progress { }, cancellationToken, recursive: false); // Validate only the collection folders for each user, just to make them available as quickly as possible - var userCollectionFolderTasks = Kernel.Users.AsParallel().Select(user => user.ValidateCollectionFolders(new Progress { }, cancellationToken)); + var userCollectionFolderTasks = Kernel.Users.AsParallel().Select(user => user.ValidateCollectionFolders(new Progress { }, cancellationToken)); await Task.WhenAll(userCollectionFolderTasks).ConfigureAwait(false); // Now validate the entire media library @@ -458,7 +458,7 @@ namespace MediaBrowser.Controller.Library foreach (var user in Kernel.Users) { - await user.ValidateMediaLibrary(new Progress { }, cancellationToken).ConfigureAwait(false); + await user.ValidateMediaLibrary(new Progress { }, cancellationToken).ConfigureAwait(false); } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index c2b11ae32..0bf3e6c1f 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -67,7 +67,6 @@ - @@ -106,6 +105,7 @@ + diff --git a/MediaBrowser.Controller/ScheduledTasks/ChapterImagesTask.cs b/MediaBrowser.Controller/ScheduledTasks/ChapterImagesTask.cs index 21f1bce5a..d3d30ed77 100644 --- a/MediaBrowser.Controller/ScheduledTasks/ChapterImagesTask.cs +++ b/MediaBrowser.Controller/ScheduledTasks/ChapterImagesTask.cs @@ -31,7 +31,7 @@ namespace MediaBrowser.Controller.ScheduledTasks /// The cancellation token. /// The progress. /// Task. - protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) + protected override Task ExecuteInternal(CancellationToken cancellationToken, IProgress progress) { var videos = Kernel.RootFolder.RecursiveChildren.OfType