Permalink
Browse files

further changes to nancy demo

  • Loading branch information...
nicholascloud committed Apr 9, 2012
1 parent dae8581 commit 636959df45854ce0ccbdf61153392c52cebdad66
Showing with 552 additions and 54 deletions.
  1. +6 −2 kcdc12/nancyfx/demo/HamstringFX.RaceService/CliArgs.cs
  2. +4 −2 kcdc12/nancyfx/demo/HamstringFX.RaceService/HamstringFX.RaceService.csproj
  3. +2 −2 kcdc12/nancyfx/demo/HamstringFX.RaceService/Program.cs
  4. +6 −1 kcdc12/nancyfx/demo/HamstringFX.RaceService/RaceServiceBootstrapper.cs
  5. +3 −0 kcdc12/nancyfx/demo/HamstringFX.RaceService/app.config
  6. +5 −0 kcdc12/nancyfx/demo/HamstringFX.RaceService/cache/races.xml
  7. +11 −3 kcdc12/nancyfx/demo/HamstringFX.RaceService/data/RaceData.cs
  8. +4 −2 kcdc12/nancyfx/demo/HamstringFX/HamstringFX.csproj
  9. +15 −0 kcdc12/nancyfx/demo/HamstringFX/data/Announcement.cs
  10. +3 −1 kcdc12/nancyfx/demo/HamstringFX/data/HamstringData.cs
  11. +5 −1 kcdc12/nancyfx/demo/HamstringFX/{model → data}/Race.cs
  12. +2 −2 kcdc12/nancyfx/demo/HamstringFX/{model → data}/RaceServiceProxy.cs
  13. +1 −0 kcdc12/nancyfx/demo/HamstringFX/model/IRaceServiceProxy.cs
  14. +6 −2 kcdc12/nancyfx/demo/HamstringFX/model/MainModelFactory.cs
  15. +1 −1 kcdc12/nancyfx/demo/HamstringFX/model/Models.cs
  16. +15 −0 kcdc12/nancyfx/demo/HamstringFX/model/RunModel.cs
  17. +13 −0 kcdc12/nancyfx/demo/HamstringFX/modules/MainModule.cs
  18. +4 −1 kcdc12/nancyfx/demo/HamstringFX/modules/RunModule.cs
  19. BIN kcdc12/nancyfx/demo/HamstringFX/public/img/runner.png
  20. +49 −14 kcdc12/nancyfx/demo/HamstringFX/public/scripts/hamstringfx.js
  21. +18 −0 kcdc12/nancyfx/demo/HamstringFX/public/scripts/lib/postal.diagnostics.js
  22. +347 −0 kcdc12/nancyfx/demo/HamstringFX/public/scripts/lib/postal.js
  23. +12 −4 kcdc12/nancyfx/demo/HamstringFX/public/styles/hamstringfx.css
  24. +1 −1 kcdc12/nancyfx/demo/HamstringFX/views/_addrun.sshtml
  25. +5 −7 kcdc12/nancyfx/demo/HamstringFX/views/_announcements.sshtml
  26. +1 −1 kcdc12/nancyfx/demo/HamstringFX/views/_races.sshtml
  27. +1 −1 kcdc12/nancyfx/demo/HamstringFX/views/hamstring.sshtml
  28. +3 −5 kcdc12/nancyfx/demo/HamstringFX/views/master.sshtml
  29. BIN kcdc12/nancyfx/demo/gfx/runner-silhouette-transp.png
  30. +9 −1 kcdc12/nancyfx/demo/schema.sql
@@ -1,15 +1,19 @@
using System.Collections.Generic;
namespace HamstringFX.RaceService {
- class CliArgs {
+ public class CliArgs {
public CliArgs(IEnumerable<string> args) {
_args = new List<string>(args);
}
private readonly List<string> _args;
public bool LaunchBrowser {
- get { return _args.Contains("-b"); }
+ get { return _args.Contains("--browser"); }
+ }
+
+ public bool AlwaysUseCache {
+ get { return _args.Contains("--cached"); }
}
}
}
@@ -9,9 +9,10 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>HamstringFX.RaceService</RootNamespace>
- <AssemblyName>HamstringFX.RaceService</AssemblyName>
+ <AssemblyName>racesrv</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <TargetFrameworkProfile>
+ </TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
@@ -62,6 +63,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
+ <None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
@@ -10,7 +10,7 @@ class Program {
//TODO: discuss self hosting in slideshow
var uri = new Uri("http://localhost:8087/");
- var host = new NancyHost(uri);
+ var host = new NancyHost(uri, new RaceServiceBootstrapper(cliargs));
host.Start();
Console.WriteLine(String.Format("HamstringFX.RaceService now listening on {0}", uri.OriginalString));
@@ -23,8 +23,8 @@ class Program {
Console.ReadKey();
host.Stop();
+ Console.WriteLine();
Console.WriteLine("HamstringFX.RaceService terminated");
-
}
}
}
@@ -3,11 +3,16 @@
namespace HamstringFX.RaceService {
public class RaceServiceBootstrapper : DefaultNancyBootstrapper {
+ public RaceServiceBootstrapper(CliArgs args) {
+ _args = args;
+ }
+
+ private readonly CliArgs _args;
protected override void ConfigureApplicationContainer(TinyIoC.TinyIoCContainer container) {
base.ConfigureApplicationContainer(container);
- container.Register<IRaceData, RaceData>().AsSingleton();
+ container.Register<IRaceData>(new RaceData(_args.AlwaysUseCache));
}
}
}
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
@@ -97,5 +97,10 @@
<link>http://www.runningintheusa.com/Race/View.aspx?RaceID=53901</link>
<pubDate>4/3/2012 1:25:00 PM</pubDate>
</item>
+ <!-- dummy data for debugging -->
+ <item>
+ <title>Foo Race ~ Florissant, MO ~ Aug 13 2012</title>
+ <link>http://foorace.com</link>
+ </item>
</channel>
</rss>
@@ -7,10 +7,18 @@
namespace HamstringFX.RaceService.data {
public class RaceData : IRaceData {
- readonly IDataStream _remote = new RemoteRaceStream();
- readonly IDataStream _cached = new CachedRaceStream();
-
+ public RaceData(bool alwaysUseCache) {
+ _alwaysUseCache = alwaysUseCache;
+ }
+
+ private readonly bool _alwaysUseCache = false;
+ private readonly IDataStream _remote = new RemoteRaceStream();
+ private readonly IDataStream _cached = new CachedRaceStream();
+
public ICollection<Race> UpcomingRaces() {
+ if (_alwaysUseCache) {
+ return ReadRaces(_cached);
+ }
try {
return ReadRaces(_remote);
@@ -81,14 +81,16 @@
<Compile Include="data\HamstringData.cs" />
<Compile Include="data\HamstringUserIdentity.cs" />
<Compile Include="data\Member.cs" />
+ <Compile Include="data\Announcement.cs" />
<Compile Include="data\Playlist.cs" />
<Compile Include="data\Privilege.cs" />
<Compile Include="model\IRaceServiceProxy.cs" />
<Compile Include="model\MainModelFactory.cs" />
<Compile Include="model\PortalModelFactory.cs" />
<Compile Include="model\IModelFactory.cs" />
- <Compile Include="model\Race.cs" />
- <Compile Include="model\RaceServiceProxy.cs" />
+ <Compile Include="data\Race.cs" />
+ <Compile Include="data\RaceServiceProxy.cs" />
+ <Compile Include="model\RunModel.cs" />
<Compile Include="modules\MainModule.cs" />
<Compile Include="security\AuthenticationResult.cs" />
<Compile Include="security\IHashStrategy.cs" />
@@ -0,0 +1,15 @@
+using System;
+using System.ComponentModel.DataAnnotations;
+
+namespace HamstringFX.data {
+ public class Announcement {
+ [Key]
+ public Guid Id { get; set; }
+ public DateTime ReportedAt { get; set; }
+ public String Content { get; set; }
+
+ public String FormattedDate {
+ get { return ReportedAt.ToString("dddd, MM/dd/yyyy"); }
+ }
+ }
+}
@@ -9,7 +9,8 @@ public interface IHamstringData {
IDbSet<Run> Runs { get; set; }
IDbSet<Member> Members { get; set; }
IDbSet<Privilege> Privileges { get; set; }
- IDbSet<Playlist> Playlists { get; set; }
+ IDbSet<Playlist> Playlists { get; set; }
+ IDbSet<Announcement> Announcements { get; set; }
}
public class HamstringData : DbContext, IHamstringData {
@@ -18,5 +19,6 @@ public class HamstringData : DbContext, IHamstringData {
public IDbSet<Member> Members { get; set; }
public IDbSet<Privilege> Privileges { get; set; }
public IDbSet<Playlist> Playlists { get; set; }
+ public IDbSet<Announcement> Announcements { get; set; }
}
}
@@ -1,10 +1,14 @@
using System;
-namespace HamstringFX.model {
+namespace HamstringFX.data {
public class Race {
public String Name { get; set; }
public String Location { get; set; }
public DateTime ScheduledAt { get; set; }
public String URL { get; set; }
+
+ public String FormattedDate {
+ get { return ScheduledAt.ToString("MM/dd/yyyy"); }
+ }
}
}
@@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
using System.IO;
using System.Net;
+using HamstringFX.model;
using Nancy.Json;
-namespace HamstringFX.model {
+namespace HamstringFX.data {
class RaceServiceProxy : IRaceServiceProxy {
public RaceServiceProxy(String endpoint) {
_endpoint = endpoint;
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using HamstringFX.data;
namespace HamstringFX.model {
public interface IRaceServiceProxy {
@@ -1,16 +1,20 @@
using System.Linq;
+using HamstringFX.data;
namespace HamstringFX.model {
public class MainModelFactory : IModelFactory {
- public MainModelFactory(IRaceServiceProxy proxy) {
+ public MainModelFactory(IHamstringData db, IRaceServiceProxy proxy) {
+ _db = db;
_proxy = proxy;
}
+ private readonly IHamstringData _db;
private readonly IRaceServiceProxy _proxy;
public dynamic Create() {
return new {
- UpcomingRaces = _proxy.UpcomingRaces()
+ UpcomingRaces = _proxy.UpcomingRaces(),
+ Announcements = _db.Announcements.OrderByDescending(n => n.ReportedAt).ToList()
};
}
}
@@ -12,7 +12,7 @@ public sealed class Models {
private readonly IRaceServiceProxy _proxy;
public IModelFactory MainModel () {
- return new MainModelFactory(_proxy);
+ return new MainModelFactory(_db, _proxy);
}
public IModelFactory PortalModel (Member member) {
@@ -0,0 +1,15 @@
+using System;
+
+namespace HamstringFX.model {
+ public class RunModel {
+ public DateTime When { get; set; }
+ public Guid Where { get; set; }
+ public Int32 Hour { get; set; }
+ public Int32 Min { get; set; }
+ public Int32 Sec { get; set; }
+
+ public String Time {
+ get { return String.Format("{0}:{1}:{2}", Hour, Min, Sec); }
+ }
+ }
+}
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using HamstringFX.model;
using HamstringFX.security;
using Nancy;
@@ -8,8 +9,12 @@
namespace HamstringFX.modules {
public class MainModule : NancyModule {
+ private readonly Dictionary<String, dynamic> _cache = new Dictionary<string, dynamic>();
+
public MainModule (IMemberAuthentication auth, Models models) {
+
+
Get["/"] = routeParams => {
var model = models.MainModel().Create();
return View["hamstring.sshtml", model];
@@ -40,6 +45,14 @@ public class MainModule : NancyModule {
};
Get["/logout"] = routeParams => this.LogoutAndRedirect("~/");
+
+ //
+
+ Before += ctx => {
+ return null;
+ };
}
+
+
}
}
@@ -1,7 +1,9 @@
using System;
using System.Linq;
using HamstringFX.data;
+using HamstringFX.model;
using Nancy;
+using Nancy.ModelBinding;
using Nancy.Security;
namespace HamstringFX.modules {
@@ -19,7 +21,8 @@ public class RunModule : NancyModule {
Post["/run"] = p => {
try {
Guid newId = Guid.NewGuid();
-
+ var runModel = this.Bind<RunModel>();
+
return HttpStatusCode.OK;
} catch (Exception ex) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 636959d

Please sign in to comment.