コード例 #1
0
        private TDestination GetDestinationTemplate(Type targetType)
        {
            TDestination result = GetNewDestination(DestinationType, PropModel, _viewModelFactory, _propBagMapperService, PropFactory, fullClassName: null);

            if (TestCreateDest(targetType, result))
            {
                // TODO: Consider removing the responsiblity of fixing the store's PropNodeCollection from the AbstractPropBagMapper class.
                if (!PropModel.IsFixed)
                {
                    PropModel.Fix();
                }

                if (!_viewModelFactory.PropStoreAccessServiceCreator.IsPropItemSetFixed(result))
                {
                    // Fix the template's PropNodeCollection to improve performance.
                    PropItemSetKeyType propItemSetKey = new PropItemSetKeyType(PropModel);
                    _viewModelFactory.PropStoreAccessServiceCreator.TryFixPropItemSet(result, propItemSetKey);
                }
            }
            else
            {
                // It turns out that we cannot use the template after all.
                result = null;
            }

            return(result);
        }
コード例 #2
0
 private void CheckPropItemSetId(PropItemSetKeyType propItemSetKey)
 {
     if (propItemSetKey.IsEmpty)
     {
         throw new ArgumentException("The PropItemSetKey cannot be empty when creating a Fixed PropNodeCollection.");
     }
 }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
        public PropNodeCollectionFixed(IEnumerable <PropNode> propNodes, PropItemSetKeyType propItemSetKey, int maxPropsPerObject)
        {
            MaxPropsPerObject = maxPropsPerObject;

            CheckPropItemSetId(propItemSetKey);
            _propItemSetKey = propItemSetKey;

            _children       = PopulateChildren(propNodes);
            PropItemsByName = _children.ToDictionary(k => k.PropertyName, v => v);
            _hashCode       = ComputeHashCode();
        }
コード例 #5
0
 public bool TryFixPropItemSet(IPropBag propBag, PropItemSetKeyType propItemSetKey)
 {
     if (TryGetPropBagNode(propBag, out BagNode propBagNode))
     {
         bool result = TryFixPropItemSet(propBagNode, propItemSetKey);
         return(result);
     }
     else
     {
         throw new InvalidOperationException($"Could not retrieve a BagNode for the given propBag.");
     }
 }
コード例 #6
0
        public PropNodeCollectionShared(IEnumerable <PropNode> propNodes, PropItemSetKeyType propItemSetKey, int maxPropsPerObject)
        {
            MaxPropsPerObject = maxPropsPerObject;

            CheckPropItemSetId(propItemSetKey);

            _propItemSetKey = propItemSetKey;

            _children = new Dictionary <ExKeyT, PropNode>();
            Add(propNodes);

            _nameToIdMap = BuildByNameDict();

            CheckChildCount(_nameToIdMap.Count);
        }
コード例 #7
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);
        }
コード例 #8
0
        public object GetValueFast(ExKeyT compKey, PropItemSetKeyType propItemSetKey)
        {
            if (!TryGetSharedPropCollection(propItemSetKey, out PropNodelCollectionSharedInterface sharedPropCollection))
            {
                throw new InvalidOperationException($"Could not retrieve the SharedPropCollection for {propItemSetKey.FullClassName} .");
            }

            if (!sharedPropCollection.TryGetPropNode(compKey, out PropNode propNode))
            {
                throw new KeyNotFoundException($"The {sharedPropCollection} could not retrieve a PropNode for {compKey}.");
            }

            object result = propNode.PropData_Internal.TypedProp.TypedValueAsObject;

            return(result);
        }
コード例 #9
0
        public PropItemFixedPropertyDescriptor
        (
            PropertyDescriptorValues <T> tdConfig,
            PSFastAccessServiceInterface psFastAccessService,
            PropModelType propModel,
            PropIdType propId
        )
            : base(tdConfig.Name, tdConfig.Attributes)
        {
            _tdConfig            = tdConfig;
            _psFastAccessService = psFastAccessService;
            _propItemSetKey      = new PropItemSetKeyType(propModel);
            PropId = propId;

            _compKey = new SimpleExKey(10, propId);
        }
コード例 #10
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);
        }
コード例 #11
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);
            }
        }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
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);
        }
コード例 #14
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);
        }
コード例 #15
0
ファイル: PropNodeCollection.cs プロジェクト: drminor/propbag
        public PropNodeCollection(IEnumerable <PropNode> propNodes, PropItemSetKeyType propItemSetKey, int maxPropsPerObject)
        {
            MaxPropsPerObject = maxPropsPerObject;

            _propItemSetKey = propItemSetKey;

            if (propNodes == null)
            {
                _children       = new Dictionary <PropIdType, PropNode>();
                m_PropIdCounter = 0; // The first PropId issued will be 1. (0 is reserved to indicate all Properties or that the ExplodedKey identifies an Object.)
            }
            else
            {
                _children = propNodes.ToDictionary(k => k.PropId, v => v);
                CheckChildCount(_children.Count);

                // TODO: See if we have the caller provide this value.
                m_PropIdCounter = propNodes.Max(pn => pn.CompKey.Level2Key);
            }

            _propItemsByName = null;
        }
コード例 #16
0
        public bool SetValueFast(ExKeyT compKey, PropItemSetKeyType propItemSetKey, object value)
        {
            if (!TryGetSharedPropCollection(propItemSetKey, out PropNodelCollectionSharedInterface sharedPropCollection))
            {
                throw new InvalidOperationException($"Could not retrieve the SharedPropCollection for {propItemSetKey.FullClassName} .");
            }

            if (!sharedPropCollection.TryGetPropNode(compKey, out PropNode propNode))
            {
                throw new KeyNotFoundException($"The {sharedPropCollection} could not retrieve a PropNode for {compKey}.");
            }

            if (!propNode.Parent.TryGetPropBag(out IPropBag propBag))
            {
                // The target has been garbage collected.
                return(false);
            }

            bool result = SetPropValue(propBag, propNode, compKey.Level2Key, value);

            return(result);
        }
コード例 #17
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);
        }
コード例 #18
0
        public bool SetValueFast(ExKeyT compKey, PropItemSetKeyType propItemSetKey, object value)
        {
            bool result = _propStoreAccessServiceProvider.SetValueFast(compKey, propItemSetKey, value);

            return(result);
        }
コード例 #19
0
        public object GetValueFast(ExKeyT compKey, PropItemSetKeyType propItemSetKey)
        {
            object result = _propStoreAccessServiceProvider.GetValueFast(compKey, propItemSetKey);

            return(result);
        }
コード例 #20
0
        private bool TryGetSharedPropCollection(PropItemSetKeyType propItemSetKey, out PropNodelCollectionSharedInterface sharedPropCollection)
        {
            bool result = _storeByType.TryGetValue(propItemSetKey, out sharedPropCollection);

            return(result);
        }
コード例 #21
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);
        }
コード例 #22
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);
        }
コード例 #23
0
 public PropNodeCollectionFixed(PropNodeCollectionIntInterface sourcePropNodes, PropItemSetKeyType propItemSetKey)
     : this(sourcePropNodes.GetPropNodes(), propItemSetKey, sourcePropNodes.MaxPropsPerObject)
 {
 }