Skip to content

Commit

Permalink
fixed ninjet's race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kayone committed Oct 10, 2010
1 parent b112e28 commit 30d38ee
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 65 deletions.
55 changes: 39 additions & 16 deletions NzbDrone.Core/CentralDispatch.cs
Expand Up @@ -7,6 +7,7 @@
using NzbDrone.Core.Entities;
using NzbDrone.Core.Entities.Episode;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Fakes;
using SubSonic.DataProviders;
using SubSonic.Repository;
using NLog;
Expand All @@ -15,24 +16,33 @@ namespace NzbDrone.Core
{
public static class CentralDispatch
{
private static IKernel _kernel;
private static readonly Object kernelLock = new object();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

public static void BindKernel(IKernel kernel)
public static void BindKernel()
{
string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
provider.Log = new SonicTrace();
provider.LogParams = true;

kernel.Bind<ISeriesProvider>().To<SeriesProvider>().InSingletonScope();
kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
kernel.Bind<IDiskProvider>().To<DiskProvider>();
kernel.Bind<ITvDbProvider>().To<TvDbProvider>();
kernel.Bind<IConfigProvider>().To<ConfigProvider>().InSingletonScope();
kernel.Bind<INotificationProvider>().To<NotificationProvider>().InSingletonScope();
kernel.Bind<IRepository>().ToMethod(c => new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();

ForceMigration(kernel.Get<IRepository>());
lock (kernelLock)
{
Logger.Debug("Binding Ninject's Kernel");
_kernel = new StandardKernel();

string connectionString = String.Format("Data Source={0};Version=3;", Path.Combine(AppPath, "nzbdrone.db"));
var provider = ProviderFactory.GetProvider(connectionString, "System.Data.SQLite");
provider.Log = new SonicTrace();
provider.LogParams = true;

_kernel.Bind<ISeriesProvider>().To<SeriesProvider>().InSingletonScope();
_kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
_kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
_kernel.Bind<IDiskProvider>().To<DiskProvider>();
_kernel.Bind<ITvDbProvider>().To<TvDbProvider>();
_kernel.Bind<IConfigProvider>().To<ConfigProvider>().InSingletonScope();
_kernel.Bind<INotificationProvider>().To<FakeNotificationProvider>().InSingletonScope();
_kernel.Bind<IRepository>().ToMethod(c => new SimpleRepository(provider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();

ForceMigration(_kernel.Get<IRepository>());
}
}

public static String AppPath
Expand All @@ -48,6 +58,19 @@ public static String AppPath

}

public static IKernel NinjectKernel
{
get
{

if (_kernel == null)
{
BindKernel();
}

return _kernel;
}
}

public static void ConfigureNlog()
{
Expand Down
1 change: 1 addition & 0 deletions NzbDrone.Core/NzbDrone.Core.csproj
Expand Up @@ -149,6 +149,7 @@
<Compile Include="Entities\Notification\BasicNotification.cs" />
<Compile Include="Entities\Notification\NotificationStatus.cs" />
<Compile Include="Entities\Notification\NotificationType.cs" />
<Compile Include="Providers\Fakes\FakeNotificationProvider.cs" />
<Compile Include="Providers\INotificationProvider.cs" />
<Compile Include="Providers\IMediaDiscoveryProvider.cs" />
<Compile Include="Providers\IMediaProvider.cs" />
Expand Down
56 changes: 56 additions & 0 deletions NzbDrone.Core/Providers/Fakes/FakeNotificationProvider.cs
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using NzbDrone.Core.Entities.Notification;

namespace NzbDrone.Core.Providers.Fakes
{
class FakeNotificationProvider : INotificationProvider
{
private readonly Dictionary<Guid, BasicNotification> _basicNotifications = new Dictionary<Guid, BasicNotification>();
private readonly Dictionary<Guid, ProgressNotification> _progressNotification = new Dictionary<Guid, ProgressNotification>();
private readonly Object _lock = new object();


ProgressNotification fakeNotification = new ProgressNotification("Updating Series");
public void Register(ProgressNotification notification)
{
_progressNotification.Add(notification.Id, notification);
}

public void Register(BasicNotification notification)
{
_basicNotifications.Add(notification.Id, notification);
}

public List<BasicNotification> BasicNotifications
{
get { return new List<BasicNotification>(_basicNotifications.Values); }
}

public List<ProgressNotification> ProgressNotifications
{

get
{
fakeNotification.Status = NotificationStatus.InProgress;
fakeNotification.CurrentStatus = DateTime.Now.ToString();
return new List<ProgressNotification> { fakeNotification };
}
}

public void Dismiss(Guid notificationId)
{
lock (_lock)
{
if (_basicNotifications.ContainsKey(notificationId))
{
_basicNotifications.Remove(notificationId);
}
else if (_progressNotification.ContainsKey(notificationId))
{
_progressNotification.Remove(notificationId);
}
}
}
}
}
13 changes: 13 additions & 0 deletions NzbDrone.Web/Content/ui.notify.css
@@ -0,0 +1,13 @@
.ui-notify { width:350px; position:fixed; top:10px; right:10px; }
.ui-notify-message { padding:10px; margin-bottom:15px; -moz-border-radius:8px; -webkit-border-radius:8px; border-radius:8px }
.ui-notify-message h1 { font-size:14px; margin:0; padding:0 }
.ui-notify-message p { margin:3px 0; padding:0; line-height:18px }
.ui-notify-message:last-child { margin-bottom:0 }
.ui-notify-message-style { background:#000; background:rgba(0,0,0,0.8); -moz-box-shadow: 0 0 6px #000; -webkit-box-shadow: 0 0 6px #000; box-shadow: 0 0 6px #000; }
.ui-notify-message-style h1 { color:#fff; font-weight:bold }
.ui-notify-message-style p { color:#fff }
.ui-notify-close { color:#fff; text-decoration:underline }
.ui-notify-click { cursor:pointer }
.ui-notify-cross { margin-top:-4px; float:right; cursor:pointer; text-decoration:none; font-size:12px; font-weight:bold; text-shadow:0 1px 1px #fff; padding:2px }
.ui-notify-cross:hover { color:#ffffab }
.ui-notify-cross:active { position:relative; top:1px }
6 changes: 2 additions & 4 deletions NzbDrone.Web/Global.asax.cs
Expand Up @@ -9,7 +9,6 @@ namespace NzbDrone.Web
{
public class MvcApplication : NinjectHttpApplication
{
private StandardKernel _kernel;

public static void RegisterRoutes(RouteCollection routes)
{
Expand All @@ -35,9 +34,8 @@ protected override void OnApplicationStarted()

protected override IKernel CreateKernel()
{
_kernel = new StandardKernel();
CentralDispatch.BindKernel(_kernel);
return _kernel;
return CentralDispatch.NinjectKernel;

}


Expand Down
3 changes: 3 additions & 0 deletions NzbDrone.Web/NzbDrone.Web.csproj
Expand Up @@ -161,6 +161,7 @@
<Content Include="Content\Telerik\sprite.png" />
<Content Include="Content\Telerik\treeview-line.png" />
<Content Include="Content\Telerik\treeview-nodes.png" />
<Content Include="Content\ui.notify.css" />
<Content Include="Content\Vista\editor.png" />
<Content Include="Content\Vista\loading.gif" />
<Content Include="Content\Vista\sprite.png" />
Expand Down Expand Up @@ -201,6 +202,8 @@
<Content Include="Scripts\2010.2.825\telerik.textbox.min.js" />
<Content Include="Scripts\2010.2.825\telerik.treeview.min.js" />
<Content Include="Scripts\2010.2.825\telerik.window.min.js" />
<Content Include="Scripts\jquery.msg.js" />
<Content Include="Scripts\Notifications.js" />
<Content Include="Views\Series\Details.aspx" />
<Content Include="Views\Series\index.aspx" />
<Content Include="Views\Series\Unmapped.aspx" />
Expand Down
12 changes: 12 additions & 0 deletions NzbDrone.Web/Scripts/Notifications.js
@@ -0,0 +1,12 @@
/// <reference path="jquery-1.4.1-vsdoc.js" />
$(function () {
alert("Notification");

var container = $("#container-bottom").notify({ stack: 'above' });
container.notify("create", {
title: 'Look ma, two containers!',
text: 'This container is positioned on the bottom of the screen. Notifications will stack on top of each other with the <code>position</code> attribute set to <code>above</code>.'
}, { expires: false });


});
97 changes: 97 additions & 0 deletions NzbDrone.Web/Scripts/jquery.msg.js
@@ -0,0 +1,97 @@
/*
Copyright (c) 2010 Diego Uría Martínez
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
* Add a message to the body.
*
* Example:
* $('a').click(function() {
* $.fn.jQueryMsg({
* msg: 'Hello world!!'
* });
* });
*
* TODO:
* - don't set 'speed' too high, it may loose some events
* - option: message tag
* - option: content tag
*/
(function($,undefined){
var name = 'jQueryMsg';
var timeout;

$.fn.jQueryMsg = function(params)
{
var settings = $.extend(
{},
{
msgClass : 'jquerymsgclass', //container class
speed : 0, //effects' speed
delay: 100, //delay between messages
timeout: 3000, //maximum time the message is shown on the screen. 0 for permanent
fx: 'none' //effect: set it to none, fade or slide
},
params);

if(typeof(settings.msg) === 'string')
{
var show = {width: 'show', height: 'show'};
var hide = {width: 'hide', height: 'hide'};
switch(settings.fx) {
case 'fade':
show = {opacity: 'show'};
hide = {opacity: 'hide'};
break;
case 'slide':
show = {height: 'show'};
hide = {height: 'hide'};
break;
}

var msg;
if($('p.'+name).size() > 0) {
msg = $('p.'+name);
msg.click().delay(settings.delay);
}
else {
msg = $('<p class="'+name+'"></p>');
msg.hide().appendTo('body');
}

clearTimeout(timeout);

msg.one('click',function() {
msg.animate(hide, settings.speed, function() {
msg.removeClass().addClass(name);
});
}).queue(function() {
msg.html(settings.msg).addClass(settings.msgClass).animate(show, settings.speed).dequeue();

if(settings.timeout > 0) {
timeout = setTimeout(function() {
msg.click();
}, settings.timeout);
}
});
}
}
})(jQuery);
62 changes: 30 additions & 32 deletions NzbDrone.Web/Views/Shared/Site.Master
@@ -1,10 +1,4 @@
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

<%@ Import Namespace="Helpers" %>
<%@ Import Namespace="Telerik.Web.Mvc.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!--
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License
Expand All @@ -13,42 +7,28 @@ Name : Concurrence
Description: A two-column, fixed-width design for 1024x768 screen resolutions.
Version : 1.0
Released : 20100727

-->

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>

<%@ Import Namespace="Helpers" %>
<%@ Import Namespace="Telerik.Web.Mvc.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>NZBDrone </title>
<title>NZBDrone</title>
<%
Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.sitefinity.css")).Render();
%>
<link href="../../Content/ui.notify.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery.msg.js" type="text/javascript"></script>
<link href="../../Content/style.css" rel="stylesheet" type="text/css" media="screen" />
<style>
.Mediabox
{
background:black;
}
.Play
{
cursor:pointer;
padding:5px;

}
.Pause
{
cursor:pointer;
padding:5px;
}
.Stop
{
cursor:pointer;
padding:5px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="../../Scripts/Notifications.js" type="text/javascript"></script>
<script type="text/javascript">
<asp:ContentPlaceHolder ID="JavascriptContent" runat="server" />
</script>

</head>
<body>
<div id="header">
Expand Down Expand Up @@ -78,6 +58,24 @@ Released : 20100727
</div>
</div>
</div>
<div id="container-bottom" style="display: none; top: auto; right: 0; padding: 10px;
bottom: 0; margin: 0 0 10px 10px">
<div>
<h1>
#{title}</h1>
<p>
#{text}</p>
<p style="margin-top: 10px; text-align: center">
<input type="button" class="confirm" value="Create Another Notification!" />
</p>
</div>
<div>
<h1>
#{title}</h1>
<p>
#{text}</p>
</div>
</div>
<div id="footer">
<p class="style1">
Design by Free CSS Templates.</p>
Expand Down

0 comments on commit 30d38ee

Please sign in to comment.