mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-27 18:10:54 +01:00
mono progress - able to start app
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
<RootNamespace>MediaBrowser.Server.Mono</RootNamespace>
|
||||
<AssemblyName>MediaBrowser.Server.Mono</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<StartupObject>MediaBrowser.Server.Mono.MainClass</StartupObject>
|
||||
<ApplicationIcon>..\MediaBrowser.ServerApplication\Resources\Images\Icon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -43,6 +45,12 @@
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="ServiceStack.Common">
|
||||
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Common.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ServiceStack.Interfaces">
|
||||
<HintPath>..\packages\ServiceStack.Common.3.9.62\lib\net35\ServiceStack.Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="gtk-gui\gui.stetic">
|
||||
@@ -50,6 +58,9 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedVersion.cs">
|
||||
<Link>Properties\SharedVersion.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="gtk-gui\generated.cs" />
|
||||
<Compile Include="MainWindow.cs" />
|
||||
<Compile Include="gtk-gui\MainWindow.cs" />
|
||||
@@ -72,7 +83,6 @@
|
||||
</Compile>
|
||||
<Compile Include="Native\HttpMessageHandlerFactory.cs" />
|
||||
<Compile Include="Native\Assemblies.cs" />
|
||||
<Compile Include="Native\Sqlite.cs" />
|
||||
<Compile Include="Native\NativeApp.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
@@ -112,8 +122,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="EntryPoints\" />
|
||||
<Folder Include="Implementations\" />
|
||||
<Folder Include="Native\" />
|
||||
<Folder Include="FFMpeg\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using MediaBrowser.Server.Mono;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
/// <summary>
|
||||
@@ -11,7 +12,7 @@ namespace MediaBrowser.ServerApplication.Native
|
||||
/// </summary>
|
||||
public static void Shutdown()
|
||||
{
|
||||
|
||||
MainClass.Shutdown ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -19,7 +20,7 @@ namespace MediaBrowser.ServerApplication.Native
|
||||
/// </summary>
|
||||
public static void Restart()
|
||||
{
|
||||
|
||||
MainClass.Restart ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.ServerApplication.Native
|
||||
{
|
||||
/// <summary>
|
||||
/// Class Sqlite
|
||||
/// </summary>
|
||||
public static class Sqlite
|
||||
{
|
||||
/// <summary>
|
||||
/// Connects to db.
|
||||
/// </summary>
|
||||
/// <param name="dbPath">The db path.</param>
|
||||
/// <returns>Task{IDbConnection}.</returns>
|
||||
/// <exception cref="System.ArgumentNullException">dbPath</exception>
|
||||
public static async Task<IDbConnection> OpenDatabase(string dbPath)
|
||||
{
|
||||
var connectionstr = new SQLiteConnectionStringBuilder
|
||||
{
|
||||
PageSize = 4096,
|
||||
CacheSize = 4096,
|
||||
SyncMode = SynchronizationModes.Normal,
|
||||
DataSource = dbPath,
|
||||
JournalMode = SQLiteJournalModeEnum.Wal
|
||||
};
|
||||
|
||||
var connection = new SQLiteConnection(connectionstr.ConnectionString);
|
||||
|
||||
await connection.OpenAsync().ConfigureAwait(false);
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,188 @@
|
||||
using MediaBrowser.Common.Constants;
|
||||
using MediaBrowser.Common.Implementations.Logging;
|
||||
using MediaBrowser.Common.Implementations.Updates;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Server.Implementations;
|
||||
using MediaBrowser.ServerApplication;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using Gtk;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Server.Mono
|
||||
{
|
||||
class MainClass
|
||||
public class MainClass
|
||||
{
|
||||
private static ApplicationHost _appHost;
|
||||
|
||||
private static Mutex _singleInstanceMutex;
|
||||
|
||||
private static ILogger _logger;
|
||||
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
Application.Init ();
|
||||
|
||||
var appPaths = CreateApplicationPaths();
|
||||
|
||||
var logManager = new NlogManager(appPaths.LogDirectoryPath, "server");
|
||||
logManager.ReloadLogger(LogSeverity.Info);
|
||||
|
||||
var logger = _logger = logManager.GetLogger("Main");
|
||||
|
||||
BeginLog(logger);
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
bool createdNew;
|
||||
|
||||
var runningPath = Process.GetCurrentProcess().MainModule.FileName.Replace(Path.DirectorySeparatorChar.ToString(), string.Empty);
|
||||
|
||||
_singleInstanceMutex = new Mutex(true, @"Local\" + runningPath, out createdNew);
|
||||
|
||||
if (!createdNew)
|
||||
{
|
||||
_singleInstanceMutex = null;
|
||||
logger.Info("Shutting down because another instance of Media Browser Server is already running.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (PerformUpdateIfNeeded(appPaths, logger))
|
||||
{
|
||||
logger.Info("Exiting to perform application update.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
RunApplication(appPaths, logManager);
|
||||
}
|
||||
finally
|
||||
{
|
||||
logger.Info("Shutting down");
|
||||
|
||||
ReleaseMutex(logger);
|
||||
|
||||
_appHost.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static ServerApplicationPaths CreateApplicationPaths()
|
||||
{
|
||||
return new ServerApplicationPaths("D:\\MonoTest");
|
||||
}
|
||||
|
||||
private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager)
|
||||
{
|
||||
// TODO: Show splash here
|
||||
|
||||
SystemEvents.SessionEnding += SystemEvents_SessionEnding;
|
||||
|
||||
_appHost = new ApplicationHost(appPaths, logManager);
|
||||
|
||||
var task = _appHost.Init();
|
||||
Task.WaitAll (task);
|
||||
|
||||
task = _appHost.RunStartupTasks();
|
||||
Task.WaitAll (task);
|
||||
|
||||
// TODO: Hide splash here
|
||||
MainWindow win = new MainWindow ();
|
||||
|
||||
win.Show ();
|
||||
|
||||
Application.Run ();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the SessionEnding event of the SystemEvents control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <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)
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Begins the log.
|
||||
/// </summary>
|
||||
/// <param name="logger">The logger.</param>
|
||||
private static void BeginLog(ILogger logger)
|
||||
{
|
||||
logger.Info("Media Browser Server started");
|
||||
logger.Info("Command line: {0}", string.Join(" ", Environment.GetCommandLineArgs()));
|
||||
|
||||
logger.Info("Server: {0}", Environment.MachineName);
|
||||
logger.Info("Operating system: {0}", Environment.OSVersion.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the UnhandledException event of the CurrentDomain control.
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the event.</param>
|
||||
/// <param name="e">The <see cref="UnhandledExceptionEventArgs"/> instance containing the event data.</param>
|
||||
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
var exception = (Exception)e.ExceptionObject;
|
||||
|
||||
_logger.ErrorException("UnhandledException", exception);
|
||||
|
||||
if (!Debugger.IsAttached)
|
||||
{
|
||||
Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(exception));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the mutex.
|
||||
/// </summary>
|
||||
internal static void ReleaseMutex(ILogger logger)
|
||||
{
|
||||
if (_singleInstanceMutex == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.Debug("Releasing mutex");
|
||||
|
||||
_singleInstanceMutex.ReleaseMutex();
|
||||
_singleInstanceMutex.Close();
|
||||
_singleInstanceMutex.Dispose();
|
||||
_singleInstanceMutex = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs the update if needed.
|
||||
/// </summary>
|
||||
/// <param name="appPaths">The app paths.</param>
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
|
||||
private static bool PerformUpdateIfNeeded(ServerApplicationPaths appPaths, ILogger logger)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void Shutdown()
|
||||
{
|
||||
Application.Quit ();
|
||||
}
|
||||
|
||||
public static void Restart()
|
||||
{
|
||||
// Second instance will start first, so release the mutex and dispose the http server ahead of time
|
||||
ReleaseMutex (_logger);
|
||||
|
||||
_appHost.Dispose();
|
||||
|
||||
Application.Quit ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,4 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("Luke")]
|
||||
[assembly: AssemblyTrademark ("")]
|
||||
[assembly: AssemblyCulture ("")]
|
||||
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
[assembly: AssemblyVersion ("1.0.*")]
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
//[assembly: AssemblyDelaySign(false)]
|
||||
//[assembly: AssemblyKeyFile("")]
|
||||
|
||||
[assembly: AssemblyCulture ("")]
|
||||
14
MediaBrowser.Server.Mono/app.config
Normal file
14
MediaBrowser.Server.Mono/app.config
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
|
||||
</configSections>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<targets async="true"></targets>
|
||||
</nlog>
|
||||
<appSettings>
|
||||
<add key="DebugProgramDataPath" value="..\..\..\..\ProgramData-Server" />
|
||||
<add key="ReleaseProgramDataPath" value="%ApplicationData%" />
|
||||
<add key="ProgramDataFolderName" value="MediaBrowser-Server" />
|
||||
</appSettings>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user