GUI/CrashReportForm.cs
author moel.mich
Sat, 24 Apr 2010 19:59:52 +0000
changeset 90 3333b29a1746
parent 86 b4f0f206173d
child 98 4775bffe6173
permissions -rw-r--r--
Implemented APIC based CPU enumeration (Issue 41).
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@86
    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@86
    72
        reportTextBox.Text = s.ToString();
moel@86
    73
      }
moel@86
    74
    }
moel@86
    75
moel@86
    76
    private void sendButton_Click(object sender, EventArgs e) {
moel@87
    77
      try {
moel@87
    78
        Version version = typeof(CrashReportForm).Assembly.GetName().Version;
moel@87
    79
        WebRequest request = WebRequest.Create(
moel@87
    80
          "http://openhardwaremonitor.org/report.php");
moel@87
    81
        request.Method = "POST";
moel@87
    82
        request.Timeout = 3000;
moel@87
    83
        request.ContentType = "application/x-www-form-urlencoded";
moel@86
    84
moel@87
    85
        string report =
moel@87
    86
          "version=" + HttpUtility.UrlEncode(version.ToString()) + "&" +
moel@87
    87
          "report=" + HttpUtility.UrlEncode(reportTextBox.Text +
moel@87
    88
          commentTextBox.Text);
moel@87
    89
        byte[] byteArray = Encoding.UTF8.GetBytes(report);
moel@87
    90
        request.ContentLength = byteArray.Length;
moel@87
    91
moel@87
    92
        Stream dataStream = request.GetRequestStream();
moel@87
    93
        dataStream.Write(byteArray, 0, byteArray.Length);
moel@86
    94
        dataStream.Close();
moel@87
    95
        try {
moel@87
    96
          WebResponse response = request.GetResponse();
moel@87
    97
          dataStream = response.GetResponseStream();
moel@87
    98
          StreamReader reader = new StreamReader(dataStream);
moel@87
    99
          string responseFromServer = reader.ReadToEnd();
moel@87
   100
          reader.Close();
moel@87
   101
          dataStream.Close();
moel@87
   102
          response.Close();
moel@87
   103
        } catch (WebException) {
moel@87
   104
        }
moel@87
   105
      } finally {
moel@87
   106
        Close();
moel@86
   107
      }
moel@86
   108
    }
moel@86
   109
  }  
moel@86
   110
}