Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var registry = KontrolSystemKSPRegistry.CreateKSP();

            var context = registry.AddDirectory(Path.Combine(Directory.GetCurrentDirectory(), "GameData", "KontrolSystem", "to2"));

            GenerateDocs(context.CreateModuleContext("docs"), registry);
        }
Exemplo n.º 2
0
        public LambertBench()
        {
            csharpSolver =
                typeof(LambertIzzoSolver).GetMethod("Solve")
                .CreateDelegate(typeof(LambertSolve)) as
                LambertSolve;     // Also use delegate so that invocation overhead ist the same

            var registry = KontrolSystemKSPRegistry.CreateKSP();

            registry.AddDirectory("to2Bench");

            var to2Lambert      = registry.modules["lambert"];
            var to2LambertSolve = to2Lambert.FindFunction("solve_lambert");

            ContextHolder.CurrentContext.Value = new EmptyContext(false);
            to2Solver = to2LambertSolve.RuntimeMethod.CreateDelegate(typeof(LambertSolve)) as LambertSolve;
        }
Exemplo n.º 3
0
        private async void DoReboot(KontrolSystemConfig config)
        {
            rebooting = true;
            State nextState = await Task.Run(() => {
                Stopwatch stopwatch = new Stopwatch();
                try {
                    stopwatch.Start();
                    string registryPath = Path.GetFullPath(config.TO2BaseDir).TrimEnd(PathSeparator);

                    PluginLogger.Instance.Info($"Rebooting Mainframe on path {registryPath}");

                    Directory.CreateDirectory(registryPath);

                    KontrolRegistry nextRegistry = KontrolSystemKSPRegistry.CreateKSP();

                    if (KontrolSystemConfig.Instance.IncludeStdLib)
                    {
                        PluginLogger.Instance.Debug($"Add Directory: {KontrolSystemConfig.Instance.StdLibDir}");
                        nextRegistry.AddDirectory(KontrolSystemConfig.Instance.StdLibDir);
                    }

                    PluginLogger.Instance.Debug($"Add Directory: {registryPath}");
                    nextRegistry.AddDirectory(registryPath);
                    stopwatch.Stop();

                    return(new State(nextRegistry, stopwatch.Elapsed, new List <MainframeError>()));
                } catch (CompilationErrorException e) {
                    PluginLogger.Instance.Debug(e.ToString());

                    foreach (StructuralError error in e.errors)
                    {
                        PluginLogger.Instance.Info(error.ToString());
                    }

                    return(new State(state?.registry, stopwatch.Elapsed, e.errors.Select(error => new MainframeError(
                                                                                             error.start,
                                                                                             error.errorType.ToString(),
                                                                                             error.message
                                                                                             )).ToList()));
                } catch (ParseException e) {
                    PluginLogger.Instance.Debug(e.ToString());
                    PluginLogger.Instance.Info(e.Message);

                    return(new State(state?.registry, stopwatch.Elapsed, new List <MainframeError> {
                        new MainframeError(e.position, "Parsing", e.Message)
                    }));
                } catch (Exception e) {
                    PluginLogger.Instance.Error("Mainframe initialization error: " + e);

                    return(new State(state?.registry, stopwatch.Elapsed, new List <MainframeError> {
                        new MainframeError(new Position(), "Unknown error", e.Message)
                    }));
                }
            });

            if (nextState.errors.Count == 0)
            {
                processes = (processes ?? Enumerable.Empty <KontrolSystemProcess>())
                            .Where(p => p.State == KontrolSystemProcessState.Running ||
                                   p.State == KontrolSystemProcessState.Outdated).Select(p => p.MarkOutdated()).Concat(
                    nextState.registry.modules.Values
                    .Where(module =>
                           module.HasKSCEntrypoint() || module.HasEditorEntrypoint() ||
                           module.HasTrackingEntrypoint() ||
                           module.HasFlightEntrypoint())
                    .Select(module => new KontrolSystemProcess(module))).ToList();
            }

            state     = nextState;
            rebooting = false;
        }