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