Beispiel #1
0
        public bool Equals(WeakRefKey <T> other)
        {
            //if (_weakRef == null && other._weakRef == null) return true;

            //if (_weakRef == null || other._weakRef == null) return false;

            //T c1 = Target;
            //T c2 = other.Target;

            //if (c1 != null && c2 != null)
            //    return (c1 == c2); // Reference Equality, could have used ReferenceEquals(c1, c2)
            //else
            //    return (_weakRef == other._weakRef);

            T c1 = Target;
            T c2 = other.Target;

            if (c1 != null && c2 != null)
            {
                return(ReferenceEquals(c1, c2));
            }
            else
            {
                return(ReferenceEquals(_weakRef, other._weakRef));
            }
        }
Beispiel #2
0
 public PropItemSetKey()
 {
     PropModel_wrKey = default(WeakRefKey <IPropModel <L2TRaw> >);
     FullClassName   = null;
     GenerationId    = 0;
     IsFixed         = false;
 }
Beispiel #3
0
        // Target and Method. Also used for TypeDelegate and TypedAction.
        public SubscriptionKeyGen(ExKeyT sourcePropId, Type propertyType,
                                  object target, MethodInfo method,
                                  SubscriptionKind kind,
                                  SubscriptionPriorityGroup subscriptionPriorityGroup,
                                  bool keepRef,
                                  Func <ISubscriptionKeyGen, IProvideHandlerDispatchDelegateCaches, ISubscription> subscriptionFactory)
        {
            OwnerPropId  = sourcePropId;
            PropertyType = propertyType;

            SubscriptionKind          = kind;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = GetKindOfTarget(target, keepRef);

            //GenDoWhenChanged = null;
            //Action = null;

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            Target_Wrk = new WeakRefKey(target);
            Method     = method ?? throw new ArgumentNullException(nameof(method));

            SubscriptionFactory = subscriptionFactory ?? CreateSubscriptionGen;
            BindingFactory      = null;
            HasBeenUsed         = false;
        }
Beispiel #4
0
        public PSAccessServiceInterface CreatePropStoreService(IPropBag propBag, PropNodeCollectionInternalInterface propNodes, out BagNode newBagNode)
        {
            // Issue a new, unique Id for this propBag.
            ObjectIdType objectId = NextObjectId;

            // Create a new PropStoreNode for this PropBag
            newBagNode = new BagNode(objectId, propBag, propNodes, MaxPropsPerObject, _handlerDispatchDelegateCacheProvider.CallPSParentNodeChangedEventSubsCache);

            WeakRefKey <IPropBag> propBagProxy = newBagNode.PropBagProxy;

            lock (_sync)
            {
                // Add the node to the global store.
                _store.Add(propBagProxy, newBagNode);

                // If the PropNodeCollection is fixed, update our Store By Type (for fast lookups.)
                if (newBagNode.PropNodeCollection.IsFixed)
                {
                    AddFixedPropCollection(newBagNode.PropNodeCollection);
                }
            }

            // Create the access service.
            PSAccessServiceInterface result = new SimplePropStoreAccessService
                                              (
                newBagNode,
                this,
                _handlerDispatchDelegateCacheProvider
                                              );

            // Add one more to the total count of PropStoreAccessServices created.
            IncAccessServicesCreated();

            return(result);
        }
Beispiel #5
0
        public object GetValueFast(WeakRefKey <IPropBag> propBag_wrKey, PropIdType propId, PropItemSetKeyType propItemSetKey)
        {
            BagNode propBagNode = GetBagAndChild(propBag_wrKey, propItemSetKey, propId, out PropNode child);

            object result = child.PropData_Internal.TypedProp.TypedValueAsObject;

            return(result);
        }
Beispiel #6
0
        public PropItemSetKey(IPropModel <L2TRaw> propModel)
        {
            PropModel_wrKey = new WeakRefKey <IPropModel <L2TRaw> >(propModel);
            FullClassName   = propModel.FullClassName ?? throw new ArgumentNullException("The propModel must have a non-null FullClassName.");
            GenerationId    = propModel.GenerationId;
            IsFixed         = propModel.IsFixed;

            _hashCode = ComputetHashCode();
        }
