private ProductModel ConvertProduct(IProductType productType, bool flat) { var converted = _productCache.FirstOrDefault(p => p.Id == productType.Id); if (converted != null) { return(converted); } // Base object var identity = (ProductIdentity)productType.Identity ?? EmptyIdentity; converted = new ProductModel { Id = productType.Id, Type = productType.GetType().Name, Name = productType.Name, State = productType.State, Identifier = identity.Identifier, Revision = identity.Revision }; if (flat) { return(converted); } // Properties var properties = productType.GetType().GetProperties(); converted.Properties = EntryConvert.EncodeObject(productType, ProductSerialization); // Files converted.Files = ConvertFiles(productType, properties); // Recipes var recipes = RecipeManagement.GetAllByProduct(productType); converted.Recipes = recipes.Select(ConvertRecipe).ToArray(); // Parts ConvertParts(productType, properties, converted); _productCache.Add(converted); return(converted); }
public ProductModel ConvertProduct(IProductType productType, bool flat) { // Base object var identity = (ProductIdentity)productType.Identity ?? EmptyIdentity; var converted = new ProductModel { Id = productType.Id, Type = productType.GetType().Name, Name = productType.Name, State = productType.State, Identifier = identity.Identifier, Revision = identity.Revision }; if (flat) { return(converted); } // Properties var properties = productType.GetType().GetProperties(); converted.Properties = EntryConvert.EncodeObject(productType, ProductSerialization); // Files converted.Files = (from property in properties where property.PropertyType == typeof(ProductFile) select(ProductFile) property.GetValue(productType)).ToArray(); converted.FileModels = ConvertFiles(productType, properties); // Recipes var recipes = RecipeManagement.GetAllByProduct(productType); converted.Recipes = recipes.Select(ConvertRecipe).ToArray(); // Parts ConvertParts(productType, properties, converted); return(converted); }
public RecipeModel[] GetRecipes(long productId) { var product = ProductManager.LoadType(productId); return(RecipeManagement.GetAllByProduct(product).Select(ConvertRecipe).ToArray()); }