Exemple #1
0
        public MockReliableDictionary(Uri uri)
            : base(uri)
        {
            // Set the OnDictionaryChanged callback to fire the DictionaryChanged event.
            InternalDictionaryChanged +=
                (sender, c) =>
            {
                if (DictionaryChanged != null)
                {
                    NotifyDictionaryChangedEventArgs <TKey, TValue> e = null;
                    switch (c.ChangeType)
                    {
                    case ChangeType.Added:
                        e = new NotifyDictionaryItemAddedEventArgs <TKey, TValue>(c.Transaction, c.Key, c.Added);
                        break;

                    case ChangeType.Removed:
                        e = new NotifyDictionaryItemRemovedEventArgs <TKey, TValue>(c.Transaction, c.Key);
                        break;

                    case ChangeType.Updated:
                        e = new NotifyDictionaryItemUpdatedEventArgs <TKey, TValue>(c.Transaction, c.Key, c.Added);
                        break;
                    }

                    DictionaryChanged.Invoke(this, e);
                }

                MockDictionaryChanged?.Invoke(this, c);
            };
        }
Exemple #2
0
        /// <summary>
        ///     Handles the DictionaryChanged event of the Dictionary control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="string" /> instance containing the event data.</param>
        /// <exception cref="System.ArgumentOutOfRangeException"></exception>
        private void Dictionary_DictionaryChanged(object sender, NotifyDictionaryChangedEventArgs <string, UserState> e)
        {
            if (this.Partition.WriteStatus != PartitionAccessStatus.Granted)
            {
                return;
            }
            IReliableDictionary <string, UserState> dictionary = sender as IReliableDictionary <string, UserState>;

            switch (e.Action)
            {
            case NotifyDictionaryChangedAction.Add:
                NotifyDictionaryItemAddedEventArgs <string, UserState> add = e as NotifyDictionaryItemAddedEventArgs <string, UserState>;
                this.sendService.SendMessageAsync(new FabricNotifyModel
                {
                    Action        = NotifyAction.Add,
                    Value         = add?.Value.ToJson(),
                    ServiceName   = this.Context.ServiceName.AbsoluteUri,
                    DictionaryKey = dictionary?.Name.AbsolutePath,
                    Key           = null
                }).GetAwaiter().GetResult();
                break;

            case NotifyDictionaryChangedAction.Update:
                NotifyDictionaryItemUpdatedEventArgs <string, UserState> update = e as NotifyDictionaryItemUpdatedEventArgs <string, UserState>;
                this.sendService.SendMessageAsync(new FabricNotifyModel
                {
                    Action        = NotifyAction.Update,
                    Value         = update?.Value.ToJson(),
                    ServiceName   = this.Context.ServiceTypeName,
                    DictionaryKey = dictionary?.Name.AbsolutePath,
                    Key           = null
                }).GetAwaiter().GetResult();
                break;

            case NotifyDictionaryChangedAction.Remove:
                NotifyDictionaryItemRemovedEventArgs <string, UserState> remove = e as NotifyDictionaryItemRemovedEventArgs <string, UserState>;
                this.sendService.SendMessageAsync(new FabricNotifyModel
                {
                    Action        = NotifyAction.Delete,
                    Key           = remove?.Key,
                    ServiceName   = this.Context.ServiceTypeName,
                    DictionaryKey = dictionary?.Name.AbsolutePath,
                    Value         = null
                }).GetAwaiter().GetResult();
                break;

            case NotifyDictionaryChangedAction.Clear:
                break;

            case NotifyDictionaryChangedAction.Rebuild:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #3
0
 /// <summary>
 /// Called when a dictionary item remove notification has been
 /// triggered. Remove the key from our secondary index.
 /// </summary>
 /// <param name="e"></param>
 private void ProcessDictionaryRemoveNotification(NotifyDictionaryItemRemovedEventArgs <string, Order> e)
 {
     lock (this.lockObject)
     {
         var order = this.SecondaryIndex.Where(x => x.Id == e.Key).FirstOrDefault();
         if (order != null)
         {
             this.SecondaryIndex = this.SecondaryIndex.Remove(order);
         }
     }
 }
Exemple #4
0
        public MockReliableDictionary(Uri uri)
            : base(uri, null)
        {
            // Set the OnDictionaryChanged callback to fire the DictionaryChanged event.
            OnDictionaryChanged =
                (c) =>
            {
                if (DictionaryChanged != null)
                {
                    NotifyDictionaryChangedEventArgs <TKey, TValue> e;
                    switch (c.ChangeType)
                    {
                    case ChangeType.Added:
                        e = new NotifyDictionaryItemAddedEventArgs <TKey, TValue>(c.Transaction, c.Key, c.Added);
                        break;

                    case ChangeType.Removed:
                        e = new NotifyDictionaryItemRemovedEventArgs <TKey, TValue>(c.Transaction, c.Key);
                        break;

                    case ChangeType.Updated:
                        e = new NotifyDictionaryItemUpdatedEventArgs <TKey, TValue>(c.Transaction, c.Key, c.Added);
                        break;

                    default:
                        return(false);
                    }

                    DictionaryChanged.Invoke(this, e);
                }

                MockDictionaryChanged?.Invoke(this, c);

                return(true);
            };
        }
Exemple #5
0
        public void ConstructorSetsKey()
        {
            var args = new NotifyDictionaryItemRemovedEventArgs <string, string>(ExpectedKey);

            Assert.AreEqual(ExpectedKey, args.Key);
        }
Exemple #6
0
        public void ConstructorSetsActionToRemove()
        {
            var args = new NotifyDictionaryItemRemovedEventArgs <string, string>(ExpectedKey);

            Assert.AreEqual(NotifyDictionaryChangedAction.Remove, args.Action);
        }