Permalink
Browse files

VSOne demo changes

  • Loading branch information...
howarddierking committed Feb 6, 2012
1 parent a9f28a5 commit 6e26a561c87ac7c9cd3394d2cd0c5e2101760e05
@@ -1,10 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
using System.Net;
using System.Net.Http;
-using System.Text;
using System.Web.Http.Filters;
namespace RestBugs.Services.Infrastructure
@@ -16,11 +16,6 @@ public RazorHtmlMediaTypeFormatter()
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
}
- //protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext)
- //{
- // WriteStream(value, stream, contentHeaders);
- //}
-
protected override bool CanWriteType(Type type) {
return true;
}
@@ -1,40 +1,57 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
+using System.Diagnostics;
using System.IO;
-using System.Linq;
using System.Net.Http;
-using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RestBugs.Services.MessageHandlers
{
public class MessageLoggingMessageHandler : DelegatingHandler
{
- protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
- CancellationToken cancellationToken) {
- using (var requestStream = new MemoryStream()) {
- request.Content.CopyToAsync(requestStream).Wait();
- using (var requestStreamReader = new StreamReader(requestStream)) {
+ protected override Task<HttpResponseMessage> SendAsync(
+ HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ var requestStream = new MemoryStream();
+ return request.Content.CopyToAsync(requestStream).ContinueWith<Task<HttpResponseMessage>>(
+ t => {
+ if (t.Status != TaskStatus.RanToCompletion) {
+ TaskCompletionSource<HttpResponseMessage> tcs = new TaskCompletionSource<HttpResponseMessage>();
+ // Copy faulted or cancelled
+ return tcs.Task;
+ }
+
+ var requestStreamReader = new StreamReader(requestStream);
requestStream.Position = 0;
var readToEnd = requestStreamReader.ReadToEnd();
Debug.WriteLine(readToEnd);
- }
- }
- return base.SendAsync(request, cancellationToken).ContinueWith(task => {
- var resp = task.Result;
- using (var responseStream = new MemoryStream()) {
- resp.Content.CopyToAsync(responseStream).Wait();
- using (var responseStreamReader = new StreamReader(responseStream)) {
- responseStream.Position = 0;
- var readToEnd = responseStreamReader.ReadToEnd();
- Debug.WriteLine(readToEnd);
- }
- }
- return resp;
- });
+ // TODO: This is crappy, get NCL to help us clone HttpRequestMessage
+ requestStream.Position = 0;
+ request.Content = new StreamContent(requestStream);
+ requestStream = null;
+
+ return base.SendAsync(request, cancellationToken).ContinueWith(
+ tRes => {
+ var resp = tRes.Result;
+ var responseStream = new MemoryStream();
+ return resp.Content.CopyToAsync(responseStream).ContinueWith(
+ tResCopy => {
+ var responseStreamReader = new StreamReader(responseStream);
+ responseStream.Position = 0;
+ var responseText = responseStreamReader.ReadToEnd();
+ Debug.WriteLine(responseText);
+
+ responseStream.Position = 0;
+ resp.Content = new StreamContent(responseStream);
+ return resp;
+ });
+ }).Unwrap();
+ }).Unwrap().ContinueWith(innerTask => {
+ if (requestStream != null)
+ requestStream.Dispose();
+
+ return innerTask;
+ }).Unwrap();
}
}
}
@@ -41,7 +41,7 @@ public static class ServiceConfiguration
config.Formatters.Add(new TextBugsFormatter());
config.MessageHandlers.Add(new EtagMessageHandler());
- config.MessageHandlers.Add(new MessageLoggingMessageHandler());
+ //config.MessageHandlers.Add(new MessageLoggingMessageHandler());
var kernel = new StandardKernel();
kernel.Bind<IBugRepository>().To<StaticBugRepository>();
@@ -3,47 +3,54 @@
<title></title>
</head>
<body>
- <table border="1">
- <tr>
- <td>ID</td>
- <td>Name</td>
- <td>Status</td>
- <td>Priority</td>
- <td>Rank</td>
- <td>Assigned To</td>
- <td>History</td>
- <td>Item Link</td>
- <td>Resolve</td>
- </tr>
+ <table border="1">
+ <tr>
+ <td>ID</td>
+ <td>Name</td>
+ <td>Status</td>
+ <td>Priority</td>
+ <td>Rank</td>
+ <td>Assigned To</td>
+ <td>History</td>
+ <td>Item Link</td>
+ <td>Resolve</td>
+ </tr>
- @foreach (var item in @Model)
- {
- <tr class="bug-data">
- <td class="id">@item.Id</td>
- <td class="name">@item.Name</td>
- <td class="status">@item.Status</td>
- <td class="priority">@item.Priority</td>
- <td class="rank">@item.Rank</td>
- <td class="assignedTo">
- @*<form action="team/@item.AssignedTo.Id/bugs" method="post">
+ @foreach (var item in @Model)
+ {
+ <tr class="bug-data">
+ <td class="id">@item.Id</td>
+ <td class="name">@item.Name</td>
+ <td class="status">@item.Status</td>
+ <td class="priority">@item.Priority</td>
+ <td class="rank">@item.Rank</td>
+ <td class="assignedTo">
+ @*<form action="team/@item.AssignedTo.Id/bugs" method="post">
<input type="hidden" name="bugId" value="@item.Id" />
<input type="text" name="teamMemberId" value="" />
<input type="text" name="comments" value="" />
<input type="submit" value="Assign" />
</form>*@
- @LinkFromEntity(item.AssignedTo, "assignedTo")
- </td>
- <td>@LinkFromEntity("history", item, "history")</td>
- <td>@LinkFromEntity(item, "self")</td>
- <td>
- <form class="resolved" action="/bugs/resolved" method="post">
- <input type="hidden" name="id" value="@item.Id" />
- Comments <input type="text" name="comments" />
- <input type="submit" value="Resolve" />
- </form>
- </td>
- </tr>
- }
- </table>
+ @LinkFromEntity(item.AssignedTo, "assignedTo")
+ </td>
+ <td>@LinkFromEntity("history", item, "history")</td>
+ <td>@LinkFromEntity(item, "self")</td>
+ <td>
+ <form class="resolved" action="/bugs/resolved" method="post">
+ <input type="hidden" name="id" value="@item.Id" />
+ Comments <input type="text" name="comments" />
+ <input type="submit" value="Resolve" />
+ </form>
+ </td>
+ </tr>
+ }
+ </table>
+ <br/>
+ <a href="/" rel="root">Index</a><br/>
+ <a href="/bugs/pending" rel="pending bugs">Pending Bugs</a><br/>
+ <a href="/bugs/active" rel="active bugs">Active Bugs</a><br/>
+ <a href="/bugs/resolved" rel="resolved bugs">Resolved Bugs</a><br/>
+ <a href="/bugs/closed" rel="closed bugs">Closed Bugs</a><br/>
+ <a href="/team">Team</a>
</body>
</html>
@@ -3,31 +3,38 @@
<title></title>
</head>
<body>
- <table border="1">
- <tr>
- <td>ID</td>
- <td>Name</td>
- <td>Status</td>
- <td>Priority</td>
- <td>Rank</td>
- <td>Assigned To</td>
- <td>History</td>
- <td>Item Link</td>
- </tr>
-
- @foreach (var item in @Model)
- {
- <tr class="bug-data">
- <td class="id">@item.Id</td>
- <td class="name">@item.Name</td>
- <td class="status">@item.Status</td>
- <td class="priority">@item.Priority</td>
- <td class="rank">@item.Rank</td>
- <td class="assignedTo">@LinkFromEntity(item.AssignedTo, "assignedTo")</td>
- <td>@LinkFromEntity("history", item, "history")</td>
- <td>@LinkFromEntity(item, "self")</td>
+ <table border="1">
+ <tr>
+ <td>ID</td>
+ <td>Name</td>
+ <td>Status</td>
+ <td>Priority</td>
+ <td>Rank</td>
+ <td>Assigned To</td>
+ <td>History</td>
+ <td>Item Link</td>
</tr>
- }
- </table>
+
+ @foreach (var item in @Model)
+ {
+ <tr class="bug-data">
+ <td class="id">@item.Id</td>
+ <td class="name">@item.Name</td>
+ <td class="status">@item.Status</td>
+ <td class="priority">@item.Priority</td>
+ <td class="rank">@item.Rank</td>
+ <td class="assignedTo">@LinkFromEntity(item.AssignedTo, "assignedTo")</td>
+ <td>@LinkFromEntity("history", item, "history")</td>
+ <td>@LinkFromEntity(item, "self")</td>
+ </tr>
+ }
+ </table>
+ <br/>
+ <a href="/" rel="root">Index</a><br/>
+ <a href="/bugs/pending" rel="pending bugs">Pending Bugs</a><br/>
+ <a href="/bugs/active" rel="active bugs">Active Bugs</a><br/>
+ <a href="/bugs/resolved" rel="resolved bugs">Resolved Bugs</a><br/>
+ <a href="/bugs/closed" rel="closed bugs">Closed Bugs</a><br/>
+ <a href="/team">Team</a>
</body>
</html>
@@ -3,39 +3,46 @@
<title></title>
</head>
<body>
- <table border="1">
- <tr>
- <td>ID</td>
- <td>Name</td>
- <td>Status</td>
- <td>Priority</td>
- <td>Rank</td>
- <td>Assigned To</td>
- <td>History</td>
- <td>Item Link</td>
- <td>Activate</td>
- </tr>
-
- @foreach (var item in @Model)
- {
- <tr class="bug-data">
- <td class="id">@item.Id</td>
- <td class="name">@item.Name</td>
- <td class="status">@item.Status</td>
- <td class="priority">@item.Priority</td>
- <td class="rank">@item.Rank</td>
- <td class="assignedTo">@LinkFromEntity(item.AssignedTo, "assignedTo")</td>
- <td>@LinkFromEntity("history", item, "history")</td>
- <td>@LinkFromEntity(item, "self")</td>
- <td>
- <form class="active" action="/bugs/active" method="post">
- <input type="hidden" name="id" value="@item.Id" />
- Comments <input type="text" name="comments" />
- <input type="submit" value="activate" />
- </form>
- </td>
+ <table border="1">
+ <tr>
+ <td>ID</td>
+ <td>Name</td>
+ <td>Status</td>
+ <td>Priority</td>
+ <td>Rank</td>
+ <td>Assigned To</td>
+ <td>History</td>
+ <td>Item Link</td>
+ <td>Activate</td>
</tr>
- }
- </table>
+
+ @foreach (var item in @Model)
+ {
+ <tr class="bug-data">
+ <td class="id">@item.Id</td>
+ <td class="name">@item.Name</td>
+ <td class="status">@item.Status</td>
+ <td class="priority">@item.Priority</td>
+ <td class="rank">@item.Rank</td>
+ <td class="assignedTo">@LinkFromEntity(item.AssignedTo, "assignedTo")</td>
+ <td>@LinkFromEntity("history", item, "history")</td>
+ <td>@LinkFromEntity(item, "self")</td>
+ <td>
+ <form class="active" action="/bugs/active" method="post">
+ <input type="hidden" name="id" value="@item.Id" />
+ Comments <input type="text" name="comments" />
+ <input type="submit" value="activate" />
+ </form>
+ </td>
+ </tr>
+ }
+ </table>
+ <br/>
+ <a href="/" rel="root">Index</a><br/>
+ <a href="/bugs/pending" rel="pending bugs">Pending Bugs</a><br/>
+ <a href="/bugs/active" rel="active bugs">Active Bugs</a><br/>
+ <a href="/bugs/resolved" rel="resolved bugs">Resolved Bugs</a><br/>
+ <a href="/bugs/closed" rel="closed bugs">Closed Bugs</a><br/>
+ <a href="/team">Team</a>
</body>
</html>
Oops, something went wrong.

0 comments on commit 6e26a56

Please sign in to comment.