public static MetaTable GetTable(this IDynamicDataSource dataSource)
        {
            if (dataSource == null)
            {
                return(null);
            }

            string entitySetName = dataSource.EntitySetName;

            if (String.IsNullOrEmpty(entitySetName))
            {
                // LAMESPEC: MSDN says we should throw in this case, but .NET calls
                // DynamicDataRouteHandler.GetRequestMetaTable(HttpContext
                // httpContext) instead (eventually)
                MetaTable ret = DynamicDataRouteHandler.GetRequestMetaTable(HttpContext.Current);
                if (ret == null)
                {
                    throw new InvalidOperationException("The control '" + GetDataSourceId(dataSource) +
                                                        "' does not have a TableName property and a table name cannot be inferred from the URL.");
                }
            }

            Type contextType = dataSource.ContextType;

            if (contextType == null)
            {
                throw new InvalidOperationException("The ContextType property of control '" + GetDataSourceId(dataSource) + "' must specify a data context");
            }

            return(MetaModel.GetModel(contextType).GetTable(entitySetName));
        }
Exemple #2
0
        private MetaTable GetTableFromTableName()
        {
            var tableName       = TableName;
            var contextTypeName = ContextTypeName;

            Debug.Assert(!String.IsNullOrEmpty(tableName));

            if (!String.IsNullOrEmpty(contextTypeName))
            {
                // context type allows to disambiguate table names
                Type      contextType = BuildManager.GetType(contextTypeName, /* throwOnError */ true, /* ignoreCase */ true);
                MetaModel model       = MetaModel.GetModel(contextType);
                MetaTable table       = model.GetTable(tableName, contextType);
                return(table);
            }
            else
            {
                var table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
                if (table == null)
                {
                    return(null);
                }
                return(table.Model.GetTable(tableName));
            }
        }
Exemple #3
0
        // internal for unit testing
        internal virtual MetaTable GetTable()
        {
            MetaTable table;

            if (!String.IsNullOrEmpty(TableName))
            {
                table = GetTableFromTableName();
            }
            else
            {
                table = DynamicDataRouteHandler.GetRequestMetaTable(Context);
            }
            return(table);
        }
Exemple #4
0
        private MetaTable GetTable()
        {
            if (!String.IsNullOrEmpty(ContextTypeName) || !String.IsNullOrEmpty(TableName))
            {
                // get table from control properties

                string contextTypeName = ContextTypeName;
                string tableName       = TableName;

                if (String.IsNullOrEmpty(ContextTypeName))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterRepeater_MissingContextTypeName,
                                                                      ID));
                }
                else if (String.IsNullOrEmpty(tableName))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterRepeater_MissingTableName,
                                                                      ID));
                }

                Type contextType = null;
                if (!String.IsNullOrEmpty(ContextTypeName))
                {
                    try {
                        contextType = BuildManager.GetType(contextTypeName, /*throwOnError*/ true, /*ignoreCase*/ true);
                    } catch (Exception e) {
                        throw new InvalidOperationException(String.Format(
                                                                CultureInfo.CurrentCulture,
                                                                DynamicDataResources.FilterRepeater_InvalidContextTypeName,
                                                                ID,
                                                                contextTypeName), e);
                    }
                }
                MetaModel model;
                try {
                    model = MetaModel.GetModel(contextType);
                } catch (InvalidOperationException e) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterRepeater_UnknownContextTypeName,
                                                                      ID,
                                                                      contextType.FullName), e);
                }
                try {
                    return(model.GetTable(tableName));
                } catch (ArgumentException e) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterRepeater_InvalidTableName,
                                                                      ID,
                                                                      tableName), e);
                }
            }
            else
            {
                MetaTable table = DynamicDataRouteHandler.GetRequestMetaTable(HttpContext.Current);
                if (table == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterRepeater_CantInferInformationFromUrl,
                                                                      ID));
                }
                return(table);
            }
        }
        private void EnsureInit()
        {
            if (_column != null)
            {
                return;
            }

            // make sure we have a DataField
            if (String.IsNullOrEmpty(DataField))
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  DynamicDataResources.FilterUserControlBase_MissingDataField,
                                                                  ID));
            }

            MetaTable table = null;

            if (!String.IsNullOrEmpty(ContextTypeName) || !String.IsNullOrEmpty(TableName))
            {
                // make sure both ContextTypeName and TableName are specified together
                if (String.IsNullOrEmpty(ContextTypeName))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterUserControlBase_MissingContextTypeName,
                                                                      ID));
                }
                if (String.IsNullOrEmpty(TableName))
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterUserControlBase_MissingTableName,
                                                                      ID));
                }

                Type      contextType = GetContextType(ContextTypeName);
                MetaModel model       = null;
                try {
                    model = MetaModel.GetModel(contextType);
                } catch (InvalidOperationException e) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterUserControlBase_UnknownContextType,
                                                                      ID,
                                                                      contextType.FullName), e);
                }

                string tableName = TableName;
                try {
                    table = model.GetTable(tableName);
                } catch (ArgumentException e) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterUserControlBase_InvalidTableName,
                                                                      ID,
                                                                      tableName), e);
                }
            }
            else
            {
                // get context information from request context
                table = DynamicDataRouteHandler.GetRequestMetaTable(HttpContext.Current);
                if (table == null)
                {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                      DynamicDataResources.FilterUserControlBase_CantInferInformationFromRequestUrl,
                                                                      ID));
                }
            }

            try {
                _column = table.GetColumn(DataField);
            } catch (InvalidOperationException e) {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture,
                                                                  DynamicDataResources.FilterUserControlBase_InvalidDataField,
                                                                  ID,
                                                                  DataField), e);
            }

            // create appropriate filter implementation based on column type
            if (_column is MetaForeignKeyColumn)
            {
                _filterDelegate = new ForeignKeyFilterDelegate(this);
            }
            else if (_column.ColumnType == typeof(bool) && !_column.IsCustomProperty)
            {
                _filterDelegate = new BooleanPropertyFilterDelegate(this);
            }
            else
            {
                _filterDelegate = new DefaultPropertyFilterDelegate(this);
            }
        }