2012-08-21 17:00:40 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Drawing ;
using System.Data ;
using System.Linq ;
using System.Text ;
using System.Windows.Forms ;
using System.IO ;
2015-02-21 14:53:11 +00:00
using System.Diagnostics ;
using System.Threading.Tasks ;
using System.Reflection ;
2012-08-21 17:00:40 +00:00
namespace AnxSampleBrowser
{
2012-09-08 08:40:36 +00:00
public partial class SampleDataHalfVisual : UserControl
2012-08-21 17:00:40 +00:00
{
private SampleData _source ;
private AnxSampleBrowser _parent ;
2015-02-21 14:53:11 +00:00
private StringBuilder _processOutput ;
2012-08-21 17:00:40 +00:00
2012-09-08 08:40:36 +00:00
public SampleDataHalfVisual ( SampleData source , AnxSampleBrowser parent )
2012-08-21 17:00:40 +00:00
{
InitializeComponent ( ) ;
2012-09-08 08:40:36 +00:00
2012-08-21 17:00:40 +00:00
//until error is gone
2012-09-08 08:40:36 +00:00
// _pImage.Visible = false;
2012-08-21 17:00:40 +00:00
_rDescription . ReadOnly = true ;
_parent = parent ;
_source = source ;
this . _lName . Text = _source . Name ;
this . _rDescription . Text = _source . Description ;
if ( source . ImagePath . Length > 0 )
{
Bitmap b = new Bitmap ( source . ImagePath ) ;
2012-09-08 08:40:36 +00:00
_pImage . BackgroundImage = b ;
2012-08-21 17:00:40 +00:00
}
2015-02-21 14:53:11 +00:00
_bOpen . Enabled = File . Exists ( Path . GetFullPath ( Path . Combine ( _parent . SamplePath , _source . ProjectPath ) ) ) ;
_bLaunch . Enabled = File . Exists ( Path . GetFullPath ( Path . Combine ( _parent . SamplePath , _source . ExecPath ) ) ) ;
}
public SampleData SampleData
{
get { return _source ; }
2012-08-21 17:00:40 +00:00
}
private void _bLaunch_Click ( object sender , EventArgs e )
{
2015-02-21 14:53:11 +00:00
LaunchExternal ( ) ;
}
private void _bOpen_Click ( object sender , EventArgs e )
{
Process . Start ( Path . GetFullPath ( _parent . SamplePath + _source . ProjectPath ) ) ;
}
private void LaunchExternal ( )
{
IntPtr handle = this . FindForm ( ) . Handle ;
_processOutput = new StringBuilder ( ) ;
2012-08-21 17:00:40 +00:00
try
{
2015-02-21 14:53:11 +00:00
Process process = new Process ( ) ;
ProcessStartInfo startInfo = new ProcessStartInfo ( Path . GetFullPath ( _parent . SamplePath + _source . ExecPath ) ) ;
startInfo . WorkingDirectory = Path . GetDirectoryName ( Path . GetFullPath ( _parent . SamplePath + _source . ExecPath ) ) ;
startInfo . ErrorDialog = true ;
startInfo . ErrorDialogParentHandle = handle ;
startInfo . RedirectStandardError = true ;
startInfo . UseShellExecute = false ;
process . StartInfo = startInfo ;
process . EnableRaisingEvents = true ;
process . Exited + = process_Exited ;
process . ErrorDataReceived + = process_ErrorDataReceived ;
process . Start ( ) ;
process . BeginErrorReadLine ( ) ;
2012-08-21 17:00:40 +00:00
}
catch ( Win32Exception ex )
{
2015-02-21 14:53:11 +00:00
MessageBox . Show ( "Can´ t find the specified file at " + _parent . SamplePath + _source . ExecPath + '\n' + '\n' + '\n' + ex . Message , "Sample file not found" ) ;
2012-08-21 17:00:40 +00:00
}
}
2015-02-21 14:53:11 +00:00
void process_ErrorDataReceived ( object sender , DataReceivedEventArgs e )
{
//Samples only output error data.
_processOutput . Append ( e . Data ) ;
}
2012-08-21 17:00:40 +00:00
2015-02-21 14:53:11 +00:00
void process_Exited ( object sender , EventArgs e )
{
Process process = ( Process ) sender ;
if ( process . ExitCode ! = 0 )
MessageBox . Show ( "Process " + Path . GetFileNameWithoutExtension ( process . StartInfo . FileName ) + " exited with code " + process . ExitCode + " and message: " + _processOutput . ToString ( ) , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2012-08-21 17:00:40 +00:00
}
}