コード例 #1
0
        internal Core(string[] args)
        {
            Console.Title = $"Initializing...";
            Logger        = InternalLogger.GetOrCreateLogger <Core>(this, nameof(Core));
            OS.Init(true);
            RuntimeSpanCounter.Restart();
            File.WriteAllText("version.txt", Constants.Version?.ToString());

            ParseStartupArguments();

            if (File.Exists(Constants.TraceLogFile))
            {
                File.Delete(Constants.TraceLogFile);
            }

            Config = new CoreConfig(this);
            Config.LoadAsync().Wait();
            IsUpdatesAllowed = !NoUpdates && Config.AutoUpdates;
            Config.LocalIP   = Helpers.GetLocalIpAddress()?.ToString() ?? "-Invalid-";
            Config.PublicIP  = Helpers.GetPublicIP()?.ToString() ?? "-Invalid-";

            if (!IsNetworkAvailable)
            {
                Logger.Warn("No Internet connection.");
                Logger.Info($"Starting offline mode...");
            }

            Pins = new PinsWrapper(
                Config.GpioConfiguration.OutputModePins,
                Config.GpioConfiguration.InputModePins,
                Constants.BcmGpioPins,
                Config.GpioConfiguration.RelayPins,
                Config.GpioConfiguration.InfraredSensorPins,
                Config.GpioConfiguration.SoundSensorPins
                );

            Controller   = new GpioCore(Pins, this, Config.GpioConfiguration.GpioSafeMode);
            ModuleLoader = new ModuleLoader();
            RestServer   = new RestCore(Config.RestServerPort, Config.Debug);

            JobManager.AddJob(() => SetConsoleTitle(), (s) => s.WithName("ConsoleUpdater").ToRunEvery(1).Seconds());
            Logger.CustomLog(FiggleFonts.Ogre.Render("LUNA"), ConsoleColor.Green);
            Logger.CustomLog($"---------------- Starting Luna v{Constants.Version} ----------------", ConsoleColor.Blue);
            IsBaseInitiationCompleted = true;
            PostInitiation().Wait();
            InternalConfigWatcher = new ConfigWatcher(this);
            InternalModuleWatcher = new ModuleWatcher(this);
            InitiationCompleted   = true;
        }
コード例 #2
0
        internal async Task KeepAlive()
        {
            Logger.CustomLog($"Press {Constants.ShellKeyChar} for shell.", ConsoleColor.Green);
            while (!KeepAliveToken.Token.IsCancellationRequested)
            {
                try {
                    if (Interpreter.PauseShell)
                    {
                        if (!Console.KeyAvailable)
                        {
                            continue;
                        }

                        ConsoleKeyInfo pressedKey = Console.ReadKey(true);

                        switch (pressedKey.Key)
                        {
                        case Constants.ShellKey:
                            Interpreter.Resume();
                            continue;

                        default:
                            continue;
                        }
                    }
                }
                finally {
                    await Task.Delay(1).ConfigureAwait(false);
                }
            }
        }