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);
            }
            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 -----");
        }
Beispiel #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 -----");
        }
Beispiel #3
0
 [SetUp] public void Init()
 {
     // Watch out for logged errors and warnings. Serialization is
     // designed to be as robust as possible and trying to not throw
     // errors. It may log errors and warnings though.
     this.logWatcher.Reset();
     Logs.AddGlobalOutput(this.logWatcher);
 }
Beispiel #4
0
        [Test] public void CyclicRequirements()
        {
            ComponentRequirementMap map = new ComponentRequirementMap();

            // In a cyclic dependency situation, behavior is undefined and there is no "right" solution.
            // For this test, just expect the system to not crash. Check some select results that we
            // can safely expect.
            TestingLogOutput logWatcher = new TestingLogOutput();

            Logs.AddGlobalOutput(logWatcher);

            map.GetRequirements(typeof(TestComponentC1));
            map.GetRequirements(typeof(TestComponentC2));
            map.GetRequirements(typeof(TestComponentC3));

            logWatcher.AssertNoErrors();
            logWatcher.AssertWarning();

            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC1));
            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC2));
            map.GetRequirementsToCreate(new GameObject(), typeof(TestComponentC3));

            logWatcher.AssertNoErrors();
            logWatcher.AssertWarning();

            Assert.IsFalse(map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC1)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC2)));
            Assert.IsFalse(map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC3)));

            map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC2));
            map.IsRequired(typeof(TestComponentC1), typeof(TestComponentC3));
            map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC1));
            map.IsRequired(typeof(TestComponentC2), typeof(TestComponentC3));
            map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC1));
            map.IsRequired(typeof(TestComponentC3), typeof(TestComponentC2));

            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3));
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC1), new[] { typeof(TestComponentC2), typeof(TestComponentC3) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC2), new[] { typeof(TestComponentC3), typeof(TestComponentC1) });
            map.IsRequirementMet(new GameObject(), typeof(TestComponentC3), new[] { typeof(TestComponentC1), typeof(TestComponentC2) });

            Logs.RemoveGlobalOutput(logWatcher);
        }
Beispiel #5
0
        public void BeforeTest(ITest 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 (this.consoleLogOutput == null)
            {
                this.consoleLogOutput = new TextWriterLogOutput(Console.Out);
            }
            Logs.AddGlobalOutput(this.consoleLogOutput);

            // Initialize Duality
            DualityApp.Init(
                DualityApp.ExecutionEnvironment.Launcher,
                DualityApp.ExecutionContext.Game,
                new DefaultAssemblyLoader(),
                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();
                this.dummyWindow = DualityApp.OpenWindow(options);
            }

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

            Console.WriteLine("----- Duality environment setup complete -----");
        }
Beispiel #6
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));
            }
        }
