Exemple #1
0
        /// <inheritdoc />
        protected override bool CanBindImpl(DataBinding binding)
        {
            string bindingPath = binding.Path;

            if (bindingPath == null)
            {
                return(false);
            }

            string fullPath = itemPath + "/" + bindingPath;

            try
            {
                IXPathNavigable document = documentProvider();
                return(document.CreateNavigator().Select(fullPath).MoveNext());
            }
            catch (XPathException)
            {
                // Return false if the combined path is not a valid XPath expression.
                return(false);
            }
        }
        /// <summary>
        /// Registers a data binding for a given data set and adds the data set
        /// to the list of data sets to be enumerated during data binding.
        /// Returns a <see cref="IDataAccessor" /> that may be used to
        /// retrieve the values associated with the binding.
        /// </summary>
        /// <remarks>
        /// <para>
        /// A <see cref="IDataBinder" /> uses this method to register interest
        /// in querying a particular <see cref="IDataSet" />.  It must do so
        /// before <see cref="GetItems" /> is called to ensure that the <see cref="IDataSet"/>
        /// is included in the enumeration.
        /// </para>
        /// </remarks>
        /// <param name="dataSet">The data set.</param>
        /// <param name="binding">The data binding.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="dataSet"/> or <paramref name="binding"/> is null.</exception>
        public IDataAccessor RegisterBinding(IDataSet dataSet, DataBinding binding)
        {
            if (dataSet == null)
            {
                throw new ArgumentNullException("dataSet");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            if (!joinedDataSet.DataSets.Contains(dataSet))
            {
                joinedDataSet.AddDataSet(dataSet);
            }

            DataBinding translatedBinding = joinedDataSet.TranslateBinding(dataSet, binding);

            translatedBindings.Add(translatedBinding);

            return(new BoundDataAccessor(translatedBinding));
        }
Exemple #3
0
 /// <inheritdoc />
 protected override bool CanBindImpl(DataBinding binding)
 {
     // TODO: compute from the document
     return(true);
 }
 /// <inheritdoc />
 protected override bool CanBindImpl(DataBinding binding)
 {
     return binding.Index.GetValueOrDefault(-1) == 0;
 }
Exemple #5
0
 /// <summary>
 /// Determines whether a binding can be satisfied by the data set.
 /// </summary>
 /// <param name="binding">The data binding, not null.</param>
 /// <returns>True if the binding can be satisfied.</returns>
 protected abstract bool CanBindImpl(DataBinding binding);
Exemple #6
0
 /// <inheritdoc />
 protected override object GetValueImpl(DataBinding binding)
 {
     return(null);
 }
Exemple #7
0
 /// <summary>
 /// Implements <see cref="GetValue" />.
 /// </summary>
 /// <param name="binding">The binding, never null.</param>
 /// <returns>The associated value.</returns>
 protected abstract object GetValueImpl(DataBinding binding);
 /// <summary>
 /// Creates an exception with an associated data binding.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="binding">The associated data binding, or null if none.</param>
 /// <param name="innerException">The inner exception.</param>
 public DataBindingException(string message, DataBinding binding, Exception innerException)
     : base(FormatMessageWithBinding(message, binding), innerException)
 {
 }
 private static string FormatMessageWithBinding(string message, DataBinding binding)
 {
     return(binding != null ? message + "\nAttempted binding: " + binding : message);
 }
Exemple #10
0
 public ResolvedBinding(DataSetInfo dataSetInfo, DataBinding inner, int?externalIndex)
     : base(externalIndex, inner.Path)
 {
     this.dataSetInfo = dataSetInfo;
     this.inner       = inner;
 }
 /// <summary>
 /// Creates an exception with an associated data binding.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <param name="binding">The associated data binding, or null if none.</param>
 public DataBindingException(string message, DataBinding binding)
     : base(FormatMessageWithBinding(message, binding))
 {
 }
Exemple #12
0
        private ResolvedBinding ResolveBinding(DataBinding binding)
        {
            var resolvedBinding = binding as ResolvedBinding;

            if (resolvedBinding != null && resolvedBinding.DataSetInfo.IsOwnedBy(this))
            {
                return(resolvedBinding);
            }

            int?externalIndex = binding.Index;

            if (!externalIndex.HasValue)
            {
                foreach (IDataSet dataSet in DataSets)
                {
                    if (dataSet.CanBind(binding))
                    {
                        return(new ResolvedBinding(lookupTable[dataSet], binding, null));
                    }
                }
            }
            else
            {
                DataBinding nullIndexBinding = null;

                int currentOffset = 0;
                foreach (IDataSet dataSet in DataSets)
                {
                    int currentColumnCount = dataSet.ColumnCount;

                    DataBinding currentBinding;
                    if (currentOffset == 0)
                    {
                        currentBinding = binding;
                    }
                    else
                    {
                        int internalIndex = externalIndex.Value - currentOffset;
                        if (internalIndex < 0 || internalIndex >= currentColumnCount)
                        {
                            if (nullIndexBinding == null)
                            {
                                nullIndexBinding = binding.ReplaceIndex(null);
                            }
                            currentBinding = nullIndexBinding;
                        }
                        else
                        {
                            currentBinding = binding.ReplaceIndex(internalIndex);
                        }
                    }

                    if (dataSet.CanBind(currentBinding))
                    {
                        return(new ResolvedBinding(lookupTable[dataSet], currentBinding, binding.Index));
                    }

                    currentOffset += currentColumnCount;
                }
            }

            return(null);
        }
Exemple #13
0
        /// <inheritdoc />
        protected override bool CanBindImpl(DataBinding binding)
        {
            ResolvedBinding resolvedBinding = ResolveBinding(binding);

            return(resolvedBinding != null && DataSets[resolvedBinding.DataSetInfo.DataSetIndex].CanBind(resolvedBinding.Inner));
        }
        /// <inheritdoc />
        protected override bool CanBindImpl(DataBinding binding)
        {
            int bindingIndex = binding.Index.GetValueOrDefault(int.MaxValue);

            return(bindingIndex >= 0 && bindingIndex < columnCount);
        }
Exemple #15
0
        private DataBinding ReverseTranslateBinding(DataBinding binding)
        {
            string alias = FindAliasForIndex(binding.Index);

            return(alias != null ? new DataBinding(binding.Index, alias) : binding);
        }
Exemple #16
0
 /// <inheritdoc />
 protected override bool CanBindImpl(DataBinding binding)
 {
     return(true);
 }