Example #1
0
        void OnMessage(string m)
        {
            var changedItem = JsonMapper.ToObject <TableNotificationMessage <T> >(m);

            // notify listeners
            if (_notifications.ContainsKey(changedItem.eventType))
            {
                var itemSnapshot = new ItemSnapshot(changedItem.data, _storage, TableMeta);
                var notification = _notifications[changedItem.eventType];

                NotifyListeners(StorageNotificationType.ON, notification, itemSnapshot);
                NotifyListeners(StorageNotificationType.ONCE, notification, itemSnapshot);
                NotifyListeners(StorageNotificationType.DELETE, notification, itemSnapshot);
            }
        }
Example #2
0
        void NotifyListeners(StorageNotificationType notificationType, IDictionary <StorageNotificationType, List <Action <ItemSnapshot> > > notification, ItemSnapshot itemSnapshot)
        {
            if (notification.ContainsKey(notificationType))
            {
                var events = notification[notificationType];
                foreach (var evt in events)
                {
                    evt.Invoke(itemSnapshot);
                }

                if (notificationType == StorageNotificationType.ONCE)
                {
                    notification[notificationType].Clear();
                }
            }
        }