Permalink
Browse files

Initial version

  • Loading branch information...
0 parents commit 0506fefc43906a1205dd6e670a08a279abda0b1b @danhigham committed Jan 17, 2012
Showing with 23,628 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +97 −0 Nancy.Hosting.Self/Nancy.Hosting.Self.csproj
  3. BIN Nancy.Hosting.Self/Nancy.Hosting.Self.pidb
  4. +198 −0 Nancy.Hosting.Self/NancyHost.cs
  5. +26 −0 Nancy.Hosting.Self/nancy.hosting.self.nuspec
  6. +16 −0 Nancy.Hosting.Wcf/FileSystemRootPathProvider.cs
  7. +111 −0 Nancy.Hosting.Wcf/Nancy.Hosting.Wcf.csproj
  8. BIN Nancy.Hosting.Wcf/Nancy.Hosting.Wcf.pidb
  9. +124 −0 Nancy.Hosting.Wcf/NancyWcfGenericService.cs
  10. +25 −0 Nancy.Hosting.Wcf/nancy.hosting.wcf.nuspec
  11. +62 −0 Nancy/AfterPipeline.cs
  12. +81 −0 Nancy/BeforePipeline.cs
  13. +155 −0 Nancy/Bootstrapper/AppDomainAssemblyTypeScanner.cs
  14. +36 −0 Nancy/Bootstrapper/CollectionTypeRegistration.cs
  15. +20 −0 Nancy/Bootstrapper/DefaultModuleKeyGenerator.cs
  16. +17 −0 Nancy/Bootstrapper/IModuleKeyGenerator.cs
  17. +19 −0 Nancy/Bootstrapper/INancyBootstrapper.cs
  18. +39 −0 Nancy/Bootstrapper/IPipelines.cs
  19. +31 −0 Nancy/Bootstrapper/IStartup.cs
  20. +41 −0 Nancy/Bootstrapper/InstanceRegistration.cs
  21. +22 −0 Nancy/Bootstrapper/ModuleRegistrationType.cs
  22. +516 −0 Nancy/Bootstrapper/NancyBootstrapperBase.cs
  23. +40 −0 Nancy/Bootstrapper/NancyBootstrapperLocator.cs
  24. +151 −0 Nancy/Bootstrapper/NancyBootstrapperWithRequestContainerBase.cs
  25. +189 −0 Nancy/Bootstrapper/NancyInternalConfiguration.cs
  26. +85 −0 Nancy/Bootstrapper/Pipelines.cs
  27. +46 −0 Nancy/Bootstrapper/TypeRegistration.cs
  28. +40 −0 Nancy/Conventions/DefaultStaticContentsConventions.cs
  29. +68 −0 Nancy/Conventions/DefaultViewLocationConventions.cs
  30. +23 −0 Nancy/Conventions/IConvention.cs
  31. +83 −0 Nancy/Conventions/NancyConventions.cs
  32. +89 −0 Nancy/Conventions/StaticContentConventionBuilder.cs
  33. +52 −0 Nancy/Conventions/ViewLocationConventions.cs
  34. +53 −0 Nancy/Cookies/INancyCookie.cs
  35. +118 −0 Nancy/Cookies/NancyCookie.cs
  36. +19 −0 Nancy/Cryptography/Base64Helpers.cs
  37. +53 −0 Nancy/Cryptography/CryptographyConfiguration.cs
  38. +65 −0 Nancy/Cryptography/DefaultHmacProvider.cs
  39. +44 −0 Nancy/Cryptography/HmacComparer.cs
  40. +22 −0 Nancy/Cryptography/IEncryptionProvider.cs
  41. +27 −0 Nancy/Cryptography/IHmacProvider.cs
  42. +15 −0 Nancy/Cryptography/IKeyGenerator.cs
  43. +32 −0 Nancy/Cryptography/NoEncryptionProvider.cs
  44. +36 −0 Nancy/Cryptography/PassphraseKeyGenerator.cs
  45. +21 −0 Nancy/Cryptography/RandomKeyGenerator.cs
  46. +71 −0 Nancy/Cryptography/RijndaelEncryptionProvider.cs
  47. +174 −0 Nancy/DefaultNancyBootstrapper.cs
  48. +17 −0 Nancy/DefaultNancyContextFactory.cs
  49. +55 −0 Nancy/DefaultObjectSerializer.cs
  50. +56 −0 Nancy/DefaultResponseFormatter.cs
  51. +36 −0 Nancy/DefaultResponseFormatterFactory.cs
  52. +168 −0 Nancy/DynamicDictionary.cs
  53. +509 −0 Nancy/DynamicDictionaryValue.cs
  54. +117 −0 Nancy/ErrorHandling/DefaultErrorHandler.cs
  55. +22 −0 Nancy/ErrorHandling/IErrorHandler.cs
  56. +93 −0 Nancy/ErrorHandling/Resources/404.html
  57. +136 −0 Nancy/ErrorHandling/Resources/500.html
  58. +83 −0 Nancy/ErrorPipeline.cs
  59. +38 −0 Nancy/Extensions/AssemblyExtensions.cs
  60. +49 −0 Nancy/Extensions/CollectionExtensions.cs
  61. +76 −0 Nancy/Extensions/ContextExtensions.cs
  62. +40 −0 Nancy/Extensions/ModuleExtensions.cs
  63. +24 −0 Nancy/Extensions/RequestExtensions.cs
  64. +67 −0 Nancy/Extensions/StringExtensions.cs
  65. +15 −0 Nancy/Extensions/TypeExtensions.cs
  66. +73 −0 Nancy/FormatterExtensions.cs
  67. +22 −0 Nancy/HeadResponse.cs
  68. +915 −0 Nancy/Helpers/HttpEncoder.cs
  69. +759 −0 Nancy/Helpers/HttpUtility.cs
  70. +289 −0 Nancy/Helpers/ReflectionUtils.cs
  71. +43 −0 Nancy/HttpFile.cs
  72. +117 −0 Nancy/HttpMultipart.cs
  73. +105 −0 Nancy/HttpMultipartBoundary.cs
  74. +71 −0 Nancy/HttpMultipartBuffer.cs
  75. +221 −0 Nancy/HttpMultipartSubStream.cs
  76. +250 −0 Nancy/HttpStatusCode.cs
  77. +38 −0 Nancy/IHideObjectMembers.cs
  78. +14 −0 Nancy/INancyContextFactory.cs
  79. +32 −0 Nancy/INancyEngine.cs
  80. +25 −0 Nancy/INancyModuleCatalog.cs
  81. +406 −0 Nancy/IO/RequestStream.cs
  82. +320 −0 Nancy/IO/UnclosableStreamWrapper.cs
  83. +22 −0 Nancy/IObjectSerializer.cs
  84. +14 −0 Nancy/IObjectSerializerSelector.cs
  85. +28 −0 Nancy/IResponseFormatter.cs
  86. +15 −0 Nancy/IResponseFormatterFactory.cs
  87. +24 −0 Nancy/IRootPathProvider.cs
  88. +23 −0 Nancy/ISerializer.cs
  89. +67 −0 Nancy/Json/Converters/TimeSpanConverter.cs
  90. +43 −0 Nancy/Json/JavaScriptConverter.cs
  91. +471 −0 Nancy/Json/JavaScriptSerializer.cs
  92. +41 −0 Nancy/Json/JavaScriptTypeResolver.cs
  93. +126 −0 Nancy/Json/Json.cs
  94. +911 −0 Nancy/Json/JsonDeserializer.cs
  95. +552 −0 Nancy/Json/JsonSerializer.cs
  96. +33 −0 Nancy/Json/JsonSettings.cs
  97. +37 −0 Nancy/Json/ScriptIgnoreAttribute.cs
  98. +175 −0 Nancy/Json/StringBuilderExtensions.cs
  99. +75 −0 Nancy/Jsonp.cs
  100. +33 −0 Nancy/JsonpStartup.cs
  101. +599 −0 Nancy/MimeTypes.cs
  102. +42 −0 Nancy/ModelBinding/BindingContext.cs
  103. +61 −0 Nancy/ModelBinding/BindingDefaults.cs
  104. +198 −0 Nancy/ModelBinding/DefaultBinder.cs
  105. +74 −0 Nancy/ModelBinding/DefaultBodyDeserializers/JsonBodyDeserializer.cs
  106. +42 −0 Nancy/ModelBinding/DefaultBodyDeserializers/XmlBodyDeserializer.cs
  107. +154 −0 Nancy/ModelBinding/DefaultConverters/CollectionConverter.cs
  108. +49 −0 Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs
  109. +32 −0 Nancy/ModelBinding/DefaultFieldNameConverter.cs
  110. +44 −0 Nancy/ModelBinding/DefaultModelBinderLocator.cs
  111. +69 −0 Nancy/ModelBinding/DynamicModelBinderAdapter.cs
  112. +19 −0 Nancy/ModelBinding/IBinder.cs
  113. +27 −0 Nancy/ModelBinding/IBodyDeserializer.cs
  114. +16 −0 Nancy/ModelBinding/IFieldNameConverter.cs
  115. +17 −0 Nancy/ModelBinding/IModelBinder.cs
  116. +17 −0 Nancy/ModelBinding/IModelBinderLocator.cs
  117. +28 −0 Nancy/ModelBinding/ITypeConverter.cs
  118. +28 −0 Nancy/ModelBinding/ModelBindingException.cs
  119. +28 −0 Nancy/ModelBinding/ModuleExtensions.cs
  120. +210 −0 Nancy/NamedPipelineBase.cs
  121. +315 −0 Nancy/Nancy.csproj
  122. BIN Nancy/Nancy.pidb
  123. +60 −0 Nancy/NancyContext.cs
  124. +242 −0 Nancy/NancyEngine.cs
  125. +302 −0 Nancy/NancyModule.cs
  126. +11 −0 Nancy/NotFoundResponse.cs
  127. +27 −0 Nancy/PipelineItem.cs
  128. +253 −0 Nancy/Request.cs
  129. +21 −0 Nancy/RequestExecutionException.cs
  130. +321 −0 Nancy/RequestHeaders.cs
  131. +108 −0 Nancy/Response.cs
  132. +115 −0 Nancy/ResponseExtensions.cs
  133. +65 −0 Nancy/Responses/DefaultJsonSerializer.cs
  134. +47 −0 Nancy/Responses/DefaultXmlSerializer.cs
  135. +124 −0 Nancy/Responses/GenericFileResponse.cs
  136. +44 −0 Nancy/Responses/HtmlResponse.cs
  137. +33 −0 Nancy/Responses/JsonResponse.cs
  138. +53 −0 Nancy/Responses/RedirectResponse.cs
  139. +35 −0 Nancy/Responses/StreamResponse.cs
  140. +25 −0 Nancy/Responses/XmlResponse.cs
  141. +44 −0 Nancy/RootPathStartup.cs
  142. +49 −0 Nancy/Routing/DefaultNancyModuleBuilder.cs
  143. +29 −0 Nancy/Routing/DefaultRouteCacheProvider.cs
  144. +86 −0 Nancy/Routing/DefaultRoutePatternMatcher.cs
  145. +156 −0 Nancy/Routing/DefaultRouteResolver.cs
  146. +16 −0 Nancy/Routing/INancyModuleBuilder.cs
  147. +13 −0 Nancy/Routing/IRouteCache.cs
  148. +14 −0 Nancy/Routing/IRouteCacheProvider.cs
  149. +21 −0 Nancy/Routing/IRoutePatternMatchResult.cs
  150. +17 −0 Nancy/Routing/IRoutePatternMatcher.cs
  151. +18 −0 Nancy/Routing/IRouteResolver.cs
  152. +25 −0 Nancy/Routing/MethodNotAllowedRoute.cs
  153. +14 −0 Nancy/Routing/NotFoundRoute.cs
  154. +32 −0 Nancy/Routing/Route.cs
  155. +48 −0 Nancy/Routing/RouteCache.cs
  156. +30 −0 Nancy/Routing/RouteDescription.cs
  157. +32 −0 Nancy/Routing/RoutePatternMatchResult.cs
  158. +145 −0 Nancy/Security/Csrf.cs
  159. +74 −0 Nancy/Security/CsrfStartup.cs
  160. +85 −0 Nancy/Security/CsrfToken.cs
  161. +50 −0 Nancy/Security/CsrfTokenExtensions.cs
  162. +33 −0 Nancy/Security/CsrfTokenValidationResult.cs
  163. +15 −0 Nancy/Security/CsrfValidationException.cs
  164. +64 −0 Nancy/Security/DefaultCsrfTokenValidator.cs
  165. +19 −0 Nancy/Security/ICsrfTokenValidator.cs
  166. +13 −0 Nancy/Security/IUserIdentity.cs
  167. +103 −0 Nancy/Security/ModuleSecurity.cs
  168. +194 −0 Nancy/Session/CookieBasedSessions.cs
  169. +33 −0 Nancy/Session/ISession.cs
  170. +85 −0 Nancy/Session/NullSessionProvider.cs
  171. +62 −0 Nancy/Session/Session.cs
  172. +94 −0 Nancy/StaticConfiguration.cs
  173. +62 −0 Nancy/StaticContentStartup.cs
  174. +3,401 −0 Nancy/TinyIoc/TinyIoC.cs
  175. +130 −0 Nancy/Url.cs
  176. +56 −0 Nancy/Validation/CompositeValidator.cs
  177. +60 −0 Nancy/Validation/DefaultValidatorLocator.cs
  178. +20 −0 Nancy/Validation/IModelValidator.cs
  179. +17 −0 Nancy/Validation/IModelValidatorFactory.cs
  180. +17 −0 Nancy/Validation/IModelValidatorLocator.cs
  181. +28 −0 Nancy/Validation/ModelValidationDescriptor.cs
  182. +50 −0 Nancy/Validation/ModelValidationError.cs
  183. +19 −0 Nancy/Validation/ModelValidationException.cs
  184. +66 −0 Nancy/Validation/ModelValidationResult.cs
  185. +68 −0 Nancy/Validation/ModelValidationRule.cs
  186. +25 −0 Nancy/Validation/ModuleExtensions.cs
  187. +12 −0 Nancy/Validation/Rules/ComparisonOperator.cs
  188. +32 −0 Nancy/Validation/Rules/ComparisonValidationRule.cs
  189. +17 −0 Nancy/Validation/Rules/NotEmptyValidationRule.cs
  190. +17 −0 Nancy/Validation/Rules/NotNullValidationRule.cs
  191. +22 −0 Nancy/Validation/Rules/RegexValidationRule.cs
  192. +37 −0 Nancy/Validation/Rules/StringLengthValidationRule.cs
  193. +26 −0 Nancy/ViewEngines/AmbiguousViewsException.cs
  194. +33 −0 Nancy/ViewEngines/DefaultFileSystemReader.cs
  195. +96 −0 Nancy/ViewEngines/DefaultRenderContext.cs
  196. +35 −0 Nancy/ViewEngines/DefaultRenderContextFactory.cs
  197. +37 −0 Nancy/ViewEngines/DefaultResourceAssemblyProvider.cs
  198. +38 −0 Nancy/ViewEngines/DefaultResourceReader.cs
  199. +38 −0 Nancy/ViewEngines/DefaultViewCache.cs
  200. +137 −0 Nancy/ViewEngines/DefaultViewFactory.cs
  201. +48 −0 Nancy/ViewEngines/DefaultViewLocationCache.cs
  202. +82 −0 Nancy/ViewEngines/DefaultViewLocator.cs
  203. +83 −0 Nancy/ViewEngines/DefaultViewResolver.cs
  204. +36 −0 Nancy/ViewEngines/Extensions.cs
  205. +73 −0 Nancy/ViewEngines/FileSystemViewLocationProvider.cs
  206. +20 −0 Nancy/ViewEngines/IFileSystemReader.cs
  207. +47 −0 Nancy/ViewEngines/IRenderContext.cs
  208. +15 −0 Nancy/ViewEngines/IRenderContextFactory.cs
  209. +17 −0 Nancy/ViewEngines/IResourceAssemblyProvider.cs
  210. +21 −0 Nancy/ViewEngines/IResourceReader.cs
  211. +88 −0 Nancy/ViewEngines/IStartup.cs
  212. +19 −0 Nancy/ViewEngines/IViewCache.cs
  213. +34 −0 Nancy/ViewEngines/IViewEngine.cs
  214. +20 −0 Nancy/ViewEngines/IViewFactory.cs
  215. +8 −0 Nancy/ViewEngines/IViewLocationCache.cs
  216. +18 −0 Nancy/ViewEngines/IViewLocationProvider.cs
  217. +15 −0 Nancy/ViewEngines/IViewLocator.cs
  218. +17 −0 Nancy/ViewEngines/IViewResolver.cs
  219. +161 −0 Nancy/ViewEngines/ResourceViewLocationProvider.cs
  220. +45 −0 Nancy/ViewEngines/SuperSimpleViewEngine/IViewEngineHost.cs
  221. +80 −0 Nancy/ViewEngines/SuperSimpleViewEngine/NancyViewEngineHost.cs
  222. +557 −0 Nancy/ViewEngines/SuperSimpleViewEngine/SuperSimpleViewEngine.cs
  223. +56 −0 Nancy/ViewEngines/SuperSimpleViewEngine/SuperSimpleViewEngineWrapper.cs
  224. +65 −0 Nancy/ViewEngines/ViewEngineStartup.cs
  225. +37 −0 Nancy/ViewEngines/ViewEngineStartupContext.cs
  226. +25 −0 Nancy/ViewEngines/ViewLocationContext.cs
  227. +100 −0 Nancy/ViewEngines/ViewLocationResult.cs
  228. +29 −0 Nancy/ViewEngines/ViewNotFoundException.cs
  229. BIN Nancy/favicon.ico
  230. +22 −0 Nancy/nancy.nuspec
  231. +48 −0 NancyWebTest.sln
  232. +31 −0 NancyWebTest.userprefs
  233. +27 −0 NancyWebTest/AssemblyInfo.cs
  234. +23 −0 NancyWebTest/Main.cs
  235. +64 −0 NancyWebTest/Modules/ImageUploadModule.cs
  236. +69 −0 NancyWebTest/NancyWebTest.csproj
  237. BIN NancyWebTest/NancyWebTest.pidb
  238. +14 −0 NancyWebTest/Views/index.html
  239. +6 −0 NancyWebTest/app.config