Beispiel #7
0
        public bool TryGetPropBagNode(IPropBag propBag, out BagNode propBagNode)
        {
            WeakRefKey <IPropBag> propBag_wrKey = new WeakRefKey <IPropBag>(propBag);

            bool result = TryGetPropBagNode(propBag_wrKey, out propBagNode);

            if (!result)
            {
                System.Diagnostics.Debug.WriteLine($"The PropStore could not retreive a BagNode for the PropBag with full classname = {propBag.FullClassName}.");
            }
            return(result);
        }
        public ParentNCSubscriptionRequest(ExKeyT sourcePropId, EventHandler <PSNodeParentChangedEventArgs> handler)
        {
            OwnerPropId = sourcePropId;

            object target = handler.Target ?? throw new ArgumentNullException(nameof(handler.Target));

            Target_Wrk = new WeakRefKey(target);
            Method     = handler.Method ?? throw new ArgumentNullException(nameof(handler.Method));

            SubscriptionFactory = CreateSubscriptionGen;
            HasBeenUsed         = false;
        }
Beispiel #9
0
        internal bool TryGetPropBagNode(WeakRefKey <IPropBag> propBag_wrKey, out BagNode propBagNode)
        {
            lock (_sync)
            {
                if (_store.TryGetValue(propBag_wrKey, out propBagNode))
                {
                    return(true);
                }
            }

            propBagNode = null;
            return(false);
        }
Beispiel #10
0
        public bool SetValueFast(WeakRefKey <IPropBag> propBag_wrKey, PropIdType propId, PropItemSetKeyType propItemSetKey, object value)
        {
            if (!propBag_wrKey.TryGetTarget(out IPropBag component))
            {
                // The target has been Garbage Collected, its ok to simply return false since the client is no longer waiting for our result.
                return(false);
            }

            BagNode propBagNode = GetBagAndChild(propBag_wrKey, propItemSetKey, propId, out PropNode child);

            bool result = SetPropValue(component, child, propId, value);

            return(result);
        }
Beispiel #11
0
        public bool SetValueFast(IPropBag component, PropIdType propId, PropItemSetKeyType propItemSetKey, object value)
        {
            if (component is IPropBagInternal ipbi)
            {
                if (ipbi is IHaveTheStoreNode ihtsn)
                {
                    BagNode propBagNode = (ipbi as IHaveTheStoreNode)?.PropBagNode;
                    bool    result1     = _propStoreAccessServiceProvider.SetValueFast(propBagNode, propId, propItemSetKey, value);
                    return(result1);
                }
            }

            //ExKeyT compKey = GetCompKey(component, propId);
            WeakRefKey <IPropBag> propBag_wrKey = new WeakRefKey <IPropBag>(component);
            bool result2 = _propStoreAccessServiceProvider.SetValueFast(propBag_wrKey, propId, propItemSetKey, value);

            return(result2);
        }
Beispiel #12
0
        public object GetValueFast(IPropBag component, PropIdType propId, PropItemSetKeyType propItemSetKey)
        {
            if (component is IPropBagInternal ipbi)
            {
                //if(ipbi.ItsStoreAccessor is IHaveTheStoreNode ihtsn)
                //{
                //    BagNode propBagNode = ihtsn.PropBagNode;
                //    object result1 = _propStoreAccessServiceProvider.GetValueFast(propBagNode, propId, propItemSetKey);
                //    return result1;
                //}

                BagNode propBagNode = ((IHaveTheStoreNode)ipbi.ItsStoreAccessor).PropBagNode;
                object  result1     = _propStoreAccessServiceProvider.GetValueFast(propBagNode, propId, propItemSetKey);
                return(result1);
            }

            //ExKeyT compKey = GetCompKey(component, propId);
            WeakRefKey <IPropBag> propBag_wrKey = new WeakRefKey <IPropBag>(component);
            object result2 = _propStoreAccessServiceProvider.GetValueFast(propBag_wrKey, propId, propItemSetKey);

            return(result2);
        }
