예제 #1
0
        //Lazy<IValueConverter> _defaultConverter;
        //public virtual Lazy<IValueConverter> DefaultConverter
        //{
        //    get
        //    {
        //        if(_defaultConverter == null)
        //        {
        //            return new Lazy<IValueConverter>(() => new PropValueConverter());
        //        }
        //        return _defaultConverter;
        //    }
        //    set
        //    {
        //        _defaultConverter = value;
        //    }
        //}

        //Func<BindingTarget, MyBindingInfo, Type, string, object> _defConvParamBuilder;
        //public virtual Func<BindingTarget, MyBindingInfo, Type, string, object> DefaultConverterParameterBuilder
        //{
        //    get
        //    {
        //        if (_defConvParamBuilder == null)
        //        {
        //            return OurDefaultConverterParameterBuilder;
        //        }
        //        return _defConvParamBuilder;
        //    }
        //    set
        //    {
        //        _defConvParamBuilder = value;
        //    }
        //}
        #endregion

        #region Constructor

        internal LocalBinder(PSAccessServiceInterface propStoreAccessService, LocalBindingInfo bindingInfo, IReceivePropStoreNodeUpdates storeNodeUpdateReceiver)
        {
            _propStoreAccessService_wr = new WeakReference <PSAccessServiceInterface>(propStoreAccessService);
            _bindingInfo             = bindingInfo;
            _storeNodeUpdateReceiver = storeNodeUpdateReceiver;

            _bindingTarget = new SimpleExKey();

            // Get the PropStore Node for the IPropBag object hosting the property that is the target of the binding.
            // TODO: Instead of doing this now, create a property that allows us to access upon first access.
            _ourNode = GetPropBagNode(propStoreAccessService);

            _targetObject = null;

            _propertyName   = null;
            _targetHasStore = PropStorageStrategyEnum.Virtual;

            _pathElements = GetPathElements(_bindingInfo, out _isPathAbsolute, out _firstNamedStepIndex);

            if (_isPathAbsolute)
            {
                _rootListener = CreateAndListen(_ourNode, "root", SourceKindEnum.AbsRoot);
            }
            else
            {
                _rootListener = null;
            }

            _pathListeners = new OSCollection <T>();

            _isComplete = StartBinding(_targetObject, _pathElements, _pathListeners, _isPathAbsolute);
        }
예제 #2
0
 private void CheckForIHaveTheStoreNode(PSAccessServiceInterface propStoreAccessService)
 {
     if (!(propStoreAccessService is IHaveTheStoreNode storeNodeProvider))
     {
         throw new InvalidOperationException($"The {nameof(propStoreAccessService)} does not implement the {nameof(IHaveTheStoreNode)} interface.");
     }
 }
예제 #3
0
        // Base Constructor
        private LocalWatcher(PSAccessServiceInterface propStoreAccessService, LocalBindingInfo bindingInfo)
        {
            if (propStoreAccessService is PSAccessServiceInternalInterface propStoreAccessService_Internal)
            {
                _propStoreAccessService_wr = new WeakReference <PSAccessServiceInternalInterface>(propStoreAccessService_Internal);
            }
            else
            {
                throw new InvalidOperationException($"The propStoreAcccessService does not implement the internal interface: {nameof(PSAccessServiceInternalInterface)}.");
            }


            _ourNode     = GetPropBagNode(propStoreAccessService);
            _bindingInfo = bindingInfo;

            _pathListeners = new OSCollection <T>();

            BindingPathParser pathParser = new BindingPathParser();

            _pathElements = pathParser.GetPathElements(bindingInfo, out _isPathAbsolute, out _firstNamedStepIndex);

            if (_isPathAbsolute)
            {
                _rootListener = CreateAndListen(_ourNode, "root", SourceKindEnum.AbsRoot);
            }
            else
            {
                _rootListener = null;
            }
        }
