Esempio n. 1
0
        protected QueryableDataSourceEditData BuildInsertObject(IDictionary values, IDictionary <string, Exception> validationErrors)
        {
            QueryableDataSourceEditData editData = new QueryableDataSourceEditData();
            Type        dataObjectType           = EntityType;
            IDictionary caseInsensitiveNewValues = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    InsertParameters,
                                                    InsertParameters.GetValues(_context, _owner),
                                                    caseInsensitiveNewValues,
                                                    validationErrors))
            {
                return(editData);
            }

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    InsertParameters,
                                                    values,
                                                    caseInsensitiveNewValues, validationErrors))
            {
                return(editData);
            }

            editData.NewDataObject = DataSourceHelper.BuildDataObject(dataObjectType, caseInsensitiveNewValues, validationErrors);
            return(editData);
        }
Esempio n. 2
0
 protected virtual void TrackViewState()
 {
     _isTracking = true;
     DataSourceHelper.TrackViewState(_whereParameters);
     DataSourceHelper.TrackViewState(_orderByParameters);
     DataSourceHelper.TrackViewState(_groupByParameters);
     DataSourceHelper.TrackViewState(_orderGroupsByParameters);
     DataSourceHelper.TrackViewState(_selectNewParameters);
 }
Esempio n. 3
0
        DataSourceView IDataSource.GetView(string viewName)
        {
            IDataSource source = this._dataSource as IDataSource;

            if (source != null)
            {
                return(source.GetView(viewName));
            }
            return(new ReadOnlyDataSourceView(this, this._dataMember, DataSourceHelper.GetResolvedDataSource(this._dataSource, this._dataMember)));
        }
        /// <devdoc>
        /// Check for IDataSource, IListSource, and IEnumerable, and return an
        /// approprite DataSourceView.
        /// </devdoc>
        DataSourceView IDataSource.GetView(string viewName)
        {
            // Check first for IDataSource
            IDataSource ds = _dataSource as IDataSource;

            if (ds != null)
            {
                return(ds.GetView(viewName));
            }

            IEnumerable enumerable = DataSourceHelper.GetResolvedDataSource(_dataSource, _dataMember);

            return(new ReadOnlyDataSourceView(this, _dataMember, enumerable));
        }
Esempio n. 5
0
        protected virtual object SaveViewState()
        {
            object[] myState = new object[6];
            myState[0] = DataSourceHelper.SaveViewState(_whereParameters);
            myState[1] = DataSourceHelper.SaveViewState(_orderByParameters);
            myState[2] = DataSourceHelper.SaveViewState(_groupByParameters);
            myState[3] = DataSourceHelper.SaveViewState(_orderGroupsByParameters);
            myState[4] = DataSourceHelper.SaveViewState(_selectNewParameters);
            if ((_originalValues != null) && (_originalValues.Count > 0))
            {
                myState[5] = _originalValues;
            }

            return(myState);
        }
                                                                           @"(\s+(asc|ascending|desc|descending))?\s*$", RegexOptions.IgnoreCase); // order operators

        internal static IQueryable AsQueryable(object o)
        {
            IQueryable oQueryable = o as IQueryable;

            if (oQueryable != null)
            {
                return(oQueryable);
            }

            // Wrap strings in IEnumerable<string> instead of treating as IEnumerable<char>.
            string oString = o as string;

            if (oString != null)
            {
                return(Queryable.AsQueryable(new string[] { oString }));
            }

            IEnumerable oEnumerable = o as IEnumerable;

            if (oEnumerable != null)
            {
                // IEnumerable<T> can be directly converted to an IQueryable<T>.
                Type genericType = FindGenericEnumerableType(o.GetType());
                if (genericType != null)
                {
                    // The non-generic Queryable.AsQueryable gets called for array types, executing
                    // the FindGenericType logic again.  Might want to investigate way to avoid this.
                    return(Queryable.AsQueryable(oEnumerable));
                }
                // Wrap non-generic IEnumerables in IEnumerable<object>.
                List <object> genericList = new List <object>();
                foreach (object item in oEnumerable)
                {
                    genericList.Add(item);
                }
                return(Queryable.AsQueryable(genericList));
            }

            // Wrap non-IEnumerable types in IEnumerable<T>.
            Type  listType = typeof(List <>).MakeGenericType(o.GetType());
            IList list     = (IList)DataSourceHelper.CreateObjectInstance(listType);

            list.Add(o);
            return(Queryable.AsQueryable(list));
        }
Esempio n. 7
0
        protected QueryableDataSourceEditData BuildDeleteObject(IDictionary keys, IDictionary oldValues, IDictionary <string, Exception> validationErrors)
        {
            QueryableDataSourceEditData editData = new QueryableDataSourceEditData();
            Type        dataObjectType           = EntityType;
            IDictionary caseInsensitiveOldValues = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
            IDictionary originalValues           = GetOriginalValues(keys);

            ParameterCollection deleteParameters = DeleteParameters;

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    deleteParameters,
                                                    keys,
                                                    caseInsensitiveOldValues,
                                                    validationErrors))
            {
                return(editData);
            }

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    deleteParameters,
                                                    oldValues,
                                                    caseInsensitiveOldValues,
                                                    validationErrors))
            {
                return(editData);
            }

            if (originalValues != null)
            {
                if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                        deleteParameters,
                                                        originalValues,
                                                        caseInsensitiveOldValues,
                                                        validationErrors))
                {
                    return(editData);
                }
            }

            editData.OriginalDataObject = DataSourceHelper.BuildDataObject(dataObjectType, caseInsensitiveOldValues, validationErrors);
            return(editData);
        }
 protected virtual object CreateContext(Type contextType)
 {
     return(DataSourceHelper.CreateObjectInstance(contextType));
 }
Esempio n. 9
0
        protected QueryableDataSourceEditData BuildUpdateObjects(IDictionary keys, IDictionary values, IDictionary oldValues, IDictionary <string, Exception> validationErrors)
        {
            QueryableDataSourceEditData editData = new QueryableDataSourceEditData();
            Type        dataObjectType           = EntityType;
            IDictionary caseInsensitiveNewValues = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
            IDictionary caseInsensitiveOldValues = new OrderedDictionary(StringComparer.OrdinalIgnoreCase);
            IDictionary originalValues           = GetOriginalValues(keys);

            // We start out with the old values, just to pre-populate the list with items
            // that might not have corresponding new values. For example if a GridView has
            // a read-only field, there will be an old value, but no new value. The data object
            // still has to have *some* value for a given field, so we just use the old value.
            ParameterCollection updateParameters = UpdateParameters;

            // If we have validation errors bail out while merging bailout

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    updateParameters,
                                                    oldValues,
                                                    caseInsensitiveOldValues,
                                                    caseInsensitiveNewValues,
                                                    validationErrors))
            {
                return(editData);
            }

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    updateParameters,
                                                    keys,
                                                    caseInsensitiveOldValues,
                                                    caseInsensitiveNewValues,
                                                    validationErrors))
            {
                return(editData);
            }

            if (originalValues != null)
            {
                if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                        updateParameters,
                                                        originalValues,
                                                        caseInsensitiveOldValues,
                                                        caseInsensitiveNewValues,
                                                        validationErrors))
                {
                    return(editData);
                }
            }

            if (!DataSourceHelper.MergeDictionaries(dataObjectType,
                                                    updateParameters,
                                                    values,
                                                    caseInsensitiveNewValues,
                                                    validationErrors))
            {
                return(editData);
            }

            editData.NewDataObject = DataSourceHelper.BuildDataObject(dataObjectType, caseInsensitiveNewValues, validationErrors);

            if (editData.NewDataObject != null)
            {
                editData.OriginalDataObject = DataSourceHelper.BuildDataObject(dataObjectType, caseInsensitiveOldValues, validationErrors);
            }
            return(editData);
        }
Esempio n. 10
0
        /// <include file='doc\ListControl.uex' path='docs/doc[@for="ListControl.OnDataBinding"]/*' />
        /// <internalonly/>
        /// <devdoc>
        /// </devdoc>
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);

            // create items using the datasource
            IEnumerable dataSource = DataSourceHelper.GetResolvedDataSource(this.DataSource, this.DataMember);

            if (dataSource != null)
            {
                bool fieldsSpecified = false;
                bool formatSpecified = false;

                string textField  = DataTextField;
                string valueField = DataValueField;
                string textFormat = DataTextFormatString;

                Items.Clear();
                ICollection collection = dataSource as ICollection;
                if (collection != null)
                {
                    Items.Capacity = collection.Count;
                }

                if ((textField.Length != 0) || (valueField.Length != 0))
                {
                    fieldsSpecified = true;
                }
                if (textFormat.Length != 0)
                {
                    formatSpecified = true;
                }

                foreach (object dataItem in dataSource)
                {
                    ListItem item = new ListItem();

                    if (fieldsSpecified)
                    {
                        if (textField.Length > 0)
                        {
                            item.Text = DataBinder.GetPropertyValue(dataItem, textField, textFormat);
                        }
                        if (valueField.Length > 0)
                        {
                            item.Value = DataBinder.GetPropertyValue(dataItem, valueField, null);
                        }
                    }
                    else
                    {
                        if (formatSpecified)
                        {
                            item.Text = String.Format(textFormat, dataItem);
                        }
                        else
                        {
                            item.Text = dataItem.ToString();
                        }
                        item.Value = dataItem.ToString();
                    }

                    Items.Add(item);
                }
            }

            // try to apply the cached SelectedIndex and SelectedValue now
            if (cachedSelectedValue != null)
            {
                int cachedSelectedValueIndex = -1;

                cachedSelectedValueIndex = Items.FindByValueInternal(cachedSelectedValue);
                if (-1 == cachedSelectedValueIndex)
                {
                    throw new ArgumentOutOfRangeException("value");
                }

                if ((cachedSelectedIndex != -1) && (cachedSelectedIndex != cachedSelectedValueIndex))
                {
                    throw new ArgumentException(HttpRuntime.FormatResourceString(SR.Attributes_mutually_exclusive, "SelectedIndex", "SelectedValue"));
                }

                SelectedIndex       = cachedSelectedValueIndex;
                cachedSelectedValue = null;
                cachedSelectedIndex = -1;
            }
            else
            {
                if (cachedSelectedIndex != -1)
                {
                    SelectedIndex       = cachedSelectedIndex;
                    cachedSelectedIndex = -1;
                }
            }
        }
Esempio n. 11
0
        /// <include file='doc\Repeater.uex' path='docs/doc[@for="Repeater.CreateControlHierarchy"]/*' />
        /// <devdoc>
        ///    A protected method. Creates a control
        ///    hierarchy, with or without the data source as specified.
        /// </devdoc>
        protected virtual void CreateControlHierarchy(bool useDataSource)
        {
            IEnumerable dataSource = null;
            int         count      = -1;

            if (itemsArray != null)
            {
                itemsArray.Clear();
            }
            else
            {
                itemsArray = new ArrayList();
            }

            if (useDataSource == false)
            {
                // ViewState must have a non-null value for ItemCount because we check for
                // this in CreateChildControls
                count = (int)ViewState[ItemCountViewStateKey];
                if (count != -1)
                {
                    dataSource          = new DummyDataSource(count);
                    itemsArray.Capacity = count;
                }
            }
            else
            {
                dataSource = DataSourceHelper.GetResolvedDataSource(this.DataSource, this.DataMember);

                ICollection collection = dataSource as ICollection;
                if (collection != null)
                {
                    itemsArray.Capacity = collection.Count;
                }
            }

            if (dataSource != null)
            {
                ControlCollection controls = Controls;
                RepeaterItem      item;
                ListItemType      itemType;
                int index = 0;

                bool hasSeparators = (separatorTemplate != null);
                count = 0;

                if (headerTemplate != null)
                {
                    CreateItem(-1, ListItemType.Header, useDataSource, null);
                }

                foreach (object dataItem in dataSource)
                {
                    // rather than creating separators after the item, we create the separator
                    // for the previous item in all iterations of this loop.
                    // this is so that we don't create a separator for the last item
                    if (hasSeparators && (count > 0))
                    {
                        CreateItem(index - 1, ListItemType.Separator, useDataSource, null);
                    }

                    itemType = (index % 2 == 0) ? ListItemType.Item : ListItemType.AlternatingItem;
                    item     = CreateItem(index, itemType, useDataSource, dataItem);
                    itemsArray.Add(item);

                    count++;
                    index++;
                }

                if (footerTemplate != null)
                {
                    CreateItem(-1, ListItemType.Footer, useDataSource, null);
                }
            }

            if (useDataSource)
            {
                // save the number of items contained in the repeater for use in round-trips
                ViewState[ItemCountViewStateKey] = ((dataSource != null) ? count : -1);
            }
        }