Beispiel #7
0
        public DualityTestFixture()
        {
            Console.WriteLine("----- Beginning Duality environment setup -----");

            // Set environment directory to Duality binary directory
            _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 (_consoleLogOutput == null)
            {
                _consoleLogOutput = new TextWriterLogOutput(Console.Out);
            }
            Logs.AddGlobalOutput(_consoleLogOutput);

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

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

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

            Console.WriteLine("----- Duality environment setup complete -----");
        }
		[Test] public void ExecOrderLoopResolve()
		{
			// If there is a loop in the execution order requirements, make sure
			// a log informs the user about this.
			TestingLogOutput logWatcher = new TestingLogOutput();
			Logs.AddGlobalOutput(logWatcher);

			ComponentExecutionOrder order = new ComponentExecutionOrder();

			List<Type> types = new List<Type>();
			types.Add(typeof(TestComponentE1));
			types.Add(typeof(TestComponentE2));
			types.Add(typeof(TestComponentE3));

			// Assert that we're still able to perform exec order sorting and
			// the constraint loop doesn't cause further problems.
			order.SortTypes(types, false);
			
			// Assert that there were no errors, but we got a warning.
			logWatcher.AssertNoErrors();
			logWatcher.AssertWarning();

			Logs.RemoveGlobalOutput(logWatcher);
		}
        public static void Init(MainWindow mainWindow)
        {
            CoheeEditorApp.mainWindow = mainWindow;

            // Set up an in-memory data log so plugins can access the log history when needed
            editorLogOutput = new EditorLogOutput();
            Logs.AddGlobalOutput(editorLogOutput);

            // Create working directories, if not existing yet.
            if (!Directory.Exists(CoheeApp.DataDirectory))
            {
                Directory.CreateDirectory(CoheeApp.DataDirectory);
                using (FileStream s = File.OpenWrite(Path.Combine(CoheeApp.DataDirectory, "WorkingFolderIcon.ico")))
                {
                    Properties.GeneralRes.IconWorkingFolder.Save(s);
                }
                using (StreamWriter w = new StreamWriter(Path.Combine(CoheeApp.DataDirectory, "desktop.ini")))
                {
                    w.WriteLine("[.ShellClassInfo]");
                    w.WriteLine("ConfirmFileOp=0");
                    w.WriteLine("NoSharing=0");
                    w.WriteLine("IconFile=WorkingFolderIcon.ico");
                    w.WriteLine("IconIndex=0");
                    w.WriteLine("InfoTip=This is Dualitors working folder");
                }

                DirectoryInfo dirInfo = new DirectoryInfo(CoheeApp.DataDirectory);
                dirInfo.Attributes |= FileAttributes.System;

                FileInfo fileInfoDesktop = new FileInfo(Path.Combine(CoheeApp.DataDirectory, "desktop.ini"));
                fileInfoDesktop.Attributes |= FileAttributes.Hidden;

                FileInfo fileInfoIcon = new FileInfo(Path.Combine(CoheeApp.DataDirectory, "WorkingFolderIcon.ico"));
                fileInfoIcon.Attributes |= FileAttributes.Hidden;
            }

            if (!Directory.Exists(CoheeApp.PluginDirectory))
            {
                Directory.CreateDirectory(CoheeApp.PluginDirectory);
            }

            if (!Directory.Exists(EditorHelper.SourceDirectory))
            {
                Directory.CreateDirectory(EditorHelper.SourceDirectory);
            }
            if (!Directory.Exists(EditorHelper.SourceMediaDirectory))
            {
                Directory.CreateDirectory(EditorHelper.SourceMediaDirectory);
            }
            if (!Directory.Exists(EditorHelper.SourceCodeDirectory))
            {
                Directory.CreateDirectory(EditorHelper.SourceCodeDirectory);
            }

            //// Initialize Package Management system
            //packageManager = new PackageManager();

            // Initialize Cohee Core
            EditorHintImageAttribute.ImageResolvers += EditorHintImageResolver;
            CoheeApp.CorePluginManager.PluginsReady += CoheeApp_CorePluginsReady;
            CoheeApp.Init(CoheeApp.ExecutionEnvironment.Editor, CoheeApp.ExecutionContext.Editor, new DefaultAssemblyLoader(), null);

            // Initialize the plugin manager for the editor. We'll use the same loader as the core.
            editorPluginManager.Init(CoheeApp.CorePluginManager.AssemblyLoader);
            // Need to load editor plugins before initializing the graphics context, so the backend is available
            editorPluginManager.LoadPlugins();

            // Need to initialize graphics context and default content before instantiating anything that could require any of them
            InitMainGraphicsContext();
            CoheeApp.InitPostWindow();

            //LoadUserData();

            editorPluginManager.InitPlugins();



            // Allow the engine to run
            appSuspended = false;
        }
Beispiel #10
0
 [SetUp] public void Init()
 {
     this.logWatcher.Reset();
     Logs.AddGlobalOutput(this.logWatcher);
 }
Beispiel #11
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
            Logs.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);
                Logs.AddGlobalOutput(logfileOutput);
            }
            catch (Exception e)
            {
                Logs.Core.WriteWarning("Text Logfile unavailable: {0}", LogFormat.Exception(e));
            }

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

            // Write initial log message before actually booting Duality
            Logs.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 DefaultAssemblyLoader(),
                args);

            // Open up a new window
            WindowOptions options = new WindowOptions
            {
                Size                = DualityApp.UserData.WindowSize,
                ScreenMode          = isDebugging ? ScreenMode.Window : DualityApp.UserData.WindowMode,
                RefreshMode         = (isDebugging || isProfiling) ? RefreshMode.NoSync : DualityApp.UserData.WindowRefreshMode,
                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)
            {
                Logs.RemoveGlobalOutput(logfileOutput);
                logfileWriter.Flush();
                logfileWriter.Close();
                logfileWriter = null;
                logfileOutput = null;
            }
        }
Beispiel #12
0
 /// <summary>
 /// Adds a global log output and also makes sure its removed when <see cref="Dispose"/> is called
 /// </summary>
 /// <param name="logOutput"></param>
 public void AddGlobalOutput(ILogOutput logOutput)
 {
     this.logOutputs.Add(logOutput);
     Logs.AddGlobalOutput(logOutput);
 }
Beispiel #13
0
 /// <summary>
 /// Adds a global log output and also makes sure its removed when <see cref="Dispose"/> is called
 /// </summary>
 /// <param name="logOutput"></param>
 private void AddLogOutput(ILogOutput logOutput)
 {
     this.logOutputs.Add(logOutput);
     Logs.AddGlobalOutput(logOutput);
 }