aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Controller/Entities/Folder.cs29
-rw-r--r--MediaBrowser.Controller/Notifications/INotificationsRepository.cs6
-rw-r--r--MediaBrowser.Controller/Persistence/IItemRepository.cs1
-rw-r--r--MediaBrowser.Controller/Persistence/IUserRepository.cs2
-rw-r--r--MediaBrowser.Mono.userprefs13
-rw-r--r--MediaBrowser.Server.Implementations/Dto/DtoService.cs2
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs18
-rw-r--r--MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs17
-rw-r--r--MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj16
-rw-r--r--MediaBrowser.Server.Mono/Native/NativeApp.cs7
-rw-r--r--MediaBrowser.Server.Mono/Native/Sqlite.cs36
-rw-r--r--MediaBrowser.Server.Mono/Program.cs174
-rw-r--r--MediaBrowser.Server.Mono/Properties/AssemblyInfo.cs11
-rw-r--r--MediaBrowser.Server.Mono/app.config14
-rw-r--r--MediaBrowser.ServerApplication/App.xaml.cs2
-rw-r--r--MediaBrowser.ServerApplication/ApplicationHost.cs37
-rw-r--r--MediaBrowser.ServerApplication/MainStartup.cs2
-rw-r--r--MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj9
-rw-r--r--MediaBrowser.ServerApplication/Native/Sqlite.cs36
-rw-r--r--MediaBrowser.ServerApplication/packages.config1
20 files changed, 273 insertions, 160 deletions
diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs
index 1015a3021..6f5bc3e3b 100644
--- a/MediaBrowser.Controller/Entities/Folder.cs
+++ b/MediaBrowser.Controller/Entities/Folder.cs
@@ -980,7 +980,7 @@ namespace MediaBrowser.Controller.Entities
var initialCount = _children.Count;
var list = new List<BaseItem>(initialCount);
- AddChildrenToList(user, includeLinkedChildren, list, false);
+ AddChildrenToList(user, includeLinkedChildren, list, false, null);
return list;
}
@@ -992,7 +992,9 @@ namespace MediaBrowser.Controller.Entities
/// <param name="includeLinkedChildren">if set to <c>true</c> [include linked children].</param>
/// <param name="list">The list.</param>
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
- private bool AddChildrenToList(User user, bool includeLinkedChildren, List<BaseItem> list, bool recursive)
+ /// <param name="filter">The filter.</param>
+ /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
+ private bool AddChildrenToList(User user, bool includeLinkedChildren, List<BaseItem> list, bool recursive, Func<BaseItem,bool> filter)
{
var hasLinkedChildren = false;
@@ -1000,7 +1002,10 @@ namespace MediaBrowser.Controller.Entities
{
if (child.IsVisible(user))
{
- list.Add(child);
+ if (filter == null || filter(child))
+ {
+ list.Add(child);
+ }
}
if (recursive)
@@ -1009,7 +1014,7 @@ namespace MediaBrowser.Controller.Entities
if (folder != null)
{
- if (folder.AddChildrenToList(user, includeLinkedChildren, list, true))
+ if (folder.AddChildrenToList(user, includeLinkedChildren, list, true, filter))
{
hasLinkedChildren = true;
}
@@ -1021,6 +1026,11 @@ namespace MediaBrowser.Controller.Entities
{
foreach (var child in GetLinkedChildren())
{
+ if (filter != null && !filter(child))
+ {
+ continue;
+ }
+
hasLinkedChildren = true;
if (child.IsVisible(user))
@@ -1043,6 +1053,11 @@ namespace MediaBrowser.Controller.Entities
/// <exception cref="System.ArgumentNullException"></exception>
public IEnumerable<BaseItem> GetRecursiveChildren(User user, bool includeLinkedChildren = true)
{
+ return GetRecursiveChildren(user, null, true);
+ }
+
+ public IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem,bool> filter, bool includeLinkedChildren = true)
+ {
if (user == null)
{
throw new ArgumentNullException();
@@ -1051,10 +1066,10 @@ namespace MediaBrowser.Controller.Entities
var initialCount = _lastRecursiveCount == 0 ? _children.Count : _lastRecursiveCount;
var list = new List<BaseItem>(initialCount);
- var hasLinkedChildren = AddChildrenToList(user, includeLinkedChildren, list, true);
+ var hasLinkedChildren = AddChildrenToList(user, includeLinkedChildren, list, true, null);
_lastRecursiveCount = list.Count;
-
+
if (includeLinkedChildren && hasLinkedChildren)
{
list = list.Distinct().ToList();
@@ -1062,7 +1077,7 @@ namespace MediaBrowser.Controller.Entities
return list;
}
-
+
/// <summary>
/// Gets the linked children.
/// </summary>
diff --git a/MediaBrowser.Controller/Notifications/INotificationsRepository.cs b/MediaBrowser.Controller/Notifications/INotificationsRepository.cs
index 8790b54f4..7a4b69b52 100644
--- a/MediaBrowser.Controller/Notifications/INotificationsRepository.cs
+++ b/MediaBrowser.Controller/Notifications/INotificationsRepository.cs
@@ -26,6 +26,12 @@ namespace MediaBrowser.Controller.Notifications
event EventHandler<NotificationReadEventArgs> NotificationsMarkedRead;
/// <summary>
+ /// Opens the connection to the repository
+ /// </summary>
+ /// <returns>Task.</returns>
+ Task Initialize();
+
+ /// <summary>
/// Gets the notifications.
/// </summary>
/// <param name="query">The query.</param>
diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs
index 8960b5dfb..e04f25605 100644
--- a/MediaBrowser.Controller/Persistence/IItemRepository.cs
+++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs
@@ -2,7 +2,6 @@
using MediaBrowser.Model.Entities;
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
diff --git a/MediaBrowser.Controller/Persistence/IUserRepository.cs b/MediaBrowser.Controller/Persistence/IUserRepository.cs
index 49c418c30..0241b8c03 100644
--- a/MediaBrowser.Controller/Persistence/IUserRepository.cs
+++ b/MediaBrowser.Controller/Persistence/IUserRepository.cs
@@ -14,7 +14,7 @@ namespace MediaBrowser.Controller.Persistence
/// Opens the connection to the repository
/// </summary>
/// <returns>Task.</returns>
- void Initialize();
+ Task Initialize();
/// <summary>
/// Deletes the user.
diff --git a/MediaBrowser.Mono.userprefs b/MediaBrowser.Mono.userprefs
index 80da5915d..b57fb35e0 100644
--- a/MediaBrowser.Mono.userprefs
+++ b/MediaBrowser.Mono.userprefs
@@ -1,15 +1,12 @@
<Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
- <MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs">
+ <MonoDevelop.Ide.Workbench ActiveDocument="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs">
<Files>
+ <File FileName="d:\Development\MediaBrowser\MediaBrowser.ServerApplication\ApplicationHost.cs" Line="442" Column="10" />
+ <File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="1" Column="1" />
+ <File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="1" Column="1" />
+ <File FileName="MediaBrowser.Server.Mono\Native\Assemblies.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
- <File FileName="MediaBrowser.Server.Mono\MainWindow.cs" Line="8" Column="12" />
- <File FileName="MediaBrowser.Server.Mono\Native\Autorun.cs" Line="17" Column="4" />
- <File FileName="MediaBrowser.Server.Mono\Native\ServerAuthorization.cs" Line="23" Column="1" />
- <File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloader.cs" Line="7" Column="14" />
- <File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="548" Column="61" />
- <File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="22" Column="13" />
- <File FileName="d:\Development\MediaBrowser\MediaBrowser.Server.Mono\Native\Sqlite.cs" Line="21" Column="14" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs
index a5f54b938..740f5fbbc 100644
--- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs
+++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs
@@ -1074,7 +1074,7 @@ namespace MediaBrowser.Server.Implementations.Dto
double totalPercentPlayed = 0;
// Loop through each recursive child
- foreach (var child in folder.GetRecursiveChildren(user, true).Where(i => !i.IsFolder).ToList())
+ foreach (var child in folder.GetRecursiveChildren(user, i => !i.IsFolder))
{
var userdata = _userDataRepository.GetUserData(user.Id, child.GetUserDataKey());
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
index f755bd4e6..d85b1d874 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteNotificationsRepository.cs
@@ -1,4 +1,6 @@
-using MediaBrowser.Controller.Notifications;
+using System.IO;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Notifications;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Notifications;
using System;
@@ -12,15 +14,15 @@ namespace MediaBrowser.Server.Implementations.Persistence
{
public class SqliteNotificationsRepository : INotificationsRepository
{
- private readonly IDbConnection _connection;
+ private IDbConnection _connection;
private readonly ILogger _logger;
+ private readonly IServerApplicationPaths _appPaths;
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
- public SqliteNotificationsRepository(IDbConnection connection, ILogManager logManager)
+ public SqliteNotificationsRepository(ILogManager logManager, IServerApplicationPaths appPaths)
{
- _connection = connection;
-
+ _appPaths = appPaths;
_logger = logManager.GetLogger(GetType().Name);
}
@@ -31,8 +33,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _replaceNotificationCommand;
private IDbCommand _markReadCommand;
- public void Initialize()
+ public async Task Initialize()
{
+ var dbFile = Path.Combine(_appPaths.DataPath, "notifications.db");
+
+ _connection = await SqliteExtensions.ConnectToDb(dbFile).ConfigureAwait(false);
+
string[] queries = {
"create table if not exists Notifications (Id GUID NOT NULL, UserId GUID NOT NULL, Date DATETIME NOT NULL, Name TEXT NOT NULL, Description TEXT, Url TEXT, Level TEXT NOT NULL, IsRead BOOLEAN NOT NULL, Category TEXT NOT NULL, RelatedId TEXT, PRIMARY KEY (Id, UserId))",
diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
index c96ed970a..1aa0e8395 100644
--- a/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
+++ b/MediaBrowser.Server.Implementations/Persistence/SqliteUserRepository.cs
@@ -1,10 +1,12 @@
-using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller;
+using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization;
using System;
using System.Collections.Generic;
using System.Data;
+using System.IO;
using System.Threading;
using System.Threading.Tasks;
@@ -20,6 +22,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
private IDbConnection _connection;
+ private readonly IServerApplicationPaths _appPaths;
/// <summary>
/// Gets the name of the repository
@@ -42,19 +45,19 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// <summary>
/// Initializes a new instance of the <see cref="SqliteUserRepository" /> class.
/// </summary>
- /// <param name="connection">The connection.</param>
/// <param name="jsonSerializer">The json serializer.</param>
/// <param name="logManager">The log manager.</param>
+ /// <param name="appPaths">The app paths.</param>
/// <exception cref="System.ArgumentNullException">appPaths</exception>
- public SqliteUserRepository(IDbConnection connection, IJsonSerializer jsonSerializer, ILogManager logManager)
+ public SqliteUserRepository(IJsonSerializer jsonSerializer, ILogManager logManager, IServerApplicationPaths appPaths)
{
if (jsonSerializer == null)
{
throw new ArgumentNullException("jsonSerializer");
}
- _connection = connection;
_jsonSerializer = jsonSerializer;
+ _appPaths = appPaths;
_logger = logManager.GetLogger(GetType().Name);
}
@@ -63,8 +66,12 @@ namespace MediaBrowser.Server.Implementations.Persistence
/// Opens the connection to the database
/// </summary>
/// <returns>Task.</returns>
- public void Initialize()
+ public async Task Initialize()
{
+ var dbFile = Path.Combine(_appPaths.DataPath, "users.db");
+
+ _connection = await SqliteExtensions.ConnectToDb(dbFile).ConfigureAwait(false);
+
string[] queries = {
"create table if not exists users (guid GUID primary key, data BLOB)",
diff --git a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
index 1c369daac..267dfb78a 100644
--- a/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
+++ b/MediaBrowser.Server.Mono/MediaBrowser.Server.Mono.csproj
@@ -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> \ No newline at end of file
diff --git a/MediaBrowser.Server.Mono/Native/NativeApp.cs b/MediaBrowser.Server.Mono/Native/NativeApp.cs
index bb47f6ea4..4cc2dcebf 100644
--- a/MediaBrowser.Server.Mono/Native/NativeApp.cs
+++ b/MediaBrowser.Server.Mono/Native/NativeApp.cs
@@ -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 ();
}
}
}
diff --git a/MediaBrowser.Server.Mono/Native/Sqlite.cs b/MediaBrowser.Server.Mono/Native/Sqlite.cs
deleted file mode 100644
index cc20952d7..000000000
--- a/MediaBrowser.Server.Mono/Native/Sqlite.cs
+++ /dev/null
@@ -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;
- }
- }
-}
diff --git a/MediaBrowser.Server.Mono/Program.cs b/MediaBrowser.Server.Mono/Program.cs
index 72dee1162..1a3ce414e 100644
--- a/MediaBrowser.Server.Mono/Program.cs
+++ b/MediaBrowser.Server.Mono/Program.cs
@@ -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 ();
+ }
}
}
diff --git a/MediaBrowser.Server.Mono/Properties/AssemblyInfo.cs b/MediaBrowser.Server.Mono/Properties/AssemblyInfo.cs
index 0a2e93220..3d6ac0bc1 100644
--- a/MediaBrowser.Server.Mono/Properties/AssemblyInfo.cs
+++ b/MediaBrowser.Server.Mono/Properties/AssemblyInfo.cs
@@ -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 ("")] \ No newline at end of file
diff --git a/MediaBrowser.Server.Mono/app.config b/MediaBrowser.Server.Mono/app.config
new file mode 100644
index 000000000..0f0042497
--- /dev/null
+++ b/MediaBrowser.Server.Mono/app.config
@@ -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>
diff --git a/MediaBrowser.ServerApplication/App.xaml.cs b/MediaBrowser.ServerApplication/App.xaml.cs
index ad4727023..7bfebdfe9 100644
--- a/MediaBrowser.ServerApplication/App.xaml.cs
+++ b/MediaBrowser.ServerApplication/App.xaml.cs
@@ -55,8 +55,6 @@ namespace MediaBrowser.ServerApplication
public void OnUnhandledException(Exception ex)
{
- _logger.ErrorException("UnhandledException", ex);
-
MessageBox.Show("Unhandled exception: " + ex.Message);
}
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index 3090ad033..4327f4149 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -53,7 +53,6 @@ using MediaBrowser.ServerApplication.Native;
using MediaBrowser.WebDashboard.Api;
using System;
using System.Collections.Generic;
-using System.Data;
using System.IO;
using System.Linq;
using System.Net.Http;
@@ -157,7 +156,7 @@ namespace MediaBrowser.ServerApplication
private ISessionManager SessionManager { get; set; }
private ILiveTvManager LiveTvManager { get; set; }
-
+
private ILocalizationManager LocalizationManager { get; set; }
/// <summary>
@@ -329,13 +328,9 @@ namespace MediaBrowser.ServerApplication
private async Task<IUserRepository> GetUserRepository()
{
- var dbFile = Path.Combine(ApplicationPaths.DataPath, "users.db");
-
- var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
+ var repo = new SqliteUserRepository(JsonSerializer, LogManager, ApplicationPaths);
- var repo = new SqliteUserRepository(connection, JsonSerializer, LogManager);
-
- repo.Initialize();
+ await repo.Initialize().ConfigureAwait(false);
return repo;
}
@@ -346,13 +341,9 @@ namespace MediaBrowser.ServerApplication
/// <returns>Task.</returns>
private async Task ConfigureNotificationsRepository()
{
- var dbFile = Path.Combine(ApplicationPaths.DataPath, "notifications.db");
-
- var connection = await ConnectToDb(dbFile).ConfigureAwait(false);
+ var repo = new SqliteNotificationsRepository(LogManager, ApplicationPaths);
- var repo = new SqliteNotificationsRepository(connection, LogManager);
-
- repo.Initialize();
+ await repo.Initialize().ConfigureAwait(false);
NotificationsRepository = repo;
@@ -389,22 +380,6 @@ namespace MediaBrowser.ServerApplication
}
/// <summary>
- /// Connects to db.
- /// </summary>
- /// <param name="dbPath">The db path.</param>
- /// <returns>Task{IDbConnection}.</returns>
- /// <exception cref="System.ArgumentNullException">dbPath</exception>
- private static Task<IDbConnection> ConnectToDb(string dbPath)
- {
- if (string.IsNullOrEmpty(dbPath))
- {
- throw new ArgumentNullException("dbPath");
- }
-
- return Sqlite.OpenDatabase(dbPath);
- }
-
- /// <summary>
/// Dirty hacks
/// </summary>
private void SetStaticProperties()
@@ -550,7 +525,7 @@ namespace MediaBrowser.ServerApplication
.Select(LoadAssembly)
.Where(a => a != null)
.ToList();
-
+
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
diff --git a/MediaBrowser.ServerApplication/MainStartup.cs b/MediaBrowser.ServerApplication/MainStartup.cs
index 55fa60ed2..a6a403609 100644
--- a/MediaBrowser.ServerApplication/MainStartup.cs
+++ b/MediaBrowser.ServerApplication/MainStartup.cs
@@ -314,6 +314,8 @@ namespace MediaBrowser.ServerApplication
{
var exception = (Exception)e.ExceptionObject;
+ _logger.ErrorException("UnhandledException", ex);
+
if (_backgroundService == null)
{
_app.OnUnhandledException(exception);
diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
index ddbe05e59..0d052db6a 100644
--- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
+++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj
@@ -167,14 +167,6 @@
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
- <Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\System.Data.SQLite.x86.1.0.88.0\lib\net45\System.Data.SQLite.dll</HintPath>
- </Reference>
- <Reference Include="System.Data.SQLite.Linq, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\packages\System.Data.SQLite.x86.1.0.88.0\lib\net45\System.Data.SQLite.Linq.dll</HintPath>
- </Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Net" />
<Reference Include="System.Net.Http" />
@@ -212,7 +204,6 @@
<Compile Include="BackgroundServiceInstaller.cs">
<SubType>Component</SubType>
</Compile>
- <Compile Include="Native\Sqlite.cs" />
<Compile Include="Splash\SplashWindow.xaml.cs">
<DependentUpon>SplashWindow.xaml</DependentUpon>
</Compile>
diff --git a/MediaBrowser.ServerApplication/Native/Sqlite.cs b/MediaBrowser.ServerApplication/Native/Sqlite.cs
deleted file mode 100644
index cc20952d7..000000000
--- a/MediaBrowser.ServerApplication/Native/Sqlite.cs
+++ /dev/null
@@ -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;
- }
- }
-}
diff --git a/MediaBrowser.ServerApplication/packages.config b/MediaBrowser.ServerApplication/packages.config
index d776597ec..fd96a8fc1 100644
--- a/MediaBrowser.ServerApplication/packages.config
+++ b/MediaBrowser.ServerApplication/packages.config
@@ -10,5 +10,4 @@
<package id="ServiceStack.Redis" version="3.9.44" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.62" targetFramework="net45" />
<package id="SimpleInjector" version="2.3.5" targetFramework="net45" />
- <package id="System.Data.SQLite.x86" version="1.0.88.0" targetFramework="net45" />
</packages> \ No newline at end of file