Esempio n. 1
0
		public void Constructor ()
		{
			var ddrh = new DynamicDataRouteHandler ();

			Assert.AreEqual (null, ddrh.Model, "#A1");
		}
		public DynamicDataRoute (string url)
			: base (url, null)
		{
			Model = MetaModel.Default;
			RouteHandler = new DynamicDataRouteHandler ();
		}
Esempio n. 3
0
        void EnsureInitialized()
        {
            if (initDone)
            {
                return;
            }

            // We need to lock since we might be stored in the RouteTable.Routes
            // collection which might be accessed from many concurrent requests.
            lock (initLock)
            {
                if (initDone)
                {
                    return;
                }

                initDone = true;

                DynamicDataRouteHandler rh = RouteHandler;
                if (rh != null)
                {
                    rh.Model = Model;
                }

                string action = Action, table = Table;
                if (action == null && table == null)
                {
                    return;
                }

                RouteValueDictionary defaults = Defaults;
                if (defaults == null)
                {
                    Defaults = defaults = new RouteValueDictionary();
                }

                if (table != null)
                {
                    // Force check for table existence
                    MetaModel model = Model ?? MetaModel.Default;
                    if (model != null)
                    {
                        Model.GetTable(table);
                    }

                    if (defaults.ContainsKey("Table"))
                    {
                        defaults ["Table"] = table;
                    }
                    else
                    {
                        defaults.Add("Table", table);
                    }
                }

                if (action != null)
                {
                    if (defaults.ContainsKey("Action"))
                    {
                        defaults ["Action"] = action;
                    }
                    else
                    {
                        defaults.Add("Action", action);
                    }
                }
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 public DynamicDataRoute(string url)
     : base(url, null)
 {
     Model        = MetaModel.Default;
     RouteHandler = new DynamicDataRouteHandler();
 }