A ILogOutput">Log output that uses a
Inheritance: ILogOutput
Ejemplo n.º 1
0
        public void AfterTest(TestDetails details)
        {
            Console.WriteLine("----- Beginning Duality environment teardown -----");

            // Remove NUnit Console logs
            Log.RemoveGlobalOutput(this.consoleLogOutput);
            this.consoleLogOutput = null;

            if (this.dummyWindow != null)
            {
                ContentProvider.ClearContent();
                ContentProvider.DisposeDefaultContent();
                this.dummyWindow.Dispose();
                this.dummyWindow = null;
            }
            DualityApp.Terminate();
            Environment.CurrentDirectory = this.oldEnvDir;

            // Save local testing memory
            if (TestContext.CurrentContext.Result.Status == TestStatus.Passed && !System.Diagnostics.Debugger.IsAttached)
            {
                Serializer.WriteObject(TestHelper.LocalTestMemory, TestHelper.LocalTestMemoryFilePath, SerializeMethod.Xml);
            }

            Console.WriteLine("----- Duality environment teardown complete -----");
        }
Ejemplo n.º 2
0
		public void BeforeTest(TestDetails details)
		{
			Console.WriteLine("----- Beginning Duality Editor environment setup -----");

			// Set environment directory to Duality binary directory
			this.oldEnvDir = Environment.CurrentDirectory;
			string codeBaseURI = typeof(DualityEditorApp).Assembly.CodeBase;
			string codeBasePath = codeBaseURI.StartsWith("file:") ? codeBaseURI.Remove(0, "file:".Length) : codeBaseURI;
			codeBasePath = codeBasePath.TrimStart('/');
			Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

			// Add some Console logs manually for NUnit
			if (!Log.Core.Outputs.OfType<TextWriterLogOutput>().Any(o => o.Target == Console.Out))
			{
				if (this.consoleLogOutput == null) this.consoleLogOutput = new TextWriterLogOutput(Console.Out);
				Log.AddGlobalOutput(this.consoleLogOutput);
			}

			// Create a dummy window for the editor
			if (this.dummyWindow == null)
				this.dummyWindow = new MainForm();

			// Initialize the Duality Editor
			DualityEditorApp.Init(this.dummyWindow, false);

			Console.WriteLine("----- Duality Editor environment setup complete -----");
		}
Ejemplo n.º 3
0
		public void BeforeTest(TestDetails details)
		{
			Console.WriteLine("----- Beginning Duality environment setup -----");

			// Set environment directory to Duality binary directory
			this.oldEnvDir = Environment.CurrentDirectory;
			string codeBaseURI = typeof(DualityApp).Assembly.CodeBase;
			string codeBasePath = codeBaseURI.StartsWith("file:") ? codeBaseURI.Remove(0, "file:".Length) : codeBaseURI;
			codeBasePath = codeBasePath.TrimStart('/');
			Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

			// Add some Console logs manually for NUnit
			if (!Log.Core.Outputs.OfType<TextWriterLogOutput>().Any(o => o.Target == Console.Out))
			{
				if (this.consoleLogOutput == null) this.consoleLogOutput = new TextWriterLogOutput(Console.Out);
				Log.AddGlobalOutput(this.consoleLogOutput);
			}

			// Initialize Duality
			DualityApp.Init(
				DualityApp.ExecutionEnvironment.Launcher, 
				DualityApp.ExecutionContext.Game, 
				new DefaultPluginLoader(),
				null);

			// Manually register pseudo-plugin for the Unit Testing Assembly
			this.unitTestPlugin = DualityApp.LoadPlugin(typeof(DualityTestsPlugin).Assembly, codeBasePath);

			// Create a dummy window, to get access to all the device contexts
			if (this.dummyWindow == null)
			{
				WindowOptions options = new WindowOptions
				{
					Width = 800,
					Height = 600
				};
				this.dummyWindow = DualityApp.OpenWindow(options);
			}

			// Load local testing memory
			TestHelper.LocalTestMemory = Serializer.TryReadObject<TestMemory>(TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer));

			Console.WriteLine("----- Duality environment setup complete -----");
		}
