Beispiel #1
0
        protected static string GetTestDirectory(string mode = null, ExecutionMode?executionMode = null)
        {
            var assembly_path = Assembly.GetExecutingAssembly().Location;

            if (string.IsNullOrEmpty(mode))
            {
                if (assembly_path.Contains("netstandard2.0"))
                {
                    mode = "netstandard2.0";
                }
                else if (assembly_path.Contains("net461"))
                {
                    mode = "net461";
                }
                else
                {
                    mode = "unknown";
                }
            }

            var rv = Configuration.CloneTestDirectory(Configuration.TestProjectsDirectory, mode);

            if (executionMode == ExecutionMode.DotNet)
            {
                Configuration.CopyDotNetSupportingFiles(rv);
            }

            return(rv);
        }
Beispiel #2
0
        public void Suspend()
        {
            pauseAllThreads();

            // set the active execution mode back to null to set the state checking back to when it can be resumed.
            activeExecutionMode = null;
        }
Beispiel #3
0
 public void Suspend()
 {
     lock (startStopLock)
     {
         pauseAllThreads();
         activeExecutionMode = null;
     }
 }
Beispiel #4
0
 public ExecuteHandler(
     WorkspaceConnection ws,
     SQLiteConnection localConnection,
     ExecutionMode?mode = null)
 {
     _ws = ws;
     _localConnection = localConnection;
     _mode            = mode ?? Program.Settings.ExecutionMode;
 }
 protected internal void SetProperty <T>(ref T field, T newValue, [CallerMemberName] string propName = "",
                                         ExecutionMode?executionMode = null)
 {
     if (!EqualityComparer <T> .Default.Equals(field, newValue))
     {
         field = newValue;
         OnPropertyChanged(propName, executionMode.GetValueOrDefault(PropertyChangeExecutionMode));
     }
 }
Beispiel #6
0
        private void ensureCorrectExecutionMode()
        {
            if (ExecutionMode == activeExecutionMode)
            {
                return;
            }

            if (activeExecutionMode == null)
            {
                // in the case we have not yet got an execution mode, set this early to allow usage in GameThread.Initialize overrides.
                activeExecutionMode = ThreadSafety.ExecutionMode = ExecutionMode;
            }

            // shut down threads in reverse to ensure audio stops last (other threads may be waiting on a queued event otherwise)
            foreach (var t in Threads.Reverse())
            {
                t.Pause();
            }

            switch (ExecutionMode)
            {
            case ExecutionMode.MultiThreaded:
            {
                // switch to multi-threaded
                foreach (var t in Threads)
                {
                    t.Start();
                    t.Clock.Throttling = true;
                }

                break;
            }

            case ExecutionMode.SingleThread:
            {
                // switch to single-threaded.
                foreach (var t in Threads)
                {
                    // only throttle for the main thread
                    t.Initialize(withThrottling: t == mainThread);
                }

                // this is usually done in the execution loop, but required here for the initial game startup,
                // which would otherwise leave values in an incorrect state.
                ThreadSafety.ResetAllForCurrentThread();
                break;
            }
            }

            activeExecutionMode = ThreadSafety.ExecutionMode = ExecutionMode;

            updateMainThreadRates();
        }
Beispiel #7
0
 protected void SetProperty <T>(ref T propertyValue, T newValue, Expression <Func <T> > expression,
                                ExecutionMode?executionMode = null)
 {
     if (Equals(propertyValue, newValue))
     {
         return;
     }
     propertyValue = newValue;
     if (executionMode == null)
     {
         executionMode = PropertyChangeExecutionMode;
     }
     OnPropertyChanged(expression, executionMode.Value);
 }
Beispiel #8
0
 protected void SetProperty <T>(ref T propertyValue, T newValue, [CallerMemberName] string propName = "",
                                ExecutionMode?executionMode = null)
 {
     if (Equals(propertyValue, newValue))
     {
         return;
     }
     propertyValue = newValue;
     if (executionMode == null)
     {
         executionMode = PropertyChangeExecutionMode;
     }
     OnPropertyChanged(propName, executionMode.Value);
 }
Beispiel #9
0
        private void ensureCorrectExecutionMode()
        {
            // locking is required as this method may be called from two different threads.
            lock (startStopLock)
            {
                // pull into a local variable as the property is not locked during writes.
                var executionMode = ExecutionMode;

                if (executionMode == activeExecutionMode)
                {
                    return;
                }

                activeExecutionMode = ThreadSafety.ExecutionMode = executionMode;
                Logger.Log($"Execution mode changed to {activeExecutionMode}");
            }

            pauseAllThreads();

            switch (activeExecutionMode)
            {
            case ExecutionMode.MultiThreaded:
            {
                // switch to multi-threaded
                foreach (var t in Threads)
                {
                    t.Start();
                }

                break;
            }

            case ExecutionMode.SingleThread:
            {
                // switch to single-threaded.
                foreach (var t in Threads)
                {
                    // only throttle for the main thread
                    t.Initialize(withThrottling: t == mainThread);
                }

                // this is usually done in the execution loop, but required here for the initial game startup,
                // which would otherwise leave values in an incorrect state.
                ThreadSafety.ResetAllForCurrentThread();
                break;
            }
            }

            updateMainThreadRates();
        }
        private void ensureCorrectExecutionMode()
        {
            if (ExecutionMode == activeExecutionMode)
            {
                return;
            }

            // if null, we have not yet got an execution mode, so set this early to allow usage in GameThread.Initialize overrides.
            activeExecutionMode ??= ThreadSafety.ExecutionMode = ExecutionMode;
            Logger.Log($"Execution mode changed to {activeExecutionMode}");

            pauseAllThreads();

            switch (ExecutionMode)
            {
            case ExecutionMode.MultiThreaded:
            {
                // switch to multi-threaded
                foreach (var t in Threads)
                {
                    t.Start();
                    t.Clock.Throttling = true;
                }

                break;
            }

            case ExecutionMode.SingleThread:
            {
                // switch to single-threaded.
                foreach (var t in Threads)
                {
                    // only throttle for the main thread
                    t.Initialize(withThrottling: t == mainThread);
                }

                // this is usually done in the execution loop, but required here for the initial game startup,
                // which would otherwise leave values in an incorrect state.
                ThreadSafety.ResetAllForCurrentThread();
                break;
            }
            }

            activeExecutionMode = ThreadSafety.ExecutionMode = ExecutionMode;

            updateMainThreadRates();
        }
