GUI/CrashReportForm.cs
author moel.mich
Mon, 07 Jun 2010 20:35:05 +0000
changeset 137 9ed52fa44ecf
parent 106 6d6683c2895b
permissions -rw-r--r--
Added support for a second miniNG on the T-Balancer bigNG.
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.Drawing;
moel@86
    42
using System.IO;
moel@86
    43
using System.Net;
moel@86
    44
using System.Text;
moel@86
    45
using System.Web;
moel@86
    46
using System.Windows.Forms;
moel@86
    47
moel@86
    48
namespace OpenHardwareMonitor.GUI {
moel@86
    49
  public partial class CrashReportForm : Form {
moel@86
    50
moel@86
    51
    private Exception exception;
moel@86
    52
moel@86
    53
    public CrashReportForm() {
moel@86
    54
      InitializeComponent();
moel@86
    55
    }
moel@86
    56
moel@86
    57
    public Exception Exception {
moel@86
    58
      get { return exception; }
moel@86
    59
      set {
moel@86
    60
        exception = value;
moel@86
    61
        StringBuilder s = new StringBuilder();
moel@86
    62
        Version version = typeof(CrashReportForm).Assembly.GetName().Version;
moel@106
    63
        s.Append("Version: "); s.AppendLine(version.ToString());        
moel@86
    64
        s.AppendLine();
moel@86
    65
        s.AppendLine(exception.ToString());
moel@86
    66
        s.AppendLine();
moel@86
    67
        if (exception.InnerException != null) {
moel@86
    68
          s.AppendLine(exception.InnerException.ToString());
moel@86
    69
          s.AppendLine();
moel@86
    70
        }
moel@106
    71
        s.Append("Common Language Runtime: "); 
moel@106
    72
        s.AppendLine(Environment.Version.ToString());
moel@106
    73
        s.Append("Operating System: ");
moel@106
    74
        s.AppendLine(Environment.OSVersion.ToString());
moel@106
    75
        s.Append("Process Type: ");
moel@106
    76
        s.AppendLine(IntPtr.Size == 4 ? "32-Bit" : "64-Bit");
moel@106
    77
        reportTextBox.Text = s.ToString();        
moel@86
    78
      }
moel@86
    79
    }
moel@86
    80
moel@86
    81
    private void sendButton_Click(object sender, EventArgs e) {
moel@87
    82
      try {
moel@87
    83
        Version version = typeof(CrashReportForm).Assembly.GetName().Version;
moel@87
    84
        WebRequest request = WebRequest.Create(
moel@87
    85
          "http://openhardwaremonitor.org/report.php");
moel@87
    86
        request.Method = "POST";
moel@98
    87
        request.Timeout = 5000;
moel@87
    88
        request.ContentType = "application/x-www-form-urlencoded";
moel@86
    89
moel@87
    90
        string report =
moel@87
    91
          "version=" + HttpUtility.UrlEncode(version.ToString()) + "&" +
moel@106
    92
          "report=" + HttpUtility.UrlEncode(reportTextBox.Text) + "&" +
moel@106
    93
          "comment=" + HttpUtility.UrlEncode(commentTextBox.Text) + "&" +
moel@106
    94
          "email=" + HttpUtility.UrlEncode(emailTextBox.Text);
moel@87
    95
        byte[] byteArray = Encoding.UTF8.GetBytes(report);
moel@87
    96
        request.ContentLength = byteArray.Length;
moel@87
    97
moel@87
    98
        try {
moel@98
    99
          Stream dataStream = request.GetRequestStream();
moel@98
   100
          dataStream.Write(byteArray, 0, byteArray.Length);
moel@98
   101
          dataStream.Close();
moel@98
   102
moel@87
   103
          WebResponse response = request.GetResponse();
moel@87
   104
          dataStream = response.GetResponseStream();
moel@87
   105
          StreamReader reader = new StreamReader(dataStream);
moel@87
   106
          string responseFromServer = reader.ReadToEnd();
moel@87
   107
          reader.Close();
moel@87
   108
          dataStream.Close();
moel@87
   109
          response.Close();
moel@98
   110
moel@98
   111
          Close();
moel@87
   112
        } catch (WebException) {
moel@98
   113
          MessageBox.Show("Sending the crash report failed.", "Error", 
moel@98
   114
            MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@87
   115
        }
moel@98
   116
      } catch {
moel@86
   117
      }
moel@86
   118
    }
moel@86
   119
  }  
moel@86
   120
}