mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-19 21:46:43 -04:00
imported signalr 1.1.3 into NzbDrone.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Microsoft.AspNet.SignalR.Infrastructure;
|
||||
|
||||
namespace Microsoft.AspNet.SignalR.Hosting
|
||||
{
|
||||
public static class HostDependencyResolverExtensions
|
||||
{
|
||||
public static void InitializeHost(this IDependencyResolver resolver, string instanceName, CancellationToken hostShutdownToken)
|
||||
{
|
||||
if (resolver == null)
|
||||
{
|
||||
throw new ArgumentNullException("resolver");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(instanceName))
|
||||
{
|
||||
throw new ArgumentNullException("instanceName");
|
||||
}
|
||||
|
||||
// Initialize the performance counters
|
||||
resolver.InitializePerformanceCounters(instanceName, hostShutdownToken);
|
||||
|
||||
// Dispose the dependency resolver on host shut down (cleanly)
|
||||
resolver.InitializeResolverDispose(hostShutdownToken);
|
||||
}
|
||||
|
||||
private static void InitializePerformanceCounters(this IDependencyResolver resolver, string instanceName, CancellationToken hostShutdownToken)
|
||||
{
|
||||
var counters = resolver.Resolve<IPerformanceCounterManager>();
|
||||
if (counters != null)
|
||||
{
|
||||
counters.Initialize(instanceName, hostShutdownToken);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InitializeResolverDispose(this IDependencyResolver resolver, CancellationToken hostShutdownToken)
|
||||
{
|
||||
// TODO: Guard against multiple calls to this
|
||||
|
||||
// When the host triggers the shutdown token, dispose the resolver
|
||||
hostShutdownToken.Register(state =>
|
||||
{
|
||||
((IDependencyResolver)state).Dispose();
|
||||
},
|
||||
resolver,
|
||||
useSynchronizationContext: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user