GUI/ReportForm.cs
author StephaneLenclud
Sun, 03 Feb 2013 18:01:50 +0100
branchMiniDisplay
changeset 433 090259cfd699
parent 206 1fa8eddc24a7
permissions -rw-r--r--
Adding SoundGraphDisplay and SensorFrontView classes.
They were respectively based on SystemTray and SensorNotifyIcon.
SoundGraphDisplay is now able to load iMONDisplay.dll providing it lives on your PATH.
Adding option to sensor context menu for adding it into FrontView.
moel@150
     1
/*
moel@150
     2
 
moel@344
     3
  This Source Code Form is subject to the terms of the Mozilla Public
moel@344
     4
  License, v. 2.0. If a copy of the MPL was not distributed with this
moel@344
     5
  file, You can obtain one at http://mozilla.org/MPL/2.0/.
moel@150
     6
 
moel@344
     7
  Copyright (C) 2009-2010 Michael Möller <mmoeller@openhardwaremonitor.org>
moel@344
     8
	
moel@150
     9
*/
moel@150
    10
moel@150
    11
using System;
moel@150
    12
using System.Drawing;
moel@150
    13
using System.IO;
moel@150
    14
using System.Net;
moel@150
    15
using System.Text;
moel@150
    16
using System.Windows.Forms;
moel@150
    17
moel@150
    18
namespace OpenHardwareMonitor.GUI {
moel@150
    19
  public partial class ReportForm : Form {
moel@150
    20
moel@150
    21
    private string report;
moel@150
    22
moel@150
    23
    public ReportForm() {
moel@150
    24
      InitializeComponent();
moel@150
    25
      try {
moel@150
    26
        titleLabel.Font = new Font(SystemFonts.DefaultFont, FontStyle.Bold);      
moel@150
    27
        reportTextBox.Font = new Font(FontFamily.GenericMonospace,
moel@150
    28
          SystemFonts.DefaultFont.Size);
moel@150
    29
      } catch { }
moel@150
    30
    }
moel@150
    31
moel@150
    32
    public string Report {
moel@150
    33
      get { return report; }
moel@150
    34
      set { 
moel@150
    35
        report = value;
moel@150
    36
        reportTextBox.Text = report;
moel@150
    37
      }      
moel@150
    38
    }
moel@150
    39
moel@150
    40
    private void sendButton_Click(object sender, EventArgs e) {
moel@150
    41
      Version version = typeof(CrashForm).Assembly.GetName().Version;
moel@150
    42
      WebRequest request = WebRequest.Create(
moel@150
    43
        "http://openhardwaremonitor.org/report.php");
moel@150
    44
      request.Method = "POST";
moel@150
    45
      request.Timeout = 5000;
moel@150
    46
      request.ContentType = "application/x-www-form-urlencoded";
moel@150
    47
moel@150
    48
      string report =
moel@206
    49
        "type=hardware&" +
moel@206
    50
        "version=" + Uri.EscapeDataString(version.ToString()) + "&" +
moel@206
    51
        "report=" + Uri.EscapeDataString(reportTextBox.Text) + "&" +
moel@206
    52
        "comment=" + Uri.EscapeDataString(commentTextBox.Text) + "&" +
moel@206
    53
        "email=" + Uri.EscapeDataString(emailTextBox.Text);
moel@150
    54
      byte[] byteArray = Encoding.UTF8.GetBytes(report);
moel@150
    55
      request.ContentLength = byteArray.Length;
moel@150
    56
moel@150
    57
      try {
moel@150
    58
        Stream dataStream = request.GetRequestStream();
moel@150
    59
        dataStream.Write(byteArray, 0, byteArray.Length);
moel@150
    60
        dataStream.Close();
moel@150
    61
moel@150
    62
        WebResponse response = request.GetResponse();
moel@150
    63
        dataStream = response.GetResponseStream();
moel@150
    64
        StreamReader reader = new StreamReader(dataStream);
moel@150
    65
        string responseFromServer = reader.ReadToEnd();
moel@150
    66
        reader.Close();
moel@150
    67
        dataStream.Close();
moel@150
    68
        response.Close();
moel@150
    69
moel@150
    70
        Close();
moel@150
    71
      } catch (WebException) {
moel@150
    72
        MessageBox.Show("Sending the hardware report failed.", "Error",
moel@150
    73
          MessageBoxButtons.OK, MessageBoxIcon.Error);
moel@150
    74
      }
moel@150
    75
    }
moel@150
    76
  }  
moel@150
    77
}