├── VERSION.txt
├── src
├── .nuget
│ ├── NuGet.exe
│ ├── NuGet.Config
│ └── NuGet.targets
├── Fix
│ ├── NugetPack.cmd
│ ├── IFixAdapter.cs
│ ├── Body.cs
│ ├── EnumerableEx.cs
│ ├── TaskHelper.cs
│ ├── ExceptionBody.cs
│ ├── InvokeAndForget.cs
│ ├── AssemblyManager.cs
│ ├── Fixer.cs
│ ├── OwinKeys.cs
│ ├── Mapper.cs
│ ├── Converter.cs
│ ├── Fix40.csproj
│ ├── Fix.csproj
│ └── AppFuncBuilder.cs
├── Fix.AspNet
│ ├── NugetPack.cmd
│ ├── web.config.transform
│ ├── FixHttpHandler.cs
│ ├── Fix.AspNet40.csproj
│ ├── Fix.AspNet.csproj
│ └── Bridge.cs
├── Fix.AppBuilder
│ ├── packages.config
│ ├── AppBuilderAdapter.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── FixAppBuilder.cs
│ ├── Fix.AppBuilder40.csproj
│ └── Fix.AppBuilder.csproj
├── FixConsole
│ ├── app.config
│ ├── Program.cs
│ └── FixUp.csproj
├── SimpleNowinDemo
│ ├── App.config
│ ├── packages.config
│ ├── Program.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── SimpleNowinDemo.csproj
├── FileHandler
│ ├── index.html
│ ├── FileHandler.csproj
│ └── FileReturner.cs
├── OwinHelpers
│ ├── NullDisposable.cs
│ ├── ExceptionBody.cs
│ ├── DictionaryExtensions.cs
│ ├── FileBody.cs
│ ├── BodyExtensions.cs
│ ├── EnvironmentExtensions.cs
│ ├── ActionObserver.cs
│ ├── EnumerableDictionaryExtension.cs
│ ├── StringBody.cs
│ ├── DelegateExtensions.cs
│ ├── AsyncExtensions.cs
│ ├── Body.cs
│ └── OwinHelpers.csproj
├── Tests
│ └── Fix.AppBuilder.Test
│ │ ├── packages.config
│ │ ├── Properties
│ │ └── AssemblyInfo.cs
│ │ ├── AppBuilderAdapterTest.cs
│ │ └── Fix.AppBuilder.Test.csproj
├── packages
│ └── repositories.config
├── TestServer
│ ├── StreamEx.cs
│ ├── NameValueCollectionEx.cs
│ ├── TestServer.csproj
│ └── Server.cs
├── CommonAssemblyInfo.cs
├── FixAsp
│ ├── Web.config
│ ├── Web.Debug.config
│ ├── OwinAppSetup.cs
│ ├── Web.Release.config
│ └── FixAsp.csproj
├── TestModule
│ ├── MethodDownshifter.cs
│ └── TestModule.csproj
├── Info
│ ├── InfoPrinter.cs
│ └── Info.csproj
├── Print
│ ├── Print.csproj
│ └── RequestPrinter.cs
└── Fix.sln
├── tools
└── xUnit
│ ├── xunit.dll
│ ├── xunit.console.exe
│ ├── xunit.console.clr4.exe
│ ├── xunit.console.x86.exe
│ ├── xunit.extensions.dll
│ ├── xunit.runner.tdnet.dll
│ ├── xunit.runner.msbuild.dll
│ ├── xunit.runner.utility.dll
│ ├── xunit.console.clr4.x86.exe
│ ├── xunit.dll.tdnet
│ ├── xunit.console.exe.config
│ ├── xunit.console.x86.exe.config
│ ├── xunit.console.clr4.exe.config
│ ├── xunit.console.clr4.x86.exe.config
│ ├── license.txt
│ ├── NUnitXml.xslt
│ └── HTML.xslt
├── Gemfile
├── InstallGems.bat
├── installgems.sh
├── .gitignore
├── README.md
├── packaging
└── nuspec
│ ├── Fix.nuspec
│ ├── Fix.AppBuilder.nuspec
│ └── Fix.AspNet.nuspec
├── LICENSE.txt
└── rakefile.rb
/VERSION.txt:
--------------------------------------------------------------------------------
1 | BUILD_VERSION = "0.8.1"
2 | NUGET_PACKAGE_VERSION = "0.8.1-pre"
--------------------------------------------------------------------------------
/src/.nuget/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/src/.nuget/NuGet.exe
--------------------------------------------------------------------------------
/tools/xUnit/xunit.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.dll
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.console.exe
--------------------------------------------------------------------------------
/src/Fix/NugetPack.cmd:
--------------------------------------------------------------------------------
1 | nuget pack -sym Fix.csproj -Properties Configuration=Release;Platform=AnyCPU -Build
2 |
--------------------------------------------------------------------------------
/src/Fix.AspNet/NugetPack.cmd:
--------------------------------------------------------------------------------
1 | nuget pack -sym Fix.AspNet.csproj -Properties Configuration=Release;Platform=AnyCPU -Build
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.clr4.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.console.clr4.exe
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.x86.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.console.x86.exe
--------------------------------------------------------------------------------
/tools/xUnit/xunit.extensions.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.extensions.dll
--------------------------------------------------------------------------------
/tools/xUnit/xunit.runner.tdnet.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.runner.tdnet.dll
--------------------------------------------------------------------------------
/Gemfile:
--------------------------------------------------------------------------------
1 | source :rubygems
2 |
3 | gem "rubyzip", "0.9.8"
4 | gem "albacore", ">=0.3.4.0"
5 | gem "rake", ">=10.0.3.0"
--------------------------------------------------------------------------------
/tools/xUnit/xunit.runner.msbuild.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.runner.msbuild.dll
--------------------------------------------------------------------------------
/tools/xUnit/xunit.runner.utility.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.runner.utility.dll
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.clr4.x86.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FixProject/Fix/HEAD/tools/xUnit/xunit.console.clr4.x86.exe
--------------------------------------------------------------------------------
/InstallGems.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 | SETLOCAL
3 |
4 | @call bundle -v
5 | IF ERRORLEVEL 1 (@call gem install bundler)
6 |
7 | @call bundle install
8 |
--------------------------------------------------------------------------------
/src/Fix.AppBuilder/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/src/FixConsole/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/installgems.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if ! which bundle > /dev/null; then
4 | echo "*** Installing Bundler"
5 | gem install bundler --no-rdoc --no-ri
6 | fi
7 |
8 | bundle install
9 |
--------------------------------------------------------------------------------
/src/Fix/IFixAdapter.cs:
--------------------------------------------------------------------------------
1 | namespace Fix
2 | {
3 | using System;
4 |
5 | public interface IFixerAdapter
6 | {
7 | Type AdaptedType { get; }
8 | object Adapt(Fixer fixer);
9 | }
10 | }
--------------------------------------------------------------------------------
/src/SimpleNowinDemo/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tools/xUnit/xunit.dll.tdnet:
--------------------------------------------------------------------------------
1 |
2 | xUnit.net {0}.{1}.{2} build {3}
3 | xunit.runner.tdnet.dll
4 | Xunit.Runner.TdNet.TdNetRunner
5 |
--------------------------------------------------------------------------------
/src/FileHandler/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Static HTML file
5 |
6 |
7 | This is a static HTML file.
8 |
9 |
--------------------------------------------------------------------------------
/src/Fix.AspNet/web.config.transform:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/OwinHelpers/NullDisposable.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace OwinHelpers
4 | {
5 | internal class NullDisposable : IDisposable
6 | {
7 | public void Dispose()
8 | {
9 |
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/Tests/Fix.AppBuilder.Test/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/SimpleNowinDemo/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/.nuget/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/packages/repositories.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/Fix/Body.cs:
--------------------------------------------------------------------------------
1 | namespace Fix
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 |
8 | public static class Body
9 | {
10 | public static Func FromException(Exception ex)
11 | {
12 | return new ExceptionBody(ex).ToAction();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/TestServer/StreamEx.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace TestServer
4 | {
5 | static class StreamEx
6 | {
7 | public static byte[] ToBytes(this Stream stream)
8 | {
9 | var bytes = new byte[stream.Length];
10 | if (bytes.Length > 0)
11 | stream.Read(bytes, 0, bytes.Length);
12 | return bytes;
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Fix.AppBuilder/AppBuilderAdapter.cs:
--------------------------------------------------------------------------------
1 | namespace Fix.AppBuilder
2 | {
3 | using System;
4 | using Owin;
5 |
6 | public class AppBuilderAdapter : IFixerAdapter
7 | {
8 | public Type AdaptedType
9 | {
10 | get { return typeof (IAppBuilder); }
11 | }
12 |
13 | public object Adapt(Fixer fixer)
14 | {
15 | return new FixAppBuilder(fixer);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | obj
2 | bin
3 | deploy
4 | *.csproj.user
5 | *.suo
6 | *.cache
7 | ~$*
8 | *~
9 | *ReSharper*
10 | *.swp
11 | *.testsettings
12 | TestResults/*
13 | *.dbmdl
14 | Releases/2*
15 | *ncrunch*
16 | Fix.sln.DotSettings
17 | Fix.sln.DotSettings.user
18 | *.nupkg
19 | nohup.out
20 | build
21 | src/CommonAssemblyInfo.cs
22 | Gemfile.lock
23 | results
24 | nuget
25 | src/packages/*
26 | !src/packages/repositories.config
27 | artifacts
28 | src/Fix.sln.ide
29 |
30 |
--------------------------------------------------------------------------------
/src/Fix/EnumerableEx.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Fix
7 | {
8 | static class EnumerableEx
9 | {
10 | public static IEnumerable Append(this IEnumerable source, T itemToAppend)
11 | {
12 | foreach (var item in source)
13 | {
14 | yield return item;
15 | }
16 |
17 | yield return itemToAppend;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Fix/TaskHelper.cs:
--------------------------------------------------------------------------------
1 | namespace Fix
2 | {
3 | using System.Threading.Tasks;
4 |
5 | public static class TaskHelper
6 | {
7 | public static Task Completed()
8 | {
9 | var tcs = new TaskCompletionSource();
10 | tcs.SetResult(0);
11 | return tcs.Task;
12 | }
13 |
14 | public static Task Completed(T result)
15 | {
16 | var tcs = new TaskCompletionSource();
17 | tcs.SetResult(result);
18 | return tcs.Task;
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/TestServer/NameValueCollectionEx.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Collections.Specialized;
3 | using System.Linq;
4 |
5 | namespace TestServer
6 | {
7 | static class NameValueCollectionEx
8 | {
9 | public static IEnumerable> ToKeyValuePairs(this NameValueCollection nameValueCollection)
10 | {
11 | return from key in nameValueCollection.AllKeys
12 | from value in nameValueCollection.GetValues(key)
13 | select new KeyValuePair(key, value);
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.x86.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.clr4.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/tools/xUnit/xunit.console.clr4.x86.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/CommonAssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.CompilerServices;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 | [assembly: AssemblyCompany("Mark Rendle")]
5 | [assembly: AssemblyProduct("Fix")]
6 | [assembly: AssemblyCopyright("Copyright (C) Mark Rendle 2010-2013")]
7 | [assembly: AssemblyTrademark("28779d381dcc746ac339e92e6e3eed69b358bdd7")]
8 | [assembly: ComVisible(false)]
9 | [assembly: AssemblyVersion("0.4.0.50044")]
10 | [assembly: AssemblyFileVersion("0.4.0.50044")]
11 |
12 | [assembly: AssemblyConfiguration("Release")]
13 | [assembly: AssemblyInformationalVersion("0.4.0.50044")]
14 |
15 | [assembly: InternalsVisibleTo("Tests")]
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Fix
2 | An ultra-lightweight web glue for .NET, written in C#.
3 | ## README needs updating
4 | This README is out of date. I've just picked Fix up again to use with Simple.Web, so the information below is wrong. I'll update it soon.
5 | MR 21-Jul-2012
6 | ## What?
7 | Fix joins together web servers, request handlers and "infixes", or middleware, in such a way that the implementations of each don't need to know anything about each other, or, indeed, about Fix itself.
8 | ### Example?
9 | Hello again. I've completely failed to update this, but I have at least deleted the old wrong examples.
10 | MR 02-Dec-2013
11 |
12 | I'd love to hear people's thoughts on this. Best way is to catch me on [Twitter](http://twitter.com/markrendle).
13 |
--------------------------------------------------------------------------------
/src/Fix/ExceptionBody.cs:
--------------------------------------------------------------------------------
1 | namespace Fix
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Text;
6 | using System.Threading;
7 | using System.Threading.Tasks;
8 |
9 | internal class ExceptionBody
10 | {
11 | private readonly Exception _error;
12 |
13 | public ExceptionBody(Exception error)
14 | {
15 | _error = error;
16 | }
17 |
18 | public Func ToAction()
19 | {
20 | var buffer = Encoding.Default.GetBytes(_error.ToString());
21 | return (stream, token) => Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, buffer, 0, buffer.Length, null);
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/src/Fix.AspNet/FixHttpHandler.cs:
--------------------------------------------------------------------------------
1 | namespace Fix.AspNet
2 | {
3 | using System;
4 | using System.Web;
5 |
6 | public class FixHttpHandler : IHttpAsyncHandler
7 | {
8 | public void ProcessRequest(HttpContext context)
9 | {
10 | throw new NotImplementedException();
11 | }
12 |
13 | public bool IsReusable { get; private set; }
14 |
15 | public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
16 | {
17 | var task = Bridge.RunContext(context);
18 | task.ContinueWith(t => cb(task));
19 | return task;
20 | }
21 |
22 | public void EndProcessRequest(IAsyncResult result)
23 | {
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/OwinHelpers/ExceptionBody.cs:
--------------------------------------------------------------------------------
1 | namespace OwinHelpers
2 | {
3 | using System;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using BodyDelegate = System.Func;
7 |
8 | internal class ExceptionBody
9 | {
10 | private readonly Exception _error;
11 |
12 | public ExceptionBody(Exception error)
13 | {
14 | _error = error;
15 | }
16 |
17 | public BodyDelegate ToAction()
18 | {
19 | var buffer = Encoding.Default.GetBytes(_error.ToString());
20 | return (stream, token) => Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, buffer, 0, buffer.Length, null);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/OwinHelpers/DictionaryExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace OwinHelpers
7 | {
8 | public static class DictionaryExtensions
9 | {
10 | public static TValue GetValueOrDefault(this IDictionary dictionary, TKey key, TValue defaultValue)
11 | {
12 | TValue value;
13 | if (!dictionary.TryGetValue(key, out value))
14 | {
15 | value = defaultValue;
16 | }
17 | return value;
18 | }
19 |
20 | public static TValue GetValueOrDefault(this IDictionary dictionary, TKey key)
21 | {
22 | return GetValueOrDefault(dictionary, key, default(TValue));
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/FixAsp/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/OwinHelpers/FileBody.cs:
--------------------------------------------------------------------------------
1 | namespace OwinHelpers
2 | {
3 | using System;
4 | using System.IO;
5 | using System.Threading;
6 | using System.Threading.Tasks;
7 | using BodyDelegate = System.Func;
8 |
9 | internal class FileBody
10 | {
11 | private readonly FileInfo _fileInfo;
12 |
13 | public FileBody(FileInfo fileInfo)
14 | {
15 | _fileInfo = fileInfo;
16 | }
17 |
18 | public BodyDelegate ToAction()
19 | {
20 | return (stream, token) =>
21 | {
22 | using (var fileStream = _fileInfo.OpenRead())
23 | {
24 | fileStream.CopyTo(stream);
25 | }
26 | return TaskHelper.Completed();
27 | };
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packaging/nuspec/Fix.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Fix
5 | 0.3.2
6 | Mark Rendle
7 | Mark Rendle
8 | Mark Rendle
9 | http://www.opensource.org/licenses/mit-license.php
10 | http://github.com/FixProject/Fix
11 | false
12 | A glue for OWIN.
13 | A glue for OWIN.
14 | fix owin http
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (C) 2013 Mark Rendle
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/src/Fix/InvokeAndForget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using RequestHandler = System.Action>, System.Func, System.Action>, System.Func>, System.Action, System.Delegate>;
4 | using ResponseHandler = System.Action>, System.Func>;
5 |
6 | namespace Fix
7 | {
8 | //static class InvokeAndForgetEx
9 | //{
10 | // public static void InvokeAndForget(this RequestHandler handler, IEnumerable> env, Func body, ResponseHandler responseHandler, Action exceptionHandler, Delegate next)
11 | // {
12 | // handler.BeginInvoke(env, body, responseHandler, exceptionHandler, next, handler.EndInvoke, null);
13 | // }
14 | //}
15 | }
16 |
--------------------------------------------------------------------------------
/src/FixConsole/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel.Composition;
3 | using System.ComponentModel.Composition.Hosting;
4 | using System.Linq;
5 | using Fix;
6 | using TestServer;
7 |
8 | namespace FixUp
9 | {
10 | class Program
11 | {
12 | static void Main(string[] args)
13 | {
14 | var prefix = args.Length == 1 ? args[0] : "http://*:3333/";
15 | using (var server = new Server(prefix))
16 | {
17 | var fixer = new Fixer(func => server.Start(func), server.Stop);
18 |
19 | using (var catalog = new DirectoryCatalog(Environment.CurrentDirectory))
20 | {
21 | var container = new CompositionContainer(catalog);
22 | container.ComposeParts(fixer);
23 | }
24 |
25 | fixer.Start();
26 | Console.Write("Running. Press Enter to stop.");
27 | Console.ReadLine();
28 | fixer.Stop();
29 | }
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/OwinHelpers/BodyExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace OwinHelpers
7 | {
8 | public static class BodyExtensions
9 | {
10 | public static IObservable ToObservable(this Action, Action, Action> source)
11 | {
12 | return new ActionObservable(source);
13 | }
14 |
15 | private class ActionObservable : IObservable
16 | {
17 | private readonly Action, Action, Action> _action;
18 |
19 | public ActionObservable(Action, Action, Action> action)
20 | {
21 | _action = action;
22 | }
23 |
24 | public IDisposable Subscribe(IObserver observer)
25 | {
26 | _action.BeginInvoke(observer.OnNext, observer.OnCompleted, observer.OnError, _action.EndInvoke, null);
27 | return new NullDisposable();
28 | }
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/packaging/nuspec/Fix.AppBuilder.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Fix.AppBuilder
5 | 0.4.0.51807
6 | Mark Rendle
7 | Mark Rendle
8 | Mark Rendle
9 | http://www.opensource.org/licenses/mit-license.php
10 | http://github.com/FixProject/Fix
11 | false
12 | A glue for OWIN.
13 | Owin.IAppBuilder support for Fix, a glue for OWIN.
14 | fix owin http
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/packaging/nuspec/Fix.AspNet.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Fix.AspNet
5 | 0.0.0
6 | Mark Rendle
7 | Mark Rendle
8 | Mark Rendle
9 | http://www.opensource.org/licenses/mit-license.php
10 | http://github.com/FixProject/Fix
11 | false
12 | A glue for OWIN.
13 | Asp.Net support for Fix, a glue for OWIN.
14 | fix owin http
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/OwinHelpers/EnvironmentExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Environment = System.Collections.Generic.IEnumerable>;
6 |
7 | namespace OwinHelpers
8 | {
9 | public static class EnvironmentExtensions
10 | {
11 | public static string GetPath(this Environment env)
12 | {
13 | return GetValue(env, "owin.RequestPath");
14 | }
15 |
16 | public static string GetRequestMethod(this Environment env)
17 | {
18 | return GetValue(env, "owin.RequestMethod");
19 | }
20 |
21 | private static string GetValue(Environment env, string key)
22 | {
23 | var dictionary = env as IDictionary;
24 | if (dictionary != null)
25 | {
26 | return dictionary.GetValueOrDefault(key, string.Empty).ToString();
27 | }
28 | var pair = env.FirstOrDefault(kvp => kvp.Key.Equals(key));
29 | return (pair.Value != null) ? pair.Value.ToString() : string.Empty;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Fix/AssemblyManager.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace Fix
7 | {
8 | using System.Reflection;
9 |
10 | public static class AssemblyManager
11 | {
12 | private static List _cache;
13 |
14 | public static IEnumerable GetReferencedAssemblies()
15 | {
16 | return _cache ?? FindReferencedAssemblies();
17 | }
18 |
19 | private static IEnumerable FindReferencedAssemblies()
20 | {
21 | var assembly = Assembly.GetEntryAssembly();
22 | var cache = new List {assembly};
23 | yield return assembly;
24 |
25 | foreach (var referencedAssembly in assembly.GetReferencedAssemblies())
26 | {
27 | assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == referencedAssembly.FullName) ??
28 | Assembly.Load(referencedAssembly);
29 | cache.Add(assembly);
30 | yield return assembly;
31 | }
32 |
33 | _cache = cache;
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/SimpleNowinDemo/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace SimpleNowinDemo
4 | {
5 | using Fix;
6 | using Nowin;
7 | using Simple.Web;
8 | using Simple.Web.Behaviors;
9 |
10 | class Program
11 | {
12 | static void Main()
13 | {
14 | // Build the OWIN app
15 | var app = new Fixer()
16 | .Use(next => env => Application.Run(env, () => next(env)))
17 | .Build();
18 |
19 | // Set up the Nowin server
20 | var builder = ServerBuilder.New()
21 | .SetPort(31337)
22 | .SetOwinApp(app);
23 |
24 | // Run
25 | using (builder.Start())
26 | {
27 | Console.WriteLine("Listening on port 31337. Enter to exit.");
28 | Console.ReadLine();
29 | }
30 | }
31 | }
32 |
33 | [UriTemplate("/")]
34 | public class Index : IGet, IOutput
35 | {
36 | public Status Get()
37 | {
38 | return 200;
39 | }
40 |
41 | public RawHtml Output
42 | {
43 | get { return "Ta dah!
"; }
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/OwinHelpers/ActionObserver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace OwinHelpers
5 | {
6 | internal class ActionObserver : IObserver
7 | {
8 | private readonly Action _onFile;
9 | private readonly Action _onNext;
10 | private readonly Action _onCompleted;
11 | private readonly Action _onError;
12 |
13 | public ActionObserver(Action onNext, Action onFile, Action onCompleted, Action onError)
14 | {
15 | _onFile = onFile;
16 | _onNext = onNext ?? new Action(x => { });
17 | _onError = onError ?? new Action(x => { });
18 | _onCompleted = onCompleted ?? new Action(() => { });
19 | }
20 |
21 | public void OnNext(T value)
22 | {
23 | _onNext(value);
24 | }
25 |
26 | public void OnFile(FileInfo fileInfo)
27 | {
28 | _onFile(fileInfo);
29 | }
30 |
31 | public void OnError(Exception error)
32 | {
33 | _onError(error);
34 | }
35 |
36 | public void OnCompleted()
37 | {
38 | _onCompleted();
39 | }
40 | }
41 | }
--------------------------------------------------------------------------------
/src/OwinHelpers/EnumerableDictionaryExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace OwinHelpers
7 | {
8 | public static class EnumerableDictionaryExtension
9 | {
10 | public static IDictionary ToDictionary(this IEnumerable> source)
11 | {
12 | var alreadyDictionary = source as IDictionary;
13 | if (alreadyDictionary != null)
14 | {
15 | return new Dictionary(alreadyDictionary);
16 | }
17 | return source.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
18 | }
19 |
20 | public static IEnumerable> Mutate(this IEnumerable> source,
21 | Func, bool> predicate, Func,KeyValuePair> mutator)
22 | {
23 | foreach (var pair in source)
24 | {
25 | if (predicate(pair))
26 | {
27 | yield return mutator(pair);
28 | }
29 | else
30 | {
31 | yield return pair;
32 | }
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/FixAsp/Web.Debug.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
29 |
30 |
--------------------------------------------------------------------------------
/src/FixAsp/OwinAppSetup.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using System.IO;
5 |
6 | namespace FixAsp
7 | {
8 | using System.Text;
9 | using Fix;
10 | using AppFunc = Func, Task>;
11 |
12 | public static class OwinAppSetup
13 | {
14 | public static void Setup(Action> use, Action> map)
15 | {
16 | map("/mapped", next => async env =>
17 | {
18 | var stream = (Stream) env["owin.ResponseBody"];
19 | await stream.WriteAsync("MAPPED!
");
20 | await stream.WriteAsync("" + env[OwinKeys.RequestPath] + "
");
21 | env["owin.ResponseStatusCode"] = 200;
22 | });
23 | use(next => async env =>
24 | {
25 | var stream = (Stream) env["owin.ResponseBody"];
26 | await stream.WriteAsync("OWIN!
");
27 | await stream.WriteAsync("" + env[OwinKeys.RequestPath] + "
");
28 | env["owin.ResponseStatusCode"] = 200;
29 | });
30 | }
31 |
32 | public static Task WriteAsync(this Stream stream, string text)
33 | {
34 | var bytes = Encoding.Default.GetBytes(text);
35 | return stream.WriteAsync(bytes, 0, bytes.Length);
36 | }
37 | }
38 | }
--------------------------------------------------------------------------------
/src/FixAsp/Web.Release.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
17 |
18 |
19 |
30 |
31 |
--------------------------------------------------------------------------------
/src/OwinHelpers/StringBody.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | namespace OwinHelpers
7 | {
8 | using System.Threading.Tasks;
9 | using BodyDelegate = System.Func;
10 | internal class StringBody : IObservable>
11 | {
12 | private readonly byte[] _bytes;
13 |
14 | public StringBody(string text) : this(text, Encoding.Default)
15 | {
16 | }
17 |
18 | public StringBody(string text, Encoding encoding)
19 | {
20 | _bytes = encoding.GetBytes(text);
21 | }
22 |
23 | public BodyDelegate ToAction()
24 | {
25 | return (stream, token) => Task.Factory.FromAsync(stream.BeginWrite, stream.EndWrite, _bytes, 0, _bytes.Length, null);
26 | }
27 |
28 | public int Length
29 | {
30 | get { return _bytes.Length; }
31 | }
32 |
33 | public IDisposable Subscribe(IObserver> observer)
34 | {
35 | Action action = () =>
36 | {
37 | observer.OnNext(new ArraySegment(_bytes));
38 | observer.OnCompleted();
39 | };
40 | action.BeginInvoke(action.EndInvoke, null);
41 | return new NullDisposable();
42 | }
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/TestModule/MethodDownshifter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel.Composition;
4 | using OwinHelpers;
5 | using App = System.Action>, System.Func, System.Action>, System.Action>, System.Action, System.Action, System.Action>>, System.Delegate>;
6 | using ResponseHandler = System.Action>, System.Action>, System.Action, System.Action, System.Action>>;
7 |
8 | namespace TestModule
9 | {
10 | public class MethodDownshifter
11 | {
12 | [Export("Owin.Middleware")]
13 | public void DownshiftMethod(IEnumerable> env, Func body,
14 | ResponseHandler responseHandler, Delegate next)
15 | {
16 | var nextInfix = next as App;
17 | if (nextInfix != null)
18 | {
19 | env = env.Mutate(kvp => kvp.Key.Equals("REQUEST_METHOD"),
20 | kvp => new KeyValuePair("REQUEST_METHOD", kvp.Value.ToString().ToLower()));
21 | nextInfix(env, body, responseHandler, null);
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Fix.AppBuilder/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Fix.AppBuilder")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Fix.AppBuilder")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("867778ee-13e4-4c41-994e-50914f30d78a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/SimpleNowinDemo/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("SimpleNowinDemo")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("SimpleNowinDemo")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("942f5e77-092f-40fb-9e26-ae5afd434f6d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Tests/Fix.AppBuilder.Test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("Fix.AppBuilder.Test")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("Fix.AppBuilder.Test")]
13 | [assembly: AssemblyCopyright("Copyright © 2013")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("377e7b0a-c54b-4b7a-b328-a27a6f24a974")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/src/Fix.AppBuilder/FixAppBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 | using Owin;
5 |
6 | namespace Fix.AppBuilder
7 | {
8 | using AppFunc = Func, Task>;
9 |
10 | class FixAppBuilder : IAppBuilder
11 | {
12 | private readonly IDictionary _properties = new Dictionary();
13 | private readonly Fixer _fixer;
14 |
15 | public FixAppBuilder(Fixer fixer)
16 | {
17 | _fixer = fixer;
18 | }
19 |
20 | public IAppBuilder Use(object middleware, params object[] args)
21 | {
22 | var properFunc = middleware as Func;
23 | if (properFunc != null)
24 | {
25 | _fixer.Use(properFunc);
26 | return this;
27 | }
28 | throw new NotSupportedException("FixAppBuilder can't use that middleware.");
29 | }
30 |
31 | public object Build(Type returnType)
32 | {
33 | var output = _fixer.Build();
34 | if (output.GetType() != returnType)
35 | {
36 | throw new NotSupportedException("FixAppBuilder can't Build that Type.");
37 | }
38 | return output;
39 | }
40 |
41 | public IAppBuilder New()
42 | {
43 | return new FixAppBuilder(new Fixer());
44 | }
45 |
46 | public IDictionary Properties
47 | {
48 | get
49 | {
50 | return _properties;
51 | }
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/src/OwinHelpers/DelegateExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using Env = System.Collections.Generic.IDictionary;
6 | using Headers = System.Collections.Generic.IDictionary;
7 | using BodyDelegate = System.Func;
8 | using ResponseHandler = System.Func, System.Func, System.Threading.Tasks.Task>;
9 | using App = System.Func, System.Collections.Generic.IDictionary, System.IO.Stream, System.Threading.CancellationToken, System.Func, System.Func, System.Threading.Tasks.Task>, System.Delegate, System.Threading.Tasks.Task>;
10 |
11 | namespace OwinHelpers
12 | {
13 | using System.IO;
14 | using System.Threading;
15 | using System.Threading.Tasks;
16 |
17 | public static class DelegateExtensions
18 | {
19 | public static Task InvokeAsNextApp(this Delegate @delegate, Env env, Headers headers, Stream body, CancellationToken token, ResponseHandler responseHandler)
20 | {
21 | var nextApp = @delegate as App;
22 | if (nextApp != null)
23 | {
24 | return nextApp(env, headers, body, token, responseHandler, null);
25 | }
26 |
27 | return TaskHelper.Completed();
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Tests/Fix.AppBuilder.Test/AppBuilderAdapterTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Fix.AppBuilder.Test
8 | {
9 | using System.Reflection;
10 | using Owin;
11 | using Xunit;
12 | using AppFunc = Func, Task>;
13 |
14 | public class AppBuilderAdapterTest
15 | {
16 | [Fact]
17 | public void FixWorksWithIAppBuilderUsingAdapter()
18 | {
19 | var assemblies = new[] {Assembly.GetExecutingAssembly(), typeof (AppBuilderAdapter).Assembly};
20 | var startupEnv = new Dictionary();
21 | var appFuncBuilder = AppFuncBuilder.Create(assemblies, startupEnv);
22 | var func = appFuncBuilder.Build();
23 | var dict = new Dictionary();
24 | func(dict);
25 | Assert.Equal("Yes", startupEnv["Constructed"]);
26 | Assert.Equal("Passed", dict["Test"]);
27 | }
28 | }
29 |
30 | public class OwinAppSetup
31 | {
32 | public OwinAppSetup(IDictionary startupEnv)
33 | {
34 | startupEnv["Constructed"] = "Yes";
35 | }
36 |
37 | public void Setup(Action> use)
38 | {
39 | use(Run);
40 | }
41 |
42 | private static AppFunc Run(AppFunc _)
43 | {
44 | return env =>
45 | {
46 | env["Test"] = "Passed";
47 | var tcs = new TaskCompletionSource();
48 | tcs.SetResult(0);
49 | return tcs.Task;
50 | };
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/Fix/Fixer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 |
5 | namespace Fix
6 | {
7 | using System.Threading;
8 | using Env = IDictionary;
9 | using ComponentFunc = Func, Func,Task>, Task>;
10 | using BuilderFunc = Func, Task>, Func, Task>>;
11 | using AppFunc = Func, Task>;
12 |
13 | public class Fixer
14 | {
15 | private readonly Stack _funcs = new Stack();
16 | private int _useCount = 0;
17 |
18 | public Fixer Use(BuilderFunc component)
19 | {
20 | _funcs.Push(component);
21 | return this;
22 | }
23 |
24 | public Fixer Map(string mapPath, BuilderFunc component)
25 | {
26 | _funcs.Push(Mapper.Map(mapPath, component));
27 | return this;
28 | }
29 |
30 | public AppFunc Build()
31 | {
32 | if (Interlocked.Increment(ref _useCount) > 1)
33 | {
34 | throw new InvalidOperationException("Fixer instances may only be used once.");
35 | }
36 |
37 | var lastFunc = _funcs.Pop();
38 | AppFunc f = lastFunc(Completed);
39 |
40 | while (_funcs.Count > 0)
41 | {
42 | var func = _funcs.Pop();
43 | f = func(f);
44 | }
45 |
46 | return f;
47 | }
48 |
49 | private static Task Completed(IDictionary _)
50 | {
51 | var tcs = new TaskCompletionSource();
52 | tcs.SetResult(0);
53 | return tcs.Task;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Fix/OwinKeys.cs:
--------------------------------------------------------------------------------
1 | namespace Fix
2 | {
3 | public static class OwinKeys
4 | {
5 | public const string CallCompleted = "owin.CallCompleted";
6 | public const string RequestScheme = "owin.RequestScheme";
7 | public const string RequestMethod = "owin.RequestMethod";
8 | public const string RequestPathBase = "owin.RequestPathBase";
9 | public const string RequestPath = "owin.RequestPath";
10 | public const string RequestQueryString = "owin.RequestQueryString";
11 | public const string RequestProtocol = "owin.RequestProtocol";
12 |
13 | public const string RequestHeaders = "owin.RequestHeaders";
14 | public const string RequestBody = "owin.RequestBody";
15 |
16 | public const string ResponseBody = "owin.ResponseBody";
17 | public const string ResponseHeaders = "owin.ResponseHeaders";
18 | public const string ResponseStatusCode = "owin.ResponseStatusCode";
19 | public const string ResponseReasonPhrase = "owin.ResponseReasonPhrase";
20 | public const string ResponseProtocol = "owin.ResponseProtocol";
21 |
22 | public const string Version = "owin.Version";
23 | public const string CallCancelled = "owin.CallCancelled";
24 | }
25 |
26 | public static class ServerKeys
27 | {
28 | public const string RemoteIpAddress = "server.RemoteIpAddress";
29 | public const string RemotePort = "server.RemotePort";
30 | public const string LocalIpAddress = "server.LocalIpAddress";
31 | public const string LocalPort = "server.LocalPort";
32 | public const string IsLocal = "server.IsLocal";
33 | }
34 |
35 | public static class SendFileKeys
36 | {
37 | public const string Version = "sendfile.Version";
38 | public const string Support = "sendfile.Support";
39 | public const string Concurrency = "sendfile.Concurrency";
40 | public const string SendAsync = "sendfile.SendAsync";
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Fix/Mapper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading.Tasks;
4 |
5 | namespace Fix
6 | {
7 | using AppFunc = Func, Task>;
8 | public static class Mapper
9 | {
10 | public static Func Map(string mapPath, Func mappedFunc)
11 | {
12 | if (mapPath == null) throw new ArgumentNullException("mapPath");
13 | mapPath = '/' + mapPath.Trim('/');
14 |
15 | return next =>
16 | {
17 | var func = mappedFunc(NotFound);
18 | return async env =>
19 | {
20 | var path = (string)env["owin.RequestPath"];
21 | if (path.Equals(mapPath, StringComparison.OrdinalIgnoreCase))
22 | {
23 | var pathBase = env.GetValueOrDefault("owin.RequestPathBase", string.Empty);
24 | env["owin.RequestPathBase"] = pathBase + mapPath;
25 | await func(env);
26 | }
27 | else if (path.StartsWith(mapPath + '/'))
28 | {
29 | var pathBase = env.GetValueOrDefault("owin.RequestPathBase", string.Empty);
30 | env["owin.RequestPathBase"] = pathBase + mapPath;
31 | env["owin.RequestPath"] = path.Substring(mapPath.Length);
32 | await func(env);
33 | }
34 | else
35 | {
36 | await next(env);
37 | }
38 | };
39 | };
40 | }
41 |
42 | private static Task NotFound(IDictionary env)
43 | {
44 | env["owin.ResponseStatusCode"] = 404;
45 | return Task.FromResult(0);
46 | }
47 | public static T GetValueOrDefault(this IDictionary dict, string key,
48 | T defaultValue = default(T))
49 | {
50 | object value;
51 | if (!dict.TryGetValue(key, out value)) return defaultValue;
52 | return value != null ? (T)value : defaultValue;
53 | }
54 |
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/Fix/Converter.cs:
--------------------------------------------------------------------------------
1 | //namespace Fix
2 | //{
3 | // using System;
4 | // using System.Collections.Generic;
5 | // using System.IO;
6 | // using System.Threading;
7 | // using System.Threading.Tasks;
8 | // using _BodyDelegate = System.Func;
9 | // using _ResponseHandler = System.Func, System.Func, System.Threading.Tasks.Task>;
10 | // using _App = System.Func, System.Collections.Generic.IDictionary, System.IO.Stream, System.Threading.CancellationToken, System.Func, System.Func, System.Threading.Tasks.Task>, System.Threading.Tasks.Task>;
11 |
12 | // public delegate Task Body(Stream stream, CancellationToken cancellationToken);
13 |
14 | // public delegate Task Respond(int status, IDictionary headers, Body body);
15 |
16 | // public delegate Task App(IDictionary env, IDictionary headers, Stream input, CancellationToken cancellation, Respond respond);
17 |
18 | // public static class Converter
19 | // {
20 | // public static App ToApp(Func, IDictionary, Stream, CancellationToken, Func, Func, Task>, Task> appFunc)
21 | // {
22 | // return (env, headers, input, cancellation, respond) =>
23 | // appFunc(env, headers, input, cancellation, respond.ToRespondFunc());
24 | // }
25 |
26 | // public static Body ToBody(this Func bodyFunc)
27 | // {
28 | // return (stream, token) => bodyFunc(stream, token);
29 | // }
30 |
31 | // public static Func, Func,Task> ToRespondFunc(this Respond respond)
32 | // {
33 | // return (status, headers, body) => respond(status, headers, body.ToBody());
34 | // }
35 | // }
36 | //}
--------------------------------------------------------------------------------
/src/OwinHelpers/AsyncExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace OwinHelpers
2 | {
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Text;
7 | using System.Threading;
8 | using System.Threading.Tasks;
9 | using Result = System.Tuple< //Result
10 | System.Collections.Generic.IDictionary, // Properties
11 | int, // Status
12 | System.Collections.Generic.IDictionary, // Headers
13 | System.Func< // Body
14 | System.IO.Stream, // Output
15 | System.Threading.Tasks.Task>>; // Done
16 |
17 | public static class AsyncExtensions
18 | {
19 | public static Task WriteAsync(this Stream stream, byte[] bytes, int offset, int count, CancellationToken cancellationToken = default(CancellationToken))
20 | {
21 | var factory = cancellationToken.Equals(default(CancellationToken))
22 | ? Task.Factory
23 | : new TaskFactory(cancellationToken);
24 | return factory.FromAsync(stream.BeginWrite, stream.EndWrite, bytes, offset, count, null);
25 | }
26 |
27 | public static Task WriteAsync(this Stream stream, string text)
28 | {
29 | var bytes = Encoding.UTF8.GetBytes(text);
30 | return stream.WriteAsync(bytes, 0, bytes.Length);
31 | }
32 | }
33 |
34 | public static class TaskHelper
35 | {
36 | public static Task Completed()
37 | {
38 | var tcs = new TaskCompletionSource