/// <summary> /// Añade una tarea a la cola y la ejecuta /// </summary> public void Process(AbstractTask processor) { Task task; // Añade el procesador a la cola Queue.Add(processor); // Asigna los manejador de eventos processor.ActionProcess += (sender, evntArgs) => ActionProcess?.Invoke(sender, evntArgs); processor.Progress += (sender, evntArgs) => Progress?.Invoke(sender, evntArgs); processor.ProgressAction += (sender, evntArgs) => ProgressAction?.Invoke(sender, evntArgs); processor.EndProcess += (sender, evntArgs) => TreatEndProcess(sender as AbstractTask, evntArgs); // Crea la tarea para la compilación en otro hilo task = new Task(() => processor.Process()); // Arranca la tarea de generación try { task.Start(); } catch (Exception exception) { TreatEndProcess(processor, new EventArguments.EndProcessEventArgs($"Error al lanzar el proceso{Environment.NewLine}{exception.Message}", new List <string> { exception.Message })); } }
public void WhenObservationIsPaused_IsCurrentlyObservingIsFalse() { bool processWasExecuted = false; ActionProcess process = new ActionProcess(AssertIsNotObserving); Outcome testOutcome = new Outcome(); Observer.ObserveInteractions(process, testOutcome); Assert.That(processWasExecuted, $"The process that tests {nameof(Observer.IsCurrentlyObserving)} did not run. "); TestContext.WriteLine($"Process was Executed => {processWasExecuted}"); void AssertIsNotObserving() { bool isObserving = true; using (Observer.PauseObservation()) { isObserving = Observer.IsCurrentlyObserving; } Assert.False(isObserving); TestContext.WriteLine($"Is Observing => {isObserving}"); processWasExecuted = true; } }
public void WhenNestedProcessIsFinishedBeingObserved_ObservationReturnsToOuterProcess() { int testStarted = 1; int enteredOuterProcess = 2; int enteredInnerProcess = 3; int returnedToOuterProcess = 4; int currentPhase = 0; ActionProcess innerProcess = new ActionProcess(InnerProcess); Outcome innerOutcome = new Outcome(); Outcome outerOutcome = new Outcome(); ActionProcess outerProcess = new ActionProcess(OuterProcess); currentPhase = testStarted; Observer.ObserveInteractions(outerProcess, outerOutcome); Assert.That(currentPhase, Is.EqualTo(returnedToOuterProcess)); void OuterProcess() { Assert.That(currentPhase, Is.EqualTo(testStarted)); currentPhase = enteredOuterProcess; TestContext.WriteLine("Entered outer process. "); Observer.ObserveInteractions(innerProcess, innerOutcome); Assert.That(currentPhase, Is.EqualTo(enteredInnerProcess)); currentPhase = returnedToOuterProcess; TestContext.WriteLine("Returned to outer process. "); } void InnerProcess() { Assert.That(currentPhase, Is.EqualTo(enteredOuterProcess)); currentPhase = enteredInnerProcess; TestContext.WriteLine("Entered inner process. "); } }
void ActivateNode(NarrativeNode _node) { currentNode = _node; ActionProcess action = new ActionProcess(this, currentNode); processMgr.Launch(action); }
public void WhenObservationIsResumedAfterAPause_ConnectionsAreRegistered() { State involvedState = new State(); Outcome outcomeToTest = new Outcome(); IProcess process = new ActionProcess(PauseAndAfterwardNotifyInvolved); bool wasPaused = false; Assert.False(outcomeToTest.IsBeingAffected); Assert.False(involvedState.IsConsequential); Observer.ObserveInteractions(process, outcomeToTest); Assert.That(wasPaused); Assert.That(outcomeToTest.IsBeingAffected); Assert.That(involvedState.IsConsequential); void PauseAndAfterwardNotifyInvolved() { using (Observer.PauseObservation()) { wasPaused = true; } involvedState.NotifyInvolved(); } }
protected virtual void onAuction() { if (ActionProcess != null) { var delegates = ActionProcess.GetInvocationList(); Parallel.ForEach(delegates, d => d.DynamicInvoke(this, new AuctionEventArg() { Auction = _auction })); } }
public void IfObservationIsPausedWhileInProgress_NoDependenciesAreCreated() { State involvedState = new State(); Outcome outcomeToTest = new Outcome(); IProcess process = new ActionProcess(PauseAndNotifyInvolved); Assert.False(outcomeToTest.IsBeingAffected); Assert.False(involvedState.IsConsequential); Observer.ObserveInteractions(process, outcomeToTest); Assert.False(outcomeToTest.IsBeingAffected); Assert.False(involvedState.IsConsequential); void PauseAndNotifyInvolved() { using (Observer.PauseObservation()) { involvedState.NotifyInvolved(); } } }
public void WhenAStateNotifiesItsInvolvedDuringObservation_OutcomeIsDependentOnState() { State involvedState = new State(); Outcome outcomeToTest = new Outcome(); ActionProcess process = new ActionProcess(InvolveState); Assert.False(outcomeToTest.IsBeingAffected); Assert.False(involvedState.IsConsequential); Observer.ObserveInteractions(process, outcomeToTest); Assert.That(outcomeToTest.IsBeingAffected); Assert.That(involvedState.IsConsequential); void InvolveState() { Observer.NotifyInvolved(involvedState); } }
public void WhenPausedUsingPauseToken_ObservationsResumeAfterTokenIsDisposed() { State involvedState = new State(); Outcome outcome = new Outcome(); IProcess process = new ActionProcess(PauseAndCheckIfObserving); IDisposable pauseToken = null; bool processWasExecuted = false; Observer.ObserveInteractions(process, outcome); Assert.That(processWasExecuted); void PauseAndCheckIfObserving() { Assert.That(Observer.IsCurrentlyObserving); pauseToken = Observer.PauseObservation(); Assert.False(Observer.IsCurrentlyObserving); pauseToken.Dispose(); Assert.That(Observer.IsCurrentlyObserving); processWasExecuted = true; } }
/// <summary> /// Lanza un evento /// </summary> protected void RaiseEvent(EventArguments.ActionEventArgs.ActionType action, string message) { ActionProcess?.Invoke(this, new EventArguments.ActionEventArgs(action, Source, message)); }