Ejemplo n.º 1
0
        private async void buttonComDevice_Click(object sender, EventArgs e)
        {
            DeviceManagerApi.ToogleComPortDevice(new System.IO.Ports.SerialPort("COM1"), false);
            await Task.Delay(5000);

            DeviceManagerApi.ToogleComPortDevice(new System.IO.Ports.SerialPort("COM1"), true);
        }
Ejemplo n.º 2
0
        public static async Task CheckSensor()
        {
            Ex.Log("SystemManager.CheckSensor()");
            Task checking = Task.CompletedTask;
            CancellationTokenSource cancelTokenSource = null;
            short count = 0;

            while (true)
            {
                await Task.Delay(2000);

                Ex.TryLog("Попытка скрыть панель задач", () =>
                {
#pragma warning disable CS0162 // Unreachable code detected
                    if (false)
                    {
                        Taskbar.Hide();
                    }
#pragma warning restore CS0162 // Unreachable code detected
#if DEBUG
#else
                    Taskbar.Hide();
#endif
                });
                cancelTokenSource = cancelTokenSource ?? new CancellationTokenSource();
                bool isTaskComplete = checking.IsCompleted;
                //Ex.Log($"isTaskComplete={checking.Status}({checking.IsCompleted})");
                bool isFound = await DeviceManagerApi.IsSensorExistAsync();

                //bool isFound = boolTest; //TEST
                if (isFound)
                {
                    if (count < 3)
                    {
                        Ex.Log("Task CheckSensor(): Sensor Found");
                    }
                    if (count < 5)
                    {
                        count++;
                    }
                    if (isTaskComplete)
                    {
                        Ex.Log("Task CheckSensor(): Sensor Connected");
                        OnSensorFound();
                        CancellationToken token = cancelTokenSource.Token;
                        checking = CheckBrowser(token);
                        checking.Start();
                        Ex.Log($"Task CheckSensor(): Task CheckBrowser IsCompleted={checking.IsCompleted}; Status={checking.Status}");
                    }
                }
                else
                {
                    //Ex.Log("не найден сенсор. посылаем токен отмены");
                    cancelTokenSource.Cancel();
                    cancelTokenSource = null;
                }
            }
            Ex.Log("Task CheckSensor(): while(true) finished");
        }
Ejemplo n.º 3
0
        private async void buttonSHG8200_Click(object sender, EventArgs e)
        {
            string guidPanel = "745a17a0-74d3-11d0-b6fe-00a0c90f57da";

            //var getx = DeviceManagerApi.GetInstancePaths(guidPanel);
            //await Task.Delay(5000);
            //DeviceManagerApi.ToogleSHG8200(true);
            //var hz = DeviceManagerApi.IsSensorExist();
            buttonSHG8200.Text = DeviceManagerApi.DeviceCount().ToString();
        }
Ejemplo n.º 4
0
 private static bool RestartRedratDevice()
 {
     try
     {
         DeviceManagerApi.ToogleRedRat(false);
         Thread.Sleep(100);
         DeviceManagerApi.ToogleRedRat(true);
         Thread.Sleep(50);
         return(true);
     } catch (Exception ex)
     {
         logger.Error(ex, ex.Message);
         PublicData.write_info($"Не удалось перезапустить Redrat - придется сделать это вручную.\n{ex.Message}");
         return(false);
     }
 }
