Exemple #1
0
        public void AfterTest(ITest details)
        {
            Console.WriteLine("----- Beginning Duality environment teardown -----");

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

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

            // Save local testing memory. As this uses Duality serializers,
            // it needs to be done before terminating Duality.
            if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed && !System.Diagnostics.Debugger.IsAttached)
            {
                Serializer.WriteObject(TestHelper.LocalTestMemory, TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer));
            }

            DualityApp.Terminate();
            Environment.CurrentDirectory = this.oldEnvDir;

            Console.WriteLine("----- Duality environment teardown complete -----");
        }
Exemple #2
0
        public void BeforeTest(ITest details)
        {
            Console.WriteLine("----- Beginning Duality Editor environment setup -----");

            // Set environment directory to Duality binary directory
            this.oldEnvDir = Environment.CurrentDirectory;
            Console.WriteLine("Testing in working directory: {0}", TestContext.CurrentContext.TestDirectory);
            Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;

            // Add some Console logs manually for NUnit
            if (this.consoleLogOutput == null)
            {
                this.consoleLogOutput = new TextWriterLogOutput(Console.Out);
            }
            Logs.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 -----");
        }
        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 -----");
        }
Exemple #4
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('/');
            Console.WriteLine("Testing Editor Assembly: {0}", codeBasePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

            // Add some Console logs manually for NUnit
            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 -----");
        }
Exemple #5
0
        public void Dispose()
        {
            Console.WriteLine("----- Beginning Duality environment teardown -----");

            // Remove NUnit Console logs
            Logs.RemoveGlobalOutput(_consoleLogOutput);
            _consoleLogOutput = null;

            if (_dummyWindow != null)
            {
                ContentProvider.ClearContent();
                _dummyWindow.Dispose();
                _dummyWindow = null;
            }

            /*// Save local testing memory. As this uses Duality serializers,
             * // it needs to be done before terminating Duality.
             * if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed && !System.Diagnostics.Debugger.IsAttached)
             * {
             *      Serializer.WriteObject(TestHelper.LocalTestMemory, TestHelper.LocalTestMemoryFilePath, typeof(XmlSerializer));
             * }*/

            try
            {
                DualityApp.Terminate();
            }
            catch (BackendException)
            {
            }

            Environment.CurrentDirectory = _oldEnvDir;

            Console.WriteLine("----- Duality environment teardown complete -----");
        }
Exemple #6
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('/');
            Console.WriteLine("Testing Core Assembly: {0}", codeBasePath);
            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.PluginManager.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 -----");
        }
Exemple #7
0
 private static void CloseLogfile()
 {
     if (logfileOutput != null)
     {
         Logs.RemoveGlobalOutput(logfileOutput);
         logfileOutput = null;
     }
     if (logfileWriter != null)
     {
         logfileWriter.Flush();
         logfileWriter.Close();
         logfileWriter = null;
     }
 }
Exemple #8
0
        private static void CreateLogfile()
        {
            if (logfileOutput != null || logfileWriter != null)
            {
                CloseLogfile();
            }

            try
            {
                logfileWriter           = new StreamWriter(DualityEditorApp.EditorLogfilePath);
                logfileWriter.AutoFlush = true;
                logfileOutput           = new TextWriterLogOutput(logfileWriter);
                Logs.AddGlobalOutput(logfileOutput);
            }
            catch (Exception e)
            {
                Logs.Core.WriteWarning("Unable to create logfile: {0}", LogFormat.Exception(e));
            }
        }
Exemple #9
0
        public void BeforeTest(ITest details)
        {
            Console.WriteLine("----- Beginning Duality environment setup -----");

            // Set environment directory to Duality binary directory
            _oldEnvDir = Environment.CurrentDirectory;
            var codeBaseUri  = typeof(DualityApp).Assembly.CodeBase;
            var codeBasePath = codeBaseUri.StartsWith("file:") ? codeBaseUri.Remove(0, "file:".Length) : codeBaseUri;

            codeBasePath = codeBasePath.TrimStart('/');
            Console.WriteLine("Testing Core Assembly: {0}", codeBasePath);
            Environment.CurrentDirectory = Path.GetDirectoryName(codeBasePath);

            // Add some Console logs manually for NUnit
            if (_consoleLogOutput == null)
            {
                _consoleLogOutput = new TextWriterLogOutput(Console.Out);
            }
            Log.AddGlobalOutput(_consoleLogOutput);

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

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

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

            Console.WriteLine("----- Duality environment setup complete -----");
        }
Exemple #10
0
        public void AfterTest(ITest details)
        {
            Console.WriteLine("----- Beginning Duality Editor environment teardown -----");

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

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

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

            Console.WriteLine("----- Duality Editor environment teardown complete -----");
        }
Exemple #11
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;
            }
        }
Exemple #12
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));
            }

            // Set up a global exception handler to log errors
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            // 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,
                new DefaultPluginLoader(),
                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;
            }
        }