1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Globalization ;
4
+ using System . Linq ;
5
+ using Exceptionless . Extensions ;
3
6
using Exceptionless . Models ;
4
7
using Exceptionless . Models . Data ;
5
8
@@ -185,6 +188,7 @@ public static void SetUserDescription(this Event ev, UserDescription description
185
188
/// <summary>
186
189
/// Sets the event geo coordinates. Can be either "lat,lon" or an IP address that will be used to auto detect the geo coordinates.
187
190
/// </summary>
191
+ /// <param name="ev">The event.</param>
188
192
/// <param name="coordinates">The event coordinates.</param>
189
193
public static void SetGeo ( this Event ev , string coordinates ) {
190
194
if ( String . IsNullOrWhiteSpace ( coordinates ) ) {
@@ -197,11 +201,11 @@ public static void SetGeo(this Event ev, string coordinates) {
197
201
else
198
202
throw new ArgumentException ( "Must be either lat,lon or an IP address." , "coordinates" ) ;
199
203
}
200
-
201
-
204
+
202
205
/// <summary>
203
206
/// Sets the event geo coordinates.
204
207
/// </summary>
208
+ /// <param name="ev">The event.</param>
205
209
/// <param name="latitude">The event latitude.</param>
206
210
/// <param name="longitude">The event longitude.</param>
207
211
public static void SetGeo ( this Event ev , double latitude , double longitude ) {
@@ -210,7 +214,70 @@ public static void SetGeo(this Event ev, double latitude, double longitude) {
210
214
if ( longitude < - 180.0 || longitude > 180.0 )
211
215
throw new ArgumentOutOfRangeException ( "longitude" , "Must be a valid longitude value between -180.0 and 180.0." ) ;
212
216
213
- ev . Geo = latitude . ToString ( "#0.0#######" ) + "," + longitude . ToString ( "#0.0#######" ) ;
217
+ ev . Geo = latitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) + "," + longitude . ToString ( "#0.0#######" , CultureInfo . InvariantCulture ) ;
218
+ }
219
+
220
+ /// <summary>
221
+ /// Adds one or more tags to the event.
222
+ /// </summary>
223
+ /// <param name="ev">The event.</param>
224
+ /// <param name="tags">The tags to be added to the event.</param>
225
+ public static void AddTags ( this Event ev , params string [ ] tags ) {
226
+ if ( tags == null || tags . Length == 0 )
227
+ return ;
228
+
229
+ ev . Tags . AddRange ( tags . Where ( t => ! String . IsNullOrWhiteSpace ( t ) ) . Select ( t => t . Trim ( ) ) ) ;
230
+ }
231
+
232
+ /// <summary>
233
+ /// Sets the event reference id.
234
+ /// </summary>
235
+ /// <param name="ev">The event.</param>
236
+ /// <param name="referenceId">The event reference id.</param>
237
+ public static void SetReferenceId ( this Event ev , string referenceId ) {
238
+ if ( ! IsValidIdentifier ( referenceId ) )
239
+ throw new ArgumentException ( "ReferenceId must contain between 8 and 100 alphanumeric or '-' characters." , "referenceId" ) ;
240
+
241
+ ev . ReferenceId = referenceId ;
242
+ }
243
+
244
+ /// <summary>
245
+ /// Returns the event reference id.
246
+ /// </summary>
247
+ /// <param name="ev">The event.</param>
248
+ /// <param name="name">Reference name</param>
249
+ /// <returns></returns>
250
+ public static string GetEventReference ( this Event ev , string name ) {
251
+ if ( ev == null || String . IsNullOrEmpty ( name ) )
252
+ return null ;
253
+
254
+ return ev . Data . GetString ( $ "@ref:{ name } ") ;
255
+ }
256
+
257
+ /// <summary>
258
+ /// Allows you to reference a parent event by its <seealso cref="Event.ReferenceId" /> property. This allows you to have parent and child relationships.
259
+ /// </summary>
260
+ /// <param name="ev">The event.</param>
261
+ /// <param name="name">Reference name</param>
262
+ /// <param name="id">The reference id that points to a specific event</param>
263
+ public static void SetEventReference ( this Event ev , string name , string id ) {
264
+ if ( String . IsNullOrEmpty ( name ) )
265
+ throw new ArgumentNullException ( "name" ) ;
266
+
267
+ if ( ! IsValidIdentifier ( id ) || String . IsNullOrEmpty ( id ) )
268
+ throw new ArgumentException ( "Id must contain between 8 and 100 alphanumeric or '-' characters." , "id" ) ;
269
+
270
+ ev . SetProperty ( String . Format ( "@ref:{0}" , name ) , id ) ;
271
+ }
272
+
273
+ private static bool IsValidIdentifier ( string value ) {
274
+ if ( value == null )
275
+ return true ;
276
+
277
+ if ( value . Length < 8 || value . Length > 100 )
278
+ return false ;
279
+
280
+ return value . IsValidIdentifier ( ) ;
214
281
}
215
282
216
283
/// <summary>
0 commit comments