コード例 #1
0
        public MidiEvent Read(MidiReader reader, ReadingSettings settings, byte currentStatusByte)
        {
            SystemRealTimeEvent systemRealTimeEvent = null;

            switch (currentStatusByte)
            {
            case EventStatusBytes.SystemRealTime.ActiveSensing:
                systemRealTimeEvent = new ActiveSensingEvent();
                break;

            case EventStatusBytes.SystemRealTime.Continue:
                systemRealTimeEvent = new ContinueEvent();
                break;

            case EventStatusBytes.SystemRealTime.Reset:
                systemRealTimeEvent = new ResetEvent();
                break;

            case EventStatusBytes.SystemRealTime.Start:
                systemRealTimeEvent = new StartEvent();
                break;

            case EventStatusBytes.SystemRealTime.Stop:
                systemRealTimeEvent = new StopEvent();
                break;

            case EventStatusBytes.SystemRealTime.TimingClock:
                systemRealTimeEvent = new TimingClockEvent();
                break;
            }

            systemRealTimeEvent.Read(reader, settings, MidiEvent.UnknownContentSize);
            return(systemRealTimeEvent);
        }
コード例 #2
0
        /// <summary>
        ///     运行部件驱动线程。
        /// </summary>
        /// <param name="runningMode">运行模式。</param>
        public virtual void Run(RunningModes runningMode)
        {
            StopEvent.Reset();

            if (_cancelTokenSource == null)
            {
                _cancelTokenSource = new CancellationTokenSource();
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Running(runningMode);
                        LogHelper.Debug($"{Name}部件启动。");
                    }
                    catch (OperationCanceledException)
                    {
                        //ignorl
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Debug("设备驱动程序异常", ex);
                    }
                }, TaskCreationOptions.AttachedToParent | TaskCreationOptions.LongRunning)
                .ContinueWith(task => Clean());
            }
        }
コード例 #3
0
        public async Task <bool> ExecuteCommand(StaticCommand staticCommand, TransmissionEvent transmissionEvent,
                                                ExecutionEvent executionEvent, StopEvent stopEvent, List <Condition> conditions, CommandTarget target)
        {
            if (conditions != null && conditions.Count == 0)
            {
                conditions = null;
            }

            var plugin = StaticCommands[staticCommand.GetType()];

            if (plugin != null)
            {
                if (!await UploadPluginToServer(plugin))
                {
                    return(false);
                }
            }

            _connectionManager.SendCommand(new DynamicCommand
            {
                CommandId         = staticCommand.CommandId,
                Target            = target,
                Conditions        = conditions,
                TransmissionEvent = transmissionEvent,
                ExecutionEvent    = executionEvent,
                CommandParameter  = staticCommand.GetCommandParameter().Data,
                PluginHash        = plugin?.PluginHash,
                StopEvent         = stopEvent
            });

            return(true);
        }
コード例 #4
0
        public QuestionGridViewModel(IEventAggregator eventAggregator, RoundService roundService, StandingsService standingsService)
        {
            _eventAggregator = eventAggregator;
            _roundService = roundService;
            _standingsService = standingsService;

            AddCommand = new DelegateCommand<object>(AddPoints);
            SubstractCommand = new DelegateCommand<object>(Substract);

            StartCommand = new DelegateCommand(Start);
            StopCommand = new DelegateCommand(Stop);
            BonusCommand = new DelegateCommand(Bonus);
            WrongCommand = new DelegateCommand(Wrong);
            CorrectCommand = new DelegateCommand(Correct);
            CloseCommand = new DelegateCommand(Close);
            BonusAddCommand = new DelegateCommand<object>(AddBonusPoints);

            _showEvent = _eventAggregator.GetEvent<ShowEvent>();
            _activateEvent = _eventAggregator.GetEvent<ActivateEvent>();
            _stopEvent = _eventAggregator.GetEvent<StopEvent>();
            _bonusEvent = _eventAggregator.GetEvent<BonusEvent>();
            _closeEvent = _eventAggregator.GetEvent<CloseEvent>();

            _newSelectorEvent = _eventAggregator.GetEvent<NewSelectorEvent>();
        }
