Skip to content

Commit

Permalink
Add initial implementation of hosted web core bits
Browse files Browse the repository at this point in the history
  • Loading branch information
bheinz-tier3 committed Jun 6, 2013
1 parent c71fcdf commit abf3fbe
Show file tree
Hide file tree
Showing 12 changed files with 1,010 additions and 0 deletions.
163 changes: 163 additions & 0 deletions IronFoundry.sln

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/IronFoundry.Warden.IisHost/App.config
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
<section name="warden-server" type="IronFoundry.Warden.Configuration.WardenSection, IronFoundry.Warden" />
</configSections>

<warden-server container-basepath="C:\IronFoundry\warden\containers" />

<!-- <nlog throwExceptions="true" internalLogToConsole="true" internalLogLevel="Debug" -->
<nlog throwExceptions="true" async="false" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="console" xsi:type="Console" layout="${longdate}|${level:uppercase=true}|${threadid}|${logger:shortName=true}|${message}${onexception:|${exception:format=message,stacktrace:maxInnerExceptionLevel=10:innerFormat=message,stacktrace}}" />
<target name="file" xsi:type="File" layout="${longdate}|${level:uppercase=true}|${threadid}|${logger:shortName=true}|${message}${onexception:|${exception:format=message,stacktrace:maxInnerExceptionLevel=10:innerFormat=message,stacktrace}}" fileName="log\log.txt" archiveFileName="log\log-{#}.txt" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="7" concurrentWrites="true" keepFileOpen="false" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minlevel="Trace" writeTo="console" />
</rules>
</nlog>

<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NLog" publicKeyToken="5120e14c03d0593c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.1.0" newVersion="2.0.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
116 changes: 116 additions & 0 deletions src/IronFoundry.Warden.IisHost/IronFoundry.Warden.IisHost.csproj
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AC8AB431-5816-424B-BD9E-07B5864AC75C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>IronFoundry.Warden.IisHost</RootNamespace>
<AssemblyName>IronFoundry.Warden.IisHost</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\shared\CommonAssemblyInfo.cs">
<Link>CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="..\shared\ExtensionMethods.cs">
<Link>ExtensionMethods.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="WebServer.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="Resources\AppHostAspNet.config" />
<None Include="Resources\AppHostStaticFiles.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="CommandLine">
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
</Reference>
<Reference Include="NLog">
<HintPath>..\..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="Readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
117 changes: 117 additions & 0 deletions src/IronFoundry.Warden.IisHost/Program.cs
@@ -0,0 +1,117 @@
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

namespace IronFoundry.Warden.IisHost
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using CommandLine;
using CommandLine.Text;
using NLog;

internal static class Program
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();

private static void Main(string[] args)
{
var exitLatch = new ManualResetEvent(false);
Console.CancelKeyPress += (s, e) =>
{
e.Cancel = true;
exitLatch.Set();
};

try
{
var options = new Options();
if (Parser.Default.ParseArguments(args, options))
{
log.Info("Port:", options.Port);
log.Info("Webroot:", options.WebRoot);
log.Info("Runtime:", options.RuntimeVersion);
}
else
{
log.Info(options.Usage());
Environment.Exit(1);
}

var runtimePath = @"%windir%\Microsoft.Net\Framework\v4.0.30319\";
switch (options.RuntimeVersion)
{
case "2":
case "2.0":
runtimePath = @"%windir%\Microsoft.Net\Framework\v2.0.50727\";
break;
}

log.Info("starting web server instance...");
using (var webServer = new WebServer(options.WebRoot, options.Port, options.WebsiteId, runtimePath))
{
webServer.Start();
Console.WriteLine("Server Started.... press CTRL + C to stop");

StartInBrowser(options);

exitLatch.WaitOne();
Console.WriteLine("Server shutting down, please wait...");
webServer.Stop();
}
}
catch (Exception ex)
{
log.ErrorException("Error on startup.", ex);
if (Environment.UserInteractive)
{
Console.ReadLine();
}
Environment.Exit(2);
}
}

private static void StartInBrowser(Options options)
{
try
{
if (Environment.UserInteractive && options.StartInBrowser)
{
Process.Start(String.Format("http://localhost:{0}", options.Port));
}
}
catch (Exception ex)
{
log.DebugException("Unable to start in browser", ex);
}
}
}

internal class Options
{
[Option('p', "port", Required = true, HelpText = "The port for the IIS website.")]
public uint Port { get; set; }

[Option('r', "webroot", Required = true, HelpText = "The local webroot path for website.")]
public string WebRoot { get; set; }

[Option('v', "runtimeVersion", Required = false, DefaultValue = "4.0", HelpText = "AppPool runtime version: 2.0 or 4.0")]
public string RuntimeVersion { get; set; }

[Option('i', "websiteId", Required = false, DefaultValue = (uint)1, HelpText = "The ID for the IIS website.")]
public uint WebsiteId { get; set; }

[Option('b', "startInBrowser", Required = false, DefaultValue = true, HelpText = "Specify true to start a browser pointing to the site.")]
public bool StartInBrowser { get; set; }

[HelpOption]
public string Usage()
{
return HelpText.AutoBuild(this, c => HelpText.DefaultParsingErrorsHandler(this, c));
}
}
}
2 changes: 2 additions & 0 deletions src/IronFoundry.Warden.IisHost/Properties/AssemblyInfo.cs
@@ -0,0 +1,2 @@
using System.Reflection;
[assembly: AssemblyTitle("IronFoundry.Warden.IISHost")]
99 changes: 99 additions & 0 deletions src/IronFoundry.Warden.IisHost/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit abf3fbe

Please sign in to comment.