Ejemplo n.º 1
0
        /// <summary>
        /// Rafraichit les bindings.
        /// </summary>
        private void RefreshBinding()
        {
            if (base.AssociatedObject == null)
            {
                return;
            }

            if (!_isBound)
            {
                var thisBinding = BindingOperations.GetBinding(this, ValueProperty);
                if (thisBinding != null)
                {
                    if (ValueType == null)
                    {
                        throw new InvalidOperationException("Définir le ValueType");
                    }

                    _bag = CreateBag(ValueType);
                    var binding = new Binding("Value")
                    {
                        Mode   = BindingMode.TwoWay,
                        Source = _bag,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    };

                    BindingOperations.SetBinding(base.AssociatedObject, _targetDp, binding);

                    _bag.PropertyChanged += _bag_PropertyChanged;

                    _isBound = true;
                }
            }

            var hasValueChanged = (_bag.InternalValue == null ^ this.Value == null) || (_bag.InternalValue != null && this.Value != null && !_bag.InternalValue.Equals(this.Value));

            if (_isBound && !_refreshingBinding && hasValueChanged)
            {
                _refreshingBinding = true;

                _bag.InternalValue = null;
                Dispatcher.BeginInvoke((Action)(() =>
                {
                    _refreshingBinding = true;
                    _bag.InternalValue = this.Value;
                    _refreshingBinding = false;
                }), System.Windows.Threading.DispatcherPriority.Loaded);

                _refreshingBinding = false;
            }
        }
Ejemplo n.º 2
0
        internal bool TryGetRouteMatch(RequestVerb verb, string uri, IValueBag parameters, out Route data)
        {
            data = null;

            // Check the verb
            if (verb != this.Verb)
            {
                return(false);
            }

            // Check the route
            var match = _resourceRegex.Match(uri);

            // Route didnt match, exit early
            if (!match.Success)
            {
                return(false);
            }

            // Check any required parameters
            if (_hasUrlParameters)
            {
                string value;

                // Try each parameter match and if any fail, exit
                foreach (var paramMatch in _paramMatches)
                {
                    // Check if the key exists and the parameter value matches the specification
                    if (!parameters.TryGetValue(paramMatch.Key, out value) || !paramMatch.ValueMatches(value))
                    {
                        // Key does not exist
                        return(false);
                    }
                }
            }

            // We made it, route matches all requirements
            data = new Route(match);
            return(true);
        }