public ChangedObjectsContainer PreSave(ChangeTracker changeTracker)
        {
            if (changeTracker == null)
            {
                return(null);
            }

            var changedObjects = changeTracker
                                 .Entries();

            if (changedObjects.Any())
            {
                var changedData = changedObjects
                                  .Select(x => new ChangedObject
                {
                    Object = x.Entity,
                    State  = x.State,
                    Type   = x.Entity.GetType()
                })
                                  .ToList();

                var changedDataContainer = new ChangedObjectsContainer()
                {
                    ChangedObjects = changedData
                };

                return(changedDataContainer);
            }

            return(null);
        }
        public async Task PostSaveAsync(ChangedObjectsContainer changedData)
        {
            if (changedData == null || changedData.ChangedObjects == null)
            {
                return;
            }

            var changedByType = changedData.ChangedObjects
                                .GroupBy(x => x.Type)
                                .ToList();

            var pendingTasks = new List <Task>();

            foreach (var typeGroup in changedByType)
            {
                var queryableTypeGroup = typeGroup
                                         .ToList();

                SubscriptionsByType subscriptionsByType;
                EntitySignalDataStore.SubscriptionsByType.TryGetValue(typeGroup.Key, out subscriptionsByType);

                if (subscriptionsByType != null)
                {
                    var method          = typeof(EntitySignalDataStore).GetMethod("GetSubscribed");
                    var genericMethod   = method.MakeGenericMethod(new[] { typeGroup.Key });
                    var subscribedUsers = (IEnumerable <UserSubscriptionResult>)genericMethod.Invoke(null, new Object[] { subscriptionsByType, queryableTypeGroup });

                    foreach (var subscribedUser in subscribedUsers)
                    {
                        if (subscribedUser.ConnectionId == null)
                        {
                            return;
                        }

                        var newTask = _dataHubContext.Clients.Client(subscribedUser.ConnectionId).Sync(subscribedUser);
                        pendingTasks.Add(newTask);
                    }
                }
            }

            await Task.WhenAll(pendingTasks);
        }
 public void PostSave(ChangedObjectsContainer changedData)
 {
     PostSaveAsync(changedData).Wait();
 }