Ejemplo n.º 4
0
		public void AfterTest(TestDetails details)
		{
			Console.WriteLine("----- Beginning Duality Editor environment teardown -----");
			
			// Remove NUnit Console logs
			Log.RemoveGlobalOutput(this.consoleLogOutput);
			this.consoleLogOutput = null;

			if (this.dummyWindow != null)
			{
				ContentProvider.ClearContent();
				ContentProvider.DisposeDefaultContent();
			    this.dummyWindow.Dispose();
			    this.dummyWindow = null;
			}

			DualityEditorApp.Terminate(false);
			Environment.CurrentDirectory = this.oldEnvDir;

			Console.WriteLine("----- Duality Editor environment teardown complete -----");
		}
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.InvariantCulture;

            bool isDebugging = System.Diagnostics.Debugger.IsAttached || args.Contains(DualityApp.CmdArgDebug);
            bool isRunFromEditor = args.Contains(DualityApp.CmdArgEditor);
            bool isProfiling = args.Contains(DualityApp.CmdArgProfiling);
            if (isDebugging || isRunFromEditor) ShowConsole();

            // Set up console logging
            Log.AddGlobalOutput(new ConsoleLogOutput());

            // Set up file logging
            StreamWriter logfileWriter = null;
            TextWriterLogOutput logfileOutput = null;
            try
            {
                logfileWriter = new StreamWriter("logfile.txt");
                logfileWriter.AutoFlush = true;
                logfileOutput = new TextWriterLogOutput(logfileWriter);
                Log.AddGlobalOutput(logfileOutput);
            }
            catch (Exception e)
            {
                Log.Core.WriteWarning("Text Logfile unavailable: {0}", Log.Exception(e));
            }

            // Write initial log message before actually booting Duality
            Log.Core.Write("Running DualityLauncher with flags: {1}{0}",
                Environment.NewLine,
                new[] { isDebugging ? "Debugging" : null, isProfiling ? "Profiling" : null, isRunFromEditor ? "RunFromEditor" : null }.NotNull().ToString(", "));

            // Initialize the Duality core
            DualityApp.Init(DualityApp.ExecutionEnvironment.Launcher, DualityApp.ExecutionContext.Game, args);

            // Open up a new window
            WindowOptions options = new WindowOptions
            {
                Width = DualityApp.UserData.GfxWidth,
                Height = DualityApp.UserData.GfxHeight,
                ScreenMode = isDebugging ? ScreenMode.Window : DualityApp.UserData.GfxMode,
                RefreshMode = (isDebugging || isProfiling) ? RefreshMode.NoSync : DualityApp.UserData.RefreshMode,
                Title = DualityApp.AppData.AppName,
                SystemCursorVisible = isDebugging || DualityApp.UserData.SystemCursorVisible
            };
            using (INativeWindow window = DualityApp.OpenWindow(options))
            {
                // Load the starting Scene
                Scene.SwitchTo(DualityApp.AppData.StartScene);

                // Enter the applications update / render loop
                window.Run();
            }

            // Shut down the Duality core
            DualityApp.Terminate();

            // Clean up the log file
            if (logfileWriter != null)
            {
                Log.RemoveGlobalOutput(logfileOutput);
                logfileWriter.Flush();
                logfileWriter.Close();
                logfileWriter = null;
                logfileOutput = null;
            }
        }
