fixed db disposals

This commit is contained in:
Luke Pulverenti 2013-04-19 16:27:02 -04:00
parent 6c1bfe661b
commit eb612bd303
8 changed files with 69 additions and 61 deletions

View File

@ -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;

View File

@ -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;

View File

@ -3,8 +3,15 @@ using MediaBrowser.Model.System;
namespace MediaBrowser.Controller
{
/// <summary>
/// Interface IServerApplicationHost
/// </summary>
public interface IServerApplicationHost : IApplicationHost
{
/// <summary>
/// Gets the system info.
/// </summary>
/// <returns>SystemInfo.</returns>
SystemInfo GetSystemInfo();
}
}

View File

@ -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();
}
/// <summary>
/// Releases the specified instance.
/// </summary>
/// <param name="instance">The instance.</param>
public override void Release(object instance)
{
// Leave this empty so SS doesn't try to dispose our objects
}
}
/// <summary>

View File

@ -160,27 +160,30 @@ namespace MediaBrowser.Server.Implementations.Sqlite
{
try
{
if (connection != null)
lock (this)
{
if (EnableDelayedCommands)
if (connection != null)
{
FlushOnDispose();
}
if (connection.IsOpen())
{
connection.Close();
if (EnableDelayedCommands)
{
FlushOnDispose();
}
if (connection.IsOpen())
{
connection.Close();
}
connection.Dispose();
connection = null;
}
connection.Dispose();
if (FlushTimer != null)
{
FlushTimer.Dispose();
FlushTimer = null;
}
}
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
/// <summary>
/// The is flushing
/// </summary>
private bool IsFlushing;
private bool _isFlushing;
/// <summary>
/// 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;
}
/// <summary>

View File

@ -159,6 +159,9 @@ namespace MediaBrowser.ServerApplication
/// </summary>
/// <value>The user data repository.</value>
private IUserDataRepository UserDataRepository { get; set; }
private IUserRepository UserRepository { get; set; }
private IDisplayPreferencesRepository DisplayPreferencesRepository { get; set; }
private IItemRepository ItemRepository { get; set; }
/// <summary>
/// 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
/// <returns>Task.</returns>
private async Task ConfigureDisplayPreferencesRepositories()
{
var repository = new SQLiteDisplayPreferencesRepository(ApplicationPaths, JsonSerializer, LogManager);
await DisplayPreferencesRepository.Initialize().ConfigureAwait(false);
await repository.Initialize().ConfigureAwait(false);
((DisplayPreferencesManager)DisplayPreferencesManager).Repository = repository;
((DisplayPreferencesManager)DisplayPreferencesManager).Repository = DisplayPreferencesRepository;
}
/// <summary>
@ -312,11 +322,9 @@ namespace MediaBrowser.ServerApplication
/// <returns>Task.</returns>
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;
}
/// <summary>
@ -328,13 +336,15 @@ namespace MediaBrowser.ServerApplication
return UserDataRepository.Initialize();
}
/// <summary>
/// Configures the user repositories.
/// </summary>
/// <returns>Task.</returns>
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;
}
/// <summary>
@ -553,21 +563,5 @@ namespace MediaBrowser.ServerApplication
process.WaitForExit();
}
}
/// <summary>
/// Gets the repository.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="repositories">The repositories.</param>
/// <param name="name">The name.</param>
/// <returns>``0.</returns>
private T GetRepository<T>(IEnumerable<T> 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();
}
}
}

View File

@ -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

View File

@ -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
{