private ParentNCSubscription CreateSubscriptionGen(ParentNCSubscriptionRequest request, ICacheDelegates <CallPSParentNodeChangedEventSubDelegate> callPSParentNodeChangedEventSubsCache)
        {
            ParentNCSubscription result = new ParentNCSubscription(request, callPSParentNodeChangedEventSubsCache);

            request.MarkAsUsed();
            return(result);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        public bool TryGetSubscription(ParentNCSubscriptionRequest request, out ParentNCSubscription subscription)
        {
            lock (_sync)
            {
                subscription = _subs.FirstOrDefault(x => SubscriptionIsForRequest(x, request));
            }

            bool result = subscription != null;

            return(result);
        }
Exemplo n.º 4
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.º 5
0
 public bool UnsubscribeToParentNodeHasChanged(ParentNCSubscriptionRequest subRequest)
 {
     lock (_sync)
     {
         if (ParentNCSubscriberCollection.TryRemoveSubscription(subRequest))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 6
0
        private bool SubscriptionIsForRequest(ParentNCSubscription subscription, ParentNCSubscriptionRequest subscriptionRequest)
        {
            // Used for debugging.
            //bool t1 = subscription.OwnerPropId.Equals(subscriptionRequest.OwnerPropId);
            //bool t2 = subscription.MethodName == subscriptionRequest.Method.Name;
            //bool t3 = subscription.Target_Wrk == subscriptionRequest.Target_Wrk;

            bool result =
                subscription.OwnerPropId.Equals(subscriptionRequest.OwnerPropId) &&
                subscription.MethodName == subscriptionRequest.Method.Name &&
                //ReferenceEquals(subscription.Target.Target, subscriptionRequest.Target);
                subscription.Target_Wrk == subscriptionRequest.Target_Wrk;

            return(result);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        public bool TryRemoveSubscription(ParentNCSubscriptionRequest request)
        {
            ParentNCSubscription subscription;

            lock (_sync)
            {
                if (null != (subscription = _subs.FirstOrDefault(x => SubscriptionIsForRequest(x, request))))
                {
                    _subs.Remove(subscription);
                    subscription.Dispose();
                    return(true);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"Could not find the subscription for {request.OwnerPropId} when trying to remove it.");
                    return(false);
                }
            }
        }
Exemplo n.º 9
0
 public UnsubscriberForPropStore(WeakReference <BagNode> wr_us, ParentNCSubscriptionRequest request)
 {
     _wr      = wr_us;
     _request = request;
 }
Exemplo n.º 10
0
        public bool UnsubscribeToParentNodeHasChanged(EventHandler <PSNodeParentChangedEventArgs> handler)
        {
            ParentNCSubscriptionRequest subRequest = new ParentNCSubscriptionRequest(CompKey, handler);

            return(UnsubscribeToParentNodeHasChanged(subRequest));
        }