Exemple #1
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;
            }
        }
Exemple #2
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);
        }
Exemple #3
0
        private string[] GetPathElements(LocalBindingInfo bInfo, out bool pathIsAbsolute, out int firstNamedStepIndex)
        {
            string[] pathElements = bInfo.PropertyPath.Path.Split('/');
            int      compCount    = pathElements.Length;

            if (compCount == 0)
            {
                throw new InvalidOperationException("The path has no components.");
            }

            if (pathElements[compCount - 1] == "..")
            {
                throw new InvalidOperationException("The last component of the path cannot be '..'");
            }

            if (compCount == 1 && pathElements[0] == ".")
            {
                // Can't bind to yourself.
            }

            // Remove initial "this" component, if present.
            if (pathElements[0] == ".")
            {
                pathElements = RemoveFirstItem(pathElements);
                compCount--;
                if (pathElements[0] == ".")
                {
                    throw new InvalidOperationException("A path that starts with '././' is not supported.");
                }
            }

            if (pathElements[0] == string.Empty)
            {
                pathIsAbsolute = true;

                // remove the initial (empty) path component.
                pathElements = RemoveFirstItem(pathElements);
                compCount--;

                if (pathElements[0] == "..")
                {
                    throw new InvalidOperationException("Absolute Paths cannot refer to a parent. (Path begins with '/../'.");
                }
                firstNamedStepIndex = 0;

                // TODO: Listen to changes in the value of our node's root.
            }
            else
            {
                pathIsAbsolute      = false;
                firstNamedStepIndex = GetFirstPathElementWithName(0, pathElements);
            }

            CheckForBadParRefs(firstNamedStepIndex + 1, pathElements);
            return(pathElements);
        }
Exemple #4
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);
        }
Exemple #5
0
        private IConvertValues GetConverter(WeakRefKey <IPropBag> bindingTarget, LocalBindingInfo bInfo, Type sourceType,
                                            string pathElement, bool isPropBagBased, out object converterParameter)
        {
            //if (isPropBagBased)
            //{
            //    if (bInfo.Converter != null)
            //    {
            //        // Use the one specified in the MarkUp
            //        converterParameter = bInfo.ConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement);
            //        return bInfo.Converter;
            //    }
            //    else
            //    {
            //        // Use the default for ItemsSource
            //        if(bindingTarget.DependencyProperty.Name == "SelectedItem")
            //        {
            //            // If this is being used to supply a SelectedItem property.
            //            converterParameter = null;
            //            return new SelectedItemConverter();
            //        }
            //        else
            //        {
            //            // Use the default converter provided by the caller or if no default provide our standard PropValueConverter.
            //            converterParameter = DefaultConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement);
            //            return DefaultConverter.Value;
            //        }
            //    }
            //}
            //else
            //{
            //    // If no converter specified and the target is SelectedItem,
            //    // use the SelectedItemConverter.
            //    if (bInfo.Converter == null && bindingTarget.DependencyProperty?.Name == "SelectedItem")
            //    {
            //        converterParameter = null;
            //        return new SelectedItemConverter();
            //    }
            //    else
            //    {
            //        // TODO: Check this. I beleive that the Microsoft Binder supplies a default converter.

            //        // If no converter specified in the markup, no converter will be used.
            //        converterParameter = bInfo.ConverterParameterBuilder(bindingTarget, bInfo, sourceType, pathElement);
            //        return bInfo.Converter;
            //    }
            //}
            converterParameter = null;
            return(null);
        }
Exemple #6
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.");
            }
        }
Exemple #7
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);
        }
Exemple #8
0
 private object OurDefaultConverterParameterBuilder(WeakRefKey <IPropBag> bindingTarget, LocalBindingInfo bInfo, Type sourceType,
                                                    string pathElement)
 {
     //return new TwoTypes(sourceType, bindingTarget.PropertyType);
     return(null);
 }