Skip to content

Commit 0d58c1b

Browse files
committed
UI bug fixes and corrections
1 parent fc137eb commit 0d58c1b

File tree

29 files changed

+287
-135
lines changed

29 files changed

+287
-135
lines changed

src/Server/Coderr.Server.Api/Core/Incidents/Queries/GetIncidentResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public string Description
138138
public string ReportHashCode { get; private set; }
139139

140140
/// <summary>
141-
/// How the devs solved it.
141+
/// How the incident was solved (the last time)
142142
/// </summary>
143143
public string Solution { get; set; }
144144

src/Server/Coderr.Server.App/Modules/Geolocation/EventHandlers/StorePositionFromNewReport.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
4343
if (string.IsNullOrEmpty(e.Report.RemoteAddress))
4444
return;
4545

46-
e.Report.RemoteAddress = "155.4.14.41";
4746
if (e.Report.RemoteAddress == "::1")
4847
return;
4948
if (e.Report.RemoteAddress == "127.0.0.1")
50-
return;
49+
e.Report.RemoteAddress = "94.254.57.227";
5150

5251
var request = WebRequest.CreateHttp("http://freegeoip.net/json/" + e.Report.RemoteAddress);
5352
string json = "";

src/Server/Coderr.Server.App/Modules/Geolocation/IErrorOriginRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public interface IErrorOriginRepository
1515
/// <summary>
1616
/// Create a new entry
1717
/// </summary>
18-
/// <param name="origin">origin</param>
18+
/// <param name="entity">origin</param>
1919
/// <param name="applicationId">Application that we received a report for</param>
2020
/// <param name="incidentId">incident that the report belongs to</param>
2121
/// <param name="reportId">report received that we got a location for</param>
2222
/// <returns>task</returns>
2323
/// <exception cref="ArgumentNullException">origin</exception>
24-
Task CreateAsync(ErrorOrigin origin, int applicationId, int incidentId, int reportId);
24+
Task CreateAsync(ErrorOrigin entity, int applicationId, int incidentId, int reportId);
2525

2626
/// <summary>
2727
/// Find all origins for a specific incident

src/Server/Coderr.Server.App/Modules/Similarities/Domain/SimilarityCollection.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
44
using System.Linq;
5+
using codeRR.Server.Api.Core.Reports;
56

67
namespace codeRR.Server.App.Modules.Similarities.Domain
78
{
89
/// <summary>
9-
/// A collection corresponding to <see cref="ContextCollectionDTO" />, but where value usage have been analysed.
10+
/// A collection corresponding to <see cref="ContextCollectionDTO" />, but where value usage have been analyzed.
1011
/// </summary>
1112
[SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix",
1213
Justification = "Namespace is named 'Similarities'.")]
@@ -68,9 +69,19 @@ public void Add(string propertyName, object adaptedValue)
6869
if (propertyName == null) throw new ArgumentNullException("propertyName");
6970
if (adaptedValue == null) throw new ArgumentNullException("adaptedValue");
7071

