예제 #1
0
        public async Task Run([TimerTrigger("0 5 0 * * SUN")] TimerInfo myTimer, ILogger log)
        {
            var allTowns = await TownService.GetAllTowns();

            foreach (var town in allTowns)
            {
                await HistoricalTurnipService.SaveTurnipData(town);

                var newTown = new TownEntity()
                {
                    PartitionKey  = town.PartitionKey,
                    RowKey        = town.RowKey,
                    MayorName     = town.MayorName,
                    OwnerUsername = town.OwnerUsername,
                    Created       = town.Created,
                    ETag          = town.ETag,
                    Name          = town.Name,
                    NativeFruit   = town.NativeFruit,
                    Timestamp     = town.Timestamp,
                    TurnipPrices  = "0.0.0.0.0.0.0.0.0.0.0.0.0.0",
                    TurnipsOwned  = 0
                };
                await TownService.UpsertTown(newTown);
            }
        }
예제 #2
0
        public void InitializeEntity(TownEntity town)
        {
            _entities.Add(town);

            town.OnTurnPassed
            .Where(_ => town.Id == _selectedTownId.Value)
            .Subscribe(_ => _outlineChangeSubject.OnNext(town.Id))
            .AddTo(this);
        }
        private void UpdateData(TownEntity entity)
        {
            if (view == null)
            {
                throw new NullReferenceException();
            }

            view.ShowOverPanel();
            view.UpdateOutline(GetTownOutlineData(entity));
        }
예제 #4
0
        private void UpdateBuildingContainer(TownEntity entity)
        {
            if (townDetailView == null)
            {
                throw new NullReferenceException();
            }

            var divisions = entity.Divisions;

            townDetailView.UpdateBuildingContainer(ConvertBuildingData(divisions));
        }
예제 #5
0
        public void Connect(TownEntity start, TownEntity end, int capacity, int length)
        {
            if (Routes.Any(route => route.From.Id == start.Id && route.To.Id == end.Id ||
                           route.From.Id == end.Id && route.To.Id == start.Id))
            {
                return;
            }

            var addRoute = new Route(capacity, length, start, end);

            Routes.Add(addRoute);
        }
예제 #6
0
        private void UpdateDivisionContainer(TownEntity entity)
        {
            if (townDetailView == null)
            {
                throw new NullReferenceException();
            }

            var popData       = entity.Pops;
            var workplaceData = entity.GetWorkplaces();

            townDetailView.UpdateDivisionContainer(CreateRowData(popData, workplaceData));
        }
예제 #7
0
        public void AddTown(Town town)
        {
            using (StoreDBcontext context = new StoreDBcontext())
            {
                TownEntity townEntity = new TownEntity
                {
                    RegionId = town.RegionId,
                    TownName = town.TownName
                };

                context.SaveChanges();
            }
        }
예제 #8
0
        public void TownInitialize()
        {
            races = new List <RaceEntity>();
            races.Add(RaceFactory.Create("Race_01", RaceType.HUMAN));

            goods = new List <GoodsEntity>();
            goods.Add(GoodsFactory.Create(GoodsType.FLOUR, "小麦"));

            var building = new SimpleProducer("農場", new ProduceAbility(goods.First(), 10), 5);

            townEntity = TownFactory.Create(0, "town_01", TownType.INLAND, races.First());
            townEntity.Build(0, building);
        }
예제 #9
0
        public async Task <TownEntity> UpsertTown(string userName, string townName, string mayorName, DateTime createdDate, int nativeFruit)
        {
            var newTown = new TownEntity()
            {
                Name          = townName,
                MayorName     = mayorName,
                OwnerUsername = userName,
                Created       = createdDate,
                NativeFruit   = nativeFruit,
                TurnipPrices  = "0.0.0.0.0.0.0.0.0.0.0.0.0.0",
                TurnipsOwned  = 0,
                PartitionKey  = userName.ToLowerInvariant(),
                RowKey        = townName.ToLowerInvariant()
            };

            return(await UpsertTown(newTown));
        }
예제 #10
0
        public async Task <TurnipEntity> SaveTurnipData(TownEntity town)
        {
            if (town.TurnipPrices == null || town.TurnipPrices.Length <= 0 || town.TurnipPrices.All(s => s < 20))
            {
                return(null);
            }
            var turnipRecord = new TurnipEntity()
            {
                MaxProfit    = this.CalculateMaxProfit(town.TurnipPrices, town.TurnipsOwned),
                StartDate    = DateTime.Now.AddDays(-7),
                TurnipPrices = town.TurnipPrices,
                TurnipsOwned = town.TurnipsOwned,
                PartitionKey = town.OwnerUsername,
                RowKey       = $"{DateTime.Now.AddDays(-7).Month}.{DateTime.Now.AddDays(-7).Day}.{DateTime.Now.AddDays(-7).Year}.{town.Name.ToLowerInvariant()}"
            };

            await this.StorageService.AddOrUpdate("Turnips", turnipRecord);

            return(turnipRecord);
        }
