Beispiel #1
0
        public static void RegisterContext(DataModelProvider model, ContextConfiguration config, bool defaultModel)
        {
            // Just in case no model has been created yet
            MetaModel m = new MetaModel();

            if (defaultModel)
            {
                m = MetaModel.Default;
            }

            Exception exception  = null;
            MetaModel registered = null;

            try {
                registered = MetaModel.GetModel(model.ContextType);
            } catch (Exception) {
                // ignore
            }

            try {
                if (registered == null)
                {
                    m.RegisterContext(model, config);
                }
            } catch (InvalidOperationException ex) {
                exception = ex;
            }

            if (exception != null)
            {
                Console.WriteLine("RegisterContext exception:");
                Console.WriteLine(exception);
            }
        }
        public static MetaTable GetTable(string contextKey)
        {
            string[] param = contextKey.Split('#');
            Debug.Assert(param.Length == 2, String.Format("The context key '{0}' is invalid", contextKey));
            Type type = Type.GetType(param[0]);

            return(MetaModel.GetModel(type).GetTable(param[1], type));
        }
Beispiel #3
0
        public void SetDataObject(object dataObject, DetailsView detailsView)
        {
            DataObject = dataObject;
            TypeDescriptionProvider typeDescriptionProvider;

            CustomTypeDescriptor = dataObject as ICustomTypeDescriptor;
            Type dataObjectType;

            if (CustomTypeDescriptor == null)
            {
                dataObjectType          = dataObject.GetType();
                typeDescriptionProvider = TypeDescriptor.GetProvider(DataObject);
                CustomTypeDescriptor    = typeDescriptionProvider.GetTypeDescriptor(DataObject);
            }
            else
            {
                dataObjectType          = GetEntityType();
                typeDescriptionProvider = new TrivialTypeDescriptionProvider(CustomTypeDescriptor);
            }

            // Set the context type and entity set name on ourselves. Note that in this scenario those
            // concepts are somewhat artificial, since we don't have a real context.

            // Set the ContextType to the dataObjectType, which is a bit strange but harmless
            Type contextType = dataObjectType;

            ((IDynamicDataSource)this).ContextType = contextType;

            // We can set the entity set name to anything, but using the
            // DataObjectType makes some Dynamic Data error messages clearer.
            ((IDynamicDataSource)this).EntitySetName = dataObjectType.Name;

            MetaModel model = null;

            try {
                model = MetaModel.GetModel(contextType);
            }
            catch {
                model = new MetaModel();
                model.RegisterContext(
                    new SimpleModelProvider(contextType, dataObjectType, dataObject),
                    new ContextConfiguration()
                {
                    MetadataProviderFactory = (type => typeDescriptionProvider)
                });
            }

            MetaTable table = model.GetTable(dataObjectType);

            if (detailsView != null)
            {
                detailsView.RowsGenerator = new AdvancedFieldGenerator(table, false);
            }
        }
Beispiel #4
0
    // Get the data model. 
    public MetaModel GetModel(bool defaultModel)
    {
        MetaModel model;

        if (defaultModel)
            model = MetaModel.Default;
        else
            model =
               MetaModel.GetModel(typeof(AdventureWorksLTDataContext));
        return model;
    }
    // <Snippet22>
    // Get the data model.
    public MetaModel GetModel(bool defaultModel)
    {
        MetaModel model;

        if (defaultModel)
        {
            model = MetaModel.Default;
        }
        else
        {
            model =
                MetaModel.GetModel(typeof(AdventureWorksLTDataContext));
        }
        return(model);
    }
Beispiel #6
0
        public static MetaModel GetModel <ContextType> ()
        {
            // This is really, really dumb but we need that since if the type has already
            // been registered by another test, or tests are re-ran without nunit having
            // reloaded the dll we'll get a duplicate entry exception.
            MetaModel m;

            try {
                m = MetaModel.GetModel(typeof(ContextType));
            } catch (InvalidOperationException) {
                m = new MetaModel();
                m.RegisterContext(typeof(ContextType));
            } finally {
                MetaModel.ResetRegistrationException();
            }

            return(m);
        }
Beispiel #7
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            DataObjectType = BuildManager.GetType(DataObjectTypeName, true);

            // Make a generic type to give us a unique key to pass to the MetaModel API
            Type contextType = typeof(DummyContext <>).MakeGenericType(DataObjectType);

            // Set the context type and entity set name on ourselves. Note that in this scenario those
            // concept are somewhat artificial, since we don't have a real context. We can set the entity set name
            // to anything, but using the DataObjectType makes some Dynamic Data error messages clearer.
            ((IDynamicDataSource)this).ContextType   = contextType;
            ((IDynamicDataSource)this).EntitySetName = DataObjectType.Name;

            MetaModel model = null;

            try {
                model = MetaModel.GetModel(contextType);
            }
            catch {
                var contextConfiguration = new ContextConfiguration()
                {
                    MetadataProviderFactory = (type => new InMemoryMetadataTypeDescriptionProvider(type, new AssociatedMetadataTypeTypeDescriptionProvider(type)))
                };

                var typeDescriptionProvider = contextConfiguration.MetadataProviderFactory(DataObjectType);
                var typeDescriptor          = typeDescriptionProvider.GetTypeDescriptor(DataObjectType);
                model = new MetaModel();
                model.RegisterContext(
                    new SimpleModelProvider(contextType, DataObjectType, typeDescriptor),
                    contextConfiguration);
            }

            Inserted += new ObjectDataSourceStatusEventHandler(DynamicObjectDataSource_Inserted);
            Updated  += new ObjectDataSourceStatusEventHandler(DynamicObjectDataSource_Updated);
        }