Axiom.Demos.Browser.CommandLine.Program.Run C# (CSharp) Method

Run() public method

public Run ( ) : void
return void
        public void Run( )
        {
#if !(XBOX || XBOX360 || SILVERLIGHT)
            AxiomSortedCollection<string, DemoItem> demoList = new AxiomSortedCollection<string, DemoItem>();
#endif
            try
            {
#if !(XBOX || XBOX360 || SILVERLIGHT)
                if (_configure())
                {

                    Assembly demos = Assembly.LoadFrom("Axiom.Demos.dll");
                    Type[] demoTypes = demos.GetTypes();
                    Type techDemo = demos.GetType("Axiom.Demos.TechDemo");

                    foreach (Type demoType in demoTypes)
                    {
                        if (demoType.IsSubclassOf(techDemo))
                        {
                            demoList.Add(demoType.Name, new DemoItem(demoType.Name, demoType));
                        }
                    }

                    {
                        Type demoType;
                        int i = 1;
                        foreach (KeyValuePair<string, DemoItem> typeName in demoList)
                        {
                            Console.WriteLine("{0}) {1}", i++, typeName.Key);
                        }
                        Console.WriteLine("Enter the number of the demo that you want to run and press enter.");
                        while (true)
                        {
                            string line = Console.ReadLine();
                            int number = -1;
                            if (line != string.Empty)
                            {
                                number = int.Parse(line.Trim());
                            }
                            if (number < 1 || number > demoList.Count)
                                Console.WriteLine("The number of the demo game must be between 1 and {0}, the number of demos games available.", demoList.Count);
                            else
                            {
                                demoType = demoList.Values[number - 1].Demo;
                                break;
                            }
                        }

                        if (demoType != null)
                        {
                            using (TechDemo demo = (TechDemo)Activator.CreateInstance(demoType))
                            {
                                demo.SetupResources();
                                demo.Start();//show and start rendering
                            }//dispose of it when done
                        }
                    }

                }
#else
                            using ( TechDemo demo = (TechDemo)(new Axiom.Demos.SkyPlane()))
                            {
                                demo.Start();//show and start rendering
                            }//dispose of it when done
#endif
            }
            catch ( Exception caughtException )
            {
                LogManager.Instance.Write( BuildExceptionString( caughtException ) );
            }
        }

Usage Example

Example #1
0
 private static void Main( string[] args )
 {
     try
     {
         using ( Program main = new Program() )
         {
             main.Run();//show and start rendering
         }//dispose of it when done
     }
     catch ( Exception ex )
     {
         Console.WriteLine( BuildExceptionString( ex ) );
         Console.WriteLine( "An exception has occurred.  Press enter to continue..." );
         Console.ReadLine();
     }
 }