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); }
private bool RemoveFixedPropCollection(ObjectIdType objectId, PropNodeCollectionInternalInterface pnc) { if (pnc.Count == 0) { return(true); } PropItemSetKeyType propItemSetKey = pnc.PropItemSetKey; lock (_syncForByTypeStore) { if (!TryGetSharedPropCollection(propItemSetKey, out PropNodelCollectionSharedInterface sharedPropNodeCollection)) { throw new InvalidOperationException($"Could not retrieve the SharedPropCollection for {propItemSetKey.FullClassName} while removing {pnc}."); } if (sharedPropNodeCollection.TryRemove(objectId)) { if (sharedPropNodeCollection.Count == 0) { _storeByType.Remove(pnc.PropItemSetKey); } return(true); } else { System.Diagnostics.Debug.WriteLine($"Could not remove {pnc} from {sharedPropNodeCollection}."); return(false); } } }
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); }
//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); }
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); } }
private PropNodelCollectionSharedInterface AddFixedPropCollection(PropNodeCollectionInternalInterface pnc) { PropItemSetKeyType propItemSetKey = pnc.PropItemSetKey; lock (_syncForByTypeStore) { if (_storeByType.TryGetValue(propItemSetKey, out PropNodelCollectionSharedInterface sharedPropCollection)) { sharedPropCollection.Add(pnc); return(sharedPropCollection); } else { sharedPropCollection = new PropNodeCollectionShared(pnc); _storeByType.Add(propItemSetKey, sharedPropCollection); return(sharedPropCollection); } } }
private bool DeleteSharedPropCollection(PropNodeCollectionInternalInterface pnc) { bool result = _storeByType.Remove(pnc.PropItemSetKey); return(result); }