Пример #1
0
            internal void Parent(ModelItem parent, ModelItem child)
            {
                if (this._featureManager == null)
                {
                    throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_ParentNotSupported, new object[2]
                    {
                        (object)parent.ItemType.Name,
                        (object)child.ItemType.Name
                    }));
                }
                ParentAdapter parentAdapter1 = (ParentAdapter)null;

                using (IEnumerator <FeatureProvider> enumerator = FeatureExtensions.CreateFeatureProviders(this._featureManager, typeof(ParentAdapter), parent).GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ParentAdapter parentAdapter2 = (ParentAdapter)enumerator.Current;
                        ModelItem     parent1        = parentAdapter2.RedirectParent(parent, child.ItemType);
                        if (parent1 == null)
                        {
                            throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_InvalidRedirectParent, new object[1]
                            {
                                (object)parentAdapter2.GetType().Name
                            }));
                        }
                        if (parent1 != parent)
                        {
                            this.Parent(parent1, child);
                            return;
                        }
                        parentAdapter1 = parentAdapter2;
                    }
                }
                if (parentAdapter1 == null || !parentAdapter1.CanParent(parent, child.ItemType))
                {
                    throw new NotSupportedException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_ParentNotSupported, new object[2]
                    {
                        (object)parent.ItemType.Name,
                        (object)child.ItemType.Name
                    }));
                }
                ModelItem parent2 = child.Parent;

                if (parent2 == parent)
                {
                    return;
                }
                if (parent2 != null)
                {
                    using (IEnumerator <FeatureProvider> enumerator = FeatureExtensions.CreateFeatureProviders(this._featureManager, typeof(ParentAdapter), parent2).GetEnumerator())
                    {
                        if (enumerator.MoveNext())
                        {
                            ((ParentAdapter)enumerator.Current).RemoveParent(parent2, parent, child);
                        }
                    }
                }
                parentAdapter1.Parent(parent, child);
            }
Пример #2
0
 internal bool CanParent(ModelItem parent, Type childType, ModelItem childItem, out ModelItem redirectedParent)
 {
     redirectedParent = (ModelItem)null;
     if (this._featureManager == null)
     {
         return(false);
     }
     using (IEnumerator <FeatureProvider> enumerator = FeatureExtensions.CreateFeatureProviders(this._featureManager, typeof(ParentAdapter), parent).GetEnumerator())
     {
         if (enumerator.MoveNext())
         {
             ParentAdapter parentAdapter = (ParentAdapter)enumerator.Current;
             redirectedParent = parentAdapter.RedirectParent(parent, childType);
             if (redirectedParent == null)
             {
                 throw new InvalidOperationException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Resources.Error_InvalidRedirectParent, new object[1]
                 {
                     (object)parentAdapter.GetType().Name
                 }));
             }
             if (redirectedParent.Equals((object)childItem))
             {
                 return(false);
             }
             ModelItem modelItem     = redirectedParent;
             ViewItem  logicalParent = ModelParent.ItemParentImplementationService.GetLogicalParent(modelItem);
             if (childItem != null)
             {
                 for (; logicalParent != (ViewItem)null; logicalParent = ModelParent.ItemParentImplementationService.GetLogicalParent(modelItem))
                 {
                     if (logicalParent.Equals((object)childItem.View))
                     {
                         return(false);
                     }
                     modelItem = modelItem.Parent;
                 }
             }
             if (childItem != null && parentAdapter.IsParent(redirectedParent, childItem))
             {
                 return(true);
             }
             if (redirectedParent == parent)
             {
                 return(parentAdapter.CanParent(parent, childType));
             }
             parent = redirectedParent;
             return(this.CanParent(parent, childType, childItem, out redirectedParent));
         }
     }
     return(false);
 }