2011-09-08 22:31:32 -03:00
using System ;
using System.Collections.Generic ;
using System.Windows.Forms ;
using System.Net ;
using System.IO ;
using System.Text ;
2012-01-15 05:00:50 -04:00
using System.Threading ;
2011-09-08 22:31:32 -03:00
namespace ArdupilotMega
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main ( )
{
//System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
//System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Application . ThreadException + = new System . Threading . ThreadExceptionEventHandler ( Application_ThreadException ) ;
2011-11-08 09:22:07 -04:00
Application . Idle + = new EventHandler ( Application_Idle ) ;
2011-11-19 20:17:17 -04:00
//MessageBox.Show("NOTE: This version may break advanced mission scripting");
2011-11-18 10:33:44 -04:00
2012-01-09 20:16:10 -04:00
//Common.linearRegression();
2011-09-08 22:31:32 -03:00
Application . EnableVisualStyles ( ) ;
Application . SetCompatibleTextRenderingDefault ( false ) ;
2011-12-17 05:22:40 -04:00
try
{
2012-02-17 05:09:27 -04:00
System . Threading . Thread . CurrentThread . Name = "Base Thread" ;
2012-01-15 05:00:50 -04:00
Application . Run ( new MainV2 ( ) ) ;
2011-12-17 05:22:40 -04:00
}
catch ( Exception ex ) { Console . WriteLine ( ex . ToString ( ) ) ; }
2011-09-08 22:31:32 -03:00
}
2011-11-08 09:22:07 -04:00
static void Application_Idle ( object sender , EventArgs e )
{
//Console.WriteLine("Idle");
}
2011-09-08 22:31:32 -03:00
static void Application_ThreadException ( object sender , System . Threading . ThreadExceptionEventArgs e )
{
Exception ex = e . Exception ;
if ( ex . Message = = "The port is closed." ) {
MessageBox . Show ( "Serial connection has been lost" ) ;
return ;
}
if ( ex . Message = = "A device attached to the system is not functioning." )
{
MessageBox . Show ( "Serial connection has been lost" ) ;
return ;
}
if ( e . Exception . GetType ( ) = = typeof ( MissingMethodException ) )
{
MessageBox . Show ( "Please Update - Some older library dlls are causing problems\n" + e . Exception . Message ) ;
return ;
}
if ( e . Exception . GetType ( ) = = typeof ( ObjectDisposedException ) | | e . Exception . GetType ( ) = = typeof ( InvalidOperationException ) ) // something is trying to update while the form, is closing.
{
return ; // ignore
}
if ( e . Exception . GetType ( ) = = typeof ( FileNotFoundException ) | | e . Exception . GetType ( ) = = typeof ( BadImageFormatException ) ) // i get alot of error from people who click the exe from inside a zip file.
{
MessageBox . Show ( "You are missing some DLL's. Please extract the zip file somewhere. OR Use the update feature from the menu" ) ;
return ;
}
2012-02-24 07:39:02 -04:00
DialogResult dr = MessageBox . Show ( "An error has occurred\n" + ex . ToString ( ) + "\n\nReport this Error???" , "Send Error" , MessageBoxButtons . YesNo ) ;
2011-09-08 22:31:32 -03:00
if ( DialogResult . Yes = = dr )
{
try
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest . Create ( "http://vps.oborne.me/mail.php" ) ;
request . Timeout = 10000 ; // 10 sec
// Set the Method property of the request to POST.
request . Method = "POST" ;
// Create POST data and convert it to a byte array.
string postData = "message=" + Environment . OSVersion . VersionString + " " + System . Reflection . Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) + " " + Application . ProductVersion + " Exception " + ex . ToString ( ) . Replace ( '&' , ' ' ) . Replace ( '=' , ' ' ) + " Stack: " + ex . StackTrace . ToString ( ) . Replace ( '&' , ' ' ) . Replace ( '=' , ' ' ) ;
byte [ ] byteArray = Encoding . ASCII . GetBytes ( postData ) ;
// Set the ContentType property of the WebRequest.
request . ContentType = "application/x-www-form-urlencoded" ;
// Set the ContentLength property of the WebRequest.
request . ContentLength = byteArray . Length ;
// Get the request stream.
Stream dataStream = request . GetRequestStream ( ) ;
// Write the data to the request stream.
dataStream . Write ( byteArray , 0 , byteArray . Length ) ;
// Close the Stream object.
dataStream . Close ( ) ;
// Get the response.
WebResponse response = request . GetResponse ( ) ;
// Display the status.
Console . WriteLine ( ( ( HttpWebResponse ) response ) . StatusDescription ) ;
// Get the stream containing content returned by the server.
dataStream = response . GetResponseStream ( ) ;
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader ( dataStream ) ;
// Read the content.
string responseFromServer = reader . ReadToEnd ( ) ;
// Display the content.
Console . WriteLine ( responseFromServer ) ;
// Clean up the streams.
reader . Close ( ) ;
dataStream . Close ( ) ;
response . Close ( ) ;
}
catch { MessageBox . Show ( "Error sending Error report!! Youre most likerly are not on the internet" ) ; }
}
}
}
}