Beispiel #1
0
        public bool TryOpenPropItemSet(BagNode propBagNode)
        {
            bool result;

            PropNodeCollectionInternalInterface pnc_int = propBagNode.PropNodeCollection;

            if (!pnc_int.IsFixed)
            {
                System.Diagnostics.Debug.WriteLine("Warning: PropStoreAccessServiceProvider is being asked to open a PropItemSet that is already open.");
                result = true;
            }
            else
            {
                // Create a new collection. (New Collections are open by default.)
                PropNodeCollectionInternalInterface newOpenCollection = new PropNodeCollection(pnc_int);

                // Remove the old set from the StoreByType
                RemoveFixedPropCollection(propBagNode.ObjectId, pnc_int);

                // Replace the exixting collection with the new one.
                propBagNode.PropNodeCollection = newOpenCollection;

                // return a reference to the new one cast as an object.
                result = true;
            }

            return(result);
        }
Beispiel #2
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 #3
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 #4
0
        public PropNode(PropIdType propId, IPropDataInternal propData_Internal, BagNode parent)
        {
            CompKey           = new SimpleExKey(parent.ObjectId, propId);
            PropData_Internal = propData_Internal ?? throw new ArgumentNullException(nameof(propData_Internal));

            //parent.AddChild(this);
            Parent = parent;

            Child = null;
        }
Beispiel #5
0
        //private bool TryRemoveBagNode(WeakRefKey<IPropBag> propBag_wrKey)
        //{
        //    try
        //    {
        //        lock (_sync)
        //        {
        //            _store.Remove(propBag_wrKey);
        //            return true;
        //        }
        //    }
        //    catch
        //    {
        //        return false;
        //    }
        //}

        public PSAccessServiceInterface ClonePSAccessService
        (
            PropNodeCollectionInternalInterface sourcePropNodeCollection,
            IPropBag targetPropBag,
            out BagNode newStoreNode
        )
        {
            PSAccessServiceInterface result = CreatePropStoreService(targetPropBag, sourcePropNodeCollection, out newStoreNode);

            return(result);
        }
Beispiel #6
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);
        }
Beispiel #7
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 #8
0
        // TODO: Instead of performing each TearDown request synchronously, create a queue
        // for a background thread to process. This background thread can remove PropBags in batches.
        // If done in batches, ranges of Ids can be removed from the Store and StoreByType dictionaries.
        public bool TearDown(BagNode propBagNode)
        {
            //WeakRefKey<IPropBag> propBag_wrKey = propBagNode.PropBagProxy;

            if (TryRemoveBagNode(propBagNode))
            {
                propBagNode.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #9
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 #10
0
        public object GetValueFast(BagNode propBagNode, PropIdType propId, PropItemSetKeyType propItemSetKey)
        {
            if (propItemSetKey != propBagNode.PropItemSetKey)
            {
                throw new InvalidOperationException("Bad PropModel.");
            }

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

            object result = child.PropData_Internal.TypedProp.TypedValueAsObject;

            return(result);
        }
Beispiel #11
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                    Parent = null;
                    Child  = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
Beispiel #12
0
        public bool TryFixPropItemSet(BagNode propBagNode, PropItemSetKeyType propItemSetKey)
        {
            PropNodeCollectionInternalInterface pnc_int = propBagNode.PropNodeCollection;

            if (pnc_int.IsFixed)
            {
                System.Diagnostics.Debug.WriteLine("Warning: PropStoreAccessServiceProvider is being asked to fix an already fixed PropItemSet.");
                return(true);
            }
            else
            {
                PropNodeCollectionFixed newFixedCollection = new PropNodeCollectionFixed(pnc_int, propItemSetKey);
                propBagNode.PropNodeCollection = newFixedCollection;

                AddFixedPropCollection(newFixedCollection);
                return(true);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Creates a new PropNode using this PropNode as a 'template.'
        /// If useExistingValues is set to True, exceptions will be thrown if
        /// the PropItem's value cannot be cloned.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="useExistingValues">
        /// If True, the current values are cloned,
        /// If False the default values are used.</param>
        /// <returns></returns>
        public PropNode CloneForNewParent(BagNode parent, bool useExistingValues)
        {
            IProp newTypeProp;

            if (useExistingValues)
            {
                newTypeProp = (IProp)PropData_Internal.TypedProp.Clone();
            }
            else
            {
                throw new NotImplementedException("CloneForNewParent only supports useExistingValues = true.");
            }

            IPropDataInternal newPropData_Internal = new PropGen(newTypeProp);
            PropNode          newPropNode          = new PropNode(PropId, newPropData_Internal, parent);

            return(newPropNode);
        }
Beispiel #14
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 #15
0
        public bool SetValueFast(BagNode propBagNode, PropIdType propId, PropItemSetKeyType propItemSetKey, object value)
        {
            if (propItemSetKey != propBagNode.PropItemSetKey)
            {
                throw new InvalidOperationException("Bad PropModel.");
            }

            if (!propBagNode.TryGetPropBag(out IPropBag component))
            {
                throw new InvalidOperationException("IPropBag target has been Garbage Collected.");
            }

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

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

            return(result);
        }
Beispiel #16
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 #17
0
        private bool TryRemoveBagNode(BagNode propBagNode)
        {
            try
            {
                lock (_sync)
                {
                    _store.Remove(propBagNode.PropBagProxy);

                    if (propBagNode.PropNodeCollection.IsFixed && !propBagNode.PropItemSetKey.IsEmpty)
                    {
                        if (_storeByType.TryGetValue(propBagNode.PropItemSetKey, out PropNodelCollectionSharedInterface sharedPropNodeCollection))
                        {
                            if (sharedPropNodeCollection.TryRemove(propBagNode.CompKey.Level1Key))
                            {
                                if (sharedPropNodeCollection.Count == 0)
                                {
                                    _storeByType.Remove(propBagNode.PropItemSetKey);
                                }
                            }
                            else
                            {
                                // TODO: Make this Debug.WriteLine better.
                                System.Diagnostics.Debug.WriteLine("Could not remove the child PropNodes from the Shared Prop Node Collection.");
                            }
                        }
                        else
                        {
                            System.Diagnostics.Debug.WriteLine("Could not find PropBagNode in the Store By Type.");
                        }
                    }
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
 public PropNode CreateAndAdd(IPropDataInternal propData_Internal, PropNameType propertyName, BagNode parent)
 {
     throw new InvalidOperationException("Cannot Add PropItems to a Fixed PropItemSet.");
 }
Beispiel #19
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);
        }
Beispiel #20
0
 public bool IsPropItemSetFixed(BagNode propBagNode)
 {
     return(propBagNode.IsFixed);
 }
Beispiel #21
0
        public PropNode CreateAndAdd(IPropDataInternal propData_Internal, PropNameType propertyName, BagNode parent)
        {
            PropIdType nextPropId  = GetNextPropId();
            PropNode   newPropNode = new PropNode(nextPropId, propData_Internal, parent);

            Add(newPropNode);
            return(newPropNode);
        }