예제 #11
0
        public void AddProduct(Product product)
        {
            ProductEntity productEntity = (ProductEntity) new ProductEntity().ConvertFromApplicationModel(product);

            using (StoreDBcontext context = new StoreDBcontext())
            {
                var town = context.Towns.Where(e => e.TownName == product.Town.TownName && e.RegionId == product.Town.RegionId).FirstOrDefault();
                if (town != null)
                {
                    productEntity.TownId = town.ID;
                }
                else
                {
                    TownEntity townEntity = new TownEntity {
                        TownName = product.Town.TownName, RegionId = product.Town.RegionId
                    };
                    productEntity.Town = townEntity;
                }
                context.Products.Add(productEntity);
                context.SaveChanges();
            }
        }
예제 #12
0
 public List <IRoute> GetConnectedRoutes(TownEntity town)
 {
     return(Routes
            .Where(route => route.From == town || route.To == town)
            .ToList());
 }
예제 #13
0
        public async Task <TownEntity> UpsertTown(TownEntity updatedTown)
        {
            await StorageService.AddOrUpdate("Towns", updatedTown);

            return(updatedTown);
        }
예제 #14
0
 private void UpdateDetail(TownEntity entity)
 {
     UpdateDivisionContainer(entity);
     UpdateBuildingContainer(entity);
 }
 private static TownOutlineData GetTownOutlineData(TownEntity entity) =>
 new TownOutlineData(entity.TownName,
                     entity.TownType.GetDescription(),
                     entity.Storages);
예제 #16
0
 public void AttachTowns(TownEntity attachedTown)
 {
     Towns.Add(attachedTown);
 }
예제 #17
0
 public bool IsOwn(TownEntity town)
 {
     return(Towns.Contains(town));
 }
예제 #18
0
        public void UpdateProduct(Product product)
        {
            using (StoreDBcontext context = new StoreDBcontext())
            {
                bool HasChanged = false;
                var  dbProduct  = context.Products
                                  .Where(e => e.ProductId == product.ProductId).FirstOrDefault();

                if (product.Name != dbProduct.Name)
                {
                    dbProduct.Name = product.Name;
                    HasChanged     = true;
                }

                if (product.Price != dbProduct.Price)
                {
                    dbProduct.Price = product.Price;
                    HasChanged      = true;
                }

                if (product.Description != dbProduct.Description)
                {
                    dbProduct.Description = product.Description;
                    HasChanged            = true;
                }

                if (product.Contacts != dbProduct.Contacts)
                {
                    dbProduct.Contacts = product.Contacts;
                }

                if (product.Town.RegionId != dbProduct.Town.RegionId)
                {
                    dbProduct.Town.RegionId = product.Town.RegionId;
                    HasChanged = true;
                }

                if (product.Town.TownName != dbProduct.Town.TownName)
                {
                    var town = context.Towns.Where(e => e.TownName == product.Town.TownName && e.RegionId == product.Town.RegionId).FirstOrDefault();
                    if (town != null)
                    {
                        dbProduct.TownId = town.ID;
                    }
                    else
                    {
                        TownEntity townEntity = new TownEntity {
                            TownName = product.Town.TownName, RegionId = product.Town.RegionId
                        };
                        dbProduct.Town = townEntity;
                    }
                    HasChanged = true;
                }

                //Images comparison
                int currentImagesCount      = product.Images.Value.Count;
                List <ImageEntity> dbImages = dbProduct.Images.OrderBy(e => e.ID).ToList();

                if (currentImagesCount > 0)
                {
                    HasChanged = true;

                    for (int i = 0; i < currentImagesCount; i++)
                    {
                        if (product.Images.Value[i] != null)
                        {
                            if (dbImages.ElementAtOrDefault(i) != null && dbImages.ElementAtOrDefault(i).ImageUrl != product.Images.Value[i].ImageUrl)
                            {
                                int id  = dbImages[i].ID;
                                var img = context.Images.Where(e => e.ID == id).FirstOrDefault();
                                img.ImageUrl = product.Images.Value[i].ImageUrl;
                            }
                            else if (dbImages.ElementAtOrDefault(i) == null)
                            {
                                dbProduct.Images.Add(new ImageEntity().ConvertFromApplicationModel(product.Images.Value[i]) as ImageEntity);
                            }
                        }
                    }
                }

                if (HasChanged)
                {
                    context.SaveChanges();
                }
            }
        }