Ejemplo n.º 5
0
        public static async Task RunGame(string _PathGame)
        {
            var task = Task.Run(async() =>
            {
                if (string.IsNullOrEmpty(_PathGame))
                {
                    Ex.Throw($"_PathGame({_PathGame}) - is empty at RunGame(string _PathGame)");
                }
                if (!File.Exists(_PathGame))
                {
                    Ex.Throw($"File is not exist at '_PathGame({_PathGame})' at RunGame(string _PathGame)");
                }

                await KillAllGames();
                //var overlay = new OverlayLauncher();
                var processLaunched = ProcessSD.Start(_PathGame);
                Ex.Log($"GameManager.RunGame(): ProcessLaunched={processLaunched}");
                await Task.Delay(1000);
                var getApps     = ProcessSD.GetProcesses().Where(x => !string.IsNullOrEmpty(x.MainWindowTitle) && !x.ProcessName.Contains("GameStand") && !x.ProcessName.Contains("devenv") && !x.ProcessName.Contains("explorer") && !x.ProcessName.Contains("TeamViewer")).ToArray();
                processLaunched = processLaunched ?? getApps.FirstOrDefault();
                Ex.Log($"GameManager.RunGame(): ProcessToFocus={processLaunched}; count={getApps?.Length};");
                SetFokus(processLaunched).RunParallel();
                //Ex.Log($"Process Launched = {processLaunched.MainWindowTitle}({processLaunched.ProcessName});");
                //Ex.Log($"Process Launched={_PathGame}");
                bool isRun = true;
                while (isRun)
                {
                    await Task.Delay(2000);
                    bool isFound = await DeviceManagerApi.IsSensorExistAsync();
                    if (!isFound)
                    {
                        Ex.Log("Сенсор отключился 1");
                        await Task.Delay(60000);
                        bool isFoundAfterTime = await DeviceManagerApi.IsSensorExistAsync();
                        if (!isFoundAfterTime)
                        {
                            //KillGame(processLaunched);
                            Ex.Log("Сенсор отключен спустя 60с -> Закрываем все;");
                            isRun = false;
                            await KillAllGames();
                        }
                    }
                }
            });
            await Task.Yield(); //Just for remove warning
        }
Ejemplo n.º 6
0
 private static bool ComRestart(SerialPort serial)
 {
     try
     {
         serial.Close();
         DeviceManagerApi.ToogleComPortDevice(serial, false);
         Thread.Sleep(100);
         DeviceManagerApi.ToogleComPortDevice(serial, true);
         Thread.Sleep(100);
         return(true);
     } catch (Exception ex)
     {
         logger.Error(ex, $"{serial.PortName}: {ex.Message}");
         PublicData.write_info($"Не удалось перезапустить порт {serial.PortName} ({ex.Message}) - придется сделать это вручную.");
         return(false);
     }
 }
Ejemplo n.º 7
0
        public static async Task OnWindowLoadedAsync()
        {
            Ex.Log("SystemManager.OnWindowLoadedAsync()");
            Ex.Catch("SystemManager: Попытка скрыть панель задач", () =>
            {
#pragma warning disable CS0162 // Unreachable code detected
                if (false)
                {
                    Taskbar.Hide();
                }
#pragma warning restore CS0162 // Unreachable code detected
#if DEBUG
#else
                Taskbar.Hide();
#endif
            });

            Ex.Log("SystemManager.Taskbar.Hide() passed.");

            if (!isRe1ParamExist)
            {
                isSensorWasActiveOnLaunch = await DeviceManagerApi.IsSensorExistAsync();
            }
            else
            {
                isSensorWasActiveOnLaunch = true;
            }

            Ex.Log($"SystemManager.isSensorWasActiveOnLaunch={isSensorWasActiveOnLaunch}");
            GameManager.KillAllGames().RunParallel();
            CheckSensor().RunParallel();
            //mh = new MouseHookAdapter();
            if (isSensorWasActiveOnLaunch == false)
            {
                OnSensorFound += RelaunchApp;
            }
            ComPort.PortReader().RunParallel();
            Ex.Log($"SystemManager.isRelaunched={isRe1ParamExist}");
            Ex.Log($"SystemManager.isShowTaskbarOnExit={isShowTaskbarOnExit}");
            SetRegDisableSwipeEdgeMachine();
            OnScreenSaverDetected += async() => await GameManager.KillAllGames();

            CheckScreenSaver().RunParallel();
            WarningSwipe();
        }