Created
April 20, 2012 17:09
-
-
Save mikeobrien/2430341 to your computer and use it in GitHub Desktop.
Download data convention
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DownloadDataModel | |
{ | |
public string Data { get; set; } | |
public string Filename { get; set; } | |
public string MimeType { get; set; } | |
} | |
public class DownloadDataBehavior : BasicBehavior | |
{ | |
private readonly IFubuRequest _request; | |
private readonly IOutputWriter _writer; | |
public DownloadDataBehavior(IOutputWriter writer, IFubuRequest request) | |
: base(PartialBehavior.Ignored) | |
{ | |
_writer = writer; | |
_request = request; | |
} | |
protected override DoNext performInvoke() | |
{ | |
var output = _request.Get<DownloadDataModel>(); | |
_writer.Write(output.MimeType, output.Data); | |
_writer.AppendHeader("Content-Disposition", "attachment; filename=" + output.Filename + ";"); | |
return DoNext.Continue; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DownloadDataConvention : ActionCallModification | |
{ | |
public DownloadDataConvention() | |
: base(call => call.AddToEnd(new OutputNode(typeof (DownloadDataBehavior))), "Adding download data behavior as the output node") | |
{ | |
Filters.Excludes.Add(call => call.HasAnyOutputBehavior()); | |
Filters.Includes.Add(call => call.OutputType().CanBeCastTo<DownloadDataModel>()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FubuConventions : FubuRegistry | |
{ | |
public FubuConventions() | |
{ | |
... | |
ApplyConvention<DownloadDataConvention>(); | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment