@@ -493,53 +493,60 @@ public void Report(string reportUrl, string reportName) {
493
493
494
494
PromptToEnable ( ( ) => {
495
495
if ( ! Enabled ) return ;
496
-
497
- var uri = new Uri ( "http://ignore.host/" + reportUrl ) ;
498
- bool reported = false ;
499
- var path = String . Join ( "" , uri . Segments ) ;
500
- var queryPrefix =
501
- ConcatenateQueryStrings (
502
- ConcatenateQueryStrings ( uri . Query ,
503
- ConcatenateQueryStrings ( CommonQuery , BaseQuery ) ) , "scope=" ) ;
504
- var fragment = uri . Fragment ;
505
- if ( ! String . IsNullOrEmpty ( BasePath ) ) path = BasePath + path ;
506
- if ( ! String . IsNullOrEmpty ( BaseReportName ) ) reportName = BaseReportName + reportName ;
507
- // Strip all extraneous path separators.
508
- while ( path . Contains ( "//" ) ) path = path . Replace ( "//" , "/" ) ;
509
- foreach ( var cookie in
510
- new KeyValuePair < string , string > [ ] {
511
- new KeyValuePair < string , string > ( Cookie , queryPrefix + "project" ) ,
512
- new KeyValuePair < string , string > ( SystemCookie , queryPrefix + "system" )
513
- } ) {
514
- if ( String . IsNullOrEmpty ( cookie . Key ) ) continue ;
515
- // See https://developers.google.com/analytics/devguides/collection/protocol/v1
516
- var status = PortableWebRequest . DefaultInstance . Post (
517
- "http://www.google-analytics.com/collect" ,
518
- new [ ] {
519
- // Version
520
- new KeyValuePair < string , string > ( "v" , "1" ) ,
521
- // Tracking ID.
522
- new KeyValuePair < string , string > ( "tid" , trackingId ) ,
523
- // Client ID.
524
- new KeyValuePair < string , string > ( "cid" , cookie . Key ) ,
525
- // Hit type.
526
- new KeyValuePair < string , string > ( "t" , "pageview" ) ,
527
- // "URL" / string to report.
528
- new KeyValuePair < string , string > (
529
- "dl" , path + "?" + cookie . Value + fragment ) ,
530
- // Document title.
531
- new KeyValuePair < string , string > ( "dt" , reportName ) ,
532
- // Cache buster
533
- new KeyValuePair < string , string > ( "z" , random . Next ( ) . ToString ( ) )
534
- } ,
535
- null , null ) ;
536
- if ( status != null ) reported = true ;
537
- }
538
- if ( reported ) {
539
- logger . Log ( String . Format ( "Reporting analytics data: {0}{1}{2} '{3}'" , path ,
540
- String . IsNullOrEmpty ( queryPrefix ) ? "" : "?" + queryPrefix ,
541
- fragment , reportName ) ,
542
- level : LogLevel . Verbose ) ;
496
+ try {
497
+ var uri = new Uri ( "http://ignore.host/" + reportUrl ) ;
498
+ bool reported = false ;
499
+ var path = String . Join ( "" , uri . Segments ) ;
500
+ var queryPrefix =
501
+ ConcatenateQueryStrings (
502
+ ConcatenateQueryStrings ( uri . Query ,
503
+ ConcatenateQueryStrings ( CommonQuery , BaseQuery ) ) , "scope=" ) ;
504
+ var fragment = uri . Fragment ;
505
+ if ( ! String . IsNullOrEmpty ( BasePath ) ) path = BasePath + path ;
506
+ if ( ! String . IsNullOrEmpty ( BaseReportName ) ) reportName = BaseReportName + reportName ;
507
+ // Strip all extraneous path separators.
508
+ while ( path . Contains ( "//" ) ) path = path . Replace ( "//" , "/" ) ;
509
+ foreach ( var cookie in
510
+ new KeyValuePair < string , string > [ ] {
511
+ new KeyValuePair < string , string > ( Cookie , queryPrefix + "project" ) ,
512
+ new KeyValuePair < string , string > ( SystemCookie , queryPrefix + "system" )
513
+ } ) {
514
+ if ( String . IsNullOrEmpty ( cookie . Key ) ) continue ;
515
+ // See https://developers.google.com/analytics/devguides/collection/protocol/v1
516
+ var status = PortableWebRequest . DefaultInstance . Post (
517
+ "http://www.google-analytics.com/collect" ,
518
+ new [ ] {
519
+ // Version
520
+ new KeyValuePair < string , string > ( "v" , "1" ) ,
521
+ // Tracking ID.
522
+ new KeyValuePair < string , string > ( "tid" , trackingId ) ,
523
+ // Client ID.
524
+ new KeyValuePair < string , string > ( "cid" , cookie . Key ) ,
525
+ // Hit type.
526
+ new KeyValuePair < string , string > ( "t" , "pageview" ) ,
527
+ // "URL" / string to report.
528
+ new KeyValuePair < string , string > (
529
+ "dl" , path + "?" + cookie . Value + fragment ) ,
530
+ // Document title.
531
+ new KeyValuePair < string , string > ( "dt" , reportName ) ,
532
+ // Cache buster
533
+ new KeyValuePair < string , string > ( "z" , random . Next ( ) . ToString ( ) )
534
+ } ,
535
+ null , null ) ;
536
+ if ( status != null ) reported = true ;
537
+ }
538
+ if ( reported ) {
539
+ logger . Log ( String . Format ( "Reporting analytics data: {0}{1}{2} '{3}'" , path ,
540
+ String . IsNullOrEmpty ( queryPrefix ) ? "" : "?" + queryPrefix ,
541
+ fragment , reportName ) ,
542
+ level : LogLevel . Verbose ) ;
543
+ }
544
+ } catch ( Exception e ) {
545
+ // Make sure no exception thrown during analytics reporting will be raised to
546
+ // the main thread and interupt the process.
547
+ logger . Log ( String . Format (
548
+ "Failed to reporting analytics data due to exception: {0}" , e ) ,
549
+ level : LogLevel . Verbose ) ;
543
550
}
544
551
} ) ;
545
552
}
0 commit comments