コード例 #1
0
 public void FromConfiguration(IConfigurationSource config)
 {
     using (var host = new NullHost(config))
     {
         _metaModelRepository = host.Resolver.Resolve(typeof(IMetaModelRepository)) as IMetaModelRepository;
     }
 }
コード例 #2
0
 protected override void SetUp()
 {
     base.SetUp();
     Resolver  = new InternalDependencyResolver();
     MetaModel = new MetaModelRepository(Resolver);
     DependencyManager.SetResolver(Resolver);
 }
コード例 #3
0
 public override void PreProcess(IMetaModelRepository repository)
 {
     foreach (var model in repository.CustomRegistrations.OfType<DependencyRegistrationModel>())
     {
         this.resolver.AddDependency(model.ServiceType, model.ConcreteType, model.Lifetime);
     }
 }
コード例 #4
0
 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);
 }
コード例 #5
0
        public void PreProcess(IMetaModelRepository repository)
        {
            var conf = repository.CustomRegistrations.OfType<CachingConfiguration>().FirstOrDefault();
            if (conf == null) return;

            _resolver.AddDependency(typeof(ICacheProvider), conf.CacheProviderType, DependencyLifetime.Singleton);
        }
コード例 #6
0
 public override void PreProcess(IMetaModelRepository repository)
 {
     foreach (var model in repository.CustomRegistrations.OfType <DependencyRegistrationModel>())
     {
         _resolver.AddDependency(model.ServiceType, model.ConcreteType, model.Lifetime);
     }
 }
コード例 #7
0
        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());
        }
コード例 #8
0
 public void Process(IMetaModelRepository repository)
 {
     foreach (var repositoryResourceRegistration in repository.ResourceRegistrations)
     {
         repositoryResourceRegistration.Hydra().SerializeFunc = GetHydraFunc(repository);
     }
 }
コード例 #9
0
 public void PreProcess(IMetaModelRepository repository)
 {
     foreach (var resourceModel in repository.ResourceRegistrations)
     {
         CreateOperationsForModel(resourceModel);
     }
 }
コード例 #10
0
 public void FromConfiguration(IConfigurationSource config)
 {
     using (var host = new NullHost(config))
     {
         _metaModelRepository = host.Resolver.Resolve(typeof(IMetaModelRepository)) as IMetaModelRepository;
     }
 }
コード例 #11
0
        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
            };
        }
コード例 #12
0
        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);
        }
コード例 #13
0
 void AnnotateTypes(IMetaModelRepository repository, ResourceModel model)
 {
     if (model.Hydra().JsonLdType == null)
     {
         model.Hydra().JsonLdType = model.GetJsonLdTypeName();
     }
 }
コード例 #14
0
        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));
        }
コード例 #15
0
 private IEnumerable<ResourceModel> SelectRegistrationsThatArentSwaggerRoutes(IMetaModelRepository metaModelRepository)
 {
     var apiResourceRegistrations =
         metaModelRepository.ResourceRegistrations.Where(
             x => !x.Handlers.Any(h => ExcludedHandlers.Contains(h.Type.StaticType)));
     return apiResourceRegistrations;
 }
コード例 #16
0
        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;
            });
        }
コード例 #17
0
 public JsonLdCodecWriter(FastUriGenerator uris, ICommunicationContext context, IResponse responseMessage, IMetaModelRepository models)
 {
     _uris                 = uris;
     _context              = context;
     _responseMessage      = responseMessage;
     _models               = models;
     _apiDocumentationLink = uris.CreateUri <ApiDocumentation>(_context.ApplicationBaseUri);
 }
コード例 #18
0
        public void PreProcess(IMetaModelRepository repository)
        {
            var operationsByResource = repository.ResourceRegistrations
                                       .Select(CreateOperationsForModel)
                                       .ToLookup(ops => ops.resourceKey, ops => ops.operations);

            MatchOperationsWithUris(repository, operationsByResource);
        }
コード例 #19
0
 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));
 }
コード例 #20
0
 public ConfigurationSourceAdapter(
     IConfigurationSource source,
     IDependencyResolver resolver,
     IMetaModelRepository repository)
 {
     _source     = source;
     _repository = repository;
     _resolver   = resolver;
 }
コード例 #21
0
 public void PreProcess(IMetaModelRepository repository)
 {
     IterateOverHydraRegistrations(repository,
                                   AnnotateCollectionTypes,
                                   AddImplicitCollectionRegistrations,
                                   AnnotateTypes,
                                   PrepareProperties,
                                   CreateClass);
 }
コード例 #22
0
 public ReverseProxyHandler(
     ReverseProxy proxy,
     IMetaModelRepository metamodelRepository,
     ICommunicationContext context)
 {
     _proxy = proxy;
     _metamodelRepository = metamodelRepository;
     _context             = context;
 }
コード例 #23
0
 public JsonLdCodec(IUriResolver uris, ICommunicationContext context, IMetaModelRepository models,
                    IResponse responseMessage)
 {
     _uris                 = uris;
     _context              = context;
     _models               = models;
     _responseMessage      = responseMessage;
     _apiDocumentationLink = uris.CreateUriFor <ApiDocumentation>();
 }
コード例 #24
0
 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);
     }
 }
コード例 #25
0
 public override void Process(IMetaModelRepository repository)
 {
     foreach (var resource in repository.ResourceRegistrations)
     {
         foreach (var handler in resource.Handlers)
         {
             _repository.AddResourceHandler(resource.ResourceKey, handler.Type);
         }
     }
 }
コード例 #26
0
 public override void Process(IMetaModelRepository repository)
 {
     foreach (var resource in repository.ResourceRegistrations)
     {
         foreach (var handler in resource.Handlers)
         {
             this.handlerRepository.AddResourceHandler(resource.ResourceKey, handler);
         }
     }
 }
コード例 #27
0
 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,
コード例 #28
0
 public override void PreProcess(IMetaModelRepository repository)
 {
     foreach (var resource in repository.ResourceRegistrations)
     {
         if (resource.ResourceKey is Type)
         {
             resource.ResourceKey = _typeSystem.FromClr((Type)resource.ResourceKey);
         }
     }
 }
コード例 #29
0
 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));
         }
     }
 }
コード例 #30
0
 public override void Process(IMetaModelRepository repository)
 {
     foreach (var resource in repository.ResourceRegistrations)
     {
         foreach (var uriRegistration in resource.Uris)
         {
             _uriResolver.Add(new UriRegistration(resource, uriRegistration));
         }
     }
 }
コード例 #31
0
 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);
         }
     }
 }
コード例 #32
0
 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);
 }
コード例 #33
0
        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);
        }
コード例 #34
0
        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);
        }
コード例 #35
0
        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);
        }
コード例 #36
0
 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>();
     }
 }
コード例 #37
0
        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;
        }
コード例 #38
0
 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);
 }
コード例 #39
0
 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);
         }
     }
 }
コード例 #40
0
 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.");
     }
 }
コード例 #41
0
 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);
 }
コード例 #42
0
 public virtual void PreProcess(IMetaModelRepository repository)
 {
 }
コード例 #43
0
 public EntityEtagContributor(IMetaModelRepository config)
 {
     _config = config;
 }
コード例 #44
0
 public EntityLastModified(IMetaModelRepository config)
 {
     _config = config;
 }
コード例 #45
0
ファイル: FluentTarget.cs プロジェクト: hibri/openrasta-core
 public FluentTarget(IDependencyResolver resolver, IMetaModelRepository repository)
 {
     _resolver = resolver;
     _repository = repository;
 }
コード例 #46
0
 public LastModifiedContributor(IMetaModelRepository config, ILogger log)
 {
     _config = config;
     _log = log;
 }
コード例 #47
0
 public void Process(IMetaModelRepository repository)
 {
 }