コード例 #1
0
 public void GetModel()
 {
     Utils.GetModel <UseOnlyInGetModelTestDataContext> ();
     AssertExtensions.Throws <ArgumentNullException> (() => MetaModel.GetModel(null), "#A1");
     AssertExtensions.Throws <InvalidOperationException> (() => MetaModel.GetModel(typeof(object)), "#A2");
     Assert.IsNotNull(MetaModel.GetModel(typeof(UseOnlyInGetModelTestDataContext)));
 }
コード例 #2
0
        static void Column_OnLoad(Page p)
        {
            var lc = p.FindControl("ListView1") as ListView;

            Assert.IsNotNull(lc, "#A1");

            var dc = lc.FindChild <DynamicControl> ("FirstName");

            Assert.IsNotNull(dc, "#A1-1");
            Assert.IsNotNull(dc.Column, "#B1");

            // Safe not to check for GetModel's return value - it throws if model isn't found, same
            // goes for GetTable and GetColumn
            MetaTable  table  = MetaModel.GetModel(typeof(EmployeesDataContext)).GetTable("EmployeeTable");
            MetaColumn column = table.GetColumn("FirstName");

            Assert.AreEqual(column, dc.Column, "#B1-1");
            Assert.AreEqual(dc.Column.Table, dc.Table, "#B1-2");

            dc.Column = column;
            Assert.AreEqual(column, dc.Column, "#C1-3");

            column    = table.GetColumn("Active");
            dc.Column = column;
            Assert.AreEqual(column, dc.Column, "#C1-4");

            // Talk about consistency...
            table     = MetaModel.GetModel(typeof(EmployeesDataContext)).GetTable("SeasonalEmployeeTable");
            column    = table.GetColumn("FirstName");
            dc.Column = column;

            Assert.AreNotEqual(dc.Column.Table, dc.Table, "#C1-5");
        }
コード例 #3
0
        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));
        }
コード例 #4
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));
            }
        }
コード例 #5
0
        public void RegisterContext4()
        {
            MetaModel m = Utils.GetModel <MyDataContext1> ();

            Assert.AreEqual(0, m.Tables.Count, "#1-1");
            Assert.AreEqual(0, m.VisibleTables.Count, "#1-2");
            Assert.IsNotNull(MetaModel.GetModel(typeof(MyDataContext1)), "#2");
        }
コード例 #6
0
        static void Table_OnLoad(Page p)
        {
            var lc = p.FindControl("ListView1") as ListView;

            Assert.IsNotNull(lc, "#A1");

            var dc = lc.FindChild <DynamicControl> ("FirstName");

            Assert.IsNotNull(dc, "#A1-1");
            Assert.IsNotNull(dc.Table, "#B1");

            // Safe not to check for GetModel's return value - it throws if model isn't found, same
            // goes for GetTable
            MetaTable table = MetaModel.GetModel(typeof(EmployeesDataContext)).GetTable("EmployeeTable");

            Assert.AreEqual(table, dc.Table, "#B1-1");
            Assert.AreEqual(dc.Table, dc.Column.Table, "#B1-2");
        }
コード例 #7
0
ファイル: FilterRepeater.cs プロジェクト: dox0/DotNet471RS3
        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);
            }
        }
コード例 #8
0
        public void Scaffold()
        {
            //
            // ScaffoldAllTables=true is in effect for this model
            //
            MetaModel m = Utils.CommonInitialize();

            MetaTable  t  = m.Tables[TestDataContext.TableBazColumnAttributes];
            MetaColumn mc = t.GetColumn("NoScaffoldColumn");

            Assert.IsNotNull(mc, "#1");
            Assert.AreEqual(false, mc.Scaffold, "#1-1");

            mc = t.GetColumn("ScaffoldAttributeColumn");
            Assert.IsNotNull(mc, "#2");
            Assert.AreEqual(true, mc.Scaffold, "#2-1");

            mc = t.GetColumn("ColumnNoAttributes");
            Assert.IsNotNull(mc, "#3");
            Assert.AreEqual(true, mc.Scaffold, "#3-1");

            // No attribute cases
            mc = t.GetColumn("UIHintColumn");
            Assert.IsNotNull(mc, "#4");
            Assert.AreEqual(true, mc.Scaffold, "#4-1");

            t  = m.Tables[TestDataContext.TableFooNoScaffold];
            mc = t.GetColumn("Column1");
            Assert.IsNotNull(mc, "#5");
            Assert.AreEqual(true, mc.Scaffold, "#5-1");

            t  = m.Tables[TestDataContext.TableBaz];
            mc = t.GetColumn("GeneratedColumn1");
            Assert.IsNotNull(mc, "#6");
            Assert.AreEqual(false, mc.Scaffold, "#6-1");

            mc = t.GetColumn("GeneratedColumn2");
            Assert.IsNotNull(mc, "#7");
            Assert.AreEqual(true, mc.Scaffold, "#7-1");

            mc = t.GetColumn("CustomPropertyColumn1");
            Assert.IsNotNull(mc, "#8");
            Assert.AreEqual(false, mc.Scaffold, "#8-1");

            mc = t.GetColumn("CustomPropertyColumn2");
            Assert.IsNotNull(mc, "#9");
            Assert.AreEqual(true, mc.Scaffold, "#9-1");

            t  = m.Tables[TestDataContext.TableAssociatedFoo];
            mc = t.GetColumn("ForeignKeyColumn1");
            Assert.IsNotNull(mc, "#10");
            Assert.AreEqual(true, mc.IsForeignKeyComponent, "#10-1");
            Assert.AreEqual(true, mc.Scaffold, "#11-2");

            m  = MetaModel.GetModel(dynamicModelProviderNoScaffold.ContextType);
            t  = m.Tables[TestDataContext2.TableFooBarNoScaffold];
            mc = t.GetColumn("Column1");
            Assert.IsNotNull(mc, "#12");
            Assert.AreEqual(true, mc.Scaffold, "#12-1");

            mc = t.GetColumn("CustomPropertyColumn1");
            Assert.IsNotNull(mc, "#13");
            Assert.AreEqual(false, mc.Scaffold, "#13-1");

            mc = t.GetColumn("CustomPropertyColumn2");
            Assert.IsNotNull(mc, "#14");
            Assert.AreEqual(true, mc.Scaffold, "#14-1");

            mc = t.GetColumn("GeneratedColumn1");
            Assert.IsNotNull(mc, "#15");
            Assert.AreEqual(false, mc.Scaffold, "#15-1");

            mc = t.GetColumn("GeneratedColumn2");
            Assert.IsNotNull(mc, "#16");
            Assert.AreEqual(true, mc.Scaffold, "#16-1");

            mc = t.GetColumn("ForeignKeyColumn1");
            Assert.IsNotNull(mc, "#17");
            Assert.AreEqual(true, mc.IsForeignKeyComponent, "#17-1");
            Assert.AreEqual(true, mc.Scaffold, "#17-2");
        }
コード例 #9
0
        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);
            }
        }