1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Globalization ;
3
4
using System . Linq ;
4
5
using System . Net ;
5
6
using System . Net . Http ;
@@ -25,10 +26,10 @@ public DefaultSubmissionClient(ExceptionlessConfiguration config) {
25
26
26
27
public SubmissionResponse PostEvents ( IEnumerable < Event > events , ExceptionlessConfiguration config , IJsonSerializer serializer ) {
27
28
if ( ! config . IsValid )
28
- return new SubmissionResponse ( 500 , message : "Invalid client configuration settings" ) ;
29
+ return SubmissionResponse . InvalidClientConfig500 ;
29
30
30
31
string data = serializer . Serialize ( events ) ;
31
- string url = String . Format ( "{0}/events" , GetServiceEndPoint ( config ) ) ;
32
+ string url = $ " { GetServiceEndPoint ( config ) } /events" ;
32
33
33
34
HttpResponseMessage response ;
34
35
try {
@@ -44,19 +45,23 @@ public SubmissionResponse PostEvents(IEnumerable<Event> events, ExceptionlessCon
44
45
return new SubmissionResponse ( 500 , exception : ex ) ;
45
46
}
46
47
47
- int settingsVersion ;
48
- if ( Int32 . TryParse ( GetSettingsVersionHeader ( response . Headers ) , out settingsVersion ) )
48
+ if ( Int32 . TryParse ( GetSettingsVersionHeader ( response . Headers ) , out int settingsVersion ) )
49
49
SettingsManager . CheckVersion ( settingsVersion , config ) ;
50
50
51
- return new SubmissionResponse ( ( int ) response . StatusCode , GetResponseMessage ( response ) ) ;
51
+ var message = GetResponseMessage ( response ) ;
52
+ if ( ( int ) response . StatusCode == 200 && "OK" . Equals ( message , StringComparison . OrdinalIgnoreCase ) ) {
53
+ return SubmissionResponse . Ok200 ;
54
+ }
55
+
56
+ return new SubmissionResponse ( ( int ) response . StatusCode , message ) ;
52
57
}
53
58
54
59
public SubmissionResponse PostUserDescription ( string referenceId , UserDescription description , ExceptionlessConfiguration config , IJsonSerializer serializer ) {
55
60
if ( ! config . IsValid )
56
- return new SubmissionResponse ( 500 , message : "Invalid client configuration settings." ) ;
61
+ return SubmissionResponse . InvalidClientConfig500 ;
57
62
58
63
string data = serializer . Serialize ( description ) ;
59
- string url = String . Format ( "{0 }/events/by-ref/{1 }/user-description", GetServiceEndPoint ( config ) , referenceId ) ;
64
+ string url = $ " { GetServiceEndPoint ( config ) } /events/by-ref/{ referenceId } /user-description";
60
65
61
66
HttpResponseMessage response ;
62
67
try {
@@ -72,18 +77,22 @@ public SubmissionResponse PostUserDescription(string referenceId, UserDescriptio
72
77
return new SubmissionResponse ( 500 , exception : ex ) ;
73
78
}
74
79
75
- int settingsVersion ;
76
- if ( Int32 . TryParse ( GetSettingsVersionHeader ( response . Headers ) , out settingsVersion ) )
80
+ if ( Int32 . TryParse ( GetSettingsVersionHeader ( response . Headers ) , out int settingsVersion ) )
77
81
SettingsManager . CheckVersion ( settingsVersion , config ) ;
78
82
79
- return new SubmissionResponse ( ( int ) response . StatusCode , GetResponseMessage ( response ) ) ;
83
+ var message = GetResponseMessage ( response ) ;
84
+ if ( ( int ) response . StatusCode == 200 && "OK" . Equals ( message , StringComparison . OrdinalIgnoreCase ) ) {
85
+ return SubmissionResponse . Ok200 ;
86
+ }
87
+
88
+ return new SubmissionResponse ( ( int ) response . StatusCode , message ) ;
80
89
}
81
90
82
91
public SettingsResponse GetSettings ( ExceptionlessConfiguration config , int version , IJsonSerializer serializer ) {
83
92
if ( ! config . IsValid )
84
- return new SettingsResponse ( false , message : "Invalid client configuration settings." ) ;
93
+ return SettingsResponse . InvalidClientConfig ;
85
94
86
- string url = String . Format ( "{0 }/projects/config?v={1}" , GetConfigServiceEndPoint ( config ) , version ) ;
95
+ string url = $ " { GetConfigServiceEndPoint ( config ) } /projects/config?v={ version . ToString ( CultureInfo . InvariantCulture ) } " ;
87
96
88
97
HttpResponseMessage response ;
89
98
try {
@@ -95,14 +104,14 @@ public SettingsResponse GetSettings(ExceptionlessConfiguration config, int versi
95
104
}
96
105
97
106
if ( response != null && response . StatusCode == HttpStatusCode . NotModified )
98
- return new SettingsResponse ( false , message : "Settings have not been modified." ) ;
107
+ return SettingsResponse . NotModified ;
99
108
100
109
if ( response == null || response . StatusCode != HttpStatusCode . OK )
101
110
return new SettingsResponse ( false , message : String . Concat ( "Unable to retrieve configuration settings: " , GetResponseMessage ( response ) ) ) ;
102
111
103
112
var json = GetResponseText ( response ) ;
104
113
if ( String . IsNullOrWhiteSpace ( json ) )
105
- return new SettingsResponse ( false , message : "Invalid configuration settings." ) ;
114
+ return SettingsResponse . InvalidConfig ;
106
115
107
116
var settings = serializer . Deserialize < ClientConfiguration > ( json ) ;
108
117
return new SettingsResponse ( true , settings . Settings , settings . Version ) ;
@@ -112,7 +121,7 @@ public void SendHeartbeat(string sessionIdOrUserId, bool closeSession, Exception
112
121
if ( ! config . IsValid )
113
122
return ;
114
123
115
- string url = String . Format ( "{0 }/events/session/heartbeat?id={1 }&close={2}" , GetHeartbeatServiceEndPoint ( config ) , sessionIdOrUserId , closeSession ) ;
124
+ string url = $ " { GetHeartbeatServiceEndPoint ( config ) } /events/session/heartbeat?id={ sessionIdOrUserId } &close={ closeSession . ToString ( CultureInfo . InvariantCulture ) } " ;
116
125
try {
117
126
_client . Value . AddAuthorizationHeader ( config . ApiKey ) ;
118
127
_client . Value . GetAsync ( url ) . ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
@@ -157,12 +166,12 @@ protected virtual HttpClient CreateHttpClient(ExceptionlessConfiguration config)
157
166
}
158
167
159
168
#if NET45
160
- private bool Validate ( object sender , X509Certificate certificate , X509Chain chain , SslPolicyErrors sslPolicyErrors , Func < CertificateData , bool > callback ) {
169
+ private static bool Validate ( object sender , X509Certificate certificate , X509Chain chain , SslPolicyErrors sslPolicyErrors , Func < CertificateData , bool > callback ) {
161
170
var certData = new CertificateData ( sender , certificate , chain , sslPolicyErrors ) ;
162
171
return callback ( certData ) ;
163
172
}
164
173
#else
165
- private bool Validate ( HttpRequestMessage httpRequestMessage , X509Certificate2 certificate , X509Chain chain , SslPolicyErrors sslPolicyErrors , Func < CertificateData , bool > callback ) {
174
+ private static bool Validate ( HttpRequestMessage httpRequestMessage , X509Certificate2 certificate , X509Chain chain , SslPolicyErrors sslPolicyErrors , Func < CertificateData , bool > callback ) {
166
175
var certData = new CertificateData ( httpRequestMessage , certificate , chain , sslPolicyErrors ) ;
167
176
return callback ( certData ) ;
168
177
}
@@ -188,7 +197,7 @@ private string GetResponseMessage(HttpResponseMessage response) {
188
197
} catch { }
189
198
}
190
199
191
- return ! String . IsNullOrEmpty ( message ) ? message : $ "{ statusCode } { response . ReasonPhrase } ";
200
+ return ! String . IsNullOrEmpty ( message ) ? message : $ "{ statusCode . ToString ( CultureInfo . InvariantCulture ) } { response . ReasonPhrase } ";
192
201
}
193
202
194
203
private string GetResponseText ( HttpResponseMessage response ) {
0 commit comments