Exemplo n.º 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.");
            }
        }
Exemplo n.º 2
0
        public IDisposable SubscribeToParentNodeHasChanged(EventHandler <PSNodeParentChangedEventArgs> handler)
        {
            ParentNCSubscriptionRequest subRequest = new ParentNCSubscriptionRequest(CompKey, handler);

            lock (_sync)
            {
                ParentNCSubscription sub = ParentNCSubscriberCollection.GetOrAdd(subRequest, _callPSParentNodeChangedEventSubsCache);
            }
            UnsubscriberForPropStore unsubscriber = new UnsubscriberForPropStore(new WeakReference <BagNode>(this), subRequest);

            return(unsubscriber);
        }
Exemplo n.º 3
0
 public bool UnsubscribeToParentNodeHasChanged(ParentNCSubscriptionRequest subRequest)
 {
     lock (_sync)
     {
         if (ParentNCSubscriberCollection.TryRemoveSubscription(subRequest))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }