Exemple #1
0
        protected BreezeGuardContextProvider()
        {
            this.context   = null;
            this.model     = null;
            this.resources = new Dictionary <Type, object>();

            ModelCache.RegisterCreateModelFunc(GetType(), CreateModel);
        }
Exemple #2
0
        private ApiModelBuilder CreateModel()
        {
            ApiModelBuilder modelBuilder = new ApiModelBuilder(
                typeof(TContext).FullName, this.ObjectContext.MetadataWorkspace);

            OnApiModelCreating(modelBuilder);

            modelBuilder.Build();

            return(modelBuilder);
        }
Exemple #3
0
        internal static IEdmModel GetODataModel(Type contextProviderType)
        {
            lock (cacheLock)
            {
                Entry entry = GetOrCreateEntry(contextProviderType);

                if (entry.odataModel == null)
                {
                    ApiModelBuilder apiModel = GetApiModel(contextProviderType);
                    entry.odataModel = ODataModelGenerator.CreateModel(apiModel);
                }

                return(entry.odataModel);
            }
        }
Exemple #4
0
        public static IEdmModel CreateModel(ApiModelBuilder apiModel)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            foreach (var entityTypeConfig in apiModel.GetEntityTypeConfigs())
            {
                EntityTypeConfiguration odataEntityTypeConfig = builder.AddEntity(entityTypeConfig.Type);

                foreach (var ignoredPropertyInfo in entityTypeConfig.GetIgnoredProperties())
                {
                    odataEntityTypeConfig.RemoveProperty(ignoredPropertyInfo);
                }
            }

            return(builder.GetEdmModel());
        }
Exemple #5
0
        public static void OnModelCreating(DbModelBuilder modelBuilder, Type contextProviderType)
        {
            ApiModelBuilder apiModel = ModelCache.GetApiModel(contextProviderType);

            // Ignore all entities not part of the API model
            modelBuilder.Ignore(apiModel.GetIgnoredEntityTypes());

            // Explicitly ignored properties
            foreach (var entityTypeConfig in apiModel.GetEntityTypeConfigs())
            {
                foreach (PropertyInfo propertyInfo in entityTypeConfig.GetIgnoredProperties())
                {
                    // Call the Ignore method below with the type parameters for this PropertyInfo
                    IgnoreMethodInfo.MakeGenericMethod(entityTypeConfig.Type, propertyInfo.PropertyType).Invoke(
                        null, new object[] { modelBuilder, propertyInfo });
                }
            }
        }
Exemple #6
0
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            JsonProperty property = base.CreateProperty(member, memberSerialization);

            if (this.model == null)
            {
                this.model = ModelCache.GetApiModel(this.ContextProviderType);
            }

            ApiEntityTypeConfiguration entityTypeConfig;
            ApiPropertyConfiguration   propertyConfig;

            if (this.model.TryGetEntityTypeConfig(member.DeclaringType, out entityTypeConfig) &&
                entityTypeConfig.TryGetPropertyConfig((PropertyInfo)member, out propertyConfig) &&
                propertyConfig.Ignored)
            {
                property.Ignored = true;
            }

            return(property);
        }
Exemple #7
0
 public BreezeGuardContractResolver(Type contextProviderType)
 {
     this.ContextProviderType = contextProviderType;
     this.model = null;
 }
Exemple #8
0
 protected abstract void OnApiModelCreating(ApiModelBuilder modelBuilder);