コード例 #5
0
        // Reads incoming data from the client's network stream
        private void Read()
        {
            // Get client stream
            // TODO - this can fail if internet drops, needs to be debugged and checked for
            var Stream = Client.GetStream();

            // Create a byte buffer
            int BytesRead = Client.Available;
            byte[] Buffer = new byte[BytesRead];

            // Create a wait handle array so we can cancel this thread if need be
            Stream.BeginRead(Buffer, 0, BytesRead, (IAsyncResult Result) =>
            {
                try
                {
                    // Check if peer has been stopped
                    if (StopEvent.WaitOne(0)) return;

                    // End reading
                    BytesRead = Stream.EndRead(Result);

                    // Check if any data was read
                    if (BytesRead > 0)
                    {
                        // Invoke data received handler
                        Server.OnDataReceived?.Invoke((this, Buffer), EventArgs.Empty);
                    }
コード例 #6
0
ファイル: P2pPeer.cs プロジェクト: Sajo8/cs-turtlecoin
        // Reads incoming data from the client's network stream
        private void Read()
        {
            // Get client stream
            var Stream = Client.GetStream();

            // Create a byte buffer
            byte[] Buffer = new byte[Client.Available];

            // Create a wait handle array so we can cancel this thread if need be
            Stream.BeginRead(Buffer, 0, Client.Available, (IAsyncResult Result) =>
            {
                try
                {
                    // Check if peer has been stopped
                    if (StopEvent.WaitOne(0))
                    {
                        return;
                    }

                    // End reading
                    var BytesRead = Stream.EndRead(Result);

                    // Check if any data was read
                    if (BytesRead > 0)
                    {
                        // Invoke data received handler
                        Server.OnDataReceived?.Invoke((this, Buffer), EventArgs.Empty);
                    }
コード例 #7
0
        /// <summary>
        ///     运行部件驱动线程。
        /// </summary>
        /// <param name="runningMode">运行模式。</param>
        public virtual void Run(RunningModes runningMode)
        {
            StopEvent.Reset();

            if (_cancelTokenSource == null)
            {
                _cancelTokenSource = new CancellationTokenSource();
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        Running(runningMode);
                        log.Debug($"{Name}部件启动。");
                    }
                    catch (OperationCanceledException ex2)
                    {
                        MessageBox.Show("yichang" + ex2.ToString());
                        //ignorl
                    }
                    catch (Exception ex)
                    {
                        log.Fatal("设备驱动程序异常", ex);
                        MessageBox.Show("yichang" + ex.ToString());
                    }
                }, TaskCreationOptions.AttachedToParent | TaskCreationOptions.LongRunning)
                .ContinueWith(task => Clean());
            }
        }
コード例 #8
0
 public void StopPlaying()
 {
     if (isPlaying)
     {
         StopEvent?.Invoke();
         SetPlayState(false);
     }
 }
コード例 #9
0
 protected virtual void OnStopped(StopEvent msg)
 {
     StoppedReason = msg.StopReason;
     StopConnection(msg.StopReason);
     if (Stopped != null)
     {
         Stopped(this, new StreamStoppedEventArgs(msg.StopReason));
     }
 }
コード例 #10
0
        /// <summary>
        /// Stops logging operations
        /// </summary>
        /// <param name="ForceStop">If this is set to true, all remaining queued messages will be dropped</param>
        public void Stop(bool ForceStop = false)
        {
            // Set whether or not the logger will ignore the remaining queue
            IgnoreQueue = ForceStop;

            // Stop the logging thread
            StopEvent.Set();
            LoggerThread.Join();
        }
コード例 #11
0
ファイル: Peer.cs プロジェクト: fexra/CantiLib
        // Disposes of this peer, stopping any threads
        internal void Dispose()
        {
            // Stop packet buffer thread
            StopEvent.Set();
            PacketBufferThread.Join();

            // Kill underlying P2P peer
            P2pPeer.Stop();
        }
コード例 #12
0
ファイル: ServiceHostBase.cs プロジェクト: toby2o12/microdot
        /// <summary>
        /// Signals the service to stop.
        /// </summary>
        public void Stop()
        {
            if (StopEvent.WaitOne(0))
            {
                throw new InvalidOperationException("Service is already stopped, or is running in an unsupported mode.");
            }

            StopEvent.Set();
        }
コード例 #13
0
ファイル: TimeManager.cs プロジェクト: pdxparrot/ssj2019
            public void Stop()
            {
                if (!IsRunning)
                {
                    return;
                }
                _isRunning = false;

                StopEvent?.Invoke(this, EventArgs.Empty);
            }
コード例 #14
0
        public override void ProcessPausingResult(DirectiveData data, CommunicationEventArgs comEventArgs)
        {
            comEventArgs.DeviceStatus = DeviceStatusEnum.Running;
            comEventArgs.Description  = IdleDesc.Paused.ToString();;
            SetStatus(DeviceStatusEnum.Running);

            StopEvent.TrySetResult(new DeviceIOResult(true));

            OnCommunicationChange(comEventArgs);
        }
コード例 #15
0
        public void OkButtonClick(CommandTarget commandTarget, TransmissionEvent transmissionEvent,
                                  ExecutionEvent executionEvent, StopEvent stopEvent)
        {
            CommandTarget     = commandTarget;
            TransmissionEvent = transmissionEvent;
            ExecutionEvent    = executionEvent;
            StopEvent         = stopEvent;

            DialogResult = true;
        }
コード例 #16
0
ファイル: ApiServer.cs プロジェクト: zpalmtree/cs-turtlecoin
 /// <summary>
 /// Stops the server and ends all associated threads
 /// </summary>
 public void Stop()
 {
     StopEvent.Set();
     ListenerThread.Join();
     foreach (Thread worker in WorkerThreads)
     {
         worker.Join();
     }
     Listener.Stop();
 }
コード例 #17
0
        private void On(StopEvent gameEvent)
        {
            if (CurrentState.State == MatchState.Completed ||
                CurrentState.State == MatchState.CompletedAndNotFinished ||
                CurrentState.State == MatchState.PastMatchImported)
            {
                throw new InvalidOperationException("Not Expected");
            }

            CurrentState.State = MatchState.CompletedAndNotFinished;
        }
コード例 #18
0
        private void ProcessItem(MailQueueItem item)
        {
            //Console.WriteLine("Start ProcessItem({0})", item.Account.Account);
            // The following code prevents current task from starting if service is stopped.
            if (StopEvent.WaitOne(0))
            {
                return;
            }

            item.Retrieve(_collector.ItemsPerSession, StopEvent);
        }
コード例 #19
0
        protected override WorkItem <MailQueueItem> Selector()
        {
            // The following block stops generating tasks if service is stopped.
            if (StopEvent.WaitOne(0))
            {
                return(null);
            }

            MailQueueItem item = _collector.GetItem();

            return(item != null ? new WorkItem <MailQueueItem>(item) : null);
        }
コード例 #20
0
 /// <summary>
 ///     停止任务线程
 /// </summary>
 public virtual void Stop()
 {
     if (_cancelTokenSource == null)
     {
         return;
     }
     if (_cancelTokenSource.Token.CanBeCanceled)
     {
         StopEvent.Set();
         _cancelTokenSource.Cancel();
         LogHelper.Debug($"{Name}部件停止。");
     }
 }
コード例 #21
0
        /// <summary>
        /// Stops this database
        /// </summary>
        public void Stop()
        {
            // Signal a stop event
            StopEvent.Set();
            WriteThread.Join();

            // Dispose of sqlite connection
            if (Connection.State == ConnectionState.Open)
            {
                Connection.Close();
            }
            Connection.Dispose();
        }
コード例 #22
0
 public void EventPublisherPublishes()
 {
     using (var scope = BeginScope())
     {
         var start = new StartEvent();
         var stop  = new StopEvent();
         var pub   = scope.Resolve <IEventPublisher>();
         pub.Publish(start);
         pub.Publish(stop);
         var handler = scope.Resolve <InfrastructureEventHandler>();
         Assert.Equal(2, handler.Events.Count);
         Assert.Equal(start, handler.Events[0]);
         Assert.Equal(stop, handler.Events[1]);
     }
 }
コード例 #23
0
 public void EventPublisherPublishes()
 {
     using (var scope = BeginScope())
     {
         var start = new StartEvent();
         var stop = new StopEvent();
         var pub = scope.Resolve<IEventPublisher>();
         pub.Publish(start);
         pub.Publish(stop);
         var handler = scope.Resolve<InfrastructureEventHandler>();
         Assert.Equal(2, handler.Events.Count);
         Assert.Equal(start, handler.Events[0]);
         Assert.Equal(stop, handler.Events[1]);
     }
 }
コード例 #24
0
        public void Rotate(Vector3 v, float deltaTime, bool active = false)
        {
            var speed = acceleration.GetSpeed(deltaTime, rotationSpeed, active);

            movement.Rotate(v * speed);

            if (previousRotationSpeed < 0.1f && speed != previousRotationSpeed)
            {
                RotateEvent?.Invoke();
            }
            else if (previousRotationSpeed > 0.1f && speed == 0)
            {
                StopEvent?.Invoke();
            }
            previousRotationSpeed = speed;
        }
コード例 #25
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                StopEvent.Dispose();
                WindowsService?.Dispose();
                MonitoredShutdownProcess?.Dispose();
            }

            disposed = true;
        }
コード例 #26
0
        private void Terminate(State <TState, TData> upcomingState)
        {
            if (_currentState.StopReason == null)
            {
                var reason = upcomingState.StopReason;
                LogTermination(reason);
                foreach (var t in _timers)
                {
                    t.Value.Cancel();
                }
                _timers.Clear();
                _currentState = upcomingState;

                var stopEvent = new StopEvent <TState, TData>(reason, _currentState.StateName, _currentState.StateData);
                _terminateEvent(stopEvent);
            }
        }
コード例 #27
0
        // Stops this peer's associated threads
        internal void Stop()
        {
            // Invoke peer disconnected callback
            Server.OnPeerDisconnected?.Invoke(this, EventArgs.Empty);

            // Set stop event
            StopEvent.Set();

            // Stop write thread
            if (WriteThread.IsAlive)
            {
                WriteThread.Join();
            }

            // Stop client
            Client.Close();
        }
コード例 #28
0
        public void LookRotate(Vector3 v, float deltaTime, bool active = false)
        {
            var speed = acceleration.GetSpeed(deltaTime, rotationSpeed, active);

            currentLookRotation = Vector3.Lerp(currentLookRotation, v, speed);
            movement.LookRotate(currentLookRotation);

            if (previousLookRotationSpeed < 0.1f && speed != previousLookRotationSpeed)
            {
                RotateEvent?.Invoke();
            }
            else if (previousLookRotationSpeed > 0.1f && speed == 0)
            {
                StopEvent?.Invoke();
            }
            previousLookRotationSpeed = speed;
        }
コード例 #29
0
 /// <summary>
 /// 停止按钮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void stop_Click(object sender, EventArgs e)
 {
     if (running)//运行中
     {
         StopEvent?.Invoke();
         running              = false;
         pausing              = false;
         Start.Enabled        = true;
         pause.Enabled        = true;
         resume.Enabled       = true;
         stop.Enabled         = true;
         SelectMethod.Enabled = true;
     }
     else
     {
         return;
     }
 }
コード例 #30
0
        // Старт процесса в режиме удаленного управления
        public async Task RemoteStart(IDevice device, string box, DateTime dateTime, bool primaryVerification)
        {
            try
            {
                Product = new ProductInfo(device, box, dateTime, primaryVerification);
                RemoteStartEvent?.Invoke(this, new EventArgs());
                cts = new CancellationTokenSource();
                await Task.Run(() => Start(device, primaryVerification, cts.Token));

                savingResults.SaveResult(Product, TestResults, dialogService);
                StopEvent?.Invoke(this, new EventArgs());
                ProcessComplete?.Invoke(this, new EventArgs());
            }
            catch (OperationCanceledException)
            {
                StopEvent?.Invoke(this, new EventArgs());
            }
        }
コード例 #31
0
        /// <summary>
        /// Emulates a signal instructing the service to close.  This will typically be used
        /// for unit testing services.
        /// </summary>
        /// <exception cref="TimeoutException">
        /// Thrown if the service did not exit gracefully in time before it would have
        /// been killed (e.g. by Kubernetes or Docker).
        /// </exception>
        public void Signal()
        {
            if (readyToExit)
            {
                // Application has already indicated that it has terminated.

                return;
            }

            var isTerminating = terminating;

            terminating = true;

            if (isTerminating)
            {
                return;     // Already terminating.
            }

            log?.LogInfo(() => $"Emulated stop request: [timeout={Timeout}]");

            cts.Cancel();

            lock (handlers)
            {
                foreach (var handler in handlers)
                {
                    new Thread(new ThreadStart(handler)).Start();
                }
            }

            StopEvent.Set();

            try
            {
                NeonHelper.WaitFor(() => readyToExit, Timeout);
                log?.LogInfo(() => "Process stopped gracefully.");
            }
            catch (TimeoutException)
            {
                log?.LogWarn(() => $"Process did not stop within [{Timeout}].");
                throw;
            }
        }
コード例 #32
0
        public static void RecordPath()
        {
            m_RecordPath = true;

            double lastSplitX = -1;
            double lastSplitY = -1;

            while (m_RecordPath)
            {
                Api.Sync.WaitOne();

                if (Api.PlayerData.Found)
                {
                    double currentX     = Api.PlayerData.PlayerXPosition;
                    double currentY     = Api.PlayerData.PlayerYPosition;
                    uint   currentMapId = Api.PlayerData.MapId;

                    if (lastSplitX == -1)
                    {
                        lastSplitX = currentX;
                        lastSplitY = currentY;

                        RecordPathEvent?.Invoke(null, new RecordPathEventArgs(new Waypoint(currentMapId, currentX, currentY)));

                        continue;
                    }

                    double splitDistance = Math.Sqrt((currentX - lastSplitX) * (currentX - lastSplitX) + (currentY - lastSplitY) * (currentY - lastSplitY));

                    if (splitDistance < SplitDistance)
                    {
                        continue;
                    }

                    lastSplitX = currentX;
                    lastSplitY = currentY;

                    RecordPathEvent?.Invoke(null, new RecordPathEventArgs(new Waypoint(currentMapId, currentX, currentY)));
                }
            }

            StopEvent?.Invoke(null, new EventArgs());
        }
コード例 #33
0
 public async Task AsyncEventPublisherPublishes()
 {
     using (var scope = BeginScope())
     {
         var start = new StartEvent();
         var stop = new StopEvent();
         var pub = scope.Resolve<IEventPublisher>();
         var handler = scope.Resolve<InfrastructureEventHandler>();
         var asyncHandler = scope.Resolve<InfrastructureAsyncEventHandler>();
         Assert.Equal(0, handler.Events.Count);
         Assert.Equal(0, asyncHandler.Events.Count);
         await pub.PublishAsync(start);
         await pub.PublishAsync(stop);
         
         Assert.Equal(2, handler.Events.Count);
         Assert.Equal(start, handler.Events[0]);
         Assert.Equal(stop, handler.Events[1]);
         Assert.Equal(2, asyncHandler.Events.Count);
         Assert.Equal(start, asyncHandler.Events[0]);
         Assert.Equal(stop, asyncHandler.Events[1]);
     }
 }
コード例 #34
0
 protected virtual void OnStopped(StopEvent msg)
 {
     StoppedReason = msg.StopReason;
       StopConnection(msg.StopReason);
       if (Stopped!=null) {
     Stopped(this, new StreamStoppedEventArgs(msg.StopReason));
       }
 }