Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var options = new KestrelServerOptions();

            options.NoDelay     = true;
            options.ThreadCount = 2;
            var applicationLifetime = new ApplicationLifetime();
            var server = new KestrelServer(new OptionsWrapper <KestrelServerOptions>(options), applicationLifetime,
                                           new LoggerFactory());

            server.Features.Get <IServerAddressesFeature>().Addresses.Add("http://localhost:8888");
            server.Start(new HttpApp());
            Console.WriteLine("Listening on 8888. Press Enter to stop.");
            Console.ReadLine();
            server.Dispose();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            if (events != null || clients != null)
            {
                EventQueue.Setup(this, clients);
            }

            // start the server
            //
            server.Start(this);

            OnStart();

            DBG(Name + " -> " + Addrs[0] + " started");

            cleaner.Start();

            if (clients != null)
            {
                // Run in the scheduler thread to repeatedly check and initiate event polling activities.
                scheduler = new Thread(() =>
                {
                    while (!stop)
                    {
                        // interval
                        Thread.Sleep(5000);

                        // a schedule cycle
                        int tick = Environment.TickCount;
                        for (int i = 0; i < Clients.Count; i++)
                        {
                            Client client = Clients[i];
                            client.TryPoll(tick);
                        }
                    }
                });
                // scheduler.Start();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method starts up the assistant core.
        /// After registration of very important events on Program.cs, control moves to here.
        /// This is basically the entry point of the application.
        /// </summary>
        /// <param name="args">The startup arguments. (if any)</param>
        /// <returns></returns>
        public static async Task <bool> InitCore(string[] args)
        {
            if (File.Exists(Constants.TraceLogPath))
            {
                File.Delete(Constants.TraceLogPath);
            }

            Helpers.CheckMultipleProcess();
            StartupTime = DateTime.Now;

            if (Helpers.CheckForInternetConnection())
            {
                IsNetworkAvailable = true;
            }
            else
            {
                Logger.Log("No internet connection.", Enums.LogLevels.Warn);
                Logger.Log($"Starting {AssistantName} in offline mode...");
                IsNetworkAvailable = false;
            }

            Config                    = Config.LoadConfig();
            RunningPlatform           = Helpers.GetOsPlatform();
            AssistantName             = Config.AssistantDisplayName;
            Logger.LogIdentifier      = AssistantName;
            Config.ProgramLastStartup = StartupTime;
            Constants.LocalIP         = Helpers.GetLocalIpAddress();

            SecureLine = new SecureLineServer(IPAddress.Any, 7777);
            SecureLine.StartSecureLine();

            SendLocalIp(!Helpers.IsNullOrEmpty(Constants.LocalIP));

            Helpers.SetFileSeperator();

            Helpers.GenerateAsciiFromText(Config.AssistantDisplayName);
            Constants.ExternelIP = Helpers.GetExternalIp();

            File.WriteAllText("version.txt", Constants.Version.ToString());

            if (Helpers.IsNullOrEmpty(Constants.ExternelIP))
            {
                Constants.ExternelIP = "Failed.";
            }

            Helpers.InBackgroundThread(SetConsoleTitle, "Console Title Updater", true);
            Logger.Log($"X---------------- Starting {AssistantName} v{Constants.Version} ----------------X", Enums.LogLevels.Ascii);

            ConfigWatcher.InitConfigWatcher();
            ParseStartupArguments(args);

            if (!Helpers.IsNullOrEmpty(Config.PushBulletApiKey))
            {
                PushBulletService = new PushBulletService(Config.PushBulletApiKey);
                (bool status, UserDeviceListResponse currentPushDevices) = PushBulletService.InitPushService();

                if (status)
                {
                    Logger.Log("Push bullet service started.", Enums.LogLevels.Trace);
                }
            }

            if (!Helpers.IsRaspberryEnvironment())
            {
                DisablePiMethods = true;
                IsUnknownOs      = true;
            }

            if (Helpers.GetOsPlatform().Equals(OSPlatform.Windows))
            {
                AssistantStatus = new ProcessStatus();
            }
            else
            {
                Logger.Log("Could not start performence counters as it is not supported on this platform.", Enums.LogLevels.Trace);
            }

            await Update.CheckAndUpdateAsync(true).ConfigureAwait(false);

            if (Config.KestrelServer && !Helpers.IsNullOrEmpty(Config.KestrelServerUrl))
            {
                await KestrelServer.Start().ConfigureAwait(false);
            }

            ModuleLoader = new ModuleInitializer();

            ModuleLoader.LoadAndStartModulesOfType <IModuleBase>();

            ModuleWatcher.InitModuleWatcher();
            Controller = new PiController(true);
            CoreInitiationCompleted = true;

            await PostInitTasks().ConfigureAwait(false);

            return(true);
        }