diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-12 23:33:51 -0500 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-11-12 23:33:51 -0500 |
| commit | 95341c5c96059e4bd70f290ff05ae3abc9c49257 (patch) | |
| tree | 720dfca45628aea49a0a554afa40cfa062121cd5 /MediaBrowser.ServerApplication | |
| parent | 3e06bda46b2569c1df47d9ab0c7a763dcf3b1451 (diff) | |
update .net core startup
Diffstat (limited to 'MediaBrowser.ServerApplication')
| -rw-r--r-- | MediaBrowser.ServerApplication/MainStartup.cs | 38 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj | 2 | ||||
| -rw-r--r-- | MediaBrowser.ServerApplication/WindowsAppHost.cs (renamed from MediaBrowser.ServerApplication/Native/WindowsApp.cs) | 173 |
3 files changed, 92 insertions, 121 deletions
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs index fa8cccf342..ab0a36affb 100644 --- a/MediaBrowser.ServerApplication/MainStartup.cs +++ b/MediaBrowser.ServerApplication/MainStartup.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.ServerApplication private static ILogger _logger; - private static bool _isRunningAsService = false; + public static bool IsRunningAsService = false; private static bool _canRestartService = false; private static bool _appHostDisposed; @@ -72,9 +72,9 @@ namespace MediaBrowser.ServerApplication public static void Main() { var options = new StartupOptions(); - _isRunningAsService = options.ContainsOption("-service"); + IsRunningAsService = options.ContainsOption("-service"); - if (_isRunningAsService) + if (IsRunningAsService) { //_canRestartService = CanRestartWindowsService(); } @@ -88,7 +88,7 @@ namespace MediaBrowser.ServerApplication var success = SetDllDirectory(architecturePath); - var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService); + var appPaths = CreateApplicationPaths(applicationPath, IsRunningAsService); var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); @@ -148,7 +148,7 @@ namespace MediaBrowser.ServerApplication try { - RunApplication(appPaths, logManager, _isRunningAsService, options); + RunApplication(appPaths, logManager, IsRunningAsService, options); } finally { @@ -204,7 +204,7 @@ namespace MediaBrowser.ServerApplication } } - if (!_isRunningAsService) + if (!IsRunningAsService) { return IsAlreadyRunningAsService(applicationPath); } @@ -272,7 +272,7 @@ namespace MediaBrowser.ServerApplication { get { - if (_isRunningAsService) + if (IsRunningAsService) { return _canRestartService; } @@ -295,7 +295,7 @@ namespace MediaBrowser.ServerApplication return false; #endif - if (_isRunningAsService) + if (IsRunningAsService) { return _canRestartService; } @@ -317,22 +317,16 @@ namespace MediaBrowser.ServerApplication /// <param name="options">The options.</param> private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, bool runService, StartupOptions options) { - var fileSystem = new WindowsFileSystem(logManager.GetLogger("FileSystem")); + var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), true, true, true); fileSystem.AddShortcutHandler(new LnkShortcutHandler()); fileSystem.AddShortcutHandler(new MbLinkShortcutHandler(fileSystem)); - var nativeApp = new WindowsApp(fileSystem, _logger) - { - IsRunningAsService = runService - }; - var imageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => _appHost.HttpClient, appPaths); - _appHost = new ApplicationHost(appPaths, + _appHost = new WindowsAppHost(appPaths, logManager, options, fileSystem, - nativeApp, new PowerManagement(), "emby.windows.zip", new EnvironmentInfo(), @@ -440,7 +434,7 @@ namespace MediaBrowser.ServerApplication public static void Invoke(Action action) { - if (_isRunningAsService) + if (IsRunningAsService) { action(); } @@ -578,7 +572,7 @@ namespace MediaBrowser.ServerApplication /// <param name="e">The <see cref="SessionEndingEventArgs"/> instance containing the event data.</param> static void SystemEvents_SessionEnding(object sender, SessionEndingEventArgs e) { - if (e.Reason == SessionEndReasons.SystemShutdown || !_isRunningAsService) + if (e.Reason == SessionEndReasons.SystemShutdown || !IsRunningAsService) { Shutdown(); } @@ -595,7 +589,7 @@ namespace MediaBrowser.ServerApplication new UnhandledExceptionWriter(_appHost.ServerConfigurationManager.ApplicationPaths, _logger, _appHost.LogManager).Log(exception); - if (!_isRunningAsService) + if (!IsRunningAsService) { MessageBox.Show("Unhandled exception: " + exception.Message); } @@ -623,7 +617,7 @@ namespace MediaBrowser.ServerApplication // Update is there - execute update try { - var serviceName = _isRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty; + var serviceName = IsRunningAsService ? BackgroundService.GetExistingServiceName() : string.Empty; new ApplicationUpdater().UpdateApplication(appPaths, updateArchive, logger, serviceName); // And just let the app exit so it can update @@ -642,7 +636,7 @@ namespace MediaBrowser.ServerApplication public static void Shutdown() { - if (_isRunningAsService) + if (IsRunningAsService) { ShutdownWindowsService(); } @@ -658,7 +652,7 @@ namespace MediaBrowser.ServerApplication { DisposeAppHost(); - if (_isRunningAsService) + if (IsRunningAsService) { RestartWindowsService(); } diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index f6aef57443..6984ff2bed 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -138,7 +138,6 @@ <Compile Include="Native\PowerManagement.cs" /> <Compile Include="Native\Standby.cs" /> <Compile Include="Native\ServerAuthorization.cs" /> - <Compile Include="Native\WindowsApp.cs" /> <Compile Include="Networking\NativeMethods.cs" /> <Compile Include="Networking\NetworkManager.cs" /> <Compile Include="Networking\NetworkShares.cs" /> @@ -156,6 +155,7 @@ <DependentUpon>SplashForm.cs</DependentUpon> </Compile> <Compile Include="Updates\ApplicationUpdater.cs" /> + <Compile Include="WindowsAppHost.cs" /> </ItemGroup> <ItemGroup> <None Include="App.config" /> diff --git a/MediaBrowser.ServerApplication/Native/WindowsApp.cs b/MediaBrowser.ServerApplication/WindowsAppHost.cs index babe952d6d..8fd7184321 100644 --- a/MediaBrowser.ServerApplication/Native/WindowsApp.cs +++ b/MediaBrowser.ServerApplication/WindowsAppHost.cs @@ -1,142 +1,96 @@ using System; -using MediaBrowser.Common.Net; -using MediaBrowser.Model.Logging; -using MediaBrowser.Server.Startup.Common; -using MediaBrowser.ServerApplication.Networking; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; -using System.Windows.Forms; using Emby.Server.Core; using Emby.Server.Core.Data; using Emby.Server.Core.FFMpeg; -using MediaBrowser.Common.IO; -using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.System; +using MediaBrowser.ServerApplication.Native; -namespace MediaBrowser.ServerApplication.Native +namespace MediaBrowser.ServerApplication { - public class WindowsApp : INativeApp + public class WindowsAppHost : ApplicationHost { - private readonly IFileSystem _fileSystem; - private readonly ILogger _logger; - - public WindowsApp(IFileSystem fileSystem, ILogger logger) + public WindowsAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, IMemoryStreamFactory memoryStreamFactory, MediaBrowser.Common.Net.INetworkManager networkManager, Action<string, string> certificateGenerator, Func<string> defaultUsernameFactory) + : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, memoryStreamFactory, networkManager, certificateGenerator, defaultUsernameFactory) { - _fileSystem = fileSystem; - _logger = logger; } - public List<Assembly> GetAssembliesWithParts() + public override bool IsRunningAsService { - var list = new List<Assembly>(); - - if (!System.Environment.Is64BitProcess) - { - //list.Add(typeof(PismoIsoManager).Assembly); - } - - list.Add(GetType().Assembly); - - return list; + get { return MainStartup.IsRunningAsService; } } - public void AuthorizeServer(int udpPort, int httpServerPort, int httpsPort, string applicationPath, string tempDirectory) + protected override FFMpegInstallInfo GetFfmpegInstallInfo() { - ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsPort, applicationPath, tempDirectory); - } + var info = new FFMpegInstallInfo(); - public bool SupportsLibraryMonitor - { - get { return true; } - } + info.FFMpegFilename = "ffmpeg.exe"; + info.FFProbeFilename = "ffprobe.exe"; + info.Version = "0"; - public bool SupportsRunningAsService - { - get - { - return true; - } + return info; } - public bool IsRunningAsService + protected override void RestartInternal() { - get; - set; + MainStartup.Restart(); } - public bool CanSelfRestart + protected override List<Assembly> GetAssembliesWithPartsInternal() { - get - { - return MainStartup.CanSelfRestart; - } - } + var list = new List<Assembly>(); - public bool SupportsAutoRunAtStartup - { - get + if (!Environment.Is64BitProcess) { - return true; + //list.Add(typeof(PismoIsoManager).Assembly); } + + list.Add(GetType().Assembly); + + return list; } - public bool CanSelfUpdate + protected override void ShutdownInternal() { - get - { - return MainStartup.CanSelfUpdate; - } + MainStartup.Shutdown(); } - public void Shutdown() + protected override void AuthorizeServer(int udpPort, int httpServerPort, int httpsServerPort, string applicationPath, string tempDirectory) { - MainStartup.Shutdown(); + ServerAuthorization.AuthorizeServer(udpPort, httpServerPort, httpsServerPort, applicationPath, tempDirectory); } - public void Restart(StartupOptions startupOptions) + protected override IDbConnector GetDbConnector() { - MainStartup.Restart(); + return new DbConnector(Logger); } - public void ConfigureAutoRun(bool autorun) + protected override void ConfigureAutoRunInternal(bool autorun) { var shortcutPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.StartMenu), "Emby", "Emby Server.lnk"); var startupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup); - + if (autorun) { //Copy our shortut into the startup folder for this user var targetPath = Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk"); - _fileSystem.CreateDirectory(Path.GetDirectoryName(targetPath)); + FileSystemManager.CreateDirectory(Path.GetDirectoryName(targetPath)); File.Copy(shortcutPath, targetPath, true); } else { //Remove our shortcut from the startup folder for this user - _fileSystem.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk")); + FileSystemManager.DeleteFile(Path.Combine(startupPath, Path.GetFileName(shortcutPath) ?? "Emby Server.lnk")); } } - public INetworkManager CreateNetworkManager(ILogger logger) - { - return new NetworkManager(logger); - } - - public FFMpegInstallInfo GetFfmpegInstallInfo() - { - var info = new FFMpegInstallInfo(); - - info.FFMpegFilename = "ffmpeg.exe"; - info.FFProbeFilename = "ffprobe.exe"; - info.Version = "0"; - - return info; - } - - public void LaunchUrl(string url) + public override void LaunchUrl(string url) { var process = new Process { @@ -156,32 +110,54 @@ namespace MediaBrowser.ServerApplication.Native } catch (Exception ex) { - _logger.ErrorException("Error launching url: {0}", ex, url); + Logger.ErrorException("Error launching url: {0}", ex, url); throw; } } - public IDbConnector GetDbConnector() - { - return new DbConnector(_logger); - } - - /// <summary> - /// Processes the exited. - /// </summary> - /// <param name="sender">The sender.</param> - /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> private static void ProcessExited(object sender, EventArgs e) { ((Process)sender).Dispose(); } - public void EnableLoopback(string appName) + protected override void EnableLoopbackInternal(string appName) { LoopUtil.Run(appName); } + public override bool SupportsRunningAsService + { + get + { + return true; + } + } + + public override bool CanSelfRestart + { + get + { + return MainStartup.CanSelfRestart; + } + } + + public override bool SupportsAutoRunAtStartup + { + get + { + return true; + } + } + + public override bool CanSelfUpdate + { + get + { + return MainStartup.CanSelfUpdate; + } + } + public bool PortsRequireAuthorization(string applicationPath) { var appNameSrch = Path.GetFileName(applicationPath); @@ -209,7 +185,7 @@ namespace MediaBrowser.ServerApplication.Native if (data.IndexOf("Block", StringComparison.OrdinalIgnoreCase) != -1) { - _logger.Info("Found potential windows firewall rule blocking Emby Server: " + data); + Logger.Info("Found potential windows firewall rule blocking Emby Server: " + data); } //var parts = data.Split('\n'); @@ -220,7 +196,7 @@ namespace MediaBrowser.ServerApplication.Native } catch (Exception ex) { - _logger.ErrorException("Error querying windows firewall", ex); + Logger.ErrorException("Error querying windows firewall", ex); // Hate having to do this try @@ -229,12 +205,13 @@ namespace MediaBrowser.ServerApplication.Native } catch (Exception ex1) { - _logger.ErrorException("Error killing process", ex1); + Logger.ErrorException("Error killing process", ex1); } throw; } } } + } -}
\ No newline at end of file +} |
