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();
            }
        }
        private void Dictionary_DictionaryChanged(object sender, NotifyDictionaryChangedEventArgs <int, NationalCountyStats> e)
        {
            switch (e.Action)
            {
            case NotifyDictionaryChangedAction.Clear:
                return;

            case NotifyDictionaryChangedAction.Add:
                NotifyDictionaryItemAddedEventArgs <int, NationalCountyStats> addEvent = e as NotifyDictionaryItemAddedEventArgs <int, NationalCountyStats>;

                long tmp = -1;

                if (this.statsDictionary.TryGetValue("totalDoctors", out tmp))
                {
                    this.statsDictionary["totalDoctors"]           += addEvent.Value.DoctorCount;
                    this.statsDictionary["totalPatientCount"]      += addEvent.Value.PatientCount;
                    this.statsDictionary["totalHealthReportCount"] += addEvent.Value.HealthReportCount;
                }
                else
                {
                    this.statsDictionary["totalDoctors"]           = addEvent.Value.DoctorCount;
                    this.statsDictionary["totalPatientCount"]      = addEvent.Value.PatientCount;
                    this.statsDictionary["totalHealthReportCount"] = addEvent.Value.HealthReportCount;
                }

                this.historyDictionary[addEvent.Key] = new DataSet(
                    addEvent.Value.DoctorCount,
                    addEvent.Value.PatientCount,
                    addEvent.Value.HealthReportCount);
                return;

            case NotifyDictionaryChangedAction.Update:
                NotifyDictionaryItemUpdatedEventArgs <int, NationalCountyStats> updateEvent =
                    e as NotifyDictionaryItemUpdatedEventArgs <int, NationalCountyStats>;
                this.statsDictionary["totalDoctors"]           += (updateEvent.Value.DoctorCount - this.historyDictionary[updateEvent.Key].totalDoctors);
                this.statsDictionary["totalPatientCount"]      += (updateEvent.Value.PatientCount - this.historyDictionary[updateEvent.Key].totalPatientCount);
                this.statsDictionary["totalHealthReportCount"] +=
                    (updateEvent.Value.HealthReportCount - this.historyDictionary[updateEvent.Key].totalHealthReportCount);
                this.historyDictionary[updateEvent.Key] = new DataSet(
                    updateEvent.Value.DoctorCount,
                    updateEvent.Value.PatientCount,
                    updateEvent.Value.HealthReportCount);
                return;

            case NotifyDictionaryChangedAction.Remove:
                return;

            default:
                break;
            }
        }
Exemple #4
0
 /// <summary>
 /// Called when a dictionary item update notification has been
 /// triggered. Add the key to our secondary index if we
 /// don't have it.
 /// </summary>
 /// <param name="e"></param>
 private void ProcessDictionaryUpdateNotification(NotifyDictionaryItemUpdatedEventArgs <string, Order> e)
 {
     if (e?.Value != null)
     {
         lock (this.lockObject)
         {
             var order = this.SecondaryIndex.
                         Where(x => x.Id == e.Value.Id).FirstOrDefault();
             if (order != null)
             {
                 this.SecondaryIndex = this.SecondaryIndex.Remove(order).Add(e.Value);
             }
         }
     }
 }
Exemple #5
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);
            };
        }
        public void ConstructorSetsValue()
        {
            var args = new NotifyDictionaryItemUpdatedEventArgs <string, string>(ExpectedKey, ExpectedValue);

            Assert.AreEqual(ExpectedValue, args.Value);
        }
        public void ConstructorSetsActionToUpdate()
        {
            var args = new NotifyDictionaryItemUpdatedEventArgs <string, string>(ExpectedKey, ExpectedValue);

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