public void FromConfiguration(IConfigurationSource config) { using (var host = new NullHost(config)) { _metaModelRepository = host.Resolver.Resolve(typeof(IMetaModelRepository)) as IMetaModelRepository; } }
protected override void SetUp() { base.SetUp(); Resolver = new InternalDependencyResolver(); MetaModel = new MetaModelRepository(Resolver); DependencyManager.SetResolver(Resolver); }
public override void PreProcess(IMetaModelRepository repository) { foreach (var model in repository.CustomRegistrations.OfType<DependencyRegistrationModel>()) { this.resolver.AddDependency(model.ServiceType, model.ConcreteType, model.Lifetime); } }
public static bool TryGetResourceModel(this IMetaModelRepository metaModelRepository, Type entityType, out ResourceModel model) { model = metaModelRepository.ResourceRegistrations.FirstOrDefault(r => Equals(r.ResourceKey, TypeSystems.Default.FromClr(entityType))); return(model != null); }
public void PreProcess(IMetaModelRepository repository) { var conf = repository.CustomRegistrations.OfType<CachingConfiguration>().FirstOrDefault(); if (conf == null) return; _resolver.AddDependency(typeof(ICacheProvider), conf.CacheProviderType, DependencyLifetime.Singleton); }
public override void PreProcess(IMetaModelRepository repository) { foreach (var model in repository.CustomRegistrations.OfType <DependencyRegistrationModel>()) { _resolver.AddDependency(model.ServiceType, model.ConcreteType, model.Lifetime); } }
Func <object, SerializationContext, Stream, Task> CreateDocumentSerializer(ResourceModel model, IMetaModelRepository repository) { var renderer = new List <Expression>(); var variables = new List <ParameterExpression>(); var resourceIn = Parameter(typeof(object), "resource"); var options = Parameter(typeof(SerializationContext), "options"); var stream = Parameter(typeof(Stream), "stream"); var retVal = Variable(typeof(Task), "retVal"); var resource = Variable(model.ResourceType, "typedResource"); renderer.Add(Assign(resource, Convert(resourceIn, model.ResourceType))); var jsonWriter = Variable(typeof(JsonWriter), "jsonWriter"); var buffer = Variable(typeof(ArraySegment <byte>), "buffer"); renderer.Add(Assign(jsonWriter, New(typeof(JsonWriter)))); TypeMethods.ResourceDocument(jsonWriter, model, resource, options, variables.Add, renderer.Add, repository); renderer.Add(Assign(buffer, JsonWriterMethods.GetBuffer(jsonWriter))); renderer.Add(Assign(retVal, ClassLibMethods.StreamWriteAsync(stream, buffer))); renderer.Add(retVal); var block = Block(variables.Concat(new[] { jsonWriter, buffer, retVal, resource }).ToArray(), renderer); var lambda = Lambda <Func <object, SerializationContext, Stream, Task> >(block, "Render", new[] { resourceIn, options, stream }); return(lambda.Compile()); }
public void Process(IMetaModelRepository repository) { foreach (var repositoryResourceRegistration in repository.ResourceRegistrations) { repositoryResourceRegistration.Hydra().SerializeFunc = GetHydraFunc(repository); } }
public void PreProcess(IMetaModelRepository repository) { foreach (var resourceModel in repository.ResourceRegistrations) { CreateOperationsForModel(resourceModel); } }
static void CreateClass(IMetaModelRepository _, ResourceModel model) { var hydraModel = model.Hydra(); var hydraClass = hydraModel.Class ?? (hydraModel.Class = new HydraCore.Class()); var vocabPrefix = hydraModel.Vocabulary.DefaultPrefix; var className = model.ResourceType.Name; var identifier = vocabPrefix != null ? $"{vocabPrefix}:{className}" : className; hydraModel.Class = new HydraCore.Class { Identifier = identifier, SupportedProperties = hydraModel.ResourceProperties .Select(p => new HydraCore.SupportedProperty { Property = new Rdf.Property { Identifier = $"{identifier}/{p.Name}", Range = p.RdfRange } } ).ToList(), SupportedOperations = hydraModel.SupportedOperations }; }
void AddImplicitCollectionRegistrations(IMetaModelRepository repository, ResourceModel model) { var hydra = model.Hydra(); if (hydra.Collection.IsCollection || hydra.Collection.IsHydraCollectionType) { return; } var collectionRm = new ResourceModel { ResourceKey = HydraTypes.Collection.MakeGenericType(model.ResourceType) }; var collectionHydra = collectionRm.Hydra(); collectionHydra.Vocabulary = Vocabularies.Hydra; collectionHydra.JsonLdTypeFunc = _ => "hydra:Collection"; collectionHydra.Collection.IsCollection = true; collectionHydra.Collection.IsFrameworkCollection = false; repository.ResourceRegistrations.Add(collectionRm); }
void AnnotateTypes(IMetaModelRepository repository, ResourceModel model) { if (model.Hydra().JsonLdType == null) { model.Hydra().JsonLdType = model.GetJsonLdTypeName(); } }
public static void ResourceDocument(ParameterExpression jsonWriter, ResourceModel model, Expression resource, Expression options, Action <ParameterExpression> variable, Action <Expression> statement, IMetaModelRepository models) { var uriResolverFunc = MakeMemberAccess(options, SerializationContextUriResolverPropertyInfo); var contextUri = StringConcat( Call(MakeMemberAccess(options, SerializationContextBaseUriPropertyInfo), typeof(object).GetMethod(nameof(ToString))), Constant(".hydra/context.jsonld")); var resolver = Variable(typeof(CustomResolver), "resolver"); variable(resolver); statement(Assign(resolver, New(typeof(CustomResolver)))); foreach (var exp in WriteBeginObjectContext(jsonWriter, contextUri)) { statement(exp); } WriteNode(jsonWriter, model, resource, variable, statement, uriResolverFunc, models, new Stack <ResourceModel>(), resolver); statement(JsonWriterMethods.WriteEndObject(jsonWriter)); }
private IEnumerable<ResourceModel> SelectRegistrationsThatArentSwaggerRoutes(IMetaModelRepository metaModelRepository) { var apiResourceRegistrations = metaModelRepository.ResourceRegistrations.Where( x => !x.Handlers.Any(h => ExcludedHandlers.Contains(h.Type.StaticType))); return apiResourceRegistrations; }
public Func <object, SerializationContext, Stream, Task> GetHydraFunc(IMetaModelRepository models) { return((entity, options, stream) => { if (entity is IEnumerable enumerableEntity) { entity = ConvertToHydraCollection(enumerableEntity); } var customConverter = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, ContractResolver = new JsonLdContractResolver(options.BaseUri, _uriResolver, models), TypeNameHandling = TypeNameHandling.None, Converters = { new StringEnumConverter(), new JsonLdTypeRefConverter(models), new HydraUriModelConverter(options.BaseUri), new ContextDocumentConverter() } }; using (var writer = new StreamWriter(stream, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), bufferSize: 1024, leaveOpen: true)) using (var jsonWriter = new JsonTextWriter(writer)) { customConverter.Serialize(jsonWriter, entity); } return Task.CompletedTask; }); }
public JsonLdCodecWriter(FastUriGenerator uris, ICommunicationContext context, IResponse responseMessage, IMetaModelRepository models) { _uris = uris; _context = context; _responseMessage = responseMessage; _models = models; _apiDocumentationLink = uris.CreateUri <ApiDocumentation>(_context.ApplicationBaseUri); }
public void PreProcess(IMetaModelRepository repository) { var operationsByResource = repository.ResourceRegistrations .Select(CreateOperationsForModel) .ToLookup(ops => ops.resourceKey, ops => ops.operations); MatchOperationsWithUris(repository, operationsByResource); }
public override void Process(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) foreach (var uriRegistration in resource.Uris) _uriResolver.Add( new UriRegistration(uriRegistration.Uri, resource.ResourceKey, uriRegistration.Name, uriRegistration.Language)); }
public ConfigurationSourceAdapter( IConfigurationSource source, IDependencyResolver resolver, IMetaModelRepository repository) { _source = source; _repository = repository; _resolver = resolver; }
public void PreProcess(IMetaModelRepository repository) { IterateOverHydraRegistrations(repository, AnnotateCollectionTypes, AddImplicitCollectionRegistrations, AnnotateTypes, PrepareProperties, CreateClass); }
public ReverseProxyHandler( ReverseProxy proxy, IMetaModelRepository metamodelRepository, ICommunicationContext context) { _proxy = proxy; _metamodelRepository = metamodelRepository; _context = context; }
public JsonLdCodec(IUriResolver uris, ICommunicationContext context, IMetaModelRepository models, IResponse responseMessage) { _uris = uris; _context = context; _models = models; _responseMessage = responseMessage; _apiDocumentationLink = uris.CreateUriFor <ApiDocumentation>(); }
public void Process(IMetaModelRepository repository) { foreach (var model in repository.ResourceRegistrations.Where(r => r.ResourceType != null)) { model.Hydra().SerializeFunc = model.ResourceType == typeof(Context) ? CreateContextSerializer() : CreateDocumentSerializer(model, repository); } }
public override void Process(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { foreach (var handler in resource.Handlers) { _repository.AddResourceHandler(resource.ResourceKey, handler.Type); } } }
public override void Process(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { foreach (var handler in resource.Handlers) { this.handlerRepository.AddResourceHandler(resource.ResourceKey, handler); } } }
static NodeProperty WriteNodeList( Variable <JsonWriter> jsonWriter, TypedExpression <string> baseUri, MemberAccess <Func <object, string> > uriGenerator, MemberAccess <Func <object, string> > typeGenerator, IMetaModelRepository models, Stack <ResourceModel> recursionDefender, PropertyInfo pi, Variable <HydraJsonFormatterResolver> resolver, List <(Type itemType, List <ResourceModel> models)> itemResourceRegistrations,
public override void PreProcess(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { if (resource.ResourceKey is Type) { resource.ResourceKey = _typeSystem.FromClr((Type)resource.ResourceKey); } } }
public override void Process(IMetaModelRepository repository) { foreach (var resourceModel in repository.ResourceRegistrations) { foreach (var contentEncoding in resourceModel.ContentEncodings) { _contentEncodingSchemeRepository.Add(new ContentEncodingScheme(contentEncoding.Scheme, contentEncoding.MediaType)); } } }
public override void Process(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { foreach (var uriRegistration in resource.Uris) { _uriResolver.Add(new UriRegistration(resource, uriRegistration)); } } }
public override void PreProcess(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { if (resource.ResourceKey is Type) { resource.ResourceKey = this.typeSystem.FromClr((Type)resource.ResourceKey); } } }
public FastUriGenerator(IMetaModelRepository repository, IUriResolver uris) { _uris = uris; _generators = (from model in repository.ResourceRegistrations let generators = model.Uris.Where(uri => uri.Properties.ContainsKey("compiled")).ToList() where generators.Count == 1 select new { model.ResourceType, generator = (Func <object, string>)(generators[0].Properties["compiled"]) }) .ToDictionary(x => x.ResourceType, x => x.generator); }
static string GetTypeName(IMetaModelRepository models, ResourceModel model) { var opts = models.CustomRegistrations.OfType <HydraOptions>().Single(); var hydraResourceModel = model.Hydra(); return((hydraResourceModel.Vocabulary?.DefaultPrefix == null ? string.Empty : $"{hydraResourceModel.Vocabulary.DefaultPrefix}:") + model.ResourceType.Name); }
protected override void SetUp() { base.SetUp(); Resolver = new InternalDependencyResolver(); Resolver.AddDependency <ITypeSystem, ReflectionBasedTypeSystem>(); MetaModel = new MetaModelRepository(Resolver); ResourceSpaceHas = new FluentTarget(Resolver, MetaModel); ResourceSpaceUses = new FluentTarget(Resolver, MetaModel); DependencyManager.SetResolver(Resolver); }
protected override void SetUp() { base.SetUp(); Resolver = new InternalDependencyResolver(); Resolver.AddDependency<ITypeSystem, ReflectionBasedTypeSystem>(); MetaModel = new MetaModelRepository(Resolver); ResourceSpaceHas = new FluentTarget(Resolver, MetaModel); ResourceSpaceUses = new FluentTarget(Resolver, MetaModel); DependencyManager.SetResolver(Resolver); }
protected void given_server_with_handler <T>() { using (var server = new InMemoryHost(() => { ResourceSpace.Has.ResourcesNamed("test") .AtUri("/resource") .HandledBy <T>(); })) { metamodel = server.Resolver.Resolve <IMetaModelRepository>(); } }
public JsonLdContractResolver(Uri baseUri, IUriResolver uris, IMetaModelRepository models) { _baseUri = baseUri; _uris = uris; _models = models; CamelCaseNamingStrategy caseNamingStrategy = new CamelCaseNamingStrategy(); caseNamingStrategy.ProcessDictionaryKeys = true; caseNamingStrategy.OverrideSpecifiedNames = true; NamingStrategy = caseNamingStrategy; }
public FastUriGeneratorLocator(IMetaModelRepository repository) { _generators = (from model in repository.ResourceRegistrations let generators = model.Uris.Where(uri => uri.Properties.ContainsKey("compiled")).ToList() where generators.Count == 1 select new { model.ResourceKey, generator = (Func <object, string>)(generators[0].Properties["compiled"]) }) .ToDictionary(x => x.ResourceKey, x => x.generator); _typeToKey = repository.ResourceRegistrations .Where(r => r.ResourceType != null) .ToLookup(r => r.ResourceKey, r => r.ResourceType); }
public override void Process(IMetaModelRepository repository) { foreach (var resource in repository.ResourceRegistrations) { foreach (var uriRegistration in resource.Uris) { _uriResolver.AddUriMapping(uriRegistration.Uri, resource.ResourceKey, uriRegistration.Language, uriRegistration.Name); } } }
public override void PreProcess(IMetaModelRepository repository) { foreach (var codec in repository.ResourceRegistrations.SelectMany(x => x.Codecs)) { if (codec.MediaTypes.Count == 0) codec.MediaTypes.AddRange(MediaTypeAttribute.Find(codec.CodecType).Select(x => new MediaTypeModel { MediaType = x.MediaType, Extensions = x.Extensions != null ? x.Extensions.ToList() : null })); if (codec.MediaTypes.Count == 0) throw new OpenRastaConfigurationException("The codec doesn't have any media type associated explicitly in the meta model and doesnt have any MediaType attribute."); } }
public override void Process(IMetaModelRepository repository) { var codecRegistrations = from resource in repository.ResourceRegistrations let isStrict = resource.IsStrictRegistration from codec in resource.Codecs from mediaType in codec.MediaTypes select new CodecRegistration( codec.CodecType, resource.ResourceKey, isStrict, mediaType.MediaType, mediaType.Extensions, codec.Configuration, false); foreach (var reg in codecRegistrations) _codecRepository.Add(reg); }
public virtual void PreProcess(IMetaModelRepository repository) { }
public EntityEtagContributor(IMetaModelRepository config) { _config = config; }
public EntityLastModified(IMetaModelRepository config) { _config = config; }
public FluentTarget(IDependencyResolver resolver, IMetaModelRepository repository) { _resolver = resolver; _repository = repository; }
public LastModifiedContributor(IMetaModelRepository config, ILogger log) { _config = config; _log = log; }
public void Process(IMetaModelRepository repository) { }