~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.LogReporting/LogReportingService.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
                {
64
64
                        ReportUnhandledException (ex, willShutDown, false);
65
65
                }
66
 
                
 
66
 
 
67
                static bool reporting;
 
68
 
67
69
                public static void ReportUnhandledException (Exception ex, bool willShutDown, bool silently)
68
70
                {
69
 
                        var oldReportCrashes = ReportCrashes;
70
 
                        
71
 
                        if (UnhandledErrorOccured != null && !silently)
72
 
                                ReportCrashes = UnhandledErrorOccured (ReportCrashes, ex, willShutDown);
73
 
                        
74
 
                        // If crash reporting has been explicitly disabled, disregard this crash
75
 
                        if (ReportCrashes.HasValue && !ReportCrashes.Value)
 
71
                        if (reporting)
76
72
                                return;
77
73
                        
78
 
                        byte[] data;
79
 
                        using (var stream = new MemoryStream ()) {
80
 
                                using (var writer = System.Xml.XmlWriter.Create (stream)) {
81
 
                                                writer.WriteStartElement ("CrashLog");
82
 
                                                writer.WriteAttributeString ("version", ServiceVersion);
83
 
                                                
84
 
                                                writer.WriteElementString ("SystemInformation", SystemInformation.ToText ());
85
 
                                                writer.WriteElementString ("Exception", ex.ToString ());
86
 
                                                
87
 
                                                writer.WriteEndElement ();
 
74
                        reporting = true;
 
75
                        try {
 
76
                                var oldReportCrashes = ReportCrashes;
 
77
                                
 
78
                                if (UnhandledErrorOccured != null && !silently)
 
79
                                        ReportCrashes = UnhandledErrorOccured (ReportCrashes, ex, willShutDown);
 
80
                                
 
81
                                // If crash reporting has been explicitly disabled, disregard this crash
 
82
                                if (ReportCrashes.HasValue && !ReportCrashes.Value)
 
83
                                        return;
 
84
                                
 
85
                                byte[] data;
 
86
                                using (var stream = new MemoryStream ()) {
 
87
                                        using (var writer = System.Xml.XmlWriter.Create (stream)) {
 
88
                                                        writer.WriteStartElement ("CrashLog");
 
89
                                                        writer.WriteAttributeString ("version", ServiceVersion);
 
90
                                                        
 
91
                                                        writer.WriteElementString ("SystemInformation", SystemInformation.GetTextDescription ());
 
92
                                                        writer.WriteElementString ("Exception", ex.ToString ());
 
93
                                                        
 
94
                                                        writer.WriteEndElement ();
 
95
                                                }
 
96
                                        data = stream.ToArray ();
 
97
                                }
 
98
                                
 
99
                                // Log to disk only if uploading fails.
 
100
                                var filename = string.Format ("{0}.{1}.{2}.crashlog", DateTime.UtcNow.ToString ("yyyy-MM-dd__HH-mm-ss"), SystemInformation.SessionUuid, Interlocked.Increment (ref CrashId));
 
101
                                ThreadPool.QueueUserWorkItem (delegate {
 
102
                                        if (!TryUploadReport (filename, data)) {
 
103
                                                if (!Directory.Exists (CrashLogDirectory))
 
104
                                                        Directory.CreateDirectory (CrashLogDirectory);
 
105
 
 
106
                                                File.WriteAllBytes (CrashLogDirectory.Combine (filename), data);
88
107
                                        }
89
 
                                data = stream.ToArray ();
90
 
                        }
91
 
                        
92
 
                        // Log to disk only if uploading fails.
93
 
                        var filename = string.Format ("{0}.{1}.{2}.crashlog", DateTime.UtcNow.ToString ("yyyy-MM-dd__HH-mm-ss"), SystemInformation.SessionUuid, Interlocked.Increment (ref CrashId));
94
 
                        ThreadPool.QueueUserWorkItem (delegate {
95
 
                                if (!TryUploadReport (filename, data)) {
96
 
                                        if (!Directory.Exists (CrashLogDirectory))
97
 
                                                Directory.CreateDirectory (CrashLogDirectory);
 
108
                                });
 
109
                                
 
110
                                //ensure we don't lose the setting
 
111
                                if (ReportCrashes != oldReportCrashes) {
 
112
                                        PropertyService.SaveProperties ();
 
113
                                }
98
114
 
99
 
                                        File.WriteAllBytes (CrashLogDirectory.Combine (filename), data);
100
 
                                }
101
 
                        });
102
 
                        
103
 
                        //ensure we don't lose the setting
104
 
                        if (ReportCrashes != oldReportCrashes) {
105
 
                                PropertyService.SaveProperties ();
 
115
                        } finally {
 
116
                                reporting = false;
106
117
                        }
107
118
                }
108
119