71-
var item =
72-
_items.FirstOrDefault(
73-
x => x.PropertyName.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
72+
Similarity item = null;
73+
74+
// ReSharper disable once ForCanBeConvertedToForeach
75+
// ReSharper disable once LoopCanBeConvertedToQuery
76+
for (var i = 0; i < _items.Count; i++)
77+
{
78+
if (_items[i].PropertyName != propertyName)
79+
continue;
80+
81+
item = _items[i];
82+
break;
83+
}
84+
7485
if (item == null)
7586
{
7687
item = new Similarity(propertyName);

src/Server/Coderr.Server.App/Modules/Triggers/Domain/Collections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected CollectionMetadata()
7171
/// <param name="name">Property name</param>
7272
public void AddOrUpdateProperty(string name)
7373
{
74-
if (Properties.Any(x => x.Equals(name, StringComparison.OrdinalIgnoreCase)))
74+
if (Properties.Contains(name))
7575
return;
7676

7777
IsUpdated = true;

src/Server/Coderr.Server.Infrastructure/Configuration/Database/DatabaseStore.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace codeRR.Server.Infrastructure.Configuration.Database
1515
/// </remarks>
1616
public class DatabaseStore : ConfigurationStore
1717
{
18-
private readonly Dictionary<Type, Wrapper> _items = new Dictionary<Type, Wrapper>();
18+
private static readonly Dictionary<Type, Wrapper> _cachedItems = new Dictionary<Type, Wrapper>();
1919
private readonly Func<IDbConnection> _connectionFactory;
2020

2121
public DatabaseStore(Func<IDbConnection> connectionFactory)
@@ -30,13 +30,8 @@ public DatabaseStore(Func<IDbConnection> connectionFactory)
3030
/// <returns>Category if found; otherwise <c>null</c>.</returns>
3131
public override T Load<T>()
3232
{
33-
lock (_items)
34-
{
35-
if (_items.TryGetValue(typeof(T), out var t) && !t.HasExpired())
36-
{
37-
return (T)t.Value;
38-
}
39-
}
33+
if (TryGetCachedItem(out T tValue))
34+
return tValue;
4035

4136
var section = new T();
4237
using (var connection = OpenConnectionFor<T>())
@@ -99,7 +94,7 @@ public override void Store(IConfigurationSection section)
9994
}
10095

10196
/// <summary>
102-
/// Allow connections to be created by another peep.
97+
/// Allow connections to be created by another peep.
10398
/// </summary>
10499
/// <typeparam name="T"></typeparam>
105100
/// <returns>open connection</returns>
@@ -109,7 +104,7 @@ protected virtual IDbConnection OpenConnectionFor<T>()
109104
}
110105

111106
/// <summary>
112-
/// Allow connections to be created by another peep.
107+
/// Allow connections to be created by another peep.
113108
/// </summary>
114109
/// <param name="configClassType">A <c>IConfigurationSection</c> type</param>
115110
/// <returns>open connection</returns>
@@ -119,12 +114,27 @@ protected virtual IDbConnection OpenConnectionFor(Type configClassType)
119114
return _connectionFactory();
120115
}
121116

122-
private void SetCache(IConfigurationSection section)
117+
protected virtual void SetCache(IConfigurationSection section)
118+
{
119+
lock (_cachedItems)
120+
{
121+
_cachedItems[section.GetType()] = new Wrapper {AddedAtUtc = DateTime.UtcNow, Value = section};
122+
}
123+
}
124+
125+
protected virtual bool TryGetCachedItem<T>(out T tValue)
123126
{
124-
lock (_items)
127+
lock (_cachedItems)
125128
{
126-
_items[section.GetType()] = new Wrapper {AddedAtUtc = DateTime.UtcNow, Value = section};
129+
if (_cachedItems.TryGetValue(typeof(T), out var t) && !t.HasExpired())
130+
{
131+
tValue = (T) t.Value;
132+
return true;
133+
}
127134
}
135+
136+
tValue = default(T);
137+
return false;
128138
}
129139

130140
private class Wrapper

src/Server/Coderr.Server.ReportAnalyzer/Handlers/ProcessReportHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Task HandleAsync(IMessageContext context, ProcessReport message)
3434
{
3535
RemoteAddress = message.RemoteAddress
3636
};
37-
_analyzer.Analyze(context.Principal, entity);
37+
_analyzer.Analyze(context, entity);
3838
}
3939
catch (Exception ex)
4040
{

src/Server/Coderr.Server.ReportAnalyzer/Handlers/Reports/ReportAnalyzer.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Diagnostics;
33
using System.Linq;
4-
using System.Security.Claims;
54
using codeRR.Server.Api.Core.Incidents;
65
using codeRR.Server.Api.Core.Incidents.Events;
76
using codeRR.Server.Api.Core.Reports;
@@ -21,9 +20,9 @@ namespace codeRR.Server.ReportAnalyzer.Handlers.Reports
2120
[Component(Lifetime = Lifetime.Scoped)]
2221
public class ReportAnalyzer
2322
{
24-
private readonly IMessageBus _messageBus;
2523
private readonly HashCodeGenerator _hashCodeGenerator;
2624
private readonly ILog _logger = LogManager.GetLogger(typeof(ReportAnalyzer));
25+
private readonly IMessageBus _messageBus;
2726
private readonly IAnalyticsRepository _repository;
2827

2928
/// <summary>
@@ -32,7 +31,8 @@ public class ReportAnalyzer
3231
/// <param name="hashCodeGenerator">Used to identify is this is a new unique exception</param>
3332
/// <param name="messageBus">to publish the <see cref="ReportAddedToIncident" /> event</param>
3433
/// <param name="repository">repos</param>
35-
public ReportAnalyzer(HashCodeGenerator hashCodeGenerator, IMessageBus messageBus, IAnalyticsRepository repository)
34+
public ReportAnalyzer(HashCodeGenerator hashCodeGenerator, IMessageBus messageBus,
35+
IAnalyticsRepository repository)
3636
{
3737
_hashCodeGenerator = hashCodeGenerator;
3838
_messageBus = messageBus;
@@ -44,7 +44,7 @@ public ReportAnalyzer(HashCodeGenerator hashCodeGenerator, IMessageBus messageBu
4444
/// </summary>
4545
/// <param name="report">report</param>
4646
/// <exception cref="ArgumentNullException">report</exception>
47-
public void Analyze(ClaimsPrincipal user, ErrorReportEntity report)
47+
public void Analyze(IMessageContext context, ErrorReportEntity report)
4848
{
4949
if (report == null) throw new ArgumentNullException("report");
5050

@@ -96,7 +96,7 @@ public void Analyze(ClaimsPrincipal user, ErrorReportEntity report)
9696
{
9797
isReOpened = true;
9898
incident.ReOpen();
99-
_messageBus.SendAsync(user, new IncidentReOpened(incident.ApplicationId, incident.Id,
99+
context.SendAsync(new IncidentReOpened(incident.ApplicationId, incident.Id,
100100
incident.CreatedAtUtc));
101101
}
102102

@@ -123,7 +123,7 @@ public void Analyze(ClaimsPrincipal user, ErrorReportEntity report)
123123
sw.Start();
124124
_logger.Debug("Publishing now: " + report.ClientReportId);
125125
var e = new ReportAddedToIncident(summary, ConvertToCoreReport(report), isReOpened);
126-
_messageBus.SendAsync(user, e);
126+
context.SendAsync(e);
127127
if (sw.ElapsedMilliseconds > 200)
128128
_logger.Debug("Publish took " + sw.ElapsedMilliseconds);
129129
sw.Stop();
@@ -135,7 +135,6 @@ private IncidentBeingAnalyzed BuildIncident(ErrorReportEntity entity)
135135
return new IncidentBeingAnalyzed(entity);
136136

137137
if (entity.Exception.Name == "AggregateException")
138-
{
139138
try
140139
{
141140
var exception = entity.Exception;
@@ -151,15 +150,13 @@ private IncidentBeingAnalyzed BuildIncident(ErrorReportEntity entity)
151150
catch (Exception)
152151
{
153152
}
154-
}
155153

156154
if (entity.Exception.Name == "ReflectionTypeLoadException")
157-
{
158155
try
159156
{
160157
var item = JObject.Parse(entity.Exception.Everything);
161158
var i = new IncidentBeingAnalyzed(entity);
162-
var items = (JObject)item["LoaderExceptions"];
159+
var items = (JObject) item["LoaderExceptions"];
163160
var exception = items.First;
164161

165162

@@ -172,7 +169,6 @@ private IncidentBeingAnalyzed BuildIncident(ErrorReportEntity entity)
172169
catch (Exception)
173170
{
174171
}
175-
}
176172

177173
return new IncidentBeingAnalyzed(entity);
178174
}
@@ -210,9 +206,7 @@ private ReportDTO ConvertToCoreReport(ErrorReportEntity report)
210206
ReportVersion = "1"
211207
};
212208
if (report.Exception != null)
213-
{
214209
dto.Exception = ConvertToCoreException(report.Exception);
215-
}
216210
return dto;
217211
}
218212
}

src/Server/Coderr.Server.SqlServer/Core/Applications/ApplicationRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public async Task<Application> GetByIdAsync(int id)
108108
cmd.AddParameter("id", id);
109109
var item = await cmd.FirstOrDefaultAsync<Application>();
110110
if (item == null)
111-
throw new EntityNotFoundException(id.ToString(), cmd);
111+
throw new EntityNotFoundException("Failed to find application with id " + id, cmd);
112112

113113
return item;
114114
}

src/Server/Coderr.Server.SqlServer/Modules/Geolocation/ErrorOriginRepository.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ public ErrorOriginRepository(IAdoNetUnitOfWork unitOfWork)
1818
_unitOfWork = unitOfWork;
1919
}
2020

21-
public async Task CreateAsync(ErrorOrigin command, int applicationId, int incidentId, int reportId)
21+
public async Task CreateAsync(ErrorOrigin entity, int applicationId, int incidentId, int reportId)
2222
{
23+
if (entity == null) throw new ArgumentNullException(nameof(entity));
24+
if (applicationId <= 0) throw new ArgumentOutOfRangeException(nameof(applicationId));
25+
if (incidentId <= 0) throw new ArgumentOutOfRangeException(nameof(incidentId));
26+
if (reportId <= 0) throw new ArgumentOutOfRangeException(nameof(reportId));
27+
2328
using (var cmd = (DbCommand) _unitOfWork.CreateCommand())
2429
{
2530
cmd.CommandText = "SELECT Id FROM ErrorOrigins WHERE IpAddress = @ip";
26-
cmd.AddParameter("ip", command.IpAddress);
31+
cmd.AddParameter("ip", entity.IpAddress);
2732
var id = await cmd.ExecuteScalarAsync();
2833
if (id is int)
2934
{
@@ -37,16 +42,16 @@ public async Task CreateAsync(ErrorOrigin command, int applicationId, int incide
3742
cmd.CommandText = "INSERT INTO ErrorOrigins (IpAddress, CountryCode, CountryName, RegionCode, RegionName, City, ZipCode, Latitude, Longitude, CreatedAtUtc) "
3843
+
3944
"VALUES (@IpAddress, @CountryCode, @CountryName, @RegionCode, @RegionName, @City, @ZipCode, @Latitude, @Longitude, @CreatedAtUtc);select cast(SCOPE_IDENTITY() as int);";
40-
cmd.AddParameter("IpAddress", command.IpAddress);
41-
cmd.AddParameter("CountryCode", command.CountryCode);
42-
cmd.AddParameter("CountryName", command.CountryName);
43-
cmd.AddParameter("RegionCode", command.RegionCode);
44-
cmd.AddParameter("RegionName", command.RegionName);
45-
cmd.AddParameter("City", command.City);
46-
cmd.AddParameter("ZipCode", command.ZipCode);
45+
cmd.AddParameter("IpAddress", entity.IpAddress);
46+
cmd.AddParameter("CountryCode", entity.CountryCode);
47+
cmd.AddParameter("CountryName", entity.CountryName);
48+
cmd.AddParameter("RegionCode", entity.RegionCode);
49+
cmd.AddParameter("RegionName", entity.RegionName);
50+
cmd.AddParameter("City", entity.City);
51+
cmd.AddParameter("ZipCode", entity.ZipCode);
4752
//cmd.AddParameter("Point", SqlGeography.Point(command.Latitude, command.Longitude, 4326));
48-
cmd.AddParameter("Latitude", command.Latitude);
49-
cmd.AddParameter("Longitude", command.Longitude);
53+
cmd.AddParameter("Latitude", entity.Latitude);
54+
cmd.AddParameter("Longitude", entity.Longitude);
5055
cmd.AddParameter("CreatedAtUtc", DateTime.UtcNow);
5156
var id = (int) await cmd.ExecuteScalarAsync();
5257
await CreateReportInfoAsync(id, applicationId, incidentId, reportId);

0 commit comments

Comments
 (0)