Exemplo n.º 1
0
        public void SelectAdapter()
        {
            var validInput = false;
            var adapters   = DxEnumerate.GetAdapters();

            if (!adapters?.Any() ?? true)
            {
                Console.WriteLine("No adapters found.");
                Console.ReadLine();
                return;
            }

            do
            {
                Console.Clear();
                Console.WriteLine($"Found adapters:");
                foreach (var adapter in adapters)
                {
                    Console.WriteLine($"{adapter.AdapterId}: Name: {adapter.Name}");
                }
                Console.WriteLine("Input a adapter(#) to connect to: ");
                var read = Console.ReadLine();
                if (int.TryParse(read, out var readInt))
                {
                    if (readInt > adapters.Count || readInt < 0)
                    {
                        continue;
                    }

                    var adapter = adapters.FirstOrDefault(x => x.AdapterId == readInt);
                    if (adapter == null)
                    {
                        continue;
                    }
                    validInput = true;
                    _config.Model.adapterId = adapter.AdapterId;
                    _config.SaveConfig();
                    _screen.Start();
                }
            }while (!validInput);
        }
Exemplo n.º 2
0
        public async Task Run(string[] args)
        {
            //If we are on windows and trying to read screen we have to set dpi awareness for DuplicateOutput1 to work.
            // DuplicateOutput1 is required for duplicate output to be hdr aware.
#if ANYCPU
#else
            try
            {
                if (Environment.OSVersion.Version >= new Version(6, 3, 0))                 // win 8.1 added support for per monitor dpi
                {
                    if (Environment.OSVersion.Version >= new Version(10, 0, 15063))        // win 10 creators update added support for per monitor v2
                    {
                        WindowsApi.SetProcessDpiAwarenessContext((int)WindowsApi.DPI_AWARENESS_CONTEXT.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
                    }
                    else
                    {
                        WindowsApi.SetProcessDpiAwareness(WindowsApi.PROCESS_DPI_AWARENESS.Process_Per_Monitor_DPI_Aware);
                    }
                }
                else
                {
                    Console.WriteLine($"{Environment.OSVersion.Version} is not supported. min req: {new Version(6, 3, 0)} (win 8.1)");
                    return;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
#endif

            try
            {
                var isHeadless = false;
                foreach (var value in args)
                {
                    if (!string.IsNullOrWhiteSpace(value) && value.Equals("--headless", StringComparison.OrdinalIgnoreCase))
                    {
                        isHeadless = true;
                        break;
                    }
                }

                _config = new Config();
                _config.LoadConfig();

                _map = ConfigureServices(isHeadless);

                _input.InstallServices(_map);
                Thread inputThread = null;
                if (!isHeadless)
                {
                    inputThread      = new Thread(new ThreadStart(_input.HandleInput));
                    inputThread.Name = "Input Thread";
                }

                _core.InstallServices(_map);

                _screen.InstallServices(_map);
                _hueClient.InstallServices(_map);
                _zoneProcesser.InstallServices(_map);
                _rgbLighter.InstallServices(_map);
                _stripLighter.InstallServices(_map);
                _socketServer.InstallServices(_map);

                inputThread?.Start();
                await _core.Start(isHeadless);

                _screen.Start();
                await _socketServer.Start();

                AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;

                Console.CancelKeyPress += Console_CancelKeyPress;

                if (isHeadless)
                {
                    await _core.StartScreenReading();
                }

                //Delay until application quit
                await Task.Delay(-1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }