Skip to content

Commit 1bf8c17

Browse files
committed
Automatic code cleanup.
1 parent 4be3694 commit 1bf8c17

File tree

105 files changed

+1398
-1437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1398
-1437
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ csharp_indent_labels = one_less_than_current
117117
csharp_indent_switch_labels = true
118118

119119
# Space preferences
120-
csharp_space_after_cast = false
120+
csharp_space_after_cast = true
121121
csharp_space_after_colon_in_inheritance_clause = true
122122
csharp_space_after_comma = true
123123
csharp_space_after_dot = false

Diagnostics/PostSharp.Samples.Audit.Extended/ExtendedAuditRecord.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using PostSharp.Patterns.Diagnostics;
1+
using PostSharp.Patterns.Diagnostics;
42
using PostSharp.Patterns.Diagnostics.Audit;
3+
using System;
4+
using System.Collections.Generic;
55

66
namespace PostSharp.Samples.Audit.Extended
77
{

Diagnostics/PostSharp.Samples.Audit.Extended/ExtendedAuditRecordBuilder.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using PostSharp.Patterns.Diagnostics.Audit;
22
using PostSharp.Patterns.Diagnostics.Backends.Audit;
33
using PostSharp.Patterns.Diagnostics.Contexts;
4-
using PostSharp.Patterns.Diagnostics.RecordBuilders;
54
using PostSharp.Patterns.Formatters;
65
using PostSharp.Reflection;
76

Diagnostics/PostSharp.Samples.Audit.Extended/Program.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Linq;
2-
using System.Security.Principal;
3-
using PostSharp.Patterns.Diagnostics;
1+
using PostSharp.Patterns.Diagnostics;
42
using PostSharp.Patterns.Diagnostics.Audit;
3+
using System.Linq;
4+
using System.Security.Principal;
55

66
namespace PostSharp.Samples.Audit.Extended
77
{

Diagnostics/PostSharp.Samples.Audit/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.Security.Principal;
2-
using PostSharp.Patterns.Diagnostics.Audit;
1+
using PostSharp.Patterns.Diagnostics.Audit;
2+
using System.Security.Principal;
33

44
namespace PostSharp.Samples.Audit
55
{

Diagnostics/PostSharp.Samples.Logging.BusinessLogic/QueueProcessor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
1+
using PostSharp.Patterns.Diagnostics;
2+
using System;
23
using System.Threading;
3-
using PostSharp.Patterns.Diagnostics;
44
using static PostSharp.Patterns.Diagnostics.FormattedMessageBuilder;
55

66
namespace PostSharp.Samples.Logging.BusinessLogic
@@ -27,7 +27,7 @@ private static void ProcessItem(QueueItem item)
2727

2828
if (item.Id == 56)
2929
{
30-
logSource.Warning.Write( Formatted("The entity {id} has been marked for deletion.", item.Id));
30+
logSource.Warning.Write(Formatted("The entity {id} has been marked for deletion.", item.Id));
3131
activity.SetSuccess();
3232
return;
3333
}

Diagnostics/PostSharp.Samples.Logging.CustomBackend.ServiceStack/ServiceStackLoggingBackend.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
2-
using PostSharp.Patterns.Diagnostics;
1+
using PostSharp.Patterns.Diagnostics;
32
using PostSharp.Patterns.Diagnostics.Backends;
43
using PostSharp.Patterns.Diagnostics.RecordBuilders;
4+
using System;
55

66
namespace PostSharp.Samples.Logging.CustomBackend.ServiceStack
77
{

Diagnostics/PostSharp.Samples.Logging.CustomBackend.ServiceStack/ServiceStackLoggingTypeSource.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
2-
using PostSharp.Patterns.Diagnostics;
1+
using PostSharp.Patterns.Diagnostics;
32
using ServiceStack.Logging;
3+
using System;
44

55
namespace PostSharp.Samples.Logging.CustomBackend.ServiceStack
66
{

Diagnostics/PostSharp.Samples.Logging.Customization/CustomLoggingBackend.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Threading;
3-
using PostSharp.Patterns.Diagnostics;
1+
using PostSharp.Patterns.Diagnostics;
42
using PostSharp.Patterns.Diagnostics.Backends.Console;
53
using PostSharp.Patterns.Diagnostics.RecordBuilders;
64
using PostSharp.Patterns.Formatters;

Diagnostics/PostSharp.Samples.Logging.Customization/ExampleFormattable.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System;
2-
using PostSharp.Patterns.Formatters;
1+
using PostSharp.Patterns.Formatters;
2+
using System;
33
using IFormattable = PostSharp.Patterns.Formatters.IFormattable;
44

55
namespace PostSharp.Samples.Logging

Diagnostics/PostSharp.Samples.Logging.Customization/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private static void Main(string[] args)
2121
// Simulate some business logic.
2222
QueueProcessor.ProcessQueue(@".\Private$\SyncRequestQueue");
2323

24-
ExampleFormattable.Greet(new ExampleFormattable {FirstName = "Yuri", LastName = "Gagarin"});
24+
ExampleFormattable.Greet(new ExampleFormattable { FirstName = "Yuri", LastName = "Gagarin" });
2525
}
2626
}
2727
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Net.Http;
4-
using System.Runtime.Serialization;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using ClientExample;
1+
using ClientExample;
82
using PostSharp.Aspects;
93
using PostSharp.Patterns.Diagnostics;
104
using PostSharp.Patterns.Formatters;
115
using PostSharp.Serialization;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Net.Http;
9+
using System.Threading.Tasks;
1210
using static PostSharp.Patterns.Diagnostics.SemanticMessageBuilder;
1311

1412
// The following attribute intercepts all calls to the specified methods of HttpClient.
@@ -19,116 +17,116 @@
1917

2018
namespace ClientExample
2119
{
22-
[PSerializable]
23-
internal class InstrumentOutgoingRequestsAspect : MethodInterceptionAspect
20+
[PSerializable]
21+
internal class InstrumentOutgoingRequestsAspect : MethodInterceptionAspect
22+
{
23+
private static readonly LogSource logSource = LogSource.Get();
24+
25+
public override async Task OnInvokeAsync(MethodInterceptionArgs args)
2426
{
25-
private static readonly LogSource logSource = LogSource.Get();
27+
var http = (HttpClient) args.Instance;
28+
var verb = Trim(args.Method.Name, "Async");
2629

27-
public override async Task OnInvokeAsync(MethodInterceptionArgs args)
30+
using (var activity = logSource.Default.OpenActivity(Semantic(verb, ("Url", args.Arguments[0]))))
31+
{
32+
try
2833
{
29-
var http = (HttpClient) args.Instance;
30-
var verb = Trim(args.Method.Name, "Async");
34+
// TODO: this implementation conflicts with System.Diagnostics.Activity and therefore Application Insights.
35+
36+
37+
// Remove headers.
38+
http.DefaultRequestHeaders.Remove("Request-Id");
39+
http.DefaultRequestHeaders.Remove("Correlation-Context");
3140

32-
using (var activity = logSource.Default.OpenActivity(Semantic(verb, ("Url", args.Arguments[0]))))
41+
42+
// Set Request-Id header.
43+
http.DefaultRequestHeaders.Add("Request-Id", activity.Context.SyntheticId);
44+
45+
46+
// Generate the Correlation-Context header.
47+
UnsafeStringBuilder correlationContextBuilder = null;
48+
var propertyNames = new HashSet<string>();
49+
try
50+
{
51+
activity.Context.ForEachProperty((LoggingProperty property, object value, ref object _) =>
3352
{
34-
try
35-
{
36-
// TODO: this implementation conflicts with System.Diagnostics.Activity and therefore Application Insights.
37-
38-
39-
// Remove headers.
40-
http.DefaultRequestHeaders.Remove("Request-Id");
41-
http.DefaultRequestHeaders.Remove("Correlation-Context");
42-
43-
44-
// Set Request-Id header.
45-
http.DefaultRequestHeaders.Add("Request-Id", activity.Context.SyntheticId);
46-
47-
48-
// Generate the Correlation-Context header.
49-
UnsafeStringBuilder correlationContextBuilder = null;
50-
var propertyNames = new HashSet<string>();
51-
try
52-
{
53-
activity.Context.ForEachProperty((LoggingProperty property, object value, ref object _) =>
54-
{
55-
if (!property.IsBaggage || !propertyNames.Add(property.Name)) return;
56-
57-
if (correlationContextBuilder == null)
58-
{
59-
propertyNames = new HashSet<string>();
60-
correlationContextBuilder = new UnsafeStringBuilder(1024);
61-
}
62-
63-
if (correlationContextBuilder.Length > 0)
64-
{
65-
correlationContextBuilder.Append(", ");
66-
}
67-
68-
correlationContextBuilder.Append(property.Name);
69-
correlationContextBuilder.Append('=');
70-
71-
var formatter =
72-
property.Formatter ?? LoggingServices.Formatters.Get(value.GetType());
73-
74-
formatter.Write(correlationContextBuilder, value);
75-
});
76-
77-
if (correlationContextBuilder != null)
78-
{
79-
http.DefaultRequestHeaders.Add("Correlation-Context", correlationContextBuilder.ToString());
80-
}
81-
}
82-
finally
83-
{
84-
correlationContextBuilder?.Dispose();
85-
}
86-
87-
88-
var t = base.OnInvokeAsync(args);
89-
90-
// We need to call Suspend/Resume because we're calling LogActivity from an aspect and
91-
// aspects are not automatically enhanced.
92-
// In other code, this is done automatically.
93-
if (!t.IsCompleted)
94-
{
95-
activity.Suspend();
96-
try
97-
{
98-
await t;
99-
}
100-
finally
101-
{
102-
activity.Resume();
103-
}
104-
}
105-
106-
107-
var response = (HttpResponseMessage) args.ReturnValue;
108-
109-
110-
if (response.IsSuccessStatusCode)
111-
{
112-
activity.SetOutcome(LogLevel.Info, Semantic("Succeeded", ("StatusCode", response.StatusCode)));
113-
}
114-
else
115-
{
116-
activity.SetOutcome(LogLevel.Warning, Semantic("Failed", ("StatusCode", response.StatusCode)));
117-
}
118-
}
119-
catch (Exception e)
120-
{
121-
activity.SetException(e);
122-
throw;
123-
}
124-
finally
125-
{
126-
http.DefaultRequestHeaders.Remove("Request-Id");
127-
}
53+
if (!property.IsBaggage || !propertyNames.Add(property.Name)) return;
54+
55+
if (correlationContextBuilder == null)
56+
{
57+
propertyNames = new HashSet<string>();
58+
correlationContextBuilder = new UnsafeStringBuilder(1024);
59+
}
60+
61+
if (correlationContextBuilder.Length > 0)
62+
{
63+
correlationContextBuilder.Append(", ");
64+
}
65+
66+
correlationContextBuilder.Append(property.Name);
67+
correlationContextBuilder.Append('=');
68+
69+
var formatter =
70+
property.Formatter ?? LoggingServices.Formatters.Get(value.GetType());
71+
72+
formatter.Write(correlationContextBuilder, value);
73+
});
74+
75+
if (correlationContextBuilder != null)
76+
{
77+
http.DefaultRequestHeaders.Add("Correlation-Context", correlationContextBuilder.ToString());
12878
}
129-
}
79+
}
80+
finally
81+
{
82+
correlationContextBuilder?.Dispose();
83+
}
84+
85+
86+
var t = base.OnInvokeAsync(args);
87+
88+
// We need to call Suspend/Resume because we're calling LogActivity from an aspect and
89+
// aspects are not automatically enhanced.
90+
// In other code, this is done automatically.
91+
if (!t.IsCompleted)
92+
{
93+
activity.Suspend();
94+
try
95+
{
96+
await t;
97+
}
98+
finally
99+
{
100+
activity.Resume();
101+
}
102+
}
103+
130104

131-
private static string Trim(string s, string suffix)
132-
=> s.EndsWith(suffix) ? s.Substring(0, s.Length - suffix.Length) : s;
105+
var response = (HttpResponseMessage) args.ReturnValue;
106+
107+
108+
if (response.IsSuccessStatusCode)
109+
{
110+
activity.SetOutcome(LogLevel.Info, Semantic("Succeeded", ("StatusCode", response.StatusCode)));
111+
}
112+
else
113+
{
114+
activity.SetOutcome(LogLevel.Warning, Semantic("Failed", ("StatusCode", response.StatusCode)));
115+
}
116+
}
117+
catch (Exception e)
118+
{
119+
activity.SetException(e);
120+
throw;
121+
}
122+
finally
123+
{
124+
http.DefaultRequestHeaders.Remove("Request-Id");
125+
}
126+
}
133127
}
128+
129+
private static string Trim(string s, string suffix)
130+
=> s.EndsWith(suffix) ? s.Substring(0, s.Length - suffix.Length) : s;
131+
}
134132
}

0 commit comments

Comments
 (0)