예제 #4
0
        public CViewManagerBinder_New
        (
            PSAccessServiceInterface propStoreAccessService,
            IViewManagerProviderKey viewManagerProviderKey,
            CrudWithMappingCreator <TDal, TSource, TDestination> crudWithMappingCreator,
            CViewProviderCreator viewBuilder            // Method that can be used to create a IProvideAView from a DataSourceProvider.
        )
        {
            ViewManagerProviderKey = viewManagerProviderKey;

            //_propBagMapperCreator = propBagMapperCreator;
            _crudWithMappingCreator = crudWithMappingCreator;

            _viewBuilder = viewBuilder;

            // Create a instance of our nested, internal class that reponds to Updates to the property store Nodes.
            IReceivePropStoreNodeUpdates_PropBag <TDal> propStoreNodeUpdateReceiver = new PropStoreNodeUpdateReceiver(this);

            // Create a new watcher, the bindingInfo specifies the PropItem for which to listen to changes,
            // the propStoreNodeUpdateReceiver will be notfied when changes occur.
            _localWatcher = new LocalWatcher <TDal>(propStoreAccessService, ViewManagerProviderKey.BindingInfo, propStoreNodeUpdateReceiver);

            //var x = _propItemParent_wr;

            //var y = _propItemParent_wr.TryGetTarget(out IPropBag target);

            //var z = target;
        }
예제 #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);
        }
예제 #6
0
        public BindingSubscription(IBindingSubscriptionKey <T> subRequestKey, PSAccessServiceInterface propStoreAccessService)
        {
            OwnerPropId = subRequestKey.OwnerPropId;
            BindingInfo = subRequestKey.BindingInfo;

            SubscriptionKind          = subRequestKey.SubscriptionKind;
            SubscriptionPriorityGroup = subRequestKey.SubscriptionPriorityGroup;
            //SubscriptionTargetKind = sKey.SubscriptionTargetKind;

            LocalBinder = new LocalBinder <T>(propStoreAccessService, OwnerPropId, subRequestKey.BindingInfo);
        }
예제 #7
0
        //public IManageTypedCViews<EndEditWrapper<TDestination>, TDestination> TypedCViewManager => throw new NotImplementedException();

        #endregion

        #region Private Methods

        private PropIdType GetPropertyId(PSAccessServiceInterface propStoreAccessService, PropNameType propertyName)
        {
            if (propStoreAccessService.TryGetPropId(propertyName, out PropIdType propId))
            {
                return(propId);
            }
            else
            {
                throw new InvalidOperationException("Cannot retrieve the Target's property name from the TargetPropId.");
            }
        }
예제 #8
0
 private StoreNodeBag GetPropBagNode(PSAccessServiceInterface propStoreAccessService)
 {
     if (propStoreAccessService is IHaveTheStoreNode storeNodeProvider)
     {
         StoreNodeBag propStoreNode = storeNodeProvider.PropStoreNode;
         return(propStoreNode);
     }
     else
     {
         throw new InvalidOperationException($"The {nameof(propStoreAccessService)} does not implement the {nameof(IHaveTheStoreNode)} interface.");
     }
 }
예제 #9
0
        //Lazy<IValueConverter> _defaultConverter;
        //public virtual Lazy<IValueConverter> DefaultConverter
        //{
        //    get
        //    {
        //        if(_defaultConverter == null)
        //        {
        //            return new Lazy<IValueConverter>(() => new PropValueConverter());
        //        }
        //        return _defaultConverter;
        //    }
        //    set
        //    {
        //        _defaultConverter = value;
        //    }
        //}

        //Func<BindingTarget, MyBindingInfo, Type, string, object> _defConvParamBuilder;
        //public virtual Func<BindingTarget, MyBindingInfo, Type, string, object> DefaultConverterParameterBuilder
        //{
        //    get
        //    {
        //        if (_defConvParamBuilder == null)
        //        {
        //            return OurDefaultConverterParameterBuilder;
        //        }
        //        return _defConvParamBuilder;
        //    }
        //    set
        //    {
        //        _defConvParamBuilder = value;
        //    }
        //}
        #endregion

        #region Constructor

        // PropBag
        internal LocalWatcher
        (
            PSAccessServiceInterface propStoreAccessService,
            LocalBindingInfo bindingInfo,
            IReceivePropStoreNodeUpdates_PropBag <T> storeNodeUpdateReceiver_PropBag
        ) : this(propStoreAccessService, bindingInfo)
        {
            _storeNodeUpdateReceiver_PropBag = storeNodeUpdateReceiver_PropBag;
            _notificationKind = PropStoreNotificationKindEnum.PropBag;

            _isComplete = StartBinding(_pathElements, _pathListeners, _isPathAbsolute, out _sourcePropNode);
        }
