Skip to content

Commit

Permalink
first thougths
Browse files Browse the repository at this point in the history
  • Loading branch information
drusellers committed Sep 29, 2011
0 parents commit 313e896
Show file tree
Hide file tree
Showing 68 changed files with 23,744 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
@@ -0,0 +1,26 @@
build_artifacts/*
build_output/*

*.suo
**/*.suo
**/**/*.suo
**/*.user
bin
obj
_ReSharper*

*.csproj.user
*.resharper.user
*.ReSharper.user
*.cache
*~
*.swp
*.bak
*.orig

TestResult.xml
submit.xml
src/tests/*
tests/*
doc/*
SolutionVersion.cs
38 changes: 38 additions & 0 deletions Hiphopanonymous.SampleWeb/App_Start/FubuMVC.cs
@@ -0,0 +1,38 @@
using System.Web.Routing;
using FubuMVC.Core;
using FubuMVC.StructureMap;
using Hiphopanonymous.SampleWeb.App_Start;
using StructureMap;

// You can remove the reference to WebActivator by calling the Start() method from your Global.asax Application_Start
[assembly: WebActivator.PreApplicationStartMethod(typeof(AppStartFubuMVC), "Start", callAfterGlobalAppStart: true)]

namespace Hiphopanonymous.SampleWeb.App_Start
{
public static class AppStartFubuMVC
{
public static void Start()
{
// FubuApplication "guides" the bootstrapping of the FubuMVC
// application
var container = new Container(cfg=>
{
cfg.For<StateMachineInstanceRepository>().Use<TestStateMachineInstanceRepository>();
});

FubuApplication.For<ConfigureFubuMVC>() // ConfigureFubuMVC is the main FubuRegistry
// for this application. FubuRegistry classes
// are used to register conventions, policies,
// and various other parts of a FubuMVC application


// FubuMVC requires an IoC container for its own internals.
// In this case, we're using a brand new StructureMap container,
// but FubuMVC just adds configuration to an IoC container so
// that you can use the native registration API's for your
// IoC container for the rest of your application
.StructureMap(container)
.Bootstrap(RouteTable.Routes);
}
}
}
29 changes: 29 additions & 0 deletions Hiphopanonymous.SampleWeb/ConfigureFubuMVC.cs
@@ -0,0 +1,29 @@
using FubuMVC.Core;

namespace Hiphopanonymous.SampleWeb
{
public class ConfigureFubuMVC : FubuRegistry
{
public ConfigureFubuMVC()
{
// This line turns on the basic diagnostics and request tracing
IncludeDiagnostics(true);

// All public methods from concrete classes ending in "Controller"
// in this assembly are assumed to be action methods
Actions.IncludeClassesSuffixedWithController();

// Policies
Routes
.IgnoreControllerNamesEntirely()
.IgnoreMethodSuffix("Html")
.RootAtAssemblyNamespace();

// Match views to action methods by matching
// on model type, view name, and namespace
Views.TryToAttachWithDefaultConventions();

new StateMachineRegistryExtension().Configure(this);
}
}
}
112 changes: 112 additions & 0 deletions Hiphopanonymous.SampleWeb/EventInvocationSource.cs
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Automatonymous;
using FubuCore;
using FubuMVC.Core;
using FubuMVC.Core.Diagnostics;
using FubuMVC.Core.Registration;
using FubuMVC.Core.Registration.Conventions;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Registration.Routes;
using Hiphop;

namespace Hiphopanonymous.SampleWeb
{
public class StateMachineRegistryExtension : IFubuRegistryExtension
{
public void Configure(FubuRegistry registry)
{

registry.Actions.FindWith<StateMachineActionSource>();
registry.Routes.UrlPolicy<StateMachineUrlPolicy>();
}
}

public class StateMachineActionSource : IActionSource
{
public IEnumerable<ActionCall> FindActions(TypePool types)
{
IEnumerable<Type> foundStateMachineTypes = new List<Type>()
{
typeof(TicketStateMachine)
};

foreach(var sm in foundStateMachineTypes)
{
//TODO: Where can I load things into the container - using ObjDef?
var machine = (StateMachine)Activator.CreateInstance(sm);



var t = typeof (StateMachineOptionsAction<>).MakeGenericType(sm);
yield return new ActionCall(t, t.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

var tt = typeof(StateMachineInstanceOptionsAction<>).MakeGenericType(sm);
yield return new ActionCall(tt, tt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

var ttt = typeof(StateMachineCurrentStateAction<>).MakeGenericType(sm);
yield return new ActionCall(ttt, ttt.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));

foreach (var @event in machine.Events)
{
//need to track the event name somehow
//between here and the event url generation
var eventName = @event.Name;
var et = typeof (StateMachineRaiseEventAction<,>).MakeGenericType(sm, @event.GetType());
var call = new ActionCall(et, et.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));
yield return call;
}
}
}
}

public class StateMachineUrlPolicy : IUrlPolicy
{
public bool Matches(ActionCall call, IConfigurationObserver log)
{
return call.HandlerType.Namespace.Contains("Hiphopanonymous");
}

public IRouteDefinition Build(ActionCall call)
{
var route = call.ToRouteDefinition();

var stateMachineType = call.HandlerType.GetGenericArguments()[0];
var machineName = stateMachineType.Name.Replace("StateMachine","").ToLower();
route.Prepend(machineName);

if(call.HandlerType.Name.Contains("Options"))
{
route.ConstrainToHttpMethods("OPTIONS");

if(call.HandlerType.Name.Contains("Instance"))
{
route.Append("{id}");
}
}

if(call.HandlerType.Name.Contains("CurrentState"))
{
route.ConstrainToHttpMethods("GET");
route.Append("{id}");
}

//add id to those that need it

//add event name
if(call.HandlerType.Closes(typeof(StateMachineRaiseEventAction<,>)))
{
//this is a fail
var eventName = call.HandlerType.GetGenericArguments()[1].Name.ToLower();
route.Append("{id}");
route.Append(eventName);
route.ConstrainToHttpMethods("POST");
}

return route;
}
}


}
146 changes: 146 additions & 0 deletions Hiphopanonymous.SampleWeb/Hiphopanonymous.SampleWeb.csproj
@@ -0,0 +1,146 @@
<?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>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{91F97E5E-C873-4F93-B52F-A9E7A2E746EE}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Hiphopanonymous.SampleWeb</RootNamespace>
<AssemblyName>Hiphopanonymous.SampleWeb</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<UseIISExpress>false</UseIISExpress>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</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\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Automatonymous">
<HintPath>..\lib\Automatonymous.dll</HintPath>
</Reference>
<Reference Include="Bottles">
<HintPath>..\packages\Bottles.0.9.1.112\lib\Bottles.dll</HintPath>
</Reference>
<Reference Include="FubuCore">
<HintPath>..\packages\FubuCore.0.9.1.39\lib\FubuCore.dll</HintPath>
</Reference>
<Reference Include="FubuLocalization">
<HintPath>..\packages\FubuLocalization.0.9.1.39\lib\FubuLocalization.dll</HintPath>
</Reference>
<Reference Include="FubuMVC.Core">
<HintPath>..\packages\FubuMVC.References.0.9.1.548\lib\FubuMVC.Core.dll</HintPath>
</Reference>
<Reference Include="FubuMVC.StructureMap">
<HintPath>..\packages\FubuMVC.References.0.9.1.548\lib\FubuMVC.StructureMap.dll</HintPath>
</Reference>
<Reference Include="HtmlTags">
<HintPath>..\packages\HtmlTags.1.0.0.23\lib\4.0\HtmlTags.dll</HintPath>
</Reference>
<Reference Include="Ionic.Zip">
<HintPath>..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Practices.ServiceLocation">
<HintPath>..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure">
<HintPath>..\packages\FubuMVC.0.9.1.544\lib\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="StructureMap">
<HintPath>..\packages\structuremap.2.6.3\lib\StructureMap.dll</HintPath>
</Reference>
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="WebActivator">
<HintPath>..\packages\WebActivator.1.1.0.0\lib\NETFramework40\WebActivator.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Web.config" />
<Content Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\FubuMVC.cs" />
<Compile Include="EventInvocationSource.cs" />
<Compile Include="ConfigureFubuMVC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestStateMachineInstanceRepository.cs" />
<Compile Include="TicketStateMachine.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="fubu-content\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hiphopanonymous\Hiphopanonymous.csproj">
<Project>{49666ABA-F14B-4D31-AF19-41AB5BC372AC}</Project>
<Name>Hiphopanonymous</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>30546</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- 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>
-->
</Project>
35 changes: 35 additions & 0 deletions Hiphopanonymous.SampleWeb/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Hiphop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Hiphop")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("47f75cbe-f91e-4d58-853b-78c28ae70ba2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 313e896

Please sign in to comment.