Esempio n. 1
0
        public async Task <ZRunResult> RunAsync()
        {
            // send request to run the game
            var request  = ZRequestFactory.CreateRunGameRequest(_targetGame.RunnableName, _runArgs);
            var response = await ZRouter.GetResponseAsync(request);

            if (response.StatusCode != ZResponseStatusCode.Ok)
            {
                return(ZRunResult.Error);
            }

            // parse run results
            var runResult = _parser.Parse(response.ResponsePackets.Single());

            // ReSharper disable once InvertIf
            if (runResult == ZRunResult.Success)
            {
                // prepare instance state to track game state
                // begin track
                _pipe            = new _GamePipe(_logger, _pipeName);
                _pipe.PipeEvent += _PipeEventHandler;

                _processTracker.ProcessDetected += _ProcessTrackerOnProcessDetected;
                _processTracker.ProcessLost     += _ProcessTrackerOnProcessLost;

                // begin track process tracker
                _processTracker.StartTrack();
            }

            return(runResult);
        }
Esempio n. 2
0
        private void _ProcessTrackerOnProcessLost(object sender, EventArgs e)
        {
            _processTracker.StopTrack();

            _processTracker.ProcessDetected -= _ProcessTrackerOnProcessDetected;
            _processTracker.ProcessLost     -= _ProcessTrackerOnProcessLost;

            _OnCustomPipeEvent("StateChanged", "State_GameClose");

            _pipe.PipeEvent -= _PipeEventHandler;
            _pipe            = null;

            // after closing the game process,
            // its pipe is destroyed automatically + the thread that processes the reading will be completed
        }