Beispiel #1
0
            /// <summary>
            /// Adds a new key to the dictionary, if it doesn't already exist in the dictionary.
            /// </summary>
            public override bool TryAdd(TKey key, TValue value)
            {
                var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>();

                this.Context.SendEvent(this.DictionaryActor, SharedDictionaryEvent.TryAddEvent(key, value, op.Actor.Id));
                var e = op.Actor.ReceiveEventAsync(typeof(SharedDictionaryResponseEvent <bool>)).Result as SharedDictionaryResponseEvent <bool>;

                return(e.Value);
            }
Beispiel #2
0
            /// <summary>
            /// Updates the value for an existing key in the dictionary, if that key has a specific value.
            /// </summary>
            public override bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue)
            {
                var op = this.Runtime.Scheduler.GetExecutingOperation <ActorOperation>();

                this.Runtime.SendEvent(this.DictionaryActor, SharedDictionaryEvent.TryUpdateEvent(key, newValue, comparisonValue, op.Actor.Id));
                var e = op.Actor.ReceiveEventAsync(typeof(SharedDictionaryResponseEvent <bool>)).Result as SharedDictionaryResponseEvent <bool>;

                return(e.Value);
            }
Beispiel #3
0
            /// <summary>
            /// Removes the specified key from the dictionary.
            /// </summary>
            public override bool TryRemove(TKey key, out TValue value)
            {
                var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>();

                this.Context.SendEvent(this.DictionaryActor, SharedDictionaryEvent.TryRemoveEvent(key, op.Actor.Id));
                var e = op.Actor.ReceiveEventAsync(typeof(SharedDictionaryResponseEvent <Tuple <bool, TValue> >)).Result
                        as SharedDictionaryResponseEvent <Tuple <bool, TValue> >;

                value = e.Value.Item2;
                return(e.Value.Item1);
            }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mock{TKey, TValue}"/> class.
 /// </summary>
 internal Mock(ActorExecutionContext.Mock context, IEqualityComparer <TKey> comparer)
     : base(null)
 {
     this.Context = context;
     if (comparer != null)
     {
         this.DictionaryActor = context.CreateActor(
             typeof(SharedDictionaryActor <TKey, TValue>),
             SharedDictionaryEvent.InitializeEvent(comparer));
     }
     else
     {
         this.DictionaryActor = context.CreateActor(typeof(SharedDictionaryActor <TKey, TValue>));
     }
 }
Beispiel #5
0
            /// <summary>
            /// Gets or sets the value associated with the specified key.
            /// </summary>
            public override TValue this[TKey key]
            {
                get
                {
                    var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>();
                    this.Context.SendEvent(this.DictionaryActor, SharedDictionaryEvent.GetEvent(key, op.Actor.Id));
                    var e = op.Actor.ReceiveEventAsync(typeof(SharedDictionaryResponseEvent <TValue>)).Result as SharedDictionaryResponseEvent <TValue>;
                    return(e.Value);
                }

                set
                {
                    this.Context.SendEvent(this.DictionaryActor, SharedDictionaryEvent.SetEvent(key, value));
                }
            }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mock{TKey, TValue}"/> class.
 /// </summary>
 internal Mock(ControlledRuntime runtime, IEqualityComparer <TKey> comparer)
     : base(null)
 {
     this.Runtime = runtime;
     if (comparer != null)
     {
         this.DictionaryActor = this.Runtime.CreateActor(
             typeof(SharedDictionaryActor <TKey, TValue>),
             SharedDictionaryEvent.InitializeEvent(comparer));
     }
     else
     {
         this.DictionaryActor = this.Runtime.CreateActor(typeof(SharedDictionaryActor <TKey, TValue>));
     }
 }