Example #1
0
		private static void RunApplication( object data )
		{
			try
			{
				bool verboseOff = (bool)( (object[]) data )[0];
				string oprFilename = (string) ( (object[]) data )[1];

				// check whether opr file exists
				if( oprFilename==null )
				{
					Console.WriteLine( "Error: -r switch was not specified." );
					_exitCode = 3;
					return;
				}

				FileInfo fileInfo = new FileInfo( oprFilename );
				if( !fileInfo.Exists )
				{
					Console.WriteLine( "Error: cannot find input file "+oprFilename );
					_exitCode = 4;
					return;
				}


				// open OPR
				CompositionManager composition = new CompositionManager();

				if( !verboseOff )
					Console.WriteLine( "Loading project file "+fileInfo.FullName+"..." );
				composition.LoadFromFile( fileInfo.FullName );


				// prepare listeners
				if( !verboseOff )
					Console.WriteLine( "Preparing listener(s)..." );
				ArrayList listOfListeners = new ArrayList();

				// logfile listener
				if( composition.LogToFile!=null && composition.LogToFile!="" )
				{
					// get composition file's directory to logfile is saved in same directory
					string logFileName = Utils.GetFileInfo( fileInfo.DirectoryName, composition.LogToFile ).FullName;
					LogFileListener logFileListener = new LogFileListener( composition.ListenedEventTypes, logFileName );
					listOfListeners.Add( logFileListener );
				}

				// console listener
				if( !verboseOff )
				{
					ConsoleListener consoleListener = new ConsoleListener( composition.ListenedEventTypes );
					listOfListeners.Add( consoleListener );
				}

				// create proxy listener
				ProxyListener proxyListener = new ProxyListener();
				proxyListener.Initialize( listOfListeners );

				// run simulation
				if( !verboseOff )
					Console.WriteLine( "Starting composition run..." );
				composition.Run( proxyListener, true );

				if( !verboseOff )
					Console.WriteLine( "Closing composition..." );
				composition.Release();

				_exitCode = 0;
			}
			catch( Exception e )
			{
				Console.WriteLine( "Exception occured: " + e.ToString() );
				_exitCode = -2;
				return;
			}
		}
Example #2
0
		private void menuDeployRun_Click(object sender, System.EventArgs e)
		{
			StopAllActions();
			
			_runProperties.PopulateDialog( _composition, _compositionFilename==null );
			DialogResult result = _runProperties.ShowDialog( this );

			UpdateTitle();

			if( result == DialogResult.OK )
			{
				// user decided to run the composition
							
				// ### prepare listeners
				ArrayList listOfListeners = new ArrayList();

				// progress bar
				ProgressBarListener progressBarListener = new ProgressBarListener( _composition.GetSimulationTimehorizon(), _runBox.ProgressBarRun );
				listOfListeners.Add( progressBarListener );

				// log file
				if( _composition.LogToFile!=null && _composition.LogToFile!="" )
				{
					// get composition file's directory to logfile is saved in same directory
					string logFileName;
					if( _compositionFilename!=null )
					{
						FileInfo compositionFileInfo = new FileInfo(_compositionFilename);
						FileInfo logFileInfo = Utils.GetFileInfo( compositionFileInfo.DirectoryName, _composition.LogToFile ); 
						logFileName = logFileInfo.FullName;
					}
					else
						logFileName = _composition.LogToFile;

					LogFileListener logFileListener = new LogFileListener( _composition.ListenedEventTypes, logFileName );
					listOfListeners.Add( logFileListener );
				}

				// list box
				if( _composition.ShowEventsInListbox )
				{
					ListViewListener listViewListener = new ListViewListener( _composition.ListenedEventTypes, _runBox.ListViewEvents, 400 );
					listOfListeners.Add( listViewListener );
				}

				const uint actionInterval = 200; // in milliseconds

				// ### create proxy listener and register other listeners to it
				IListener proxyListener;				
				if( _composition.RunInSameThread )
				{
					// DoEvents listener
					DoEventsListener doEventsListener = new DoEventsListener( actionInterval );
					listOfListeners.Add( doEventsListener );

					ProxyListener proxySingleThreadListener = new ProxyListener();
					proxySingleThreadListener.Initialize( listOfListeners );
					proxyListener = proxySingleThreadListener;
				}
				else
				{									
					ProxyMultiThreadListener proxyMultiThreadListener = new ProxyMultiThreadListener();
					proxyMultiThreadListener.Initialize( listOfListeners, _runBox.Timer, (int)actionInterval );
					proxyListener = proxyMultiThreadListener;					
				}				

				// ### populate and show run-dialog and run simulation from it					
				Invalidate();
				_runBox.PopuplateDialog( _composition, proxyListener );
				_runBox.Show( this ); // this fires simulation					
                while(_runBox.Visible)
                {
                    Application.DoEvents();
                }

                _composition.EditorMode = CompositionManager.EEditorMode.RunButNotReloaded;
                UpdateTitle();
                CompositionUpdateArea();
			}				
		}