Skip to content

Commit 3cd4da0

Browse files
committed
General cleanup of the .NET source
1 parent 94ad6a1 commit 3cd4da0

File tree

10 files changed

+32
-58
lines changed

10 files changed

+32
-58
lines changed

Source/Extras/Logging/FileExceptionlessLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FileExceptionlessLog : IExceptionlessLog, IDisposable {
1515

1616
public FileExceptionlessLog(string filePath, bool append = false) {
1717
if (String.IsNullOrEmpty(filePath))
18-
throw new ArgumentNullException("filePath");
18+
throw new ArgumentNullException(nameof(filePath));
1919

2020
FilePath = filePath;
2121
_append = append;

Source/Extras/Storage/FolderObjectStorage.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public FolderObjectStorage(IDependencyResolver resolver, string folder) {
3131

3232
public T GetObject<T>(string path) where T : class {
3333
if (String.IsNullOrWhiteSpace(path))
34-
throw new ArgumentNullException("path");
34+
throw new ArgumentNullException(nameof(path));
3535

3636
try {
3737
var json = File.ReadAllText(Path.Combine(Folder, path));
@@ -64,7 +64,7 @@ public bool Exists(string path) {
6464

6565
public bool SaveObject<T>(string path, T value) where T : class {
6666
if (String.IsNullOrWhiteSpace(path))
67-
throw new ArgumentNullException("path");
67+
throw new ArgumentNullException(nameof(path));
6868

6969
string directory = Path.GetDirectoryName(Path.Combine(Folder, path));
7070
if (!Directory.Exists(directory))
@@ -84,9 +84,9 @@ public bool SaveObject<T>(string path, T value) where T : class {
8484

8585
public bool RenameObject(string oldpath, string newpath) {
8686
if (String.IsNullOrWhiteSpace(oldpath))
87-
throw new ArgumentNullException("oldpath");
87+
throw new ArgumentNullException(nameof(oldpath));
8888
if (String.IsNullOrWhiteSpace(newpath))
89-
throw new ArgumentNullException("newpath");
89+
throw new ArgumentNullException(nameof(newpath));
9090

9191
try {
9292
lock (_lockObject) {
@@ -101,7 +101,7 @@ public bool RenameObject(string oldpath, string newpath) {
101101

102102
public bool DeleteObject(string path) {
103103
if (String.IsNullOrWhiteSpace(path))
104-
throw new ArgumentNullException("path");
104+
throw new ArgumentNullException(nameof(path));
105105

106106
try {
107107
File.Delete(Path.Combine(Folder, path));

Source/Extras/Storage/IsolatedStorageObjectStorage.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public bool Exists(string path) {
8989

9090
public T GetObject<T>(string path) where T : class {
9191
if (String.IsNullOrWhiteSpace(path))
92-
throw new ArgumentNullException("path");
92+
throw new ArgumentNullException(nameof(path));
9393

9494
try {
9595
var json = Run.WithRetries(() => {
@@ -115,7 +115,7 @@ public T GetObject<T>(string path) where T : class {
115115

116116
public bool SaveObject<T>(string path, T value) where T : class {
117117
if (String.IsNullOrWhiteSpace(path))
118-
throw new ArgumentNullException("path");
118+
throw new ArgumentNullException(nameof(path));
119119

120120
EnsureDirectory(path);
121121

@@ -150,9 +150,9 @@ public bool SaveObject<T>(string path, T value) where T : class {
150150

151151
public bool RenameObject(string oldpath, string newpath) {
152152
if (String.IsNullOrWhiteSpace(oldpath))
153-
throw new ArgumentNullException("oldpath");
153+
throw new ArgumentNullException(nameof(oldpath));
154154
if (String.IsNullOrWhiteSpace(newpath))
155-
throw new ArgumentNullException("newpath");
155+
throw new ArgumentNullException(nameof(newpath));
156156

157157
try {
158158
lock (_lockObject) {
@@ -170,7 +170,7 @@ public bool RenameObject(string oldpath, string newpath) {
170170

171171
public bool DeleteObject(string path) {
172172
if (String.IsNullOrWhiteSpace(path))
173-
throw new ArgumentNullException("path");
173+
throw new ArgumentNullException(nameof(path));
174174

175175
try {
176176
lock (_lockObject) {

Source/Extras/Utility/Run.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public static void WithRetries(Action action, int attempts = 3, TimeSpan? retryI
1212

1313
public static T WithRetries<T>(Func<T> action, int attempts = 3, TimeSpan? retryInterval = null) {
1414
if (action == null)
15-
throw new ArgumentNullException("action");
15+
throw new ArgumentNullException(nameof(action));
1616

1717
if (!retryInterval.HasValue)
1818
retryInterval = TimeSpan.FromMilliseconds(new Random().Next(75, 125));

Source/Platforms/WebApi/ExceptionlessHandleErrorAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public virtual void OnHttpException(HttpActionExecutedContext actionExecutedCont
2828
public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) {
2929
ExceptionlessClient.Default.Configuration.Resolver.GetLog().Trace("ExecuteExceptionFilterAsync executing...");
3030
if (actionExecutedContext == null)
31-
throw new ArgumentNullException("actionExecutedContext");
31+
throw new ArgumentNullException(nameof(actionExecutedContext));
3232

3333
OnHttpException(actionExecutedContext, cancellationToken);
3434
return TaskExtensions.Completed();

Source/Platforms/WebApi/ExceptionlessWebApiPlugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void Run(EventPluginContext context) {
4848

4949
private static IPrincipal GetPrincipal(HttpRequestMessage request) {
5050
if (request == null)
51-
throw new ArgumentNullException("request");
51+
throw new ArgumentNullException(nameof(request));
5252

5353
const string RequestContextKey = "MS_RequestContext";
5454

Source/Platforms/WebApi/HttpRequestInfoCollector.cs

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,9 @@ public static RequestInfo Collect(HttpActionContext context, IEnumerable<string>
3636

3737
var exclusionList = exclusions as string[] ?? exclusions.ToArray();
3838
info.Cookies = context.Request.Headers.GetCookies().ToDictionary(exclusionList);
39-
40-
//if (context.Request.Form.Count > 0) {
41-
// info.PostData = context.Request.Form.AllKeys.Distinct().Where(k => !String.IsNullOrEmpty(k) && !_ignoredFormFields.Contains(k)).ToDictionary(k => k, k => {
42-
// try {
43-
// return context.Request.Form.Get(k);
44-
// } catch (Exception ex) {
45-
// return ex.Message;
46-
// }
47-
// });
48-
//} else if (context.Request.ContentLength > 0 && context.Request.ContentLength < 1024 * 4) {
49-
// try {
50-
// context.Request.InputStream.Position = 0;
51-
// using (var inputStream = new StreamReader(context.Request.InputStream)) {
52-
// info.PostData = inputStream.ReadToEnd();
53-
// }
54-
// } catch (Exception ex) {
55-
// info.PostData = "Error retrieving POST data: " + ex.Message;
56-
// }
57-
//} else if (context.Request.ContentLength > 0) {
58-
// string value = Math.Round(context.Request.ContentLength / 1024m, 0).ToString("N0");
59-
// info.PostData = String.Format("Data is too large ({0}) to be included.", value + "kb");
60-
//}
61-
6239
info.QueryString = context.Request.RequestUri.ParseQueryString().ToDictionary(exclusionList);
63-
40+
41+
// TODO Collect form data.
6442
return info;
6543
}
6644

@@ -78,8 +56,8 @@ private static Dictionary<string, string> ToDictionary(this IEnumerable<CookieHe
7856
var d = new Dictionary<string, string>();
7957

8058
foreach (CookieHeaderValue cookie in cookies) {
81-
foreach (CookieState innerCookie in cookie.Cookies.Where(k => !String.IsNullOrEmpty(k.Name) && !k.Name.AnyWildcardMatches(_ignoredCookies, true) && !k.Name.AnyWildcardMatches(exclusions, true))) {
82-
if (innerCookie != null && !d.ContainsKey(innerCookie.Name))
59+
foreach (CookieState innerCookie in cookie.Cookies.Where(k => !String.IsNullOrEmpty(k?.Name) && !k.Name.AnyWildcardMatches(_ignoredCookies, true) && !k.Name.AnyWildcardMatches(exclusions, true))) {
60+
if (!d.ContainsKey(innerCookie.Name))
8361
d.Add(innerCookie.Name, innerCookie.Value);
8462
}
8563
}
@@ -111,14 +89,12 @@ public static string GetClientIpAddress(this HttpRequestMessage request) {
11189
try {
11290
if (request.Properties.ContainsKey("MS_HttpContext")) {
11391
object context = request.Properties["MS_HttpContext"];
114-
if (context != null) {
115-
PropertyInfo webRequestProperty = context.GetType().GetProperty("Request");
116-
if (webRequestProperty != null) {
117-
object webRequest = webRequestProperty.GetValue(context, null);
118-
PropertyInfo userHostAddressProperty = webRequestProperty.PropertyType.GetProperty("UserHostAddress");
119-
if (userHostAddressProperty != null)
120-
return userHostAddressProperty.GetValue(webRequest, null) as string;
121-
}
92+
PropertyInfo webRequestProperty = context?.GetType().GetProperty("Request");
93+
if (webRequestProperty != null) {
94+
object webRequest = webRequestProperty.GetValue(context, null);
95+
PropertyInfo userHostAddressProperty = webRequestProperty.PropertyType.GetProperty("UserHostAddress");
96+
if (userHostAddressProperty != null)
97+
return userHostAddressProperty.GetValue(webRequest, null) as string;
12298
}
12399
}
124100

Source/Shared/Plugins/Default/EnvironmentInfoPlugin.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace Exceptionless.Plugins.Default {
77
[Priority(50)]
88
public class EnvironmentInfoPlugin : IEventPlugin {
99
public void Run(EventPluginContext context) {
10-
//TODO: This needs to be uncommented when the client is sending session start and end.
11-
if (context.Event.Data.ContainsKey(Event.KnownDataKeys.EnvironmentInfo)) // || context.Event.Type != Event.KnownTypes.SessionStart)
10+
if (context.Event.Data.ContainsKey(Event.KnownDataKeys.EnvironmentInfo))
1211
return;
1312

1413
try {

Source/Shared/Queue/DefaultEventQueue.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ public void Process() {
133133
}
134134

135135
private void OnProcessQueue(object state) {
136-
if (!IsQueueProcessingSuspended && !_processingQueue)
136+
if (IsQueueProcessingSuspended)
137+
return;
138+
139+
if (!_processingQueue)
137140
Process();
138141
}
139142

@@ -159,13 +162,9 @@ public void SuspendProcessing(TimeSpan? duration = null, bool discardFutureQueue
159162
} catch (Exception) { }
160163
}
161164

162-
private bool IsQueueProcessingSuspended {
163-
get { return _suspendProcessingUntil.HasValue && _suspendProcessingUntil.Value > DateTime.Now; }
164-
}
165+
private bool IsQueueProcessingSuspended => _suspendProcessingUntil.HasValue && _suspendProcessingUntil.Value > DateTime.Now;
165166

166-
private bool AreQueuedItemsDiscarded {
167-
get { return _discardQueuedItemsUntil.HasValue && _discardQueuedItemsUntil.Value > DateTime.Now; }
168-
}
167+
private bool AreQueuedItemsDiscarded => _discardQueuedItemsUntil.HasValue && _discardQueuedItemsUntil.Value > DateTime.Now;
169168

170169
public void Dispose() {
171170
if (_queueTimer == null)

Source/Tests/Utility/RandomEventGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public StackFrame GenerateStackFrame() {
234234
Event.KnownTypes.FeatureUsage,
235235
Event.KnownTypes.Log,
236236
Event.KnownTypes.NotFound,
237-
Event.KnownTypes.SessionEnd,
237+
Event.KnownTypes.SessionStart,
238238
Event.KnownTypes.SessionEnd
239239
};
240240

0 commit comments

Comments
 (0)