예제 #1
0
        private void PublishEntities(IEnumerable <object> exportEntities)
        {
            var syncData = new SyncDataMessage(this, exportEntities, _deletedEntityKeys);

            EventFns.Publish(syncData);

            // Signal to our clients that data has changed
            if (syncData.SavedEntities.Any() || syncData.DeletedEntityKeys.Any())
            {
                RaiseDataChangedEvent(syncData.SavedEntities, syncData.DeletedEntityKeys);
            }
        }
예제 #2
0
        /// <summary>
        ///   Internal use.
        /// </summary>
        void IHandle <SyncDataMessage> .Handle(SyncDataMessage syncData)
        {
            if (syncData.IsSameProviderAs(this))
            {
                return;
            }

            // Merge deletions
            var removers = syncData.DeletedEntityKeys
                           .Select(key => Manager.FindEntity(key, false))
                           .Where(entity => entity != null)
                           .ToList();

            if (removers.Any())
            {
                Manager.RemoveEntities(removers, false);
            }

            // Merge saved entities, may take several passes
            var           savedEntities = syncData.SavedEntities.ToList();
            List <object> mergers;

            do
            {
                mergers = savedEntities.Where(SyncInterceptor.ShouldImportEntity).ToList();
                Manager.ImportEntities(mergers, MergeStrategy.PreserveChangesUpdateOriginal);

                savedEntities = savedEntities.Except(mergers).ToList();
            } while (mergers.Any());

            // Signal to our clients that data has changed
            if (syncData.SavedEntities.Any() || syncData.DeletedEntityKeys.Any())
            {
                RaiseDataChangedEvent(syncData.SavedEntities, syncData.DeletedEntityKeys);
            }
        }