Beispiel #13
0
        private BagNode GetBagAndChild(WeakRefKey <IPropBag> propBag_wrKey, PropItemSetKeyType propItemSetKey, PropIdType propId, out PropNode child)
        {
            if (!TryGetPropBagNode(propBag_wrKey, out BagNode propBagNode))
            {
                throw new InvalidOperationException("The store has lost this node.");
            }

            if (!propBag_wrKey.TryGetTarget(out IPropBag target))
            {
                throw new InvalidOperationException("IPropBag target has been Garbage Collected.");
            }

            if (propItemSetKey != propBagNode.PropItemSetKey)
            {
                throw new InvalidOperationException("Bad PropModel.");
            }

            //if (!propItemSetId.Value.TryGetTarget(out PropModelType testModel))
            //{
            //    throw new InvalidOperationException("The specified PropItemSetId has been Garbage Collected.");
            //}

            //if (!propBagNode.PropItemSetId.Value.TryGetTarget(out PropModelType testModel_fromBagNode))
            //{
            //    throw new InvalidOperationException("The PropItemSetId on our BagNode has been Garbage Collected.");
            //}

            //if(!ReferenceEquals(testModel, testModel_fromBagNode))
            //{
            //    throw new InvalidOperationException("PropItemSet do not match.");
            //}

            if (!propBagNode.TryGetChild(propId, out child))
            {
                throw new InvalidOperationException("Could not retrieve PropNode for that compKey.");
            }

            return(propBagNode);
        }
Beispiel #14
0
        // Changing PropertyChangingEventHandler
        public SubscriptionKeyGen(ExKeyT sourcePropId, PropertyChangingEventHandler changingDelegate,
                                  SubscriptionPriorityGroup subscriptionPriorityGroup, bool keepRef)
        {
            OwnerPropId  = sourcePropId;
            PropertyType = null;

            SubscriptionKind          = SubscriptionKind.ChangingHandler;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = GetKindOfTarget(standardDelegate.Target, keepRef);

            //GenDoWhenChanged = null;
            //Action = null;

            object target = changingDelegate.Target ?? throw new ArgumentNullException(nameof(changingDelegate.Target));

            Target_Wrk = new WeakRefKey(target);
            Method     = changingDelegate.Method ?? throw new ArgumentNullException(nameof(changingDelegate.Method));

            SubscriptionFactory = CreateSubscriptionGen;
            BindingFactory      = null;
            HasBeenUsed         = false;
        }
Beispiel #15
0
        // ActionNoParams
        protected SubscriptionKeyGen(ExKeyT sourcePropId, Action action,
                                     SubscriptionPriorityGroup subscriptionPriorityGroup,
                                     bool keepRef,
                                     Func <ISubscriptionKeyGen, IProvideHandlerDispatchDelegateCaches, ISubscription> subscriptionFactory)
        {
            OwnerPropId  = sourcePropId;
            PropertyType = null;

            SubscriptionKind          = SubscriptionKind.ActionNoParams;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = GetKindOfTarget(action.Target, keepRef);

            //GenDoWhenChanged = null;
            //Action = action;

            object target = action.Target ?? throw new ArgumentNullException(nameof(action.Target));

            Target_Wrk = new WeakRefKey(target);
            Method     = action.Method ?? throw new ArgumentNullException(nameof(action.Method));

            SubscriptionFactory = subscriptionFactory;
            BindingFactory      = null;
            HasBeenUsed         = false;
        }
Beispiel #16
0
        // Action<object, object>
        protected SubscriptionKeyGen(ExKeyT sourcePropId, Action <object, object> genAction,
                                     SubscriptionPriorityGroup subscriptionPriorityGroup,
                                     bool keepRef,
                                     Func <ISubscriptionKeyGen, IProvideHandlerDispatchDelegateCaches, ISubscription> subscriptionFactory)
        {
            OwnerPropId  = sourcePropId;
            PropertyType = null;

            SubscriptionKind          = SubscriptionKind.ObjectAction;
            SubscriptionPriorityGroup = subscriptionPriorityGroup;
            //SubscriptionTargetKind = GetKindOfTarget(genAction.Target, keepRef);

            //GenDoWhenChanged = genAction ?? throw new ArgumentNullException(nameof(genAction));
            //Action = null;

            object target = genAction.Target ?? throw new InvalidOperationException($"The value for Target on the GenAction action, cannot be null.");

            Target_Wrk = new WeakRefKey(target);
            Method     = genAction.Method ?? throw new ArgumentNullException(nameof(genAction.Method));

            SubscriptionFactory = subscriptionFactory;
            BindingFactory      = null;
            HasBeenUsed         = false;
        }