예제 #10
0
 public PSAccessServiceInterface CreatePropStoreService(IPropBag propBag, PropNodeCollectionInterface propNodes)
 {
     if (propNodes is PropNodeCollectionInternalInterface pisii)
     {
         PSAccessServiceInterface propStoreService = CreatePropStoreService(propBag, pisii, out BagNode dummy);
         return(propStoreService);
     }
     else
     {
         throw new InvalidOperationException("propNodes does not implement the PropItemSetInternalInterface.");
     }
 }
예제 #11
0
        //Lazy<IValueConverter> _defaultConverter;
        //public virtual Lazy<IValueConverter> DefaultConverter
        //{
        //    get
        //    {
        //        if(_defaultConverter == null)
        //        {
        //            return new Lazy<IValueConverter>(() => new PropValueConverter());
        //        }
        //        return _defaultConverter;
        //    }
        //    set
        //    {
        //        _defaultConverter = value;
        //    }
        //}

        //Func<BindingTarget, MyBindingInfo, Type, string, object> _defConvParamBuilder;
        //public virtual Func<BindingTarget, MyBindingInfo, Type, string, object> DefaultConverterParameterBuilder
        //{
        //    get
        //    {
        //        if (_defConvParamBuilder == null)
        //        {
        //            return OurDefaultConverterParameterBuilder;
        //        }
        //        return _defConvParamBuilder;
        //    }
        //    set
        //    {
        //        _defConvParamBuilder = value;
        //    }
        //}
        #endregion

        #region Constructor

        public LocalBinder(PSAccessServiceInterface propStoreAccessService, ExKeyT bindingTarget, LocalBindingInfo bindingInfo)
        {
            _bindingTarget = bindingTarget;
            _bindingInfo   = bindingInfo;

            // Get the PropStore Node for the IPropBag object hosting the property that is the target of the binding.
            BagNode ourNode = GetPropBagNode(propStoreAccessService);

            // Get a weak reference to the PropBag hosting the target property.
            _targetObject = ourNode.PropBagProxy;

            // Get the name of the target property from the PropId given to us.
            if (_targetObject.TryGetTarget(out IPropBag propBag))
            {
                PropIdType propId = _bindingTarget.Level2Key;

                _propertyName = GetPropertyName(propStoreAccessService, propBag, propId, out PropStorageStrategyEnum storageStrategy);

                if (storageStrategy == PropStorageStrategyEnum.External)
                {
                    throw new InvalidOperationException($"{storageStrategy} is not a supported Prop Storage Strategy when used as a target of a local binding.");
                }

                // We will update the target property depending on how that PropItem stores its value.
                _targetStorageStrategy = storageStrategy;

                // Create a instance of our nested, internal class that reponds to Updates to the property store Nodes.
                IReceivePropStoreNodeUpdates_PropNode <T> propStoreNodeUpdateReceiver = new PropStoreNodeUpdateReceiver(this);

                // Create a new watcher, the bindingInfo specifies the PropItem for which to listen to changes,
                // the propStoreNodeUpdateReceiver will be notfied when changes occur.
                _localWatcher = new LocalWatcher <T>(propStoreAccessService, bindingInfo, propStoreNodeUpdateReceiver);
            }
            else
            {
                // TODO: consider creating a TryCreateLocalBinding to avoid this situation.
                System.Diagnostics.Debug.WriteLine("The target was found to have been Garbage Collected when creating a Local Binding.");
            }
        }
