internal static void ScheduleChildAntiDependenciesForRebinding(CommandProcessorContext cpc, EFObject efObject)
 {
     // identify any binding that was referencing this symbol, and add it to the list of things to rebind.
     var visitor = new AntiDependencyCollectorVisitor();
     visitor.Traverse(efObject);
     ScheduleBindingsForRebind(cpc, visitor.AntiDependencyBindings);
 }
Exemplo n.º 2
0
        private static void ProcessExternalRemoveChange(
            EfiChangeGroup changeGroup, IList<ItemBinding> bindingsForRebind, ExternalXMLModelChange modelChange)
        {
            var changedEFObject = modelChange.ChangedEFObject;
            var parentEFObject = modelChange.Parent;
            if (changedEFObject != null)
            {
                var staleItemBinding = changedEFObject as ItemBinding;
                var staleDefaultableValue = changedEFObject as DefaultableValue;

                var parentEFContainer = parentEFObject as EFContainer;
                Debug.Assert(parentEFContainer != null, "parentEfObject was not an EFContainer!");
                if (staleItemBinding != null)
                {
                    // if this is an itembinding, then we have to directly null out the xobject and rebind since the refname is a "symlink" to the xattribute
                    foreach (var child in parentEFContainer.Children)
                    {
                        var updatedItemBinding = child as ItemBinding;
                        if (updatedItemBinding != null
                            && updatedItemBinding.EFTypeName == staleItemBinding.EFTypeName)
                        {
                            updatedItemBinding.SetXObject(null);
                            updatedItemBinding.Rebind();
                            changedEFObject = updatedItemBinding;
                            break;
                        }
                    }
                }
                else if (staleDefaultableValue != null)
                {
                    foreach (var child in parentEFContainer.Children)
                    {
                        var updatedDefaultableValue = child as DefaultableValue;
                        if (updatedDefaultableValue != null
                            && updatedDefaultableValue.EFTypeName == staleDefaultableValue.EFTypeName)
                        {
                            updatedDefaultableValue.SetXObject(null);
                            changedEFObject = updatedDefaultableValue;
                            break;
                        }
                    }
                }
                else
                {
                    // Find all the dependent binding.
                    var visitor = new AntiDependencyCollectorVisitor();
                    visitor.Traverse(changedEFObject);
                    foreach (var binding in visitor.AntiDependencyBindings)
                    {
                        if (!bindingsForRebind.Contains(binding))
                        {
                            bindingsForRebind.Add(binding);
                        }
                    }
                    // Delete(false) because it has already been removed from XLinq tree
                    changedEFObject.Delete(false);
                }

                // record the change so views get updated
                changeGroup.RecordModelChange(EfiChange.EfiChangeType.Delete, changedEFObject, String.Empty, String.Empty, String.Empty);
            }
            else
            {
                throw new ChangeProcessingFailedException();
            }
        }