GUI/CrashReportForm.cs
author moel.mich
Fri, 14 May 2010 22:30:06 +0000
changeset 111 2b8a8cf92c3a
parent 98 4775bffe6173
child 128 cea5477b4d72
permissions -rw-r--r--
Added a user interface to configure certain sensors as hidden. This fixed Issue 53.
moel@86
     1
/*
moel@86
     2
  
moel@86
     3
  Version: MPL 1.1/GPL 2.0/LGPL 2.1
moel@86
     4
moel@86
     5
  The contents of this file are subject to the Mozilla Public License Version
moel@86
     6
  1.1 (the "License"); you may not use this file except in compliance with
moel@86
     7
  the License. You may obtain a copy of the License at
moel@86
     8
 
moel@86
     9
  http://www.mozilla.org/MPL/
moel@86
    10
moel@86
    11
  Software distributed under the License is distributed on an "AS IS" basis,
moel@86
    12
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
moel@86
    13
  for the specific language governing rights and limitations under the License.
moel@86
    14
moel@86
    15
  The Original Code is the Open Hardware Monitor code.
moel@86
    16
moel@86
    17
  The Initial Developer of the Original Code is 
moel@86
    18
  Michael Möller <m.moeller@gmx.ch>.
moel@86
    19
  Portions created by the Initial Developer are Copyright (C) 2009-2010
moel@86
    20
  the Initial Developer. All Rights Reserved.
moel@86
    21
moel@86
    22
  Contributor(s):
moel@86
    23
moel@86
    24
  Alternatively, the contents of this file may be used under the terms of
moel@86
    25
  either the GNU General Public License Version 2 or later (the "GPL"), or
moel@86
    26
  the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
moel@86
    27
  in which case the provisions of the GPL or the LGPL are applicable instead
moel@86
    28
  of those above. If you wish to allow use of your version of this file only
moel@86
    29
  under the terms of either the GPL or the LGPL, and not to allow others to
moel@86
    30
  use your version of this file under the terms of the MPL, indicate your
moel@86
    31
  decision by deleting the provisions above and replace them with the notice
moel@86
    32
  and other provisions required by the GPL or the LGPL. If you do not delete
moel@86
    33
  the provisions above, a recipient may use your version of this file under
moel@86
    34
  the terms of any one of the MPL, the GPL or the LGPL.
moel@86
    35
 
moel@86
    36
*/
moel@86
    37
moel@86
    38
using System;
moel@86
    39
using System.Collections.Generic;
moel@86
    40
using System.ComponentModel;
moel@86
    41
using System.Data;
moel@86
    42
using System.Drawing;
moel@86
    43
using System.IO;
moel@86
    44
using System.Net;
moel@86
    45
using System.Text;
moel@86
    46
using System.Web;
moel@86
    47
using System.Windows.Forms;
moel@86
    48
moel@86
    49
namespace OpenHardwareMonitor.GUI {
moel@86
    50
  public partial class CrashReportForm : Form {
moel@86
    51
moel@86
    52
    private Exception exception;
moel@86
    53
moel@86
    54
    public CrashReportForm() {
moel@86
    55
      InitializeComponent();
moel@86
    56
    }
moel@86
    57
moel@86
    58
    public Exception Exception {
moel@86
    59
      get { return exception; }
moel@86
    60
      set {
moel@86
    61
        exception = value;
moel@86
    62
        StringBuilder s = new StringBuilder();
moel@86
    63
        Version version = typeof(CrashReportForm).Assembly.GetName().Version;
moel@106
    64
        s.Append("Version: "); s.AppendLine(version.ToString());        
moel@86
    65
        s.AppendLine();
moel@86
    66
        s.AppendLine(exception.ToString());
moel@86
    67
        s.AppendLine();
moel@86
    68
        if (exception.InnerException != null) {
moel@86
    69
          s.AppendLine(exception.InnerException.ToString());
moel@86
    70
          s.AppendLine();
moel@86
    71
        }
moel@106
    72
        s.Append("Common Language Runtime: "); 
moel@106
    73
        s.AppendLine(Environment.Version.ToString());
moel@106
    74
        s.Append("Operating System: ");
moel@106
    75
        s.AppendLine(Environment.OSVersion.ToString());
moel@106
    76
        s.Append("Process Type: ");
moel@106
    77
        s.AppendLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
moel@106
    78
        reportTextBox.Text = s.ToString();        
moel@86
    79
      }
moel@86
    80
    }
moel@86
    81
moel@86
    82
    private void sendButton_Click(object sender, EventArgs e) {
moel@87
    83
      try {
moel@87
    84
        Version version = typeof(CrashReportForm).Assembly.GetName().Version;
moel@87
    85
        WebRequest request = WebRequest.Create(
moel@87
    86
          "http://openhardwaremonitor.org/report.php");
moel@87
    87
        request.Method = "POST";
moel@98
    88
        request.Timeout = 5000;
moel@87
    89
        request.ContentType = "application/x-www-form-urlencoded";
moel@86
    90
moel@87
    91
        string report =
moel@87
    92
          "version=" + HttpUtility.UrlEncode(version.ToString()) + "&" +
moel@106
    93
          "report=" + HttpUtility.UrlEncode(reportTextBox.Text) + "&" +
moel@106
    94
          "comment=" + HttpUtility.UrlEncode(commentTextBox.Text) + "&" +
moel@106
    95
          "email=" + HttpUtility.UrlEncode(emailTextBox.Text);
moel@87
    96
        byte[] byteArray = Encoding.UTF8.GetBytes(report);
moel@87
    97
        request.ContentLength = byteArray.Length;
moel@87
    98
moel@87
    99
        try {
moel@98
   100
          Stream dataStream = request.GetRequestStream();
moel@98
   101
          dataStream.Write(byteArray, 0, byteArray.Length);
moel@98
   102
          dataStream.Close();
moel@98
   103
moel@87
   104
          WebResponse response = request.GetResponse();
moel@87
   105
          dataStream = response.GetResponseStream();
moel@87
   106
          StreamReader reader = new StreamReader(dataStream);
moel@87
   107
          string responseFromServer = reader.ReadToEnd();
moel@87
   108
          reader.Close();
moel@87
   109
          dataStream.Close();
moel@87
   110
          response.Close();
moel@98
   111
moel@98
   112
          Close();
moel@87
   113
        } catch (WebException) {
moel@98
   114
          MessageBox.Show("Sending the crash report failed.", "Error", 
moel@98
   115
            MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@87
   116
        }
moel@98
   117
      } catch {
moel@86
   118
      }
moel@86
   119
    }
moel@86
   120
  }  
moel@86
   121
}