예제 #12
0
        public LocalBinder(PSAccessServiceInterface propStoreAccessService, ExKeyT ownerPropId, LocalBindingInfo bindingInfo)
        {
            _propStoreAccessService_wr = new WeakReference <PSAccessServiceInterface>(propStoreAccessService);
            _bindingTarget             = ownerPropId;
            _bindingInfo             = bindingInfo;
            _storeNodeUpdateReceiver = null;


            // Get the PropStore Node for the IPropBag object hosting the property that is the target of the binding.
            _ourNode = GetPropBagNode(propStoreAccessService);

            PropIdType propId = _bindingTarget.Level2Key;

            _targetObject = _ourNode.PropBagProxy;

            if (_targetObject.TryGetTarget(out IPropBagInternal propBag))
            {
                _propertyName   = GetPropertyName(propStoreAccessService, propBag, propId, out PropStorageStrategyEnum storageStrategy);
                _targetHasStore = storageStrategy;
            }

            _pathElements = GetPathElements(_bindingInfo, out _isPathAbsolute, out _firstNamedStepIndex);

            if (_isPathAbsolute)
            {
                _rootListener = CreateAndListen(_ourNode, "root", SourceKindEnum.AbsRoot);
            }
            else
            {
                _rootListener = null;
            }

            _pathListeners = new OSCollection <T>();

            _isComplete = StartBinding(_targetObject, _pathElements, _pathListeners, _isPathAbsolute);
        }
예제 #13
0
        // TODO: should be able to have IPropStoreAccessServiceInternal provide all of this with a single call.
        private PropNameType GetPropertyName(PSAccessServiceInterface propStoreAccessService, IPropBag propBag, PropIdType propId, out PropStorageStrategyEnum storageStrategy)
        {
            PropNameType result;

            if (propStoreAccessService.TryGetPropName(propId, out PropNameType propertyName))
            {
                result = propertyName;
            }
            else
            {
                throw new InvalidOperationException("Cannot retrieve the Target's property name from the TargetPropId.");
            }

            if (propStoreAccessService.TryGetValue(propBag, propId, out IPropData genProp))
            {
                storageStrategy = genProp.TypedProp.PropTemplate.StorageStrategy;
            }
            else
            {
                throw new InvalidOperationException("Cannot retrieve the Target's property name from the TargetPropId.");
            }

            return(result);
        }
예제 #14
0
 public virtual ISubscription CreateBinding(PSAccessServiceInterface propStoreAccessService)
 {
     return(BindingFactory(this, propStoreAccessService));
 }
예제 #15
0
 public static ISubscription CreateBindingGen(ISubscriptionKeyGen bindingRequestGen, PSAccessServiceInterface propStoreAccessService)
 {
     return((ISubscription)CreateBinding((IBindingSubscriptionKey <T>)bindingRequestGen, propStoreAccessService));
 }
예제 #16
0
        public static IBindingSubscription <T> CreateBinding(IBindingSubscriptionKey <T> bindingRequest, PSAccessServiceInterface propStoreAccessService)
        {
            IBindingSubscription <T> result = new BindingSubscription <T>(bindingRequest, propStoreAccessService);

            bindingRequest.MarkAsUsed();

            return(result);
        }
예제 #17
0
        public PSAccessServiceInterface CreatePropStoreService(IPropBag propBag)
        {
            PSAccessServiceInterface result = CreatePropStoreService(propBag, null, out BagNode notUsed);

            return(result);
        }
예제 #18
0
 private BagNode GetPropBagNode(PSAccessServiceInterface propStoreAccessService)
 {
     CheckForIHaveTheStoreNode(propStoreAccessService);
     return(((IHaveTheStoreNode)propStoreAccessService).PropBagNode);
 }