Esempio n. 1
0
 public void Reboot(KontrolSystemConfig config)
 {
     if (rebooting)
     {
         return;
     }
     DoReboot(config);
 }
Esempio n. 2
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;
        }