Exemple #1
0
        /// <summary>
        /// Creates a new BagNode for the specified PropBag, optionally using a collection of PropNodes as the source.
        /// The source PropNodes are cloned. If the value of a PropNode cannot be cloned, an InvalidOperation exception will be thrown.
        /// This is the core of IPropBag.Clone()
        /// </summary>
        /// <param name="objectId">The new globally unique Id to use for this new BagNode.</param>
        /// <param name="propBag">The client IPropBag.</param>
        /// <param name="template">A Collection of PropNodes to use as a template for the new PropBag's Child PropItems. Can be null.</param>
        /// <param name="maxPropsPerObject">The maximum number of PropItems a single PropBag can have.</param>
        /// <param name="callPSParentNodeChangedEventSubsCache">A reference to a service that caches Parent Node Change Event dispatchers.</param>
        public BagNode(ObjectIdType objectId, IPropBag propBag, PropNodeCollectionIntInterface template, int maxPropsPerObject, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
        {
            CompKey      = new SimpleExKey(objectId, 0);
            PropBagProxy = new WeakRefKey <IPropBag>(propBag ?? throw new ArgumentNullException(nameof(propBag)));

            _callPSParentNodeChangedEventSubsCache = callPSParentNodeChangedEventSubsCache ?? throw new ArgumentNullException(nameof(callPSParentNodeChangedEventSubsCache));
            _parentNCSubscriberCollection          = null;

            if (template == null)
            {
                _propNodeCollection = new PropNodeCollection(maxPropsPerObject);
            }
            else
            {
                _propNodeCollection = ClonePropNodes(template, this);

                //var x = EqualityComparer<WeakRefKey<PropModelType>?>.Default;
                //bool propItemSetIdsMatch = x.Equals(_propNodeCollection.PropItemSetId, template.PropItemSetId);
                //System.Diagnostics.Debug.Assert(EqualityComparer<WeakRefKey<PropModelType>?>.Default.Equals(_propNodeCollection.PropItemSetId, template.PropItemSetId), "PropItemSetIds don't match.");

                bool propItemSetIdsMatch = _propNodeCollection.PropItemSetKey == template.PropItemSetKey;

                System.Diagnostics.Debug.Assert(propItemSetIdsMatch, "PropItemSetIds don't match.");
                System.Diagnostics.Debug.Assert(_propNodeCollection.IsFixed == template.IsFixed, "IsFixed doesn't match.");
            }
        }
Exemple #2
0
        private PropNodeCollectionIntInterface ClonePropNodes(PropNodeCollectionIntInterface sourcePNC, BagNode targetParent)
        {
            PropNodeCollectionIntInterface result;

            List <PropNode> newPropNodeColl = new List <PropNode>();

            foreach (PropNode propNode in sourcePNC.GetPropNodes())
            {
                PropNode newPropNode = propNode.CloneForNewParent(targetParent, useExistingValues: true);
                newPropNodeColl.Add(newPropNode);
            }

            if (sourcePNC.IsFixed)
            {
                System.Diagnostics.Debug.Assert(!sourcePNC.PropItemSetKey.IsEmpty, "We found a fixed PropSetCollection that has an empty PropItemSetKey.");
                // Create a Fixed PropNodeCollection.
                result = new PropNodeCollectionFixed(newPropNodeColl, sourcePNC.PropItemSetKey, sourcePNC.MaxPropsPerObject);
            }
            else
            {
                // Create an open PropNodeCollection.
                result = new PropNodeCollection(newPropNodeColl, sourcePNC.PropItemSetKey, sourcePNC.MaxPropsPerObject);
            }

            return(result);
        }
 public bool Equals(PropNodeCollectionIntInterface other)
 {
     return(other != null &&
            IsFixed == other.IsFixed &&
            EqualityComparer <IReadOnlyDictionary <PropNameType, IPropData> > .Default.Equals
                (GetPropDataItemsDict(), other.GetPropDataItemsDict()));
 }
Exemple #4
0
        public bool TryGetPropNodeCollection(ObjectIdType objectId, out PropNodeCollectionIntInterface propNodeCollection)
        {
            IEnumerable <PropNode> family = _children.Where(kvp => kvp.Key.Level1Key == objectId).Select(x => x.Value);

            if (family.FirstOrDefault() != null)
            {
                propNodeCollection = new PropNodeCollectionFixed(family, _propItemSetKey, MaxPropsPerObject);
                return(true);
            }
            else
            {
                propNodeCollection = null;
                return(false);
            }
        }
Exemple #5
0
 public PropNodeCollectionShared(PropNodeCollectionIntInterface sourcePropNodes)
     : this(sourcePropNodes.GetPropNodes(), sourcePropNodes.PropItemSetKey, sourcePropNodes.MaxPropsPerObject)
 {
 }
Exemple #6
0
 public void Add(PropNodeCollectionIntInterface sourcePropNodes)
 {
     Add(sourcePropNodes.GetPropNodes());
 }
 public PropNodeCollectionFixed(PropNodeCollectionIntInterface sourcePropNodes, PropItemSetKeyType propItemSetKey)
     : this(sourcePropNodes.GetPropNodes(), propItemSetKey, sourcePropNodes.MaxPropsPerObject)
 {
 }