public void UpdateBuildings(JToken entities) { if (ListClass.Startup.Count <= 0 || ListClass.AllBuildings.Count <= 0) { return; } ListClass.ProductionList.Clear(); ListClass.ResidentialList.Clear(); ListClass.GoodProductionList.Clear(); foreach (JToken cityEntity in entities.ToList()) { foreach (Building metaEntity in ListClass.AllBuildings) { if (cityEntity["cityentity_id"]?.ToString() == metaEntity.id) { EntityEx entity = GameClassHelper.CopyFrom(cityEntity); entity.name = metaEntity.name; if (metaEntity.available_products != null) { entity.available_products = metaEntity.available_products.ToList(); } entity.type = metaEntity.type; if (entity.type == "production" && metaEntity.available_products != null && entity.connected >= 1 && /*entity.hasSupplyProdAt(StaticData.UserData.ProductionOption)|| */ GameClassHelper.hasOnlySupplyProduction(entity.available_products) && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.ProductionList.Add(entity); } else if (entity.type == "residential" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.ResidentialList.Add(entity); } else if (entity.type == "goods" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.GoodProductionList.Add(entity); } } } } }
private static async Task <TResult> ReadContentAsJsonAsync <TResult>(HttpResponseMessage message) { var content = await message.Content.ReadAsStringAsync(); return(EntityEx.GetAs <TResult>(content)); }
public void UpdateBuildings(JToken entities, bool onlyFinished = false) { if (ListClass.Startup.Count <= 0 || ListClass.AllBuildings.Count <= 0) { return; } if (!onlyFinished) { ListClass.ProductionList.Clear(); ListClass.ResidentialList.Clear(); ListClass.GoodProductionList.Clear(); } ListClass.FinishedProductions.Clear(); ListClass.EveryProduction.Clear(); Parallel.ForEach(entities.ToList(), cityEntity => { Parallel.ForEach(ListClass.AllBuildings, metaEntity => { if (cityEntity["cityentity_id"]?.ToString() == metaEntity.id) { EntityEx entity = GameClassHelper.CopyFrom(cityEntity); entity.name = metaEntity.name; if (metaEntity.available_products != null) { entity.available_products = metaEntity.available_products.ToList(); } entity.type = metaEntity.type; if (entity.state["__class__"].ToString().ToLower() == "ProductionFinishedState".ToLower()) { ListClass.FinishedProductions.Add(entity); } if (!entity.type.Equals("street")) { ListClass.EveryProduction.Add(entity); } if (onlyFinished) { return; } if (entity.type == "production" && metaEntity.available_products != null && entity.connected >= 1 && /*entity.hasSupplyProdAt(StaticData.UserData.ProductionOption)|| */ GameClassHelper.hasOnlySupplyProduction(entity.available_products) && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.ProductionList.Add(entity); } else if (entity.type == "residential" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.ResidentialList.Add(entity); } else if (entity.type == "goods" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) { ListClass.GoodProductionList.Add(entity); } } }); }); //foreach (JToken cityEntity in entities.ToList()) //{ // foreach (Building metaEntity in ListClass.AllBuildings) // { // if (cityEntity["cityentity_id"]?.ToString() == metaEntity.id) // { // EntityEx entity = GameClassHelper.CopyFrom(cityEntity); // entity.name = metaEntity.name; // if (metaEntity.available_products != null) // entity.available_products = metaEntity.available_products.ToList(); // entity.type = metaEntity.type; // if (entity.state["__class__"].ToString().ToLower() == "ProductionFinishedState".ToLower()) // ListClass.FinishedProductions.Add(entity); // if (onlyFinished) continue; // if (entity.type == "production" && metaEntity.available_products != null && entity.connected >= 1 && /*entity.hasSupplyProdAt(StaticData.UserData.ProductionOption)|| */GameClassHelper.hasOnlySupplyProduction(entity.available_products) && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) // ListClass.ProductionList.Add(entity); // else if (entity.type == "residential" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) // ListClass.ResidentialList.Add(entity); // else if (entity.type == "goods" && entity.connected >= 1 && entity.state["__class__"].ToString().ToLower() != "ConstructionState".ToLower()) // ListClass.GoodProductionList.Add(entity); // } // } //} }