コード例 #1
0
        /// <summary>
        /// Register a data control to give it Dynamic Data behavior
        /// </summary>
        /// <param name="setSelectionFromUrl">When true, if a primary key is found in the route values
        ///     (typically on the query string), it will get be set as the selected item. This only applies
        ///     to list controls.</param>
        public void RegisterControl(Control control, bool setSelectionFromUrl)
        {
            //
            if (DesignMode)
            {
                return;
            }

            IDataBoundControlInterface dataBoundControl = DataControlHelper.GetDataBoundControl(control, true /*failIfNotFound*/);

            // If we can't get an associated IDynamicDataSource, don't do anything
            IDynamicDataSource dataSource = dataBoundControl.DataSourceObject as IDynamicDataSource;

            if (dataSource == null)
            {
                return;
            }
            // If we can't get a MetaTable from the data source, don't do anything
            MetaTable table = MetaTableHelper.GetTableWithFullFallback(dataSource, Context.ToWrapper());

            // Save the datasource so we can process its parameters in OnLoad. The value we set is irrelevant
            _dataSources[dataSource] = null;

            ((INamingContainer)control).SetMetaTable(table);

            BaseDataBoundControl baseDataBoundControl = control as BaseDataBoundControl;

            if (baseDataBoundControl != null)
            {
                EnablePersistedSelection(baseDataBoundControl, table);
            }

            RegisterControlInternal(dataBoundControl, dataSource, table, setSelectionFromUrl, Page.IsPostBack);
        }
コード例 #2
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
            {
                return;
            }

            MetaTable table = MetaTableHelper.FindMetaTable(this, Context);

            if (table == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  DynamicDataResources.DynamicEntity_ControlNeedsToExistInAContextSupportingDynamicData,
                                                                  this.ID));
            }

            EntityTemplateFactory     entityTemplateFactory = table.Model.EntityTemplateFactory;
            EntityTemplateUserControl entityTemplateControl = entityTemplateFactory.CreateEntityTemplate(table, Mode, UIHint);

            if (entityTemplateControl == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  DynamicDataResources.DynamicEntity_CantFindTemplate,
                                                                  table.Name,
                                                                  entityTemplateFactory.TemplateFolderVirtualPath));
            }

            entityTemplateControl.Mode            = Mode;
            entityTemplateControl.ValidationGroup = ValidationGroup;
            entityTemplateControl.Table           = table;
            Controls.Add(entityTemplateControl);
        }
コード例 #3
0
        internal static bool TryGetMetaTable(INamingContainer control, HttpContextBase context, out MetaTable table)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }

            table = MetaTableHelper.GetTableFromMapping(context, control);
            return(table != null);
        }
コード例 #4
0
        /// <summary>
        /// See IWhereParametersProvider.GetWhereParameters
        /// </summary>
        public virtual IEnumerable <Parameter> GetWhereParameters(IDynamicDataSource dataSource)
        {
            var table = MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper());

            // check makes no sense as the above call will throw
            //if (table == null) {
            //    return new Parameter[0];
            //}

            return(RouteParametersHelper.GetColumnParameters(table, Name));
        }
コード例 #5
0
        internal static DefaultValueMapping GetDefaultValueMapping(object control, HttpContextBase context)
        {
            IDictionary <object, MappingInfo> mapping = MetaTableHelper.GetMapping(context);
            MappingInfo mappingInfo;

            if (mapping.TryGetValue(control, out mappingInfo))
            {
                return(mappingInfo.DefaultValueMapping);
            }
            return(null);
        }
コード例 #6
0
        internal static bool TryGetMetaTable(IDataSource dataSource, HttpContextBase context, out MetaTable table)
        {
            if (dataSource == null)
            {
                throw new ArgumentNullException("dataSource");
            }

            Debug.Assert(context != null);

            table = MetaTableHelper.GetTableFromMapping(context, dataSource);
            if (table == null)
            {
                var dynamicDataSource = dataSource as IDynamicDataSource;
                if (dynamicDataSource != null)
                {
                    table = MetaTableHelper.GetTableFromDynamicDataSource(dynamicDataSource);
                }
            }
            return(table != null);
        }
コード例 #7
0
        internal static void SetMetaTableInternal(INamingContainer control, MetaTable table, IDictionary <string, object> defaultValues, HttpContextBase context)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            IDataBoundControl dataBoundControl = control as IDataBoundControl;
            IDataSource       dataSource       = null;

            if (dataBoundControl != null)
            {
                dataSource = dataBoundControl.DataSourceObject;
            }
            MetaTableHelper.SetTableInMapping(context, control, table, defaultValues);
            if (dataSource != null)
            {
                // If the control being mapped is a databound control then register its datasource
                MetaTableHelper.SetTableInMapping(context, dataSource, table, defaultValues);
            }
        }
コード例 #8
0
 /// <summary>
 /// Find the containing data control, and return the MetaTable associated with it, if any
 /// </summary>
 public static MetaTable FindMetaTable(this Control current)
 {
     return(MetaTableHelper.FindMetaTable(current, HttpContext.Current.ToWrapper()));
 }
コード例 #9
0
 public static MetaTable GetTable(this IDynamicDataSource dataSource)
 {
     return(MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper()));
 }
コード例 #10
0
        /// <summary>
        /// See IWhereParametersProvider.GetWhereParameters
        /// </summary>
        public virtual IEnumerable <Parameter> GetWhereParameters(IDynamicDataSource dataSource)
        {
            Debug.Assert(dataSource != null);

            // Find the control that the ControlParameter uses
            Control control = Misc.FindControl((Control)dataSource, ControlId);

            if (control == null)
            {
                throw new InvalidOperationException(String.Format(
                                                        CultureInfo.CurrentCulture, DynamicDataResources.DynamicControlParameter_DynamicDataSourceControlNotFound, ControlId));
            }

            // If the control is itself a parameter provider, delegate to it
            var whereParametersProvider = control as IWhereParametersProvider;

            if (whereParametersProvider != null)
            {
                return(whereParametersProvider.GetWhereParameters(dataSource));
            }

            IControlParameterTarget paramTarget = DynamicDataManager.GetControlParameterTarget(control);

            if (paramTarget == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  DynamicDataResources.DynamicControlParameter_DynamicDataSourceControlCannotBeUsedAsParent, ControlId));
            }

            string     columnName = Name;
            MetaColumn column     = null;
            MetaTable  table      = MetaTableHelper.GetTableWithFullFallback(dataSource, HttpContext.Current.ToWrapper());

            if (!String.IsNullOrEmpty(columnName))
            {
                column = table.GetColumn(columnName);
            }
            else
            {
                // There was no Name attribute telling us what field to filter, but maybe
                // the control given us data has that info
                column = paramTarget.FilteredColumn;
            }

            if (column == null)
            {
                // If there is no specific column, we're setting the primary key

                if (paramTarget.Table != table)
                {
                    throw new Exception(String.Format(CultureInfo.CurrentCulture,
                                                      DynamicDataResources.DynamicControlParameter_InvalidPK,
                                                      ControlId, paramTarget.Table, table.Name));
                }

                return(GetPrimaryKeyControlWhereParameters(control, paramTarget));
            }
            else if (column is MetaForeignKeyColumn)
            {
                return(GetForeignKeyControlWhereParameters(control, paramTarget, (MetaForeignKeyColumn)column));
            }
            return(GetPropertyControlWhereParameters(control, paramTarget, column));
        }