diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 293a9019e8..0a2d6453af 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -1,12 +1,8 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Entities.Audio;
-using MediaBrowser.Controller.Entities.Movies;
-using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
diff --git a/MediaBrowser.Api/UserLibrary/YearsService.cs b/MediaBrowser.Api/UserLibrary/YearsService.cs
index c7cd4ff242..b22a8dac35 100644
--- a/MediaBrowser.Api/UserLibrary/YearsService.cs
+++ b/MediaBrowser.Api/UserLibrary/YearsService.cs
@@ -2,7 +2,6 @@
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using ServiceStack.ServiceHost;
-using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
diff --git a/MediaBrowser.Controller/IServerApplicationHost.cs b/MediaBrowser.Controller/IServerApplicationHost.cs
index d64067f434..042ef30ec4 100644
--- a/MediaBrowser.Controller/IServerApplicationHost.cs
+++ b/MediaBrowser.Controller/IServerApplicationHost.cs
@@ -3,8 +3,15 @@ using MediaBrowser.Model.System;
namespace MediaBrowser.Controller
{
+ ///
+ /// Interface IServerApplicationHost
+ ///
public interface IServerApplicationHost : IApplicationHost
{
+ ///
+ /// Gets the system info.
+ ///
+ /// SystemInfo.
SystemInfo GetSystemInfo();
}
}
diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs
index 4f93f4b6e4..01b867bdb7 100644
--- a/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs
+++ b/MediaBrowser.Server.Implementations/HttpServer/HttpServer.cs
@@ -1,4 +1,3 @@
-using System.IO;
using Funq;
using MediaBrowser.Common;
using MediaBrowser.Common.Extensions;
@@ -17,6 +16,7 @@ using ServiceStack.WebHost.Endpoints.Support;
using System;
using System.Collections.Generic;
using System.Globalization;
+using System.IO;
using System.Linq;
using System.Net;
using System.Net.WebSockets;
@@ -498,6 +498,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer
_logger.Info("Calling ServiceStack AppHost.Init");
Init();
}
+
+ ///
+ /// Releases the specified instance.
+ ///
+ /// The instance.
+ public override void Release(object instance)
+ {
+ // Leave this empty so SS doesn't try to dispose our objects
+ }
}
///
diff --git a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
index 6824442f16..6179af1cb9 100644
--- a/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
+++ b/MediaBrowser.Server.Implementations/Sqlite/SQLiteRepository.cs
@@ -160,27 +160,30 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{
try
{
- if (connection != null)
+ lock (this)
{
- if (EnableDelayedCommands)
+ if (connection != null)
{
- FlushOnDispose();
+ if (EnableDelayedCommands)
+ {
+ FlushOnDispose();
+ }
+
+ if (connection.IsOpen())
+ {
+ connection.Close();
+ }
+
+ connection.Dispose();
+ connection = null;
}
-
- if (connection.IsOpen())
+
+ if (FlushTimer != null)
{
- connection.Close();
+ FlushTimer.Dispose();
+ FlushTimer = null;
}
-
- connection.Dispose();
- }
-
- if (FlushTimer != null)
- {
- FlushTimer.Dispose();
- FlushTimer = null;
}
-
}
catch (Exception ex)
{
@@ -195,13 +198,13 @@ namespace MediaBrowser.Server.Implementations.Sqlite
private void FlushOnDispose()
{
// If we're not already flushing, do it now
- if (!IsFlushing)
+ if (!_isFlushing)
{
Flush(null);
}
// Don't dispose in the middle of a flush
- while (IsFlushing)
+ while (_isFlushing)
{
Thread.Sleep(25);
}
@@ -225,7 +228,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
///
/// The is flushing
///
- private bool IsFlushing;
+ private bool _isFlushing;
///
/// Flushes the specified sender.
@@ -241,12 +244,12 @@ namespace MediaBrowser.Server.Implementations.Sqlite
return;
}
- if (IsFlushing)
+ if (_isFlushing)
{
return;
}
- IsFlushing = true;
+ _isFlushing = true;
var numCommands = 0;
using (var tran = connection.BeginTransaction())
@@ -278,7 +281,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
Logger.Debug("SQL Delayed writer executed " + numCommands + " commands");
FlushTimer.Change(TimeSpan.FromMilliseconds(FlushInterval), TimeSpan.FromMilliseconds(-1));
- IsFlushing = false;
+ _isFlushing = false;
}
///
diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs
index 94a06020e2..18916e99e2 100644
--- a/MediaBrowser.ServerApplication/ApplicationHost.cs
+++ b/MediaBrowser.ServerApplication/ApplicationHost.cs
@@ -159,6 +159,9 @@ namespace MediaBrowser.ServerApplication
///
/// The user data repository.
private IUserDataRepository UserDataRepository { get; set; }
+ private IUserRepository UserRepository { get; set; }
+ private IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
+ private IItemRepository ItemRepository { get; set; }
///
/// The full path to our startmenu shortcut
@@ -239,6 +242,15 @@ namespace MediaBrowser.ServerApplication
UserDataRepository = new SQLiteUserDataRepository(ApplicationPaths, JsonSerializer, LogManager);
RegisterSingleInstance(UserDataRepository);
+ UserRepository = new SQLiteUserRepository(ApplicationPaths, JsonSerializer, LogManager);
+ RegisterSingleInstance(UserRepository);
+
+ DisplayPreferencesRepository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
+ RegisterSingleInstance(DisplayPreferencesRepository);
+
+ ItemRepository = new SQLiteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
+ RegisterSingleInstance(ItemRepository);
+
UserManager = new UserManager(Logger, ServerConfigurationManager, UserDataRepository);
RegisterSingleInstance(UserManager);
@@ -299,11 +311,9 @@ namespace MediaBrowser.ServerApplication
/// Task.
private async Task ConfigureDisplayPreferencesRepositories()
{
- var repository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
-
- await repository.Initialize().ConfigureAwait(false);
+ await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
- ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repository;
+ ((DisplayPreferencesManager)DisplayPreferencesManager).Repository = DisplayPreferencesRepository;
}
///
@@ -312,11 +322,9 @@ namespace MediaBrowser.ServerApplication
/// Task.
private async Task ConfigureItemRepositories()
{
- var repository = new SQLiteItemRepository(ApplicationPaths, JsonSerializer, LogManager);
+ await ItemRepository.Initialize().ConfigureAwait(false);
- await repository.Initialize().ConfigureAwait(false);
-
- ((LibraryManager)LibraryManager).ItemRepository = repository;
+ ((LibraryManager)LibraryManager).ItemRepository = ItemRepository;
}
///
@@ -328,13 +336,15 @@ namespace MediaBrowser.ServerApplication
return UserDataRepository.Initialize();
}
+ ///
+ /// Configures the user repositories.
+ ///
+ /// Task.
private async Task ConfigureUserRepositories()
{
- var repository = new SQLiteUserRepository(ApplicationPaths, JsonSerializer, LogManager);
+ await UserRepository.Initialize().ConfigureAwait(false);
- await repository.Initialize().ConfigureAwait(false);
-
- ((UserManager)UserManager).UserRepository = repository;
+ ((UserManager)UserManager).UserRepository = UserRepository;
}
///
@@ -553,21 +563,5 @@ namespace MediaBrowser.ServerApplication
process.WaitForExit();
}
}
-
- ///
- /// Gets the repository.
- ///
- ///
- /// The repositories.
- /// The name.
- /// ``0.
- private T GetRepository(IEnumerable repositories, string name)
- where T : class, IRepository
- {
- var enumerable = repositories as T[] ?? repositories.ToArray();
-
- return enumerable.FirstOrDefault(r => string.Equals(r.Name, name, StringComparison.OrdinalIgnoreCase)) ??
- enumerable.FirstOrDefault();
- }
}
}
diff --git a/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs b/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs
index ae898f0f9a..bf4eb6e917 100644
--- a/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs
+++ b/MediaBrowser.ServerApplication/EntryPoints/NewItemNotifier.cs
@@ -1,5 +1,4 @@
-using System.Windows;
-using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
@@ -7,6 +6,7 @@ using MediaBrowser.ServerApplication.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
+using System.Windows;
using System.Windows.Controls.Primitives;
namespace MediaBrowser.ServerApplication.EntryPoints
diff --git a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs
index 056e50a780..a6d505d198 100644
--- a/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs
+++ b/MediaBrowser.ServerApplication/EntryPoints/WebSocketEvents.cs
@@ -1,6 +1,4 @@
-using System.Linq;
-using System.Threading;
-using MediaBrowser.Common.Events;
+using MediaBrowser.Common.Events;
using MediaBrowser.Common.Net;
using MediaBrowser.Common.Plugins;
using MediaBrowser.Common.ScheduledTasks;
@@ -15,6 +13,8 @@ using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Model.Updates;
using System;
+using System.Linq;
+using System.Threading;
namespace MediaBrowser.ServerApplication.EntryPoints
{