Permalink
Browse files

Decouple Kudu.SignalR from Ninject.

  • Loading branch information...
1 parent a3d4125 commit 46569701f8e740b68f83c06b2af7da8b9bcebff8 @davidfowl davidfowl committed Nov 9, 2011
View
@@ -28,7 +28,8 @@
<Target Name="Build" DependsOnTargets="CreateOutputPath">
<MSBuild Projects="$(ProjectRoot)\kudu.sln"
Targets="Build"
- Properties="PackageOutputDir=$(ArtifactsPath);
+ Properties="BuildPackage=true;
+ PackageOutputDir=$(ArtifactsPath);
Configuration=$(Configuration);
MSBuildExtensionsPath32=$(ProjectRoot)\Kudu.Services.Web\msbuild" />
</Target>
@@ -14,7 +14,6 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
- <BuildPackage>true</BuildPackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -14,7 +14,6 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\kudu\</SolutionDir>
<RestorePackages>true</RestorePackages>
- <BuildPackage>true</BuildPackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -13,7 +13,6 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
- <BuildPackage>true</BuildPackage>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -0,0 +1,37 @@
+using Kudu.Core.Deployment;
+using Kudu.Core.SourceControl;
+using Kudu.SignalR.Infrastructure;
+using Kudu.SignalR.Models;
+using SignalR.Infrastructure;
+
+namespace Kudu.SignalR
+{
+ public static class KuduDefaultBindings
+ {
+ public static void Initialize()
+ {
+ DependencyResolver.Register(typeof(ISiteConfiguration), GetSiteConfiguration);
+ DependencyResolver.Register(typeof(IRepository), GetRepository);
+ DependencyResolver.Register(typeof(IDeploymentManager), GetDeploymentManager);
+ }
+
+ private static ISiteConfiguration GetSiteConfiguration()
+ {
+ var application = DependencyResolver.Resolve<IApplication>();
+ return new SiteConfiguration(application);
+ }
+
+ private static IRepository GetRepository()
+ {
+ var siteConfiguration = DependencyResolver.Resolve<ISiteConfiguration>();
+ return siteConfiguration.Repository;
+ }
+
+ private static IDeploymentManager GetDeploymentManager()
+ {
+ var siteConfiguration = DependencyResolver.Resolve<ISiteConfiguration>();
+ return siteConfiguration.DeploymentManager;
+ }
+
+ }
+}
@@ -1,25 +0,0 @@
-using System.Web;
-using System.Web.Script.Serialization;
-
-namespace Kudu.SignalR.Infrastructure
-{
- public static class ApplicationNameResolver
- {
- public static string ResolveName(HttpContextBase httpContext)
- {
- var serializer = new JavaScriptSerializer();
- var request = serializer.Deserialize<HubRequest>(httpContext.Request["data"]);
- return request.State.ApplicationName;
- }
-
- private class HubRequest
- {
- public ClientState State { get; set; }
- }
-
- private class ClientState
- {
- public string ApplicationName { get; set; }
- }
- }
-}
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+using System.Web;
+using System.Web.Script.Serialization;
+
+namespace Kudu.SignalR.Infrastructure
+{
+ public static class ClientStateResolver
+ {
+ public static IDictionary<string, object> GetState(HttpContextBase httpContext)
+ {
+ var serializer = new JavaScriptSerializer();
+ var request = serializer.Deserialize<HubRequest>(httpContext.Request["data"]);
+ return request.State;
+ }
+
+ private class HubRequest
+ {
+ public IDictionary<string, object> State { get; set; }
+ }
+ }
+}
@@ -14,7 +14,6 @@
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\kudu\</SolutionDir>
<RestorePackages>true</RestorePackages>
- <BuildPackage>true</BuildPackage>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -38,9 +37,6 @@
<Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
- <Reference Include="Ninject">
- <HintPath>..\packages\Ninject.2.2.1.4\lib\net40-Full\Ninject.dll</HintPath>
- </Reference>
<Reference Include="SignalR, Version=0.3.5.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\SignalR.Server.0.3.5\lib\net40\SignalR.dll</HintPath>
@@ -61,7 +57,7 @@
</Compile>
<Compile Include="Hubs\Deployment.cs" />
<Compile Include="Hubs\DevelopmentEnvironment.cs" />
- <Compile Include="Infrastructure\ApplicationNameResolver.cs" />
+ <Compile Include="Infrastructure\ClientStateResolver.cs" />
<Compile Include="Infrastructure\ISiteConfiguration.cs" />
<Compile Include="Infrastructure\IUserInformation.cs" />
<Compile Include="Infrastructure\SiteConfiguration.cs" />
@@ -74,7 +70,7 @@
<Compile Include="ViewModels\LogEntryViewModel.cs" />
<Compile Include="ViewModels\ProjectFile.cs" />
<Compile Include="ViewModels\ProjectViewModel.cs" />
- <Compile Include="Ninject\DefaultBindings.cs" />
+ <Compile Include="DI\KuduDefaultBindings.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -1,32 +0,0 @@
-using Kudu.Core.Deployment;
-using Kudu.Core.SourceControl;
-using Kudu.SignalR.Infrastructure;
-using Ninject;
-using Ninject.Activation;
-using Ninject.Modules;
-
-namespace Kudu.SignalR
-{
- public class DefaultBindings : NinjectModule
- {
- public override void Load()
- {
- Bind<ISiteConfiguration>().To<SiteConfiguration>();
- Bind<IRepository>().ToMethod(context => GetRepository(context));
- Bind<IDeploymentManager>().ToMethod(context => GetDeploymentManager(context));
- }
-
- private static IRepository GetRepository(IContext context)
- {
- var siteConfiguration = context.Kernel.Get<ISiteConfiguration>();
- return siteConfiguration.Repository;
- }
-
- private static IDeploymentManager GetDeploymentManager(IContext context)
- {
- var siteConfiguration = context.Kernel.Get<ISiteConfiguration>();
- return siteConfiguration.DeploymentManager;
- }
-
- }
-}
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
- <package id="Ninject" version="2.2.1.4" />
<package id="SignalR.Server" version="0.3.5" />
</packages>
@@ -21,6 +21,9 @@ public static void Start()
{
IKernel kernel = CreateKernel();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
+
+ // Initialize kudu's bindings
+ KuduDefaultBindings.Initialize();
}
/// <summary>
@@ -29,7 +32,7 @@ public static void Start()
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
- var kernel = new StandardKernel(new DefaultBindings());
+ var kernel = new StandardKernel();
RegisterServices(kernel);
return kernel;
}
@@ -51,7 +54,9 @@ private static void RegisterServices(IKernel kernel)
private static IApplication GetApplication(IContext context)
{
var httpContext = context.Kernel.Get<HttpContextBase>();
- string applicationName = ApplicationNameResolver.ResolveName(httpContext);
+ var state = ClientStateResolver.GetState(httpContext);
+ var applicationName = (string)state["applicationName"];
+
using (var db = new KuduContext())
{
return db.Applications.Find(applicationName);
@@ -239,7 +239,6 @@ public ActionResult CreateDeveloperSite(string slug)
}
catch
{
- FileSystemHelpers.DeleteDirectorySafe(destRepositoryPath);
application.DeveloperSiteUrl = null;
application.DeveloperSiteState = (int)DeveloperSiteState.None;
db.SaveChanges();
@@ -3,6 +3,7 @@
using Kudu.Core.Infrastructure;
using Kudu.Web.Models;
using IIS = Microsoft.Web.Administration;
+using System.Threading;
namespace Kudu.Web.Infrastructure
{
@@ -26,6 +27,9 @@ public Site CreateSite(string applicationName)
string webRoot = Path.Combine(siteRoot, "wwwroot");
int sitePort = CreateSite(iis, siteName, webRoot);
+ // Commit the changes to iis
+ iis.CommitChanges();
+
// Map a path called app to the site root under the service site
MapServiceSitePath(iis, applicationName, "_app", siteRoot);
@@ -55,15 +59,16 @@ public bool TryCreateDeveloperSite(string applicationName, out string siteUrl)
// Get the path to the dev site
string siteRoot = PathHelper.GetDeveloperApplicationPath(applicationName);
string webRoot = Path.Combine(siteRoot, "wwwroot");
- int sitePort = CreateSite(iis, devSiteName, siteRoot);
-
- // Map a path called app to the site root under the service site
- MapServiceSitePath(iis, applicationName, "_devapp", siteRoot);
+ int sitePort = CreateSite(iis, devSiteName, webRoot);
// Ensure the directory is created
- FileSystemHelpers.EnsureDirectory(siteRoot);
+ FileSystemHelpers.EnsureDirectory(webRoot);
iis.CommitChanges();
+
+ // Map a path called app to the site root under the service site
+ MapServiceSitePath(iis, applicationName, "_devapp", siteRoot, restartSite: true);
+
siteUrl = String.Format("http://localhost:{0}/", sitePort);
return true;
}
@@ -100,7 +105,7 @@ public void SetDeveloperSiteWebRoot(string applicationName, string projectPath)
}
}
- private static void MapServiceSitePath(IIS.ServerManager iis, string applicationName, string path, string siteRoot)
+ private static void MapServiceSitePath(IIS.ServerManager iis, string applicationName, string path, string siteRoot, bool restartSite = false)
{
string serviceSiteName = GetServiceSite(applicationName);
@@ -111,10 +116,30 @@ private static void MapServiceSitePath(IIS.ServerManager iis, string application
throw new InvalidOperationException("Could not retrieve service site");
}
+
// Map the path to the live site in the service site
site.Applications.Add("/" + path, siteRoot);
iis.CommitChanges();
+
+ if (restartSite)
+ {
+ site.Stop();
+ Thread.Sleep(500);
+ site.Start();
+ }
+ }
+
+ private static IIS.ObjectState GetState(IIS.Site site)
+ {
+ try
+ {
+ return site.State;
+ }
+ catch
+ {
+ return IIS.ObjectState.Unknown;
+ }
}
private static IIS.ApplicationPool EnsureKuduAppPool(IIS.ServerManager iis)
@@ -156,7 +181,7 @@ private void DeleteSite(IIS.ServerManager iis, string siteName, bool deletePhysi
var site = iis.Sites[siteName];
if (site != null)
{
- site.Stop();
+ site.Stop();
if (deletePhysicalFiles)
{
string physicalPath = site.Applications[0].VirtualDirectories[0].PhysicalPath;

0 comments on commit 4656970

Please sign in to comment.