/// <inheritdoc />
        public bool Run()
        {
            if (InternalStorage.RunningClient != null)
            {
                throw new Exception("A game mode is already running!");
            }

            InternalStorage.RunningClient = this;

            // Prepare the synchronization context
            var queue = new SemaphoreMessageQueue();

            _synchronizationContext = new SampSharpSynchronizationContext(queue);
            _messagePump            = new MessagePump(queue);

            SynchronizationContext.SetSynchronizationContext(_synchronizationContext);

            // Initialize the game mode and start the main routine
            Initialize();

            // Pump new tasks
            _messagePump.Pump(e => OnUnhandledException(new UnhandledExceptionEventArgs("async", e)));

            // Clean up
            InternalStorage.RunningClient = null;
            CommunicationClient.Disconnect();

            return(_shuttingDown);
        }
Exemple #2
0
        public async Task DownloadVerificationTestItems(int level)
        {
            if (!CommunicationClient.IsConnected)
            {
                await CommunicationClient.Connect();
            }

            if (Instrument.CompositionType == CorrectorType.PTZ)
            {
                await DownloadTemperatureTestItems(level);
                await DownloadPressureTestItems(level);
            }

            if (Instrument.CompositionType == CorrectorType.T)
            {
                await DownloadTemperatureTestItems(level);
            }

            if (Instrument.CompositionType == CorrectorType.P)
            {
                await DownloadPressureTestItems(level);
            }

            await CommunicationClient.Disconnect();
        }
Exemple #3
0
        /// <summary>
        ///     Runs this game mode client.
        /// </summary>
        /// <returns>true if shut down by the game mode, false otherwise.</returns>
        /// <exception cref="Exception">Thrown if a game mode is already running.</exception>
        public bool Run()
        {
            if (InternalStorage.RunningClient != null)
            {
                throw new Exception("A game mode is already running!");
            }

            InternalStorage.RunningClient = this;

            // Prepare the syncronization context
            _syncronizationContext = new SampSharpSyncronizationContext();
            _messagePump           = _syncronizationContext.MessagePump;

            SynchronizationContext.SetSynchronizationContext(_syncronizationContext);

            // Initialize the game mode and start the main routine
            Initialize();

            // Pump new tasks
            _messagePump.Pump();

            // Clean up
            InternalStorage.RunningClient = null;
            CommunicationClient.Disconnect();

            return(_shuttingDown);
        }
Exemple #4
0
        private async Task LiveReadItems(Dictionary <int, ReadingStabilizer> liveReadItems)
        {
            await CommunicationClient.Connect();

            do
            {
                foreach (var item in liveReadItems)
                {
                    var liveValue = await CommunicationClient.LiveReadItemValue(item.Key);

                    item.Value.ValueQueue.Enqueue(liveValue.NumericValue);
                    Container.Resolve <IEventAggregator>()
                    .PublishOnBackgroundThread(new LiveReadEvent(item.Key, liveValue.NumericValue));
                }
            } while (liveReadItems.Any(x => !x.Value.IsStable()));

            await CommunicationClient.Disconnect();
        }
Exemple #5
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     _appQuit = true;
     if (_framesRefreshTicker != null)
     {
         _framesRefreshTicker.Dispose();
     }
     if (_client != null)
     {
         _client.Disconnect();
     }
     if (_iRobot != null)
     {
         _iRobot.Disconnect();
     }
     if (_robotController != null)
     {
         _robotController.DisconnectRFIDReader();
     }
 }