示例#1
0
        public ParentNCSubscription GetOrAdd(ParentNCSubscriptionRequest request, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
        {
            ParentNCSubscription subscription;

            lock (_sync)
            {
                if (null != (subscription = _subs.FirstOrDefault(x => SubscriptionIsForRequest(x, request))))
                {
                    System.Diagnostics.Debug.WriteLine($"The subscription for {request} has aleady been created.");
                    return(subscription);
                }
                else
                {
                    subscription = request.CreateSubscription(callPSParentNodeChangedEventSubsCache);

                    if (subscription.OwnerPropId == null)
                    {
                        // TODO: See if we make this exception message more informative.
                        throw new InvalidOperationException($"OwnerPropId is null in subscription {request.Target_Wrk.GetType().ToString()}.");
                    }
                    AddSubscription(subscription);
                    return(subscription);
                }
            }
        }
示例#2
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.");
            }
        }
示例#3
0
        //public ParentNCSubscription(ExKeyT ownerPropId, WeakRefKey target, string methodName, Delegate proxy, CallPSParentNodeChangedEventSubDelegate dispatcher)
        //{
        //    OwnerPropId = ownerPropId;
        //    Target = target;
        //    MethodName = methodName;
        //    Proxy = proxy;
        //    Dispatcher = dispatcher;
        //}

        public ParentNCSubscription(ParentNCSubscriptionRequest subRequestKey, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
        {
            OwnerPropId = subRequestKey.OwnerPropId;
            Target_Wrk  = subRequestKey.Target_Wrk; // new WeakRefKey(subRequestKey.Target_Wrk);
            MethodName  = subRequestKey.Method.Name;

            // TODO: Note: The Proxy Delegate is not being cached (using the DelegateProxyCache.)
            // Create an open delegate from the delegate provided. (An open delegate has a null value for the target.)
            Type delegateType = GetDelegateType(subRequestKey.Method);

            Proxy = MakeTheDelegate(delegateType, subRequestKey.Method);

            object target = Target_Wrk.Target;

            Type targetType = target.GetType();

            Dispatcher = callPSParentNodeChangedEventSubsCache.GetOrAdd(targetType);
        }
示例#4
0
 public BagNode(ObjectIdType objectId, IPropBag propBag, int maxPropsPerObject, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
     : this(objectId, propBag, null, maxPropsPerObject, callPSParentNodeChangedEventSubsCache)
 {
 }
        private ParentNCSubscription CreateSubscriptionGen(ParentNCSubscriptionRequest request, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
        {
            ParentNCSubscription result = new ParentNCSubscription(request, callPSParentNodeChangedEventSubsCache);

            request.MarkAsUsed();
            return(result);
        }
 public ParentNCSubscription CreateSubscription(ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
 {
     return(SubscriptionFactory(this, callPSParentNodeChangedEventSubsCache));
 }