Exemplo n.º 1
0
            public async Task RelayCollectionChangeAsync(ICollectionChangeBundle <ContentType, OriginContentType> originBundle)
            {
                var convertedApplyingBundle = createApplyingCollectionChangeConversionBundle(originBundle);

                synchronizer.ApplyCollectionChangeBundle(convertedApplyingBundle);
                var convertedAppliedBundle = synchronizer.GetAppliedCollectionChangeBundle(convertedApplyingBundle);
                var convertedChangeAppliedEventSequence = new AsyncEventSequence();
                var convertedChangeAppliedArgs          = new CollectionChangeAppliedEventArgs <ItemType, ContentType>(convertedAppliedBundle, convertedChangeAppliedEventSequence);

                synchronizer.OnCollectionChangeApplied(convertedChangeAppliedArgs);
                await convertedChangeAppliedEventSequence.FinishDependenciesAsync();

                var conversionBundles = new ConversionCollectionChangeBundles(convertedAppliedBundle, originBundle);
                var changeConversionAppliedEventSequence = new AsyncEventSequence();
                var changeConversionAppliedArgs          = CollectionChangeConversionAppliedEventArgs <ItemType, ContentType, OriginContentType> .CreateAsynchronous(conversionBundles, changeConversionAppliedEventSequence);

                OnCollectionChangeConversionApplied(changeConversionAppliedArgs);
                await convertedChangeAppliedEventSequence.FinishDependenciesAsync();
            }
Exemplo n.º 2
0
        private void ConvertedCollectionChangeNotifer_CollectionChangeConversionApplied(object sender, CollectionChangeConversionAppliedEventArgs <ConvertedItemType, OriginalItemType, OriginalContentType> args)
        {
            var convertedContentContentChange = args.ConvertedCollectionChangeBundle.ContentContentChange;
            var convertedItemItemChange       = args.ConvertedCollectionChangeBundle.ItemItemChange;

            if (convertedContentContentChange.Action != convertedItemItemChange.Action)
            {
                CollectionChangeConversionThrowHelper.ThrowChangeActionMismatchException();
            }

            var action = convertedContentContentChange.Action;

            switch (action)
            {
            case NotifyCollectionChangedAction.Remove:
            case NotifyCollectionChangedAction.Add:
                var newConvertedContentContentItems = convertedContentContentChange.NewItems ??
                                                      throw new ArgumentException("No new converted content-content-items were given that can be attached as wanted parents.");

                var newConvertedItemItemItems = convertedItemItemChange.NewItems ??
                                                throw new ArgumentException("No new converted item-item-items were given that can be attached as wanted parents.");

                var originalItemsEnumerator  = newConvertedContentContentItems.GetEnumerator();
                var convertedItemsEnumerator = newConvertedItemItemItems.GetEnumerator();

                while (originalItemsEnumerator.MoveNext() && convertedItemsEnumerator.MoveNext())
                {
                    var convertedItem = convertedItemsEnumerator.Current;

                    switch (action)
                    {
                    case NotifyCollectionChangedAction.Remove:
                        convertedItem.DetachKnownWantParentsHandler(this);
                        break;

                    case NotifyCollectionChangedAction.Add:
                        var originalItem = originalItemsEnumerator.Current ??
                                           throw new ArgumentException("One item of the new converted item-item-items is null and cannot be attached as wanted parents.");

                        void OriginalItem_WantParents(object s, HavingParentsEventArgs e)
                        => e.AttachParents(originalItem);

                        convertedItem.AttachKnownWantParentsHandler(this, OriginalItem_WantParents);
                        break;
                    }
                }

                break;
            }
        }
Exemplo n.º 3
0
 protected void OnCollectionChangeConversionApplied(CollectionChangeConversionAppliedEventArgs <ItemType, ContentType, OriginContentType> args)
 => CollectionChangeConversionApplied?.Invoke(this, args);