private static IBuilding Map(BuildingDto c)
        {
            IBuilding result;

            if (c.Type == "LivingHouse")
            {
                result = new LivingHouseClientSideEntity {
                    Type = c.Type, Guid = c.Guid
                }
            }
            ;
            else if (c.Type == "SaltEvaporationFactory")
            {
                result = new SaltEvaporationFactoryClientSideEntity {
                    Type = c.Type, Guid = c.Guid
                }
            }
            ;
            else
            {
                throw new Exception($"Unexpected building type='{c.Type}'");
            }


            foreach (var cargoDto in c.Cargos)
            {
                result.Cargos.Add(Map(cargoDto));
            }

            return(result);
        }
Exemple #2
0
        public void Test1()
        {
            var worldRepository    = new WorldRepositoryClientSide();
            var newInstanceFactory = new NewInstanceFactoryClientSide(worldRepository);
            var processorsProvider = new ProcessorsProvider(newInstanceFactory);

            var world = new WorldClientSideEntity();
            var city  = new CityClientSideEntity();

            world.Cities.Add(city);

            var livingHouse = new LivingHouseClientSideEntity();

            livingHouse.Cargos.Add(new FreshWaterClientSideEntity {
                Count = 1m
            });
            livingHouse.Cargos.Add(new SaltClientSideEntity {
                Count = 1m
            });
            city.Buildings.Add(livingHouse);

            var saltEvaporationFactory = new SaltEvaporationFactoryClientSideEntity();

            saltEvaporationFactory.Cargos.Add(new SaltWaterClientSideEntity {
                Count = 1
            });

            processorsProvider.Process(world);
        }
Exemple #3
0
        private static IWorld GetWorld()
        {
            var world = new WorldClientSideEntity();
            var city  = new CityClientSideEntity {
                Name = "SomeCity"
            };

            world.Cities.Add(city);

            var livingHouse = new LivingHouseClientSideEntity();

            livingHouse.Cargos.Add(new FreshWaterClientSideEntity {
                Count = 1m
            });
            livingHouse.Cargos.Add(new SaltClientSideEntity {
                Count = 1m
            });
            city.Buildings.Add(livingHouse);

            var saltEvaporationFactory = new SaltEvaporationFactoryClientSideEntity();

            saltEvaporationFactory.Cargos.Add(new SaltWaterClientSideEntity {
                Count = 1
            });
            city.Buildings.Add(saltEvaporationFactory);
            return(world);
        }
        public T GetNewInstance <T>(string type) where T : class, IEntityBase
        {
            T result = null;

            type = H.Get(type);

            if (type == H.Get <IWorld>())
            {
                var cc = new WorldClientSideEntity();
                WorldRepository.Add(cc);
                result = cc as T;
            }
            else if (type == H.Get <IPlayer>())
            {
                var cc = new PlayerClientSideEntity();
                result = cc as T;
            }

            else if (type == H.Get <ICity>())
            {
                var cc = new CityClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <IBramin>())
            {
                var cc = new BraminClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <ILivingHouse>())
            {
                var cc = new LivingHouseClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <ISaltEvaporationFactory>())
            {
                var cc = new SaltEvaporationFactoryClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <IFreshWater>())
            {
                var cc = new FreshWaterClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <ISaltWater>())
            {
                var cc = new SaltWaterClientSideEntity();
                result = cc as T;
            }
            else if (type == H.Get <ISalt>())
            {
                var cc = new SaltClientSideEntity();
                result = cc as T;
            }
            else
            {
                throw new Exception($"Unexpected type='{type}'");
            }

            if (result == null)
            {
                throw new Exception($"Can't cast '{type}' to {typeof(T).Name}");
            }

            return(result);
        }