public void Accept(StateChangedEvent evt) { var oldState = evt.Data.From; var state = evt.Data.To; this.OnSyncStateChanged(evt.Data.Folder, oldState, state); }
public void Accept(StateChangedEvent evt) { var oldState = evt.Data.From == "syncing" ? FolderSyncState.Syncing : FolderSyncState.Idle; var state = evt.Data.To == "syncing" ? FolderSyncState.Syncing : FolderSyncState.Idle; this.OnSyncStateChanged(evt.Data.Folder, oldState, state); }
/// <summary> /// Queues a transition in worker state for processing. Returns a task that can be awaited /// when the operation completes. /// </summary> /// <param name="request">The request.</param> /// <returns>The awaitable task.</returns> private Task <WorkerState> QueueStateChange(StateChangeRequest request) { lock (SyncLock) { if (StateChangeTask != null) { return(StateChangeTask); } var waitingTask = new Task <WorkerState>(() => { StateChangedEvent.Wait(); lock (SyncLock) { StateChangeTask = null; return(WorkerState); } }); StateChangeTask = waitingTask; StateChangedEvent.Reset(); StateChangeRequests[request] = true; waitingTask.Start(); CycleCancellation.Cancel(); return(waitingTask); } }
private void Awake() { stateChangedEvent = new StateChangedEvent(); gameState = GameState.GameStart; lastGameState = GameState.GameOver; }
private GameObject SetState(MenuState state, bool addToTrace) { MenuState previousState = _currentState; if (addToTrace && _currentState != state) { _stateTrace.Add(_currentState); } _currentState = state; if (_stateObject != null) { Destroy(_stateObject); _stateObject = null; } if (_stateMachine[state] != null) { _stateObject = Instantiate(_stateMachine[state], canvas.transform); ClearTraceIfNeeded(previousState, state); StateChangedEvent?.Invoke(previousState, state); } else { Debug.LogError($"Prefab object is null for state = {state.ToString()}. Changing state to initial."); SetInitialState(); } return(_stateObject); }
private void SetState(EXPDFConverterState _EXPDFConverterState, Exception _Exception = null) { State = _EXPDFConverterState; StateChangedEvent?.Invoke(this, new StateEventArgs <EXPDFConverterState>(State, (_Exception is null) ? ESourceState.Stable : ESourceState.Unstable, _Exception)); }
public void StopSearch() { Searcher.StopSearch(); State = ExplorerState.SearchFinished; if (StateChangedEvent != null) { StateChangedEvent.Invoke(State); } }
public void Search(string path, string fileName) { State = ExplorerState.Searching; Items.Clear(); Searcher.Search(path, fileName); if (StateChangedEvent != null) { StateChangedEvent.Invoke(State); } }
public void RemoveStateChangedEvent(string name, StateChangedEvent eventListener) { if (!changedEvents.ContainsKey(name)) { changedEvents.Add(name, eventListener); } else { changedEvents[name] -= eventListener; } }
/// <summary> /// Adds a state changed listener to the given state parameter /// </summary> /// <param name="name">The name of the state to listen to</param> /// <param name="eventListener">The event to invoke on state change</param> public void AddStateChangedEvent(string name, StateChangedEvent eventListener) { if (!myChangedEvents.ContainsKey(name)) { myChangedEvents.Add(name, eventListener); } else { myChangedEvents[name] += eventListener; } }
void SearchFinished(string fileName) { State = ExplorerState.SearchFinished; if (StateChangedEvent != null) { StateChangedEvent.Invoke(State); } if (SearcherProgressEvent != null) { SearcherProgressEvent.Invoke(fileName); } }
public void AddStateEqualsEvent(string name, object value, StateChangedEvent eventListener) { var key = new Tuple <string, object>(name, value); if (!stateEqualsEvents.ContainsKey(key)) { stateEqualsEvents.Add(key, eventListener); } else { stateEqualsEvents[key] += eventListener; } }
/// <summary> /// Removed a state equals listener to the given state parameter /// </summary> /// <param name="name">The name of the state to listen to</param> /// <param name="value">The value to invoke on</param> /// <param name="eventListener">The event to invoke on state change</param> public void RemoveStateEqualsEvent(string name, object value, StateChangedEvent eventListener) { Tuple <string, object> key = new Tuple <string, object>(name, value); if (!myStateEqualsEvents.ContainsKey(key)) { myStateEqualsEvents.Add(key, eventListener); } else { myStateEqualsEvents[key] -= eventListener; } }
/// <summary> /// Removed a state changed listener to the given state parameter /// </summary> /// <param name="name">The name of the state to listen to</param> /// <param name="index">The index of the element to listen to</param> /// <param name="eventListener">The event to invoke on state change</param> public void RemoveStateChangedEvent(string name, int index, StateChangedEvent eventListener) { name = string.Format(ARRAY_FORMAT, name, index); if (!myChangedEvents.ContainsKey(name)) { myChangedEvents.Add(name, eventListener); } else { myChangedEvents[name] -= eventListener; } }
/// <summary> /// Signals all state change requests to set. /// </summary> private void ClearStateChangeRequests() { lock (SyncLock) { // Mark all events as completed StateChangeRequests[StateChangeRequest.Start] = false; StateChangeRequests[StateChangeRequest.Pause] = false; StateChangeRequests[StateChangeRequest.Resume] = false; StateChangeRequests[StateChangeRequest.Stop] = false; StateChangedEvent.Set(); CycleCompletedEvent.Set(); } }
protected override void TransitionState(CardForERM state, StateChangedEvent <CardForERM> @event) { state.Code = @event.State.Code; state.FirmCode = @event.State.FirmCode; state.BranchCode = @event.State.BranchCode; state.CountryCode = @event.State.CountryCode; state.IsLinked = @event.State.IsLinked; state.IsActive = @event.State.IsActive; state.IsDeleted = @event.State.IsDeleted; state.ClosedForAscertainment = @event.State.ClosedForAscertainment; state.SortingPosition = @event.State.SortingPosition; state.Address = @event.State.Address; state.Rubrics = @event.State.Rubrics; }
/// <summary> /// 状态转变事件函数 /// </summary> /// <param name="act"></param> private void instOnTransitionedAction(StateMachine <StateInst, TriggerInst> .Transition act) { nlogger.Debug("On StateInst Transitioned."); TriggerInst trigger = act.Trigger; StateInst source = act.Source; StateInst dest = act.Destination; // 状态清零 _instStateCounts = 0; // 触发事件 - 状态转变 StateChangedEvent?.Invoke(dest); }
public void RemoveStateEqualsEvent(string name, int index, object value, StateChangedEvent eventListener) { name = string.Format(ARRAY_FORMAT, name, index); var key = new Tuple <string, object>(name, value); if (!stateEqualsEvents.ContainsKey(key)) { stateEqualsEvents.Add(key, eventListener); } else { stateEqualsEvents[key] -= eventListener; } }
/// <summary> /// Signals all state change requests to set. /// </summary> /// <param name="schedule">The cycle schedule.</param> /// <param name="oldState">The previosu worker state</param> /// <param name="newState">The new worker state</param> private void ClearStateChangeRequests(int schedule, WorkerState oldState, WorkerState newState) { lock (SyncLock) { // Mark all events as completed StateChangeRequests[StateChangeRequest.Start] = false; StateChangeRequests[StateChangeRequest.Pause] = false; StateChangeRequests[StateChangeRequest.Resume] = false; StateChangeRequests[StateChangeRequest.Stop] = false; StateChangedEvent.Set(); CycleCompletedEvent.Set(); OnStateChangeProcessed(oldState, newState); ScheduleCycle(schedule); } }
private void Awake() { if (!Instance) { Instance = this; OnGameStarted = new UnityEvent(); OnPause = new UnityEvent(); OnUnpause = new UnityEvent(); OnQuickTimeSuccess = new QuickTimeSuccess(); OnPlayingStateChanged = new StateChangedEvent(); OnButtonPressed = new ButtonPressed(); OnQuickTimeEventStart = new QuickTimeEventStart(); } else if (Instance != this) { Destroy(gameObject); } DontDestroyOnLoad(this); }
private void CreateNewRelayEvent(RelayState eventType, bool success, DateTime time) { var relayEvent = new RelayEvent(eventType, success, time); StateChangedEvent?.Invoke(this, new StateChangeEventArgs(EventType.RelayEvent, relayEvent)); }
private void SetState(TaskState state, object message = null) { State = state; StateChangedEvent?.Invoke(State, message); }
/// <summary> /// Executes the worker cycle control logic. /// This includes processing state change requests, /// the exeuction of use cycle code, /// and the scheduling of new cycles. /// </summary> private void ExecuteWorkerCycle() { CycleStopwatch.Restart(); lock (SyncLock) { if (IsDisposing || IsDisposed) { WorkerState = WorkerState.Stopped; // Cancel any awaiters try { StateChangedEvent.Set(); } catch { /* Ignore */ } return; } // Prevent running another instance of the cycle if (CycleCompletedEvent.IsSet == false) { return; } // Lock the cycle and capture relevant state valid for this cycle CycleCompletedEvent.Reset(); } var interruptToken = CycleCancellation.Token; var initialWorkerState = WorkerState; // Process the tasks that are awaiting if (ProcessStateChangeRequests()) { return; } try { if (initialWorkerState == WorkerState.Waiting && !interruptToken.IsCancellationRequested) { // Mark the state as Running WorkerState = WorkerState.Running; // Call the execution logic ExecuteCycleLogic(interruptToken); } } catch (Exception ex) { OnCycleException(ex); } finally { // Update the state WorkerState = initialWorkerState == WorkerState.Paused ? WorkerState.Paused : WorkerState.Waiting; lock (SyncLock) { // Signal the cycle has been completed so new cycles can be executed CycleCompletedEvent.Set(); // Schedule a new cycle ScheduleCycle(!interruptToken.IsCancellationRequested ? ComputeCycleDelay(initialWorkerState) : 0); } } }
private void OnStateChanged() { StateChangedEvent?.Invoke(this, EventArgs.Empty); }
public static void SetState(State _state) { StateChangedEvent?.Invoke(_state); }
/// <summary> /// Invoked when the toggle state changes. /// </summary> private void ToggleStateChangedInternal(object sender, StateChangedEvent eventData) { ToggleStateChanged?.Invoke(this, eventData); }
void StateChanged(UnityMCPeerID peerId, UnityMCSessionState sessionState) { StateChangedEvent?.Invoke(peerId, sessionState); }