protected override bool Act() { IOutcome <TCollection> oldOutcome = outcome; IOutcome <TCollection> newOutcome = new Outcome <TCollection>(this); IEnumerable <TValue> newElements = Observer.ObserveInteractions(reactionProcess, newOutcome); using (Observer.PauseObservation()) { // if (UsesRecycling) // { // //- TODO: Implement this. // } TCollection newCollection = CreateCollectionFromElements(newElements); newOutcome.Value = newCollection; outcome = newOutcome; if (AreCollectionsEqual(oldOutcome.Value, newOutcome.Value) == false) { SubscriptionManager.Publish(oldOutcome.Value, newOutcome.Value); //- TODO : This gives subscribers access to the internal collection. // We should return either an IEnumerable or a copy. return(true); } return(false); } }
public void ReleaseDependent(IOutcome dependentToRelease) { if (dependentToRelease != null) { RemoveAndExchangeUntilSuccessful(ref affectedOutcomes, dependentToRelease); } }
public bool AddDependent(IOutcome dependentToAdd) { if (dependentToAdd == null) { throw new ArgumentNullException(nameof(dependentToAdd)); } var oldFactorSet = affectedOutcomes; while (oldFactorSet.Contains(dependentToAdd) == false) { if (IsValid) { var newFactorSet = oldFactorSet.Add(dependentToAdd); //- TODO : Test this and make sure if this is invalidated the dependent still gets a notification. if (TryCompareExchange(ref affectedOutcomes, newFactorSet, oldFactorSet, out oldFactorSet)) { return(true); } } else { //- TODO : This code is replicated in section where the CasualEvent tries to add dependencies. dependentToAdd.Invalidate(this); return(false); } } return(false); }
public void AndWhenTheRobotMovesForwardFourSpaces() { moveOutcome = Robot.Action(RobotCommands.Move); //1,1,NORTH moveOutcome = Robot.Action(RobotCommands.Move); //1,2,NORTH moveOutcome = Robot.Action(RobotCommands.Move); //1,3,NORTH moveOutcome = Robot.Action(RobotCommands.Move); //1,4,NORTH }
public void ReadResultedIn <TState>(IOutcome <StorageException, Result> outcome, IEnumerable <TypedStateBundle> bundles, object? @object) { foreach (var stateBundle in bundles) { ReadResultedIn(outcome, stateBundle.Id, stateBundle.State, stateBundle.StateVersion, stateBundle.Metadata, @object); } }
private static void StartNewEvent(IOutcome eventOutcome) { CausalEvent newEvent = (EventPool.Count > 0)? EventPool.Pop() : new CausalEvent(); newEvent.Outcome = eventOutcome; newEvent.PriorEvent = currentEvent; currentEvent = newEvent; }
public void Success_Messages_Not_Null_By_Default() { IOutcome outcome = Outcomes.Success(); Assert.IsTrue(outcome.Success); Assert.IsNotNull(outcome.Messages); Assert.IsTrue(outcome.ToString() == string.Empty); }
/// <summary> /// Used in cases where we need to create an OutcomeResult from an Outcome. /// This was implemented for use in Outcomes.Pipeline /// </summary> internal OutcomeResult(IOutcome <TValue> outcome) { Success = outcome.Success; Messages = outcome.Messages; Value = outcome.Value; StatusCode = outcome.StatusCode; Keys = outcome.Keys; }
/// <summary> /// Used in cases where we need to create an OutcomeResult from an Outcome. /// This was implemented for use in Outcomes.Pipeline /// </summary> internal OutcomeResult(IOutcome outcome) { Success = outcome.Success; Messages = outcome.Messages; Value = default(TValue); StatusCode = outcome.StatusCode; Keys = outcome.Keys; }
public void QueryObjectResultedIn(IOutcome <StorageException, Result> outcome, QuerySingleResult result, object @object) { outcome .AndThen(good => good) .Otherwise(bad => throw new InvalidOperationException($"Bogus outcome: {bad.Message}")); _access.WriteUsing("add", result.StateObject); }
public void Success_WithMessage_Supports_Format() { IOutcome outcome = Outcomes.Success() .WithMessage("Bob {0} at {1}", "wins", "life"); Assert.True(outcome.Success); Assert.True(outcome.ToString() == "Bob wins at life"); }
public void OfType_CanConvertObservations() { IOutcome <object> outcome = Outcome.Success("Hello, World!"); var converted = outcome.OfType <string>(); Assert.IsTrue(converted.WasSuccessful); Assert.IsTrue(converted.Observations.SequenceEqual(new[] { "Hello, World!" })); }
public GallaryModel(IManufacture manufacutre, ICar car, IBuy buy, IBuyRecords buyRecords, IOutcome outcome, IPaginatedMetaService paginatedMetaService) { this.manufacutre = manufacutre; this.car = car; this.buy = buy; this.buyRecords = buyRecords; this.outcome = outcome; _paginatedMetaService = paginatedMetaService; }
public void Failure_OfT_Messages_Not_Null_By_Default() { IOutcome <int> outcome = Outcomes.Failure <int>(); Assert.False(outcome.Success); Assert.NotNull(outcome.Messages); Assert.True(outcome.Value == 0); Assert.True(outcome.ToString() == string.Empty); }
public void Success_Messages_Prepend_With_Empty_Message_Collection() { IOutcome outcome = Outcomes.Success() .PrependMessage("This should not throw an error."); Assert.True(outcome.Success); Assert.True(outcome.Messages.Count == 1); Assert.True(outcome.Messages[0] == "This should not throw an error."); }
/// <summary> /// Adds keys from the specified outcome, if any. /// </summary> /// <param name="outcome">Source outcome that messages are pulled from.</param> public SuccessOutcomeBuilder <TValue> WithKeysFrom(IOutcome outcome) { foreach (var key in outcome.Keys.Keys) { this.Keys[key] = outcome.Keys[key]; } return(this); }
public void Success_Messages_OfT_Not_Null_By_Default() { IOutcome <int> outcome = Outcomes.Success <int>(); Assert.IsTrue(outcome.Success); Assert.IsNotNull(outcome.Messages); Assert.IsTrue(outcome.Value == 0); Assert.IsTrue(outcome.ToString() == string.Empty); }
public bool AddDependent(IOutcome dependentOutcome) { //- TODO : This code is replicated in section where CasualEvent tries to add dependencies. if (dependentOutcome.IsValid) { dependentOutcome.Invalidate(this); } return(false); }
public static T ObserveInteractions<T>(IProcess<T> processToObserve, IOutcome outcomeToModify) { if (processToObserve == null) { throw new ArgumentNullException(nameof(processToObserve), ProvidedNullProcess); } if (outcomeToModify == null) { throw new ArgumentNullException(nameof(outcomeToModify), ProvidedNullOutcome); } StartNewEvent(outcomeToModify); try { return processToObserve.Execute(); } finally { ConcludeCurrentEvent(); } }
public mantainModel(IBuyRecords buyRecords, IOutcome outcome, ICash cash, IIncome income, ISellrecord sellrecord, IAfterBuyExpncess afterBuyExpncess, IAfterSellExpncess afterSellExpncess) { this.buyRecords = buyRecords; this.sellrecord = sellrecord; this.afterBuyExpncess = afterBuyExpncess; this.afterSellExpncess = afterSellExpncess; this.income = income; this.cash = cash; this.outcome = outcome; }
public QNode Generate(QNode node, IOperator op) { IOutcome outcome = env.act(node.State, op); QNode succ = new QNode(); succ.State = outcome.State; succ.Parent = node; succ.UsedOperator = op; succ.Q = 0; return(succ); }
private Outcome Create(IOutcome outcome) { var definition = GetOutcomeDefinition(outcome.DefinitionId); return new Outcome { Title = definition?.Name ?? DictionaryPhraseRepository.Current.Get("/Demo/Outcomes/Unknown Outcome", "(Unknown)"), Date = outcome.DateTime, IsCurrentVisit = outcome.InteractionId.ToGuid() == Tracker.Current.Interaction.InteractionId, OutcomeGroup = GetOutcomeGroup(definition) }; }
//================================== // ReadResultInterest //================================== public void ReadResultedIn <TState>(IOutcome <StorageException, Result> outcome, string?id, TState state, int stateVersion, Metadata?metadata, object? @object) { outcome.AndThen(result => { ((Action <TState, int>)@object) !(state, stateVersion); return(result); }).Otherwise(cause => { if (cause.Result == Result.NotFound) { ((Action <TState, int>)@object) !(default !, -1);
public ANode Generate(ANode node, IOperator op) { IOutcome outcome = env.act(node.State, op); ANode succ = new ANode(); succ.State = outcome.State; succ.UsedOperator = op; succ.Parent = node; succ.G = (int)(node.G - outcome.Reward); return(succ); }
private Outcome Create(IOutcome outcome) { var definition = GetOutcomeDefinition(outcome.DefinitionId); return(new Outcome() { Title = definition?.Name ?? DictionaryRepository.Get("/Demo/Outcomes/UnknownOutcome", "(Unknown)"), Date = outcome.DateTime, IsCurrentVisit = outcome.InteractionId.ToGuid() == Tracker.Current.Interaction.InteractionId, OutcomeGroup = GetOutcomeGroup(definition) }); }
public UCTNode Generate(UCTNode node, IOperator op) { IOutcome outcome = env.act(node.State, op); UCTNode succ = new UCTNode(); succ.State = outcome.State; succ.UsedOperator = op; succ.Parent = node; succ.Q = double.MaxValue; succ.N = 0; return(succ); }
public IEnumerator <TValue> GetEnumerator() { React(); IOutcome <TCollection> currentOutcome = outcome; //- Make sure it's the same collection each time foreach (TValue element in currentOutcome.Value) { Observer.NotifyInvolved(currentOutcome); yield return(element); } }
public void AppendAllResultedIn <TSource, TSnapshotState>(IOutcome <StorageException, Result> outcome, string streamName, int streamVersion, IEnumerable <TSource> sources, Metadata metadata, Optional <TSnapshotState> snapshot, object @object) where TSource : Source { outcome.AndThen(result => { _access.WriteUsing("appendResultedIn", new JournalData <TSource, TSnapshotState>(streamName, streamVersion, null, result, sources.ToList(), snapshot)); return(result); }).Otherwise(cause => { _access.WriteUsing("appendResultedIn", new JournalData <TSource, TSnapshotState>(streamName, streamVersion, cause, Result.Error, sources.ToList(), snapshot)); return(cause.Result); }); }
protected override bool Act() { IOutcome newOutcome = new Outcome(this); Observer.ObserveInteractions(reactionProcess, newOutcome); using (Observer.PauseObservation()) //- Prevents anything we do here from adding dependencies to any other observations this one may be nested in. { outcome = newOutcome; return(true); } }
public void WriteResultedIn <TState, TSource>(IOutcome <StorageException, Result> outcome, string id, TState state, int stateVersion, IEnumerable <Source <TSource> > sources, object @object) { outcome .AndThen(result => { _access.WriteUsing("writeStoreData", new StoreData <TSource>(1, result, state, sources, null, null)); return(result); }) .Otherwise(cause => { _access.WriteUsing("writeStoreData", new StoreData <TSource>(1, cause.Result, state, sources, null, cause)); return(cause.Result); }); }
public void ReadResultedIn <TState>(IOutcome <StorageException, Result> outcome, string id, TState state, int stateVersion, Metadata metadata, object @object) { outcome .AndThen(result => { _access.WriteUsing("readStoreData", new StoreData <TState>(1, result, state, new List <Source <TState> >(), metadata, null)); return(result); }) .Otherwise(cause => { _access.WriteUsing("readStoreData", new StoreData <TState>(1, cause.Result, state, new List <Source <TState> >(), metadata, cause)); return(cause.Result); }); }