Skip to content

Instantly share code, notes, and snippets.

@arobson
Created January 26, 2011 20:05
Show Gist options
  • Save arobson/797337 to your computer and use it in GitHub Desktop.
Save arobson/797337 to your computer and use it in GitHub Desktop.
A contrived but fun example of how to build a OWIN compliant file server using Symbiote.
using System;
using System.Collections.Generic;
using Symbiote.Core;
using Symbiote.Http;
using Symbiote.Http.Impl;
using Symbiote.Http.Owin;
using Symbiote.StructureMap;
using Symbiote.Daemon;
using Symbiote.Messaging;
using Symbiote.Actor;
namespace FileServerDemo
{
public class Program
{
static void Main(string[] args)
{
Assimilate
.Core<StructureMapAdapter>()
.Daemon(x => x.Arguments(args))
.Actors()
.Messaging()
.HttpHost(x => x
.ConfigureHttpListener(l => l.AddPort(8989))
.RegisterApplications(a => a.DefineApplication<FileServer>(r => r.Url.StartsWith("/file")))
)
.RunDaemon();
}
}
public class FileServer : IApplication
{
public void Process(IDictionary<string, object> requestItems, Action<string, IDictionary<string, IList<string>>, IEnumerable<object>> respond, Action<Exception> onException)
{
var request = requestItems.ExtractRequest();
respond
.Build()
.AppendFileContentToBody( request.Url )
.Submit( HttpStatus.Ok );
}
}
public class HostService : IDaemon
{
public IHost Host { get; set; }
public void Start()
{
Host.Start();
}
public void Stop()
{
Host.Stop();
}
public HostService(IHost host)
{
Host = host;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment