Exemplo n.º 1
0
        private void Notify(List <ChangeDetails> changes)
        {
            // Inspect the changes and push update notifications to generated groups
            foreach (var change in changes)
            {
                var notificationGroups = _notificationGroupManager.GetGroupsForEntity(change.Entity.GetType());

                foreach (var group in notificationGroups)
                {
                    var groupProperties = change.Properties.Where(c => group.PropertyNames.Contains(c.PropertyName));

                    if (change.EntityState == EntityState.Added ||
                        change.EntityState == EntityState.Modified && groupProperties.Any(p => p.IsChanged))
                    {
                        // Notify the group for the current set this entity was added to
                        var groupName    = group.GetGroupName(groupProperties.Select(p => p.CurrentValue));
                        var notification = ChangeNotification.Create(
                            ChangeType.Added,
                            change);

                        Debug.WriteLine("Change notification: A {0} with key {1} was added to notification group {2}", change.Entity.GetType().Name, String.Join(",", change.EntityKey.EntityKeyValues.Select(k => k.Value)), groupName);

                        OnChange(groupName, notification);

                        if (change.EntityState == EntityState.Modified)
                        {
                            // Notify the group for the original set this entity was removed from
                            groupName    = group.GetGroupName(groupProperties.Select(p => p.OriginalValue));
                            notification = ChangeNotification.Create(
                                ChangeType.Deleted,
                                change);

                            Debug.WriteLine("Change notification: A {0} with key {1} was removed from notification group {2}", change.Entity.GetType().Name, String.Join(",", change.EntityKey.EntityKeyValues.Select(k => k.Value)), groupName);

                            OnChange(groupName, notification);
                        }
                    }
                    else
                    {
                        // No notication group properties changed or the entity was deleted so just tell the current set group that an entity changed
                        var groupName    = group.GetGroupName(groupProperties.Select(p => p.CurrentValue));
                        var notification = ChangeNotification.Create(
                            change.EntityState,
                            change);

                        Debug.WriteLine("Change notification: A {0} with key {1} was changed in notification group {2}", change.Entity.GetType().Name, String.Join(",", change.EntityKey.EntityKeyValues.Select(k => k.Value)), groupName);

                        OnChange(groupName, notification);
                    }
                }
            }
        }
 protected abstract void OnChange(string groupName, ChangeNotification change);