@@ -0,0 +1 @@
+*/bin/
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{AA7F66EB-EC2C-47DE-855F-30B3E6EF2134}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Nancy.Hosting.Self</RootNamespace>
+ <AssemblyName>Nancy.Hosting.Self</AssemblyName>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MonoDebug|AnyCPU'">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>bin\MonoDebug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <CodeAnalysisLogFile>bin\Debug\Nancy.Hosting.Self.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
+ <CodeAnalysisFailOnMissingRules>false</CodeAnalysisFailOnMissingRules>
+ <WarningLevel>4</WarningLevel>
+ <Optimize>false</Optimize>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MonoRelease|AnyCPU'">
+ <OutputPath>bin\MonoRelease\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>AnyCPU</PlatformTarget>
+ <CodeAnalysisLogFile>bin\Release\Nancy.Hosting.Self.dll.CodeAnalysisLog.xml</CodeAnalysisLogFile>
+ <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
+ <CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
+ <ErrorReport>prompt</ErrorReport>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
+ <CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="Microsoft.CSharp" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="..\Nancy.Hosting.Wcf\FileSystemRootPathProvider.cs">
+ <Link>FileSystemRootPathProvider.cs</Link>
+ </Compile>
+ <Compile Include="NancyHost.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Nancy\Nancy.csproj">
+ <Project>{34576216-0DCA-4B0F-A0DC-9075E75A676F}</Project>
+ <Name>Nancy</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </ItemGroup>
+</Project>
Binary file not shown.
@@ -0,0 +1,198 @@
+namespace Nancy.Hosting.Self
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Globalization;
+ using System.Net;
+ using System.Threading;
+ using System.Linq;
+ using IO;
+ using Nancy.Bootstrapper;
+ using Nancy.Cookies;
+ using Nancy.Extensions;
+ using Nancy.Helpers;
+
+ /// <summary>
+ /// Allows to host Nancy server inside any application - console or windows service.
+ /// </summary>
+ /// <remarks>
+ /// NancyHost uses <see cref="System.Net.HttpListener"/> internally. Therefore, it requires full .net 4.0 profile (not client profile)
+ /// to run. <see cref="Start"/> will launch a thread that will listen for requests and then process them. All processing is done
+ /// within a single thread - self hosting is not intended for production use, but rather as a development server.
+ /// </remarks>
+ public class NancyHost
+ {
+ private readonly IList<Uri> baseUriList;
+ private readonly HttpListener listener;
+ private readonly INancyEngine engine;
+
+ public NancyHost(params Uri[] baseUris)
+ : this(NancyBootstrapperLocator.Bootstrapper, baseUris){}
+
+ public NancyHost(INancyBootstrapper bootStrapper, params Uri[] baseUris)
+ {
+ baseUriList = baseUris;
+ listener = new HttpListener();
+
+ foreach (var baseUri in baseUriList)
+ {
+ listener.Prefixes.Add(baseUri.ToString());
+ }
+
+ bootStrapper.Initialise();
+ engine = bootStrapper.GetEngine();
+ }
+
+ public NancyHost(Uri baseUri, INancyBootstrapper bootStrapper) : this (bootStrapper, baseUri) {}
+
+
+ public void Start()
+ {
+ listener.Start();
+ try
+ {
+ listener.BeginGetContext(GotCallback, null);
+ }
+ catch (HttpListenerException)
+ {
+ // this will be thrown when listener is closed while waiting for a request
+ return;
+ }
+
+ }
+
+ private void GotCallback(IAsyncResult ar)
+ {
+ try
+ {
+ HttpListenerContext ctx = listener.EndGetContext(ar);
+ listener.BeginGetContext(GotCallback, null);
+ Process(ctx);
+ }
+ catch (HttpListenerException)
+ {
+ // this will be thrown when listener is closed while waiting for a request
+ return;
+ }
+ }
+
+ private void Process(HttpListenerContext ctx)
+ {
+ var nancyRequest = ConvertRequestToNancyRequest(ctx.Request);
+ using (var nancyContext = engine.HandleRequest(nancyRequest))
+ {
+ ConvertNancyResponseToResponse(nancyContext.Response, ctx.Response);
+ }
+ }
+
+ public void Stop()
+ {
+ listener.Stop();
+ }
+
+
+ private static Uri GetUrlAndPathComponents(Uri uri)
+ {
+ // ensures that for a given url only the
+ // scheme://host:port/paths/somepath
+ return new Uri(uri.GetComponents(UriComponents.SchemeAndServer | UriComponents.Path, UriFormat.Unescaped));
+ }
+
+ private Request ConvertRequestToNancyRequest(HttpListenerRequest request)
+ {
+ var baseUri = baseUriList.FirstOrDefault(uri => uri.IsBaseOf(request.Url));
+
+ if (baseUri == null)
+ {
+ throw new InvalidOperationException(String.Format("Unable to locate base URI for request: {0}",request.Url));
+ }
+
+ var expectedRequestLength =
+ GetExpectedRequestLength(request.Headers.ToDictionary());
+
+ var relativeUrl =
+ GetUrlAndPathComponents(baseUri).MakeRelativeUri(GetUrlAndPathComponents(request.Url));
+
+ var nancyUrl = new Url
+ {
+ Scheme = request.Url.Scheme,
+ HostName = request.Url.Host,
+ Port = request.Url.IsDefaultPort ? null : (int?)request.Url.Port,
+ BasePath = baseUri.AbsolutePath.TrimEnd('/'),
+ Path = string.Concat("/", HttpUtility.UrlDecode(relativeUrl.ToString())),
+ Query = request.Url.Query,
+ Fragment = request.Url.Fragment,
+ };
+
+ return new Request(
+ request.HttpMethod,
+ nancyUrl,
+ RequestStream.FromStream(request.InputStream, expectedRequestLength, true),
+ request.Headers.ToDictionary(),
+ (request.RemoteEndPoint != null) ? request.RemoteEndPoint.Address.ToString() : null);
+ }
+
+ private static long GetExpectedRequestLength(IDictionary<string, IEnumerable<string>> incomingHeaders)
+ {
+ if (incomingHeaders == null)
+ {
+ return 0;
+ }
+
+ if (!incomingHeaders.ContainsKey("Content-Length"))
+ {
+ return 0;
+ }
+
+ var headerValue =
+ incomingHeaders["Content-Length"].SingleOrDefault();
+
+ if (headerValue == null)
+ {
+ return 0;
+ }
+
+ long contentLength;
+ if (!long.TryParse(headerValue, NumberStyles.Any, CultureInfo.InvariantCulture, out contentLength))
+ {
+ return 0;
+ }
+
+ return contentLength;
+ }
+
+ private static void ConvertNancyResponseToResponse(Response nancyResponse, HttpListenerResponse response)
+ {
+ foreach (var header in nancyResponse.Headers)
+ {
+ response.AddHeader(header.Key, header.Value);
+ }
+
+ foreach (var nancyCookie in nancyResponse.Cookies)
+ {
+ response.Headers.Add(HttpResponseHeader.SetCookie, nancyCookie.ToString());
+ }
+
+ response.ContentType = nancyResponse.ContentType;
+ response.StatusCode = (int)nancyResponse.StatusCode;
+
+ using (var output = response.OutputStream)
+ {
+ nancyResponse.Contents.Invoke(output);
+ }
+ }
+
+ private static Cookie ConvertCookie(INancyCookie nancyCookie)
+ {
+ var cookie =
+ new Cookie(nancyCookie.EncodedName, nancyCookie.EncodedValue, nancyCookie.Path, nancyCookie.Domain);
+
+ if (nancyCookie.Expires.HasValue)
+ {
+ cookie.Expires = nancyCookie.Expires.Value;
+ }
+
+ return cookie;
+ }
+ }
+}
@@ -0,0 +1,26 @@
+<?xml version="1.0"?>
+<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
+ <id>Nancy.Hosting.Self</id>
+ <version>0.0.0</version> <!-- The real version will be added by rake -->
+ <authors>Andreas Håkansson, Steven Robbins and contributors</authors>
+ <requireLicenseAcceptance>false</requireLicenseAcceptance>
+ <description>Enables hosting Nancy in any application.</description>
+ <summary>Nancy is a lightweight web framework for the .Net platform, inspired by Sinatra. Nancy aim at delivering a low ceremony approach to building light, fast web applications.</summary>
+ <language>en-US</language>
+ <copyright>Andreas Håkansson, Steven Robbins and contributors</copyright>
+ <iconUrl>http://nancyfx.org/nancy-nuget.png</iconUrl>
+ <licenseUrl>https://github.com/NancyFx/Nancy/blob/master/license.txt</licenseUrl>
+ <projectUrl>http://nancyfx.org</projectUrl>
+ <dependencies>
+ <dependency id="Nancy" />
+ </dependencies>
+ <tags>Nancy</tags>
+ </metadata>
+ <files>
+ <file src="build\binaries\Nancy.Hosting.Self.dll" target="lib\net40" />
+ <file src="build\binaries\Nancy.Hosting.Self.pdb" target="lib\net40" />
+ <file src="src\Nancy.Hosting.Self\**\*.cs" target="src" />
+ <file src="src\Nancy.Hosting.Wcf\FileSystemRootPathProvider.cs" target="src" />
+ </files>
+</package>
@@ -0,0 +1,16 @@
+namespace Nancy.Hosting.Wcf
+{
+ using System;
+ using System.IO;
+ using System.Reflection;
+
+ public class FileSystemRootPathProvider : IRootPathProvider
+ {
+ public string GetRootPath()
+ {
+ var assembly = Assembly.GetEntryAssembly();
+
+ return assembly == null ? Environment.CurrentDirectory : Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 0506fef

Please sign in to comment.