Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 149 lines (122 sloc) 5.752 kB
74ac3bb @kayone Initial Commit
kayone authored
1 using System;
273de41 @kayone Cleaned up logging code
kayone authored
2 using System.Diagnostics;
acf23d4 @kayone Removed subsonic completely
kayone authored
3 using System.Linq;
74ac3bb @kayone Initial Commit
kayone authored
4 using Ninject;
e896af5 @kayone ReSharper code cleanup
kayone authored
5 using NLog;
180da4c @kayone Migrator.net fails
kayone authored
6 using NzbDrone.Core.Datastore;
fa0af25 @kayone fixed a bunch of things. added basic support for file scanning. logs …
kayone authored
7 using NzbDrone.Core.Instrumentation;
01c1943 @kayone Renamed all Core.Controllers to Core.Providers to avoid confusion bet…
kayone authored
8 using NzbDrone.Core.Providers;
ec6a0e6 @markus101 App_Data added to .gitignore
markus101 authored
9 using NzbDrone.Core.Providers.Core;
a36d5fa @markus101 Added ExternalNotificationProviderBase based on IndexProviderBase.
markus101 authored
10 using NzbDrone.Core.Providers.ExternalNotification;
6f2dcbf @kayone Revered back to subsonic
kayone authored
11 using NzbDrone.Core.Providers.Indexer;
9028e49 @kayone Added completely awesome JobProvider. extremely easy to do async/time…
kayone authored
12 using NzbDrone.Core.Providers.Jobs;
63f6899 @kayone Added PetaPoco
kayone authored
13 using PetaPoco;
74ac3bb @kayone Initial Commit
kayone authored
14
15 namespace NzbDrone.Core
16 {
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
17 public class CentralDispatch
74ac3bb @kayone Initial Commit
kayone authored
18 {
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
19 private readonly Object KernelLock = new object();
30d38ee @kayone fixed ninjet's race condition
kayone authored
20 private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
9c7355f @kayone Cleaned up some tests
kayone authored
21
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
22 public CentralDispatch()
e896af5 @kayone ReSharper code cleanup
kayone authored
23 {
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
24 InitializeApp();
e896af5 @kayone ReSharper code cleanup
kayone authored
25 }
26
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
27 public StandardKernel Kernel { get; private set; }
28
29 private void InitializeApp()
180da4c @kayone Migrator.net fails
kayone authored
30 {
31 BindKernel();
a6ad977 @kayone Fixed import new series being stuck in a loop if an update failed
kayone authored
32
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
33 Kernel.Get<LogConfiguration>().Setup();
1ba9592 @kayone Added BuildDateTime to central dispatch
kayone authored
34
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
35 var mainConnectionString = Kernel.Get<Connection>().MainConnectionString;
a6ad977 @kayone Fixed import new series being stuck in a loop if an update failed
kayone authored
36
633f0b6 @kayone PathProvider. visit us for all of your pathing needs.
kayone authored
37 MigrationsHelper.Run(mainConnectionString, true);
1ba9592 @kayone Added BuildDateTime to central dispatch
kayone authored
38
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
39 LogConfiguration.RegisterDatabaseLogger(Kernel.Get<DatabaseTarget>());
a6ad977 @kayone Fixed import new series being stuck in a loop if an update failed
kayone authored
40
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
41 Kernel.Get<QualityProvider>().SetupDefaultProfiles();
42 Kernel.Get<QualityTypeProvider>().SetupDefault();
43 Kernel.Get<ConfigFileProvider>().CreateDefaultConfigFile();
180da4c @kayone Migrator.net fails
kayone authored
44
ee4b6c9 @markus101 ExternalNotifications enabled (Xbmc only right now).
markus101 authored
45 BindExternalNotifications();
180da4c @kayone Migrator.net fails
kayone authored
46 BindIndexers();
47 BindJobs();
48 }
49
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
50 private void BindKernel()
74ac3bb @kayone Initial Commit
kayone authored
51 {
7efbfdb @kayone removed IEpisodeProvider, ILogProvider
kayone authored
52 lock (KernelLock)
30d38ee @kayone fixed ninjet's race condition
kayone authored
53 {
54 Logger.Debug("Binding Ninject's Kernel");
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
55 Kernel = new StandardKernel();
30d38ee @kayone fixed ninjet's race condition
kayone authored
56
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
57 var connection = Kernel.Get<Connection>();
30d38ee @kayone fixed ninjet's race condition
kayone authored
58
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
59 Kernel.Bind<IDatabase>().ToMethod(c => connection.GetMainPetaPocoDb()).InTransientScope();
60 Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb(false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
61 Kernel.Bind<IDatabase>().ToMethod(c => connection.GetLogPetaPocoDb()).WhenInjectedInto<LogProvider>().InSingletonScope();
6828f09 @kayone Removed all static state tracking from job provider.
kayone authored
62
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
63 Kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
30d38ee @kayone fixed ninjet's race condition
kayone authored
64 }
74ac3bb @kayone Initial Commit
kayone authored
65 }
66
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
67 private void BindIndexers()
6f2dcbf @kayone Revered back to subsonic
kayone authored
68 {
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
69 Kernel.Bind<IndexerBase>().To<NzbsOrg>();
70 Kernel.Bind<IndexerBase>().To<NzbMatrix>();
71 Kernel.Bind<IndexerBase>().To<NzbsRUs>();
72 Kernel.Bind<IndexerBase>().To<Newzbin>();
cbbb6e2 @kayone Oh hai search!
kayone authored
73
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
74 var indexers = Kernel.GetAll<IndexerBase>();
75 Kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
6f2dcbf @kayone Revered back to subsonic
kayone authored
76 }
77
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
78 private void BindJobs()
6caae19 @kayone Timers are now initialized on startup.
kayone authored
79 {
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
80 Kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
81 Kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
82 Kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
83 Kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
84 Kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
85 Kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
86 Kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
87 Kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
88 Kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
89 Kernel.Bind<IJob>().To<SeasonSearchJob>().InSingletonScope();
90 Kernel.Bind<IJob>().To<RenameSeasonJob>().InSingletonScope();
91 Kernel.Bind<IJob>().To<SeriesSearchJob>().InSingletonScope();
92 Kernel.Bind<IJob>().To<RenameSeriesJob>().InSingletonScope();
93 Kernel.Bind<IJob>().To<BacklogSearchJob>().InSingletonScope();
94 Kernel.Bind<IJob>().To<BannerDownloadJob>().InSingletonScope();
95 Kernel.Bind<IJob>().To<ConvertEpisodeJob>().InSingletonScope();
96
97 Kernel.Get<JobProvider>().Initialize();
98 Kernel.Get<WebTimer>().StartTimer(30);
6caae19 @kayone Timers are now initialized on startup.
kayone authored
99 }
100
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
101 private void BindExternalNotifications()
a36d5fa @markus101 Added ExternalNotificationProviderBase based on IndexProviderBase.
markus101 authored
102 {
bbd5cba @markus101 Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
markus101 authored
103 Kernel.Bind<ExternalNotificationBase>().To<Xbmc>();
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
104 Kernel.Bind<ExternalNotificationBase>().To<Smtp>();
105 Kernel.Bind<ExternalNotificationBase>().To<Twitter>();
106 Kernel.Bind<ExternalNotificationBase>().To<Providers.ExternalNotification.Growl>();
bbd5cba @markus101 Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
markus101 authored
107 Kernel.Bind<ExternalNotificationBase>().To<Prowl>();
ee4b6c9 @markus101 ExternalNotifications enabled (Xbmc only right now).
markus101 authored
108
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
109 var notifiers = Kernel.GetAll<ExternalNotificationBase>();
110 Kernel.Get<ExternalNotificationProvider>().InitializeNotifiers(notifiers.ToList());
a36d5fa @markus101 Added ExternalNotificationProviderBase based on IndexProviderBase.
markus101 authored
111 }
e9c63b8 @kayone Added asp.net tick timer
kayone authored
112
273de41 @kayone Cleaned up logging code
kayone authored
113 /// <summary>
5989928 @kayone Added TimerProvider
kayone authored
114 /// Forces IISExpress process to exit with the host application
273de41 @kayone Cleaned up logging code
kayone authored
115 /// </summary>
ca7deed @kayone CentralDispatch is no longer static.
kayone authored
116 public void DedicateToHost()
273de41 @kayone Cleaned up logging code
kayone authored
117 {
118 try
119 {
8686eb5 @kayone IISExpress is now attached to NZBDrone.exe earlier, which means it sh…
kayone authored
120 var pid = Convert.ToInt32(Environment.GetEnvironmentVariable("NZBDRONE_PID"));
121
122 Logger.Debug("Attaching to parent process ({0}) for automatic termination.", pid);
123
124 var hostProcess = Process.GetProcessById(Convert.ToInt32(pid));
273de41 @kayone Cleaned up logging code
kayone authored
125
126 hostProcess.EnableRaisingEvents = true;
127 hostProcess.Exited += (delegate
e896af5 @kayone ReSharper code cleanup
kayone authored
128 {
129 Logger.Info("Host has been terminated. Shutting down web server.");
130 ShutDown();
131 });
273de41 @kayone Cleaned up logging code
kayone authored
132
8686eb5 @kayone IISExpress is now attached to NZBDrone.exe earlier, which means it sh…
kayone authored
133 Logger.Debug("Successfully Attached to host. Process [{0}]", hostProcess.ProcessName);
273de41 @kayone Cleaned up logging code
kayone authored
134 }
135 catch (Exception e)
136 {
137 Logger.Fatal(e);
138 }
139 }
140
141 private static void ShutDown()
142 {
143 Logger.Info("Shutting down application.");
0745852 @kayone JobProvider can reset itself.
kayone authored
144 WebTimer.Stop();
273de41 @kayone Cleaned up logging code
kayone authored
145 Process.GetCurrentProcess().Kill();
146 }
74ac3bb @kayone Initial Commit
kayone authored
147 }
bbd5cba @markus101 Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
markus101 authored
148 }
Something went wrong with that request. Please try again.