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