// A IResourceProvider implementation is responsible for applying the resource-metadata
        // to resources returned when the request has an Accept value (i.e. application/hal+json)
        // indicating that the returned resource should be augmented.
        private static IResourceProvider CreateProvider(IResourceMap resourceMap)
        {
            if (resourceMap.ProviderType == null)
            {
                throw new InvalidOperationException(
                          $"The resource map of type: {resourceMap.GetType()} did not set the provider type.");
            }

            return((IResourceProvider)resourceMap.ProviderType.CreateInstance());
        }
Beispiel #2
0
        /// <summary>
        /// Use a little reflection magic to help us avoid
        /// hand-writing more code than we really need to.
        /// This will return a list all non-public fields that
        /// expose the IResourceMap interface. Mostly this is used
        /// as a helper by the 'AllPaths()' method.
        /// </summary>
        /// <returns></returns>
        List <IResourceMap> AllMaps()
        {
            List <IResourceMap> map = new List <IResourceMap>();
            Type type = this.GetType();

            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            for (int i = 0; i < fields.Length; i++)
            {
                IResourceMap m = fields[i].GetValue(this) as IResourceMap;
                if (m != null)
                {
                    map.Add(m);
                }
            }
            return(map);
        }
Beispiel #3
0
        public async Task InitializeAsync()
        {
            var configs = await Task.WhenAll(_configFiles.Select(LoadConfigFile));

            var frameAnimationImages = new FrameAnimationImageResourceMap(WrapMultiplySections(configs, o => o.FrameAnimationImages));
            var themeAudios          = new InputStreamWithContentTypeResourceMap(WrapMultiplySections(configs, o => o.ThemeAudios));
            var shaders  = new InputStreamWithContentTypeResourceMap(WrapMultiplySections(configs, o => o.Shaders));
            var maps     = new InputStreamWithContentTypeResourceMap(WrapMultiplySections(configs, o => o.Maps));
            var tileSets = new TileSetContentResourceMap(WrapMultiplySections(configs, o => o.TileSets));
            var sprites  = new SpriteContentResourceMap(WrapMultiplySections(configs, o => o.Sprites));

            await Task.WhenAll(frameAnimationImages.LoadAsync(), themeAudios.LoadAsync(), shaders.LoadAsync(), maps.LoadAsync(), tileSets.LoadAsync(),
                               sprites.LoadAsync());

            FrameAnimationImages = frameAnimationImages;
            ThemeAudios          = themeAudios;
            Shaders  = shaders;
            Maps     = maps;
            TileSets = tileSets;
            UnitArts = WrapMultiplySections(configs, o => o.UnitArts);
            Sprites  = sprites;
        }
Beispiel #4
0
 public HalResourceMeta(IResourceMap resourceMap) : base(resourceMap)
 {
 }
        public ResourceMeta(IResourceMap resourceMap)
        {
            Links = _links.ToReadOnly();

            _resourceMap = resourceMap;
        }
Beispiel #6
0
        protected ResourceMeta(IResourceMap resourceMap)
        {
            Links = _links.AsReadOnly();

            _resourceMap = resourceMap ?? throw new ArgumentNullException(nameof(resourceMap));
        }
 private IResourceProvider CreateProvider(IResourceMap resourceMap)
 {
     return((IResourceProvider)resourceMap.ProviderType.CreateInstance());
 }