Beispiel #11
0
        public void RunTarget(ProjectPaths paths, string target, ExecutionMode?executionMode = null, int expectedErrorCount = 0, Dictionary <string, string> properties = null)
        {
            var rv = Engine.RunTarget(ApplePlatform, executionMode ?? Mode, paths.ProjectCSProjPath, target, properties);

            if (expectedErrorCount != Engine.ErrorEvents.Count)
            {
                foreach (var e in Engine.ErrorEvents)
                {
                    Console.WriteLine(e.Message);
                }
                Assert.AreEqual(expectedErrorCount, Engine.ErrorEvents.Count, "ExitCode/ExpectedErrorCount");
            }
            if (expectedErrorCount > 0)
            {
                Assert.AreEqual(1, rv.ExitCode, "ExitCode (failure)");
            }
            else
            {
                Assert.AreEqual(0, rv.ExitCode, "ExitCode (success)");
            }
        }
Beispiel #12
0
 public void InvalidateProperties(ExecutionMode?executionMode = null)
 {
     OnPropertyChanged(Empty.EmptyPropertyChangedArgs, executionMode.GetValueOrDefault(PropertyChangeExecutionMode));
 }
Beispiel #13
0
        static bool ProcessCommandLineArgs(string[] args, out ExecutionMode?mode, out int a, out int b,
                                           out int[] coefs, out int n, out bool minOps, out bool showBlocks, out bool noLookBack, out bool verboseSystem)
        {
            coefs  = new int[] { -1, -1, -1, -1, -1, -1, -1, -1, -1, };
            mode   = null;
            a      = b = n = -1;
            minOps = showBlocks = noLookBack = verboseSystem = false;

            for (int i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                case "-i":
                    if (mode != null)
                    {
                        return(false);
                    }

                    mode = ExecutionMode.Interactive;

                    break;

                case "-p":
                    if (mode != null)
                    {
                        return(false);
                    }

                    mode = ExecutionMode.CommandLine;

                    if (args.Length - i - 1 < 9)
                    {
                        return(false);
                    }

                    for (int j = 0; j < 9; j++)
                    {
                        if (!int.TryParse(args[i + j + 1], out coefs[j]))
                        {
                            return(false);
                        }

                        if (!(0 <= coefs[j] && coefs[j] <= 255))
                        {
                            return(false);
                        }
                    }

                    i += 9;

                    break;

                case "-f":
                    if (mode != null)
                    {
                        return(false);
                    }

                    mode = ExecutionMode.NoEquation;

                    if (args.Length - i - 1 < 1)
                    {
                        return(false);
                    }

                    if (!int.TryParse(args[i + 1], out n))
                    {
                        return(false);
                    }

                    if (!(0 <= n && n <= 255))
                    {
                        return(false);
                    }

                    i += 1;

                    break;

                case "-ex":
                    if (a != -1)
                    {
                        return(false);
                    }

                    a = 0;

                    if (args.Length - i - 1 < 1)
                    {
                        return(false);
                    }

                    if (args[i + 1].Contains("-"))
                    {
                        string[] ab = args[i + 1].Split('-');

                        if (!int.TryParse(ab[0], out a) || !int.TryParse(ab[1], out b))
                        {
                            return(false);
                        }

                        if (!(0 <= a && a <= 255) || !(0 <= b && b <= 255))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (!int.TryParse(args[i + 1], out a))
                        {
                            return(false);
                        }

                        if (!(0 <= a && a <= 255))
                        {
                            return(false);
                        }
                    }

                    i += 1;

                    break;

                case "-mo":
                    if (minOps)
                    {
                        return(false);
                    }

                    minOps = true;

                    break;

                case "-sb":
                    if (showBlocks)
                    {
                        return(false);
                    }

                    showBlocks = true;

                    break;

                case "-vs":
                    if (verboseSystem)
                    {
                        return(false);
                    }

                    verboseSystem = true;

                    break;

                case "-nlb":
                    if (noLookBack)
                    {
                        return(false);
                    }

                    noLookBack = true;

                    break;

                default:
                    int tmp;
                    if (!int.TryParse(args[i], out tmp))
                    {
                        return(false);
                    }
                    break;
                }
            }

            if (a == -1)
            {
                a = 1;
                b = 15;
            }

            return(mode != null);
        }
Beispiel #14
0
 public RequireExecutionModeAttribute(ExecutionMode mode)
 {
     _mode = mode;
 }