Ejemplo n.º 6
0
        private static void Main(string[] args)
        {
            // Parse command line arguments
            bool recover = false;
            foreach (string a in args)
            {
                if (a == "debug")
                    System.Diagnostics.Debugger.Launch();
                else if (a == "recover")
                    recover = true;
            }

            // Culture setup
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            // Set up file logging
            StreamWriter logfileWriter = null;
            TextWriterLogOutput logfileOutput = null;
            try
            {
                // If there is an existing logfile, preserve it under a different name
                if (File.Exists(DualityEditorApp.EditorLogfilePath))
                {
                    if (File.Exists(DualityEditorApp.EditorPrevLogfilePath))
                        File.Delete(DualityEditorApp.EditorPrevLogfilePath);
                    File.Move(DualityEditorApp.EditorLogfilePath, DualityEditorApp.EditorPrevLogfilePath);
                }

                // Create a new logfile
                logfileWriter = new StreamWriter(DualityEditorApp.EditorLogfilePath);
                logfileWriter.AutoFlush = true;
                logfileOutput = new TextWriterLogOutput(logfileWriter);
                Log.AddGlobalOutput(logfileOutput);
            }
            catch (Exception e)
            {
                Log.Core.WriteWarning("Text Logfile unavailable: {0}", Log.Exception(e));
            }

            // Winforms Setup
            Application.CurrentCulture = Thread.CurrentThread.CurrentCulture;
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;

            {
                PackageManager packageManager = new PackageManager();

                // On the first install startup, display a generic license agreement for Duality
                if (packageManager.IsFirstInstall)
                {
                    LicenseAcceptDialog licenseDialog = new LicenseAcceptDialog
                    {
                        DescriptionText = GeneralRes.LicenseAcceptDialog_FirstStartGeneric,
                        LicenseUrl = new Uri(DualityMainLicenseUrl)
                    };
                    DialogResult result = licenseDialog.ShowDialog();
                    if (result != DialogResult.OK)
                    {
                        Application.Exit();
                        return;
                    }
                }

                // Perform the initial package update - even before initializing the editor
                if (packageManager.IsPackageSyncRequired)
                {
                    Log.Editor.Write("Updating Packages...");
                    Log.Editor.PushIndent();
                    ProcessingBigTaskDialog setupDialog = new ProcessingBigTaskDialog(
                        GeneralRes.TaskInstallPackages_Caption,
                        GeneralRes.TaskInstallPackages_Desc,
                        SynchronizePackages,
                        packageManager);
                    setupDialog.ShowInTaskbar = true;
                    setupDialog.MainThreadRequired = false;
                    setupDialog.ShowDialog();
                    Log.Editor.PopIndent();
                }
                if (packageManager.ApplyUpdate())
                {
                    Application.Exit();
                    return;
                }
            }

            // Run the editor
            SplashScreen splashScreen = new SplashScreen(recover);
            splashScreen.Show();
            Application.Run();

            // Clean up the log file
            if (logfileWriter != null)
            {
                Log.RemoveGlobalOutput(logfileOutput);
                logfileWriter.Flush();
                logfileWriter.Close();
                logfileWriter = null;
                logfileOutput = null;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes this DualityApp. Should be called before performing any operations withing Duality.
        /// </summary>
        /// <param name="context">The <see cref="ExecutionContext"/> in which Duality runs.</param>
        /// <param name="args">
        /// Command line arguments to run this DualityApp with.
        /// Usually these are just the ones from the host application, passed on.
        /// </param>
        public static void Init(ExecutionEnvironment env = ExecutionEnvironment.Unknown, ExecutionContext context = ExecutionContext.Unknown, string[] args = null)
        {
            if (initialized)
            {
                return;
            }

            // Set main thread
            mainThread = Thread.CurrentThread;

            // Process command line options
            if (args != null)
            {
                int logArgIndex = args.IndexOfFirst("logfile");
                if (logArgIndex != -1 && logArgIndex + 1 < args.Length)
                {
                    logArgIndex++;
                }
                else
                {
                    logArgIndex = -1;
                }

                // Enter debug mode
                if (args.Contains(CmdArgDebug))
                {
                    System.Diagnostics.Debugger.Launch();
                }
                // Run from editor
                if (args.Contains(CmdArgEditor))
                {
                    runFromEditor = true;
                }
                // Set logfile path
                if (logArgIndex != -1)
                {
                    logfilePath = args[logArgIndex];
                    if (string.IsNullOrWhiteSpace(Path.GetExtension(logfilePath)))
                    {
                        logfilePath += ".txt";
                    }
                }
            }

            environment = env;
            execContext = context;

            // Initialize Logfile
            try
            {
                logfile           = new StreamWriter(logfilePath);
                logfile.AutoFlush = true;
                TextWriterLogOutput logfileOutput = new TextWriterLogOutput(logfile);
                Log.Game.AddOutput(logfileOutput);
                Log.Core.AddOutput(logfileOutput);
                Log.Editor.AddOutput(logfileOutput);
            }
            catch (Exception e)
            {
                Log.Core.WriteWarning("Text Logfile unavailable: {0}", Log.Exception(e));
            }

            // Assure Duality is properly terminated in any case and register additional AppDomain events
            AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.AssemblyResolve    += CurrentDomain_AssemblyResolve;
            AppDomain.CurrentDomain.AssemblyLoad       += CurrentDomain_AssemblyLoad;

            sound = new SoundDevice();
            LoadPlugins();
            LoadAppData();
            LoadUserData();
            LoadMetaData();

            // Determine available and default graphics modes
            int[] aaLevels = new int[] { 0, 2, 4, 6, 8, 16 };
            foreach (int samplecount in aaLevels)
            {
                GraphicsMode mode = new GraphicsMode(32, 24, 0, samplecount, new OpenTK.Graphics.ColorFormat(0), 2, false);
                if (!availModes.Contains(mode))
                {
                    availModes.Add(mode);
                }
            }
            int highestAALevel = MathF.RoundToInt(MathF.Log(MathF.Max(availModes.Max(m => m.Samples), 1.0f), 2.0f));
            int targetAALevel  = highestAALevel;

            if (appData.MultisampleBackBuffer)
            {
                switch (userData.AntialiasingQuality)
                {
                case AAQuality.High:    targetAALevel = highestAALevel;         break;

                case AAQuality.Medium:  targetAALevel = highestAALevel / 2; break;

                case AAQuality.Low:             targetAALevel = highestAALevel / 4; break;

                case AAQuality.Off:             targetAALevel = 0;                                      break;
                }
            }
            else
            {
                targetAALevel = 0;
            }
            int targetSampleCount = MathF.RoundToInt(MathF.Pow(2.0f, targetAALevel));

            defaultMode = availModes.LastOrDefault(m => m.Samples <= targetSampleCount) ?? availModes.Last();

            // Initial changed event
            OnAppDataChanged();
            OnUserDataChanged();

            Formatter.InitDefaultMethod();

            Log.Core.Write("DualityApp initialized");
            Log.Core.Write("Debug Mode: {0}", System.Diagnostics.Debugger.IsAttached);
            Log.Core.Write("Command line arguments: {0}", args != null ? args.ToString(", ") : "null");

            initialized = true;
            InitPlugins();
        }
Ejemplo n.º 8
0
		private static void Terminate(bool unexpected)
		{
			if (!initialized) return;

			if (unexpected)
			{
				Log.Core.WriteError("DualityApp terminated unexpectedly");
			}
			else
			{
				if (isUpdating)
				{
					terminateScheduled = true;
					return;
				}

				if (environment == ExecutionEnvironment.Editor && execContext == ExecutionContext.Game)
				{
					Scene.Current.Dispose();
					Log.Core.Write("DualityApp Sandbox terminated");
					terminateScheduled = false;
					return;
				}

				if (execContext != ExecutionContext.Editor)
				{
					OnTerminating();
					SaveUserData();
				}
				sound.Dispose();
				sound = null;
				ClearPlugins();
				Profile.SaveTextReport(environment == ExecutionEnvironment.Editor ? "perflog_editor.txt" : "perflog.txt");
				Log.Core.Write("DualityApp terminated");
			}

			// Terminate Logfile
			if (logfile != null)
			{
				Log.Game.RemoveOutput(logfileOutput);
				Log.Core.RemoveOutput(logfileOutput);
				Log.Editor.RemoveOutput(logfileOutput);
				logfileOutput = null;
				logfile.Flush();
				logfile.Close();
				logfile = null;
			}

			initialized = false;
			execContext = ExecutionContext.Terminated;
		}
Ejemplo n.º 9
0
		/// <summary>
		/// Initializes this DualityApp. Should be called before performing any operations withing Duality.
		/// </summary>
		/// <param name="context">The <see cref="ExecutionContext"/> in which Duality runs.</param>
		/// <param name="args">
		/// Command line arguments to run this DualityApp with. 
		/// Usually these are just the ones from the host application, passed on.
		/// </param>
		public static void Init(ExecutionEnvironment env = ExecutionEnvironment.Unknown, ExecutionContext context = ExecutionContext.Unknown, string[] args = null)
		{
			if (initialized) return;

			// Set main thread
			mainThread = Thread.CurrentThread;

			// Process command line options
			if (args != null)
			{
				int logArgIndex = args.IndexOfFirst("logfile");
				if (logArgIndex != -1 && logArgIndex + 1 < args.Length) logArgIndex++;
				else logArgIndex = -1;

				// Enter debug mode
				if (args.Contains(CmdArgDebug)) System.Diagnostics.Debugger.Launch();
				// Run from editor
				if (args.Contains(CmdArgEditor)) runFromEditor = true;
				// Set logfile path
				if (logArgIndex != -1)
				{
					logfilePath = args[logArgIndex];
					if (string.IsNullOrWhiteSpace(Path.GetExtension(logfilePath)))
						logfilePath += ".txt";
				}
			}

			environment = env;
			execContext = context;

			// Initialize Logfile
			try
			{
				logfile = new StreamWriter(logfilePath);
				logfile.AutoFlush = true;
				logfileOutput = new TextWriterLogOutput(logfile);
				Log.Game.AddOutput(logfileOutput);
				Log.Core.AddOutput(logfileOutput);
				Log.Editor.AddOutput(logfileOutput);
			}
			catch (Exception e)
			{
				Log.Core.WriteWarning("Text Logfile unavailable: {0}", Log.Exception(e));
			}

			// Assure Duality is properly terminated in any case and register additional AppDomain events
			AppDomain.CurrentDomain.ProcessExit			+= CurrentDomain_ProcessExit;
			AppDomain.CurrentDomain.UnhandledException	+= CurrentDomain_UnhandledException;
			AppDomain.CurrentDomain.AssemblyResolve		+= CurrentDomain_AssemblyResolve;
			AppDomain.CurrentDomain.AssemblyLoad		+= CurrentDomain_AssemblyLoad;

			sound = new SoundDevice();
			LoadPlugins();
			LoadAppData();
			LoadUserData();
			
			// Determine available and default graphics modes
			int[] aaLevels = new int[] { 0, 2, 4, 6, 8, 16 };
			foreach (int samplecount in aaLevels)
			{
				GraphicsMode mode = new GraphicsMode(32, 24, 0, samplecount, new OpenTK.Graphics.ColorFormat(0), 2, false);
				if (!availModes.Contains(mode)) availModes.Add(mode);
			}
			int highestAALevel = MathF.RoundToInt(MathF.Log(MathF.Max(availModes.Max(m => m.Samples), 1.0f), 2.0f));
			int targetAALevel = highestAALevel;
			if (appData.MultisampleBackBuffer)
			{
				switch (userData.AntialiasingQuality)
				{
					case AAQuality.High:	targetAALevel = highestAALevel;		break;
					case AAQuality.Medium:	targetAALevel = highestAALevel / 2; break;
					case AAQuality.Low:		targetAALevel = highestAALevel / 4; break;
					case AAQuality.Off:		targetAALevel = 0;					break;
				}
			}
			else
			{
				targetAALevel = 0;
			}
			int targetSampleCount = MathF.RoundToInt(MathF.Pow(2.0f, targetAALevel));
			defaultMode = availModes.LastOrDefault(m => m.Samples <= targetSampleCount) ?? availModes.Last();

			// Initial changed event
			OnAppDataChanged();
			OnUserDataChanged();

			Formatter.InitDefaultMethod();
			joysticks.AddGlobalDevices();
			gamepads.AddGlobalDevices();

			Log.Core.Write(
				"DualityApp initialized" + Environment.NewLine +
				"Debug Mode: {0}" + Environment.NewLine +
				"Command line arguments: {1}" + Environment.NewLine +
				"Is64BitProcess: {2}",
				System.Diagnostics.Debugger.IsAttached,
				args != null ? args.ToString(", ") : "null",
				Environment.Is64BitProcess);

			initialized = true;
			InitPlugins();
		}