コード例 #1
0
        public async Task ToArchetypes_success()
        {
            var source = @"{
fieldsets: [
    {properties: [
        {alias: 'itemid', value: 1},
        {alias: 'price', value: .5}
    ]},
    {properties: [
        {alias: 'itemid', value: 2},
        {alias: 'price', value: 1.5}
    ]}
]}";
            var rego   = new MapRegistry();
            var mapper = new Mapper(rego);

            rego.Register <TestItem>();

            var result = await source.ToArchetypes <TestItem>()(mapper, null).ConfigureAwait(false) as IList <TestItem>;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].ItemId, Is.EqualTo(1));
            Assert.That(result[0].Price, Is.EqualTo(0.5));
            Assert.That(result[1].ItemId, Is.EqualTo(2));
            Assert.That(result[1].Price, Is.EqualTo(1.5));
        }
コード例 #2
0
        public async Task ToNestedContents_success()
        {
            var source = @"[
{
    'key':'ae2df017-bc64-4d0c-8612-3e1414c3f98f',
    'name':'Item 1',
    'ncContentTypeAlias':'imageGrid',
    'price':'.5',
    'itemid':'1'
},
{
    'key':'49706a5a-2d2d-4f55-8702-c41b553d6aa0',
    'name':'Item 2',
    'ncContentTypeAlias':'info',
    'price':'1.5',
    'itemid':'2'
}]";
            var rego   = new MapRegistry();
            var mapper = new Mapper(rego);

            rego.Register <TestItem>();

            var result = await source.ToNestedContents <TestItem>()(mapper, null).ConfigureAwait(false) as IList <TestItem>;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result[0].ItemId, Is.EqualTo(1));
            Assert.That(result[0].Price, Is.EqualTo(0.5));
            Assert.That(result[1].ItemId, Is.EqualTo(2));
            Assert.That(result[1].Price, Is.EqualTo(1.5));
        }
コード例 #3
0
        public void Register_GetType_return_type()
        {
            var registry = new MapRegistry();

            registry.Register <TestItem>().AliasTo("testObj");
            Assert.That(registry.GetType("TestObj"), Is.EqualTo(typeof(TestItem)));
        }
コード例 #4
0
        public void Register_GetType_return_null()
        {
            var registry = new MapRegistry();

            registry.Register <TestItem>().AliasTo("testObj");
            Assert.That(registry.GetType("TestOb"), Is.Null);
        }
コード例 #5
0
        /// <summary>
        /// Call once to initialize the context.
        /// </summary>
        /// <typeparam name="TSite">The CMS site model type.</typeparam>
        /// <param name="cacheConfig">The cache config instance.</param>
        /// <param name="umbracoConfig">The umbraco config instance.</param>
        /// <param name="mapBuild">The map build instance.</param>
        /// <param name="cacheBuild">The cache build instance.</param>
        public static void Init <TSite>(ICacheConfig cacheConfig, IUmbracoConfig umbracoConfig, IMapBuild mapBuild, ICacheBuild cacheBuild)
            where TSite : class, ISite
        {
            MapRegistry   = new MapRegistry();
            Mapper        = new Mapper(MapRegistry);
            CacheRegistry = new CacheRegistry(cacheConfig);
            QueryFactory  = new UmbracoQueryFactory();
            CmsFetcher    = new UmbracoFetcher(umbracoConfig);
            Registry      = new Registry(MapRegistry, Mapper, CacheRegistry, QueryFactory, CmsFetcher);
            SiteCaches    = new SiteCaches(CacheRegistry);

            _siteFunc = () =>
            {
                var cache = SiteCaches.Default;
                var host  = HttpContext.Current?.Request.Url.Host ?? string.Empty;
                var sites = cache.Fetch <TSite>()?.ToList();
                return(sites?.FirstOrDefault(site => site.Hosts?.Contains(host) ?? false) ?? sites?.FirstOrDefault());
            };

            _cacheFunc = () =>
            {
                var site = _siteFunc();
                return(SiteCaches.Get(site) as Cache);
            };

            mapBuild.Setup(Registry);
            cacheBuild.Setup(CacheRegistry);
        }
