Skip to content

Commit ba411d2

Browse files
committed
Corrected a bug for error description uploads
1 parent 34b7722 commit ba411d2

File tree

10 files changed

+139
-79
lines changed

10 files changed

+139
-79
lines changed

src/Server/Coderr.Server.SqlServer/Analysis/ScanForNewFeedback.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/Server/Coderr.Server.Web/Areas/Receiver/Controllers/FeedbackController.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
using System;
22
using System.Data.Common;
3+
using System.IO;
4+
using System.IO.Compression;
35
using System.Net;
46
using System.Net.Http;
57
using System.Security.Claims;
8+
using System.Text;
69
using System.Threading.Tasks;
10+
using System.Web;
711
using System.Web.Http;
12+
using codeRR.Client.Contracts;
813
using codeRR.Server.App.Core.Applications;
914
using codeRR.Server.Infrastructure;
1015
using codeRR.Server.ReportAnalyzer.LibContracts;
1116
using codeRR.Server.Web.Areas.Receiver.Helpers;
1217
using codeRR.Server.Web.Areas.Receiver.Models;
18+
using codeRR.Server.Web.Cqs;
19+
using codeRR.Server.Web.Infrastructure.Cqs;
1320
using DotNetCqs;
1421
using DotNetCqs.Queues;
1522
using Griffin.Data;
@@ -32,10 +39,16 @@ public FeedbackController(IMessageQueueProvider queueProvider, IApplicationRepos
3239
}
3340

3441
[HttpPost, Route("receiver/report/{appKey}/feedback")]
35-
public async Task<HttpResponseMessage> SupplyFeedback(string appKey, string sig, FeedbackModel model)
42+
public async Task<HttpResponseMessage> SupplyFeedback(string appKey, string sig)
3643
{
44+
45+
var json = await UnpackContent();
46+
3747
try
3848
{
49+
var ser = new CqsJsonNetSerializer();
50+
var model = (FeedbackDTO)ser.Deserialize(typeof(FeedbackDTO), json);
51+
3952
var app = await _applicationRepository.GetByKeyAsync(appKey);
4053
using (var session = _queue.BeginSession())
4154
{
@@ -57,11 +70,24 @@ public async Task<HttpResponseMessage> SupplyFeedback(string appKey, string sig,
5770
catch (Exception ex)
5871
{
5972
_logger.Warn(
60-
"Failed to submit feedback: " + JsonConvert.SerializeObject(new { appKey, model }),
73+
"Failed to submit feedback: " + JsonConvert.SerializeObject(new { appKey, json }),
6174
ex);
6275
}
6376

6477
return new HttpResponseMessage(HttpStatusCode.NoContent);
6578
}
79+
80+
private async Task<string> UnpackContent()
81+
{
82+
var ms = new MemoryStream();
83+
using (var zipStream = new GZipStream(HttpContext.Current.Request.InputStream, CompressionMode.Decompress))
84+
{
85+
await zipStream.CopyToAsync(ms);
86+
}
87+
88+
ms.Position = 0;
89+
var sr = new StreamReader(ms, Encoding.UTF8);
90+
return sr.ReadToEnd();
91+
}
6692
}
6793
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System.IO;
2+
using System.IO.Compression;
3+
using System.Net.Http;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace codeRR.Server.Web.Infrastructure
8+
{
9+
public class CompressedRequestHandler : DelegatingHandler
10+
{
11+
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
12+
CancellationToken cancellationToken)
13+
{
14+
if (IsRequetCompressed(request))
15+
request.Content = DecompressRequestContent(request);
16+
17+
return base.SendAsync(request, cancellationToken);
18+
}
19+
20+
private HttpContent DecompressRequestContent(HttpRequestMessage request)
21+
{
22+
// Read in the input stream, then decompress in to the output stream.
23+
// Doing this asynchronously, but not really required at this point
24+
// since we end up waiting on it right after this.
25+
Stream outputStream = new MemoryStream();
26+
Task task = request.Content.ReadAsStreamAsync()
27+
.ContinueWith(t =>
28+
{
29+
var inputStream = t.Result;
30+
var gzipStream = new GZipStream(inputStream, CompressionMode.Decompress);
31+
32+
gzipStream.CopyTo(outputStream);
33+
gzipStream.Dispose();
34+
35+
outputStream.Seek(0, SeekOrigin.Begin);
36+
});
37+
38+
// Wait for inputstream and decompression to complete. Would be nice
39+
// to not block here and work asynchronous when ready instead, but I couldn't
40+
// figure out how to do it in context of a DelegatingHandler.
41+
task.Wait();
42+
43+
// Save the original content
44+
var origContent = request.Content;
45+
46+
// Replace request content with the newly decompressed stream
47+
HttpContent newContent = new StreamContent(outputStream);
48+
49+
// Copy all headers from original content in to new one
50+
foreach (var header in origContent.Headers)
51+
newContent.Headers.Add(header.Key, header.Value);
52+
53+
return newContent;
54+
}
55+
56+
private bool IsRequetCompressed(HttpRequestMessage request)
57+
{
58+
if (request.Content.Headers.ContentEncoding != null &&
59+
request.Content.Headers.ContentEncoding.Contains("gzip"))
60+
return true;
61+
62+
return false;
63+
}
64+
}
65+
}

src/Server/Coderr.Server.Web/Infrastructure/Cqs/CqsJsonNetSerializer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66

77
namespace codeRR.Server.Web.Infrastructure.Cqs
88
{
9+
/// <summary>
10+
/// This serializer is used by the client/side and MAY NOT include type definitions.
11+
/// </summary>
912
internal class CqsJsonNetSerializer
1013
{
1114
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
1215
{
1316
NullValueHandling = NullValueHandling.Ignore,
17+
TypeNameHandling = TypeNameHandling.None,
1418
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
1519
ContractResolver = new IncludeNonPublicMembersContractResolver()
1620
};

src/Server/Coderr.Server.Web/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private static void ConfigureWebApi(IAppBuilder inner)
154154
SessionStore = new SessionStoreMediator()
155155
});
156156

157+
config.MessageHandlers.Add(new CompressedRequestHandler());
157158
config.DependencyResolver = GlobalConfiguration.Configuration.DependencyResolver;
158159
config.MapHttpAttributeRoutes();
159160
//config.Routes.MapHttpRoute(

src/Server/Coderr.Server.Web/Views/Feedback/Application.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
<div id="View row" style="width:100%">
2-
<div data-collection="Items">
3-
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-12">
1+
<style>
2+
.col {
3+
min-width: 20vw;
4+
}
5+
@media only screen and (max-width: 900px) {
6+
.col {
7+
min-width: 300px;
8+
}
9+
}
10+
</style>
11+
<div id="View row" style="width:100%">
12+
<div data-collection="Items" class="row">
13+
<div class="col">
414
<div class="card-box tilebox-one">
515
<h6 class="text-muted m-b-20" data-name="Title"></h6>
616
<div data-name="Message" style="padding-bottom: 10px; padding-top: 20px; text-align: left;">

src/Server/Coderr.Server.Web/Views/Feedback/Incident.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
<div id="row" style="width:100%">
1+
<style>
2+
.col {
3+
min-width: 20vw;
4+
}
5+
6+
@media only screen and (max-width: 900px) {
7+
.col {
8+
min-width: 300px;
9+
}
10+
}
11+
</style>
12+
<div id="row" style="width:100%">
213
<div data-collection="Items">
3-
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-12">
14+
<div class="col">
415
<div class="card-box tilebox-one">
516
<h6 class="text-muted m-b-20" data-name="Title"></h6>
617
<div data-name="Message" style="padding-bottom: 10px; padding-top: 20px; text-align: left;">

src/Server/Coderr.Server.Web/Views/Feedback/Overview.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
<div id="View row" style="width:100%">
1+
<style>
2+
.col {
3+
min-width: 20vw;
4+
}
5+
6+
@media only screen and (max-width: 900px) {
7+
.col {
8+
min-width: 300px;
9+
}
10+
}
11+
</style>
12+
<div id="View row" style="width:100%">
213
<div data-collection="Items">
3-
<div class="col-xl-2 col-lg-4 col-md-6 col-sm-12">
14+
<div class="col">
415
<div class="card-box tilebox-one">
516
<h6 class="text-muted m-b-20" data-name="Title"></h6>
617
<div data-name="Message" style="padding-bottom: 10px; padding-top: 20px; text-align: left;">

src/Server/Coderr.Server.Web/Web.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<configuration>
44
<appSettings>
5-
<add key="Configured" value="false" />
5+
<add key="Configured" value="true" />
66
<add key="ConfigurationKey" value="change_this_to_your_own_password_before_running_the_installer" />
77

88
</appSettings>

src/Server/Coderr.Server.Web/codeRR.Server.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@
305305
<Compile Include="Infrastructure\Auth\ApiKeyAuthenticator.cs" />
306306
<Compile Include="Infrastructure\Auth\AuthenticationFailureResult.cs" />
307307
<Compile Include="Infrastructure\Auth\SignalRAuthenticateAttribute.cs" />
308+
<Compile Include="Infrastructure\CompressedRequestHandler.cs" />
308309
<Compile Include="Infrastructure\Cqs\CqsJsonNetSerializer.cs" />
309310
<Compile Include="Infrastructure\Cqs\CqsObjectMapper.cs" />
310311
<Compile Include="Infrastructure\CustomerInfoProvider.cs" />

0 commit comments

Comments
 (0)