Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<AssemblyName>Coderr.Server.Api.Client</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.1" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Coderr.Server.Api/Coderr.Server.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<NoWarn>1701;1702;1705;1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452'">
<Reference Include="System.Net.Http" />
Expand Down
2 changes: 1 addition & 1 deletion src/Server/Coderr.Server.App/Coderr.Server.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="ColorCode" Version="1.0.1">
<NoWarn>NU1701</NoWarn>
</PackageReference>
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="Griffin.Framework" Version="2.0.1" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Markdig" Version="0.14.9" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ namespace Coderr.Server.Domain.Core.Incidents.Events
/// </summary>
public class IncidentCreated
{
public IncidentCreated(int incidentId, string incidentDescription, string exceptionTypeName)
public IncidentCreated(int applicationId, int incidentId, string incidentDescription, string exceptionTypeName)
{
if (incidentDescription == null) throw new ArgumentNullException(nameof(incidentDescription));
if (exceptionTypeName == null) throw new ArgumentNullException(nameof(exceptionTypeName));
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
if (applicationId <= 0) throw new ArgumentOutOfRangeException(nameof(applicationId));
ApplicationId = applicationId;
IncidentId = incidentId;

var pos = incidentDescription.IndexOfAny(new[] {'\r', '\n'});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Coderr.Server.Infrastructure</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="Griffin.Framework" Version="2.0.1" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Coderr.Client.NetStd" Version="1.1.3" />
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="DotNetCqs.DependencyInjection.Microsoft" Version="1.0.0" />
<PackageReference Include="DotNetCqs.Queues.AdoNet" Version="1.0.6" />
<PackageReference Include="Griffin.Framework" Version="2.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
if (string.IsNullOrEmpty(_originConfiguration.Value?.ApiKey))
return;

if (e.Report.RemoteAddress == "::1")
return;
if (e.Report.RemoteAddress == "127.0.0.1")
// Random swedish IP for testing purposes
if (e.Report.RemoteAddress == "::1" || e.Report.RemoteAddress == "127.0.0.1")
e.Report.RemoteAddress = "94.254.57.227";

var errorOrigin = await LookupIpAddress(e);
await _repository.CreateAsync(errorOrigin, e.Incident.ApplicationId, e.Incident.Id, e.Report.Id);
}

private async Task<ErrorOrigin> LookupIpAddress(ReportAddedToIncident e)
{
var url = $"http://api.ipstack.com/{e.Report.RemoteAddress}?access_key={_originConfiguration.Value.ApiKey}";
var request = WebRequest.CreateHttp(url);
string json = "";
var json = "";
ErrorOrigin errorOrigin;
try
{
var response = await request.GetResponseAsync();
Expand All @@ -71,7 +77,7 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)

var lat = double.Parse(jsonObj["latitude"].Value<string>(), CultureInfo.InvariantCulture);
var lon = double.Parse(jsonObj["longitude"].Value<string>(), CultureInfo.InvariantCulture);
var cmd = new ErrorOrigin(e.Report.RemoteAddress, lon, lat)
errorOrigin = new ErrorOrigin(e.Report.RemoteAddress, lon, lat)
{
City = jsonObj["city"].ToString(),
CountryCode = jsonObj["country_code"].ToString(),
Expand All @@ -80,13 +86,13 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
RegionName = jsonObj["region_name"].ToString(),
ZipCode = jsonObj["zip"].ToString()
};

await _repository.CreateAsync(cmd, e.Incident.ApplicationId, e.Incident.Id, e.Report.Id);
}
catch (Exception exception)
{
_logger.Error($"Failed to store location for incident {e.Incident.Id}/report {e.Report.Id}: {json}", exception);
throw new InvalidOperationException($"Failed to call lookupService or parse the JSON: {json}.", exception);
}

return errorOrigin;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async Task Analyze(IMessageContext context, ErrorReportEntity report)
incident = BuildIncident(report);
_repository.CreateIncident(incident);

var evt = new IncidentCreated(incident.Id, incident.Description, incident.FullName)
var evt = new IncidentCreated(incident.ApplicationId, incident.Id, incident.Description, incident.FullName)
{
ApplicationVersion = applicationVersion
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="FluentAssertions" Version="5.2.0" />
<PackageReference Include="NSubstitute" Version="3.1.0" />
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>Coderr.Server.SqlServer</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetCqs" Version="2.0.9" />
<PackageReference Include="DotNetCqs" Version="2.0.10" />
<PackageReference Include="Griffin.Framework" Version="2.0.1" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<UserApplication[]> GetForUserAsync(int accountId)
if (accountId <= 0) throw new ArgumentOutOfRangeException(nameof(accountId));
using (var cmd = (DbCommand) _uow.CreateCommand())
{
cmd.CommandText = @"SELECT a.Id ApplicationId, a.Name ApplicationName, ApplicationMembers.Roles, a.NumberOfDevelopers
cmd.CommandText = @"SELECT a.Id ApplicationId, a.Name ApplicationName, ApplicationMembers.Roles, a.NumberOfFtes NumberOfDevelopers
FROM Applications a
JOIN ApplicationMembers ON (ApplicationMembers.ApplicationId = a.Id)
WHERE ApplicationMembers.AccountId = @userId
Expand Down
Loading