コード例 #6
0
        public void Register_Indexer()
        {
            var registry = new MapRegistry();

            registry.Register <TestItem>();
            Assert.That(registry[typeof(TestItem)], Is.Not.Null);
        }
コード例 #7
0
        public void Register_has()
        {
            var registry = new MapRegistry();

            registry.Register <TestItem>();
            Assert.That(registry.Has(typeof(TestItem)));
        }
コード例 #8
0
        public void Register_Map_All()
        {
            var registry = new MapRegistry();

            var task = registry.Register <TestItem>();

            Assert.That(task, Is.Not.Null);
            Assert.That(task.Maps.Count, Is.EqualTo(5));
        }
コード例 #9
0
        public static JsonPatchConverter GetConverter()
        {
            var registry = new MapRegistry();

            registry.MapType <Dog>();
            registry.MapType <UserEntity>();
            registry.MapType <Cat>();
            registry.MapType <Fruit>();
            return(new JsonPatchConverter(registry));
        }
コード例 #10
0
        public void Register_Copy_Map()
        {
            var registry = new MapRegistry();

            registry.Copy <CmsKey>()
            .Map(x => x.Key);

            var task = registry.Register <TestItem>();

            Assert.That(task, Is.Not.Null);
            Assert.That(task.Maps.Count, Is.EqualTo(6));
            Assert.That(task.Maps[5] is MapItem <CmsKey, Guid>);
        }
コード例 #11
0
        public async Task ToNestedContents_empty_return_null()
        {
            var source = @"[]";
            var rego   = new MapRegistry();
            var mapper = new Mapper(rego);

            rego.Register <TestItem>();

            var result = await source.ToNestedContents <TestItem>()(mapper, null).ConfigureAwait(false) as IList <TestItem>;

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Count, Is.EqualTo(0));
        }
コード例 #12
0
        public void LoadContent()
        {
            if (this.Content == null)
            {
                return;
            }

            Log.Verbose("Loading Content");
            if (this.Content.Textures != null)
            {
                foreach (var texture in this.Content.Textures)
                {
                    texture.Texture = ApplicationResourcesUtility.LoadTexture(texture.File);

                    if (texture.Texture == null)
                    {
                        throw new Exception($"Missing API Texture: {texture.File}");
                    }

                    Log.Verbose($"Registering new API texture: {texture.Id}");
                    TextureRegistry.RegisterItem(texture.Id, texture);
                }
            }

            if (this.Content.Maps != null)
            {
                foreach (var map in this.Content.Maps)
                {
                    map.Map = ApplicationResourcesUtility.LoadMap(map.File);

                    if (map.Map == null)
                    {
                        throw new Exception($"Missing API map: {map.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new API map: {map.Id}");
                    MapRegistry.RegisterItem(map.Id, map);
                }
            }

            if (this.Content.Xnb == null)
            {
                return;
            }

            foreach (var file in this.Content.Xnb)
            {
                if (file.IsXnb)
                {
                    throw new NotImplementedException();
                }

                file.OwningMod = null;

                if (!file.Exists(null))
                {
                    if (file.IsXnb)
                    {
                        throw new Exception($"Replacement File: {file.AbsoluteFilePath}");
                    }

                    if (file.IsTexture)
                    {
                        throw new Exception($"Replacement Texture: {file.Texture}");
                    }
                }

                Log.Verbose("Registering new API texture XNB override");
                XnbRegistry.RegisterItem(file.Original, file);
            }
        }
コード例 #13
0
 /// <summary>
 ///     Gets a map registered by this mod via it's manifest file
 /// </summary>
 /// <param name="id">
 ///     The id of the map.
 /// </param>
 /// <returns>
 ///     The registered <see cref="Map" />.
 /// </returns>
 public Map GetMap(string id)
 {
     return(MapRegistry.GetItem(id, this).Map);
 }
コード例 #14
0
        internal void LoadContent()
        {
            if (this.Content == null)
            {
                return;
            }

            Log.Verbose("Loading Content");
            if (this.Content.Textures != null)
            {
                foreach (var texture in this.Content.Textures)
                {
                    texture.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{texture.File}";

                    if (!texture.Exists())
                    {
                        throw new Exception($"Missing Texture: {texture.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new texture: {texture.Id}");
                    TextureRegistry.RegisterItem(texture.Id, texture, this);
                }
            }

            if (this.Content.Maps != null)
            {
                foreach (var map in this.Content.Maps)
                {
                    map.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{map.File}";

                    if (!map.Exists())
                    {
                        throw new Exception($"Missing map: {map.AbsoluteFilePath}");
                    }

                    Log.Verbose($"Registering new map: {map.Id}");
                    MapRegistry.RegisterItem(map.Id, map, this);
                }
            }

            if (this.Content.Xnb == null)
            {
                return;
            }

            foreach (var file in this.Content.Xnb)
            {
                if (file.IsXnb)
                {
                    file.AbsoluteFilePath = $"{this.ModDirectory}\\{Constants.ModContentDirectory}\\{file.File}";
                }

                file.OwningMod = this;
                if (!file.Exists(this))
                {
                    if (file.IsXnb)
                    {
                        throw new Exception($"Replacement File: {file.AbsoluteFilePath}");
                    }

                    if (file.IsTexture)
                    {
                        throw new Exception($"Replacement Texture: {file.Texture}");
                    }
                }

                Log.Verbose("Registering new texture XNB override");
                XnbRegistry.RegisterItem(file.Original, file, this);
            }
        }
コード例 #15
0
        public MagicTile[,] TestMapGen()
        {
            Map2 map = new Map2();

            map.Regions = new Dictionary <string, MapRegion>();
            MapRegion region = new MapRegion();

            region.Size = new Vector2(10000, 10000);
            region.PoPs = new List <PlaceOfPower>();
            PlaceOfPower pop = new PlaceOfPower();

            pop.Location  = new Point(100, 100);
            pop.PlaceType = PoPType.Fire;
            pop.Strength  = 100;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(255, 297);
            pop.PlaceType = PoPType.Earth;
            pop.Strength  = 249;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(9235, 2453);
            pop.PlaceType = PoPType.Holy;
            pop.Strength  = 106;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(2131, 2356);
            pop.PlaceType = PoPType.Void;
            pop.Strength  = 15;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(500, 8345);
            pop.PlaceType = PoPType.Water;
            pop.Strength  = 204;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(6546, 235);
            pop.PlaceType = PoPType.Air;
            pop.Strength  = 35;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(2353, 7853);
            pop.PlaceType = PoPType.Neutral;
            pop.Strength  = 75;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(3256, 6574);
            pop.PlaceType = PoPType.Protection;
            pop.Strength  = 152;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(7645, 2455);
            pop.PlaceType = PoPType.Fire;
            pop.Strength  = 163;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(9999, 9888);
            pop.PlaceType = PoPType.Holy;
            pop.Strength  = 72;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(2567, 9987);
            pop.PlaceType = PoPType.Summoning;
            pop.Strength  = 185;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(346, 7686);
            pop.PlaceType = PoPType.Arcane;
            pop.Strength  = 235;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(3216, 9785);
            pop.PlaceType = PoPType.Fire;
            pop.Strength  = 36;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(5002, 5343);
            pop.PlaceType = PoPType.Dimension;
            pop.Strength  = 125;
            region.PoPs.Add(pop);
            pop           = new PlaceOfPower();
            pop.Location  = new Point(6453, 4634);
            pop.PlaceType = PoPType.Darkness;
            pop.Strength  = 215;
            region.PoPs.Add(pop);
            map.Regions.Add("test", region);

            MagicTile[,] tiles = MapRegistry.GenerateMagicTiles(map);
            return(tiles);
        }
コード例 #16
0
 public void OnShowScreen(NodeAddedEvent e, BattleLoadScreenNode screen, [JoinAll] SingleNode <SelfBattleUserComponent> battleUser, [JoinByBattle, Context] BattleNode battle, [JoinByMap, Context] SingleNode <MapComponent> map)
 {
     screen.battleLoadScreen.InitView(battle.Entity, MapRegistry.GetMap(map.Entity));
 }
コード例 #17
0
        private ICache Setup(Action <IMapTask <TestEntity> > fit)
        {
            var mapRegistry   = new MapRegistry();
            var mapper        = new Mapper(mapRegistry);
            var root          = Substitute.For <ISite>();
            var cacheRegistry = new CacheRegistry(new TestCacheConfig());
            var cacheStore    = new CacheStore();
            var cache         = new Cache(cacheStore, cacheRegistry, root);
            var queryFactory  = Substitute.For <IQueryFactory>();
            var cmsFetcher    = Substitute.For <ICmsFetcher>();
            var registry      = new Registry(mapRegistry, mapper, cacheRegistry, queryFactory, cmsFetcher);

            mapRegistry.Copy <CmsKey>()
            .Map(x => x.Key, "key");
            mapRegistry.Copy <Model>()
            .Map(x => x.Name, "alias");

            registry.Register <TestInfo>();

            registry.Register <TestItem>()
            .MatchMany(x => x.Infos);

            fit(registry.Register <TestEntity>());

            var guid1 = Guid.NewGuid().ToString("N");
            var guid2 = Guid.NewGuid().ToString("N");
            var guid3 = Guid.NewGuid().ToString("N");
            var guid4 = Guid.NewGuid().ToString("N");
            var guid5 = Guid.NewGuid().ToString("N");
            var guid6 = Guid.NewGuid().ToString("N");

            var entity = new Dictionary <string, string>
            {
                { "key", guid1 },
                { "alias", "test" },
                { "id", "1000" },
                { "list", "a,b,c" },
                { "item", guid3 },
                { "items", guid2 + "," + guid4 }
            };
            var content = new UmbracoContent(entity);

            var item1 = new Dictionary <string, string>
            {
                { "key", guid2 },
                { "alias", "testItem1" },
                { "itemId", "1" },
                { "price", "10.00" },
                { "onSale", "true" },
                { "infos", guid5 + "," + guid6 }
            };
            var content1 = new UmbracoContent(item1);

            var item2 = new Dictionary <string, string>
            {
                { "key", guid3 },
                { "alias", "testItem2" },
                { "itemId", "2" },
                { "price", "20.00" },
                { "onSale", "true" }
            };
            var content2 = new UmbracoContent(item2);

            var item3 = new Dictionary <string, string>
            {
                { "key", guid4 },
                { "alias", "testItem3" },
                { "itemId", "3" },
                { "price", "30.00" },
                { "onSale", "true" }
            };
            var content3 = new UmbracoContent(item3);

            var info1 = new Dictionary <string, string>
            {
                { "key", guid5 },
                { "alias", "testInfo1" },
                { "infoId", "1" },
                { "info", "info1" }
            };
            var contentInfo1 = new UmbracoContent(info1);

            var info2 = new Dictionary <string, string>
            {
                { "key", guid6 },
                { "alias", "testInfo2" },
                { "infoId", "2" },
                { "info", "info2" }
            };
            var contentInfo2 = new UmbracoContent(info2);

            var mapItem     = mapRegistry.For <TestItem>() as MapTask <TestItem>;
            var mapEntity   = mapRegistry.For <TestEntity>() as MapTask <TestEntity>;
            var mapInfo     = mapRegistry.For <TestInfo>() as MapTask <TestInfo>;
            var queryItem   = Substitute.For <ICmsQuery <TestItem> >();
            var queryEntity = Substitute.For <ICmsQuery <TestEntity> >();
            var queryInfo   = Substitute.For <ICmsQuery <TestInfo> >();

            queryFactory.Create(root, mapItem).Returns(queryItem);
            queryFactory.Create(root, mapEntity).Returns(queryEntity);
            queryFactory.Create(root, mapInfo).Returns(queryInfo);

            var entityContents = new IContent[] { content };
            var itemContents   = new IContent[] { content1, content2, content3 };
            var infoContents   = new IContent[] { contentInfo2, contentInfo1 };

            cmsFetcher.Fetch(queryItem).Returns(itemContents);
            cmsFetcher.Fetch(queryEntity).Returns(entityContents);
            cmsFetcher.Fetch(queryInfo).Returns(infoContents);

            return(cache);
        }