private static MashStepDto GetMashStepDto(Model.BeerXml.MashStep mashStep)
        {
            var mashStepDto = new MashStepDto();

            mashStepDto.Length = (mashStep.StepTime.Any()) ? decimal.Parse(mashStep.StepTime, CultureInfo.InvariantCulture) : 0;
            //TODO: make double???
            mashStepDto.Temperature = (int)double.Parse(mashStep.StepTemp, CultureInfo.InvariantCulture);
            mashStepDto.Notes       = mashStep.Name;
            mashStepDto.Ingredients = new List <IIngredientStepDto>();
            return(mashStepDto);
        }
Esempio n. 2
0
        protected override IList <MashStepHop> ResolveCore(MashStepDto mashStepDto)
        {
            var mashStepHops = new List <MashStepHop>();

//             foreach (var hopStepDto in mashStepDto.Ingredients.Where(i => i.Type == "hop"))
//             {
//                 var temp = (HopStepDto) hopStepDto;
//                 var hopStep = Mapper.Map<HopStepDto,MashStepHop>(temp);
//                 mashStepHops.Add(hopStep);
//
//             }
            return(mashStepHops);
        }
Esempio n. 3
0
        protected override IList <MashStepFermentable> ResolveCore(MashStepDto mashStepDto)
        {
            var mashStepFermentagles = new List <MashStepFermentable>();

//             foreach (var fermentableStepDto in mashStepDto.Ingredients.Where(i => i.Type == "hop"))
//             {
//                 var temp = (FermentableStepDto) fermentableStepDto;
//                 var fermentalbeStep = Mapper.Map<FermentableStepDto, MashStepFermentable>(temp);
//                 mashStepFermentagles.Add(fermentalbeStep);
//
//             }
            return(mashStepFermentagles);
        }
Esempio n. 4
0
        protected override IList <MashStepOther> ResolveCore(MashStepDto mashStepDto)
        {
            var mashStepOthers = new List <MashStepOther>();

//             foreach (var ingredientStepDto in mashStepDto.Ingredients.Where(i => i.Type == "other"))
//             {
//                 var temp = (OtherStepDto)ingredientStepDto;
//                 var otherStep = Mapper.Map<OtherStepDto, MashStepOther>(temp);
//                 mashStepOthers.Add(otherStep);
//
//             }
            return(mashStepOthers);
        }
        private static MashStepDto GetMashStepDto(MashStep mashStep)
        {
            var mashStepDto = new MashStepDto();

            mashStepDto.Length = (mashStep.StepTime.Any()) ? decimal.Parse(mashStep.StepTime, CultureInfo.InvariantCulture) : 0;
            //TODO: make double???
            mashStepDto.Temperature  = (int)double.Parse(mashStep.StepTemp, CultureInfo.InvariantCulture);
            mashStepDto.Type         = mashStep.Type;
            mashStepDto.Notes        = mashStep.Name;
            mashStepDto.Hops         = new List <HopStepDto>();
            mashStepDto.Fermentables = new List <FermentableStepDto>();
            mashStepDto.Others       = new List <OtherStepDto>();
            return(mashStepDto);
        }
        private FermentableStepDto GetFermentableStepDto(Fermentable fermentable, MashStepDto mashStep)
        {
            var fermentableDto = _fermentableElasticsearch.Search(fermentable.Name, 0, 1).FirstOrDefault();

            if (fermentableDto == null)
            {
                {
                    Log.ErrorFormat("MISSING FERMENTABLE: {0}", fermentable.Name);
                    return(null);
                };
            }
            var fermentableStepDto = Mapper.Map <FermentableDto, FermentableStepDto>(fermentableDto);

            fermentableStepDto.StepNumber = mashStep.StepNumber;
            double amount = double.Parse(fermentable.Amount, CultureInfo.InvariantCulture);

            fermentableStepDto.Amount = (int)Math.Round(amount * 1000, 0);
            return(fermentableStepDto);
        }
        public RecipeDto ResolveCore(Model.BeerXml.Recipe source)
        {
            try
            {
                var    boilSize  = (int)double.Parse(source.BoilSize, CultureInfo.InvariantCulture);
                var    batchSize = (int)double.Parse(source.BatchSize, CultureInfo.InvariantCulture);
                double fg        = 0;
                if (source.Fg != null)
                {
                    fg = double.Parse(source.Fg, CultureInfo.InvariantCulture);
                }

                var recipeDto = new RecipeDto
                {
                    //MashSteps = new List<MashStepDto>(),
                    //BoilSteps = new List<BoilStepDto>(),
                    //FermentationSteps = new List<FermentationStepDto>(),
                    //SpargeStep = null, //new SpargeStepDto(),
                    Steps = new List <IStepDto>(),
                    Notes = source.Taste_Notes,
                    //Sets 60min as standard.
                    TotalBoilTime = (source.Boil_Time != null) ? double.Parse(source.Boil_Time, CultureInfo.InvariantCulture) : 60,
                    Volume        = (batchSize <= 0) ? boilSize : batchSize,
                };

                // <PRIMARY_AGE>
                if (source.PrimaryAge != null)
                {
                    var primaryAge       = (int)double.Parse(source.PrimaryAge, CultureInfo.InvariantCulture);
                    var primaryTemp      = (source.Primary_Temp == null) ? 0 : (int)double.Parse(source.Primary_Temp, CultureInfo.InvariantCulture);
                    var fermentationStep = GetFermentationStepDto(recipeDto, primaryAge);
                    if (fermentationStep != null)
                    {
                        fermentationStep.Temperature = primaryTemp;
                        recipeDto.Steps.Add(fermentationStep);
                    }
                }

                //<SECONDAY_AGE>
                if (source.Secondary_Age != null)
                {
                    var secondaryAge     = (int)double.Parse(source.Secondary_Age, CultureInfo.InvariantCulture);
                    var primaryTemp      = (source.Secondary_Temp == null) ? 0 : (int)double.Parse(source.Secondary_Temp, CultureInfo.InvariantCulture);
                    var fermentationStep = GetFermentationStepDto(recipeDto, secondaryAge);
                    if (fermentationStep != null)
                    {
                        fermentationStep.Temperature = primaryTemp;
                        recipeDto.Steps.Add(fermentationStep);
                    }
                }
                // <TERTIARYAGE>
                if (source.TertiaryAge != null)
                {
                    var tertiaryAge      = (int)double.Parse(source.TertiaryAge, CultureInfo.InvariantCulture);
                    var tertiaryTemp     = (source.TertiaryTemp == null) ? 0 : (int)double.Parse(source.TertiaryTemp, CultureInfo.InvariantCulture);
                    var fermentationStep = GetFermentationStepDto(recipeDto, tertiaryAge);
                    if (fermentationStep != null)
                    {
                        fermentationStep.Temperature = tertiaryTemp;
                        recipeDto.Steps.Add(fermentationStep);
                    }
                }

                if (!recipeDto.Steps.OfType <FermentationStepDto>().Any())
                {
                    recipeDto.Steps.Add(new FermentationStepDto
                    {
                        Length      = 14,
                        Ingredients = new List <IIngredientStepDto>(),
                    });
                }



                //Mash step from <MASH> <MASH_STEPS>
                if (source.Mash != null && source.Mash.MashSteps.Any())
                {
                    foreach (var mashStep in source.Mash.MashSteps)
                    {
                        var mashStepDto = GetMashStepDto(mashStep);
                        recipeDto.Steps.Add(mashStepDto);
                    }
                }
                else
                {
                    var mashStepDto = new MashStepDto
                    {
                        Length      = 60,
                        Temperature = 0,
                        Notes       = "",
                        Ingredients = new List <IIngredientStepDto>()
                    };
                    recipeDto.Steps.Add(mashStepDto);
                }
                //Fermentable
                if (source.Fermentables != null)
                {
                    var totalBoilTime = (int)recipeDto.TotalBoilTime;
                    var mashStep      = GetMashStepDto(recipeDto, totalBoilTime) ??
                                        recipeDto.Steps.OfType <MashStepDto>().FirstOrDefault();
                    foreach (var fermentable in source.Fermentables)
                    {
                        if (mashStep != null && (string.IsNullOrEmpty(fermentable.AddAfterBoil) || fermentable.AddAfterBoil.ToLower() == "false"))
                        {
                            IIngredientStepDto fermentableStepDto = GetFermentableStepDto(fermentable, mashStep);
                            mashStep.Ingredients.Add(fermentableStepDto);
                            break;
                        }
                        var fermentationSteps = recipeDto.Steps.OfType <FermentationStepDto>();
                        var fermentationStep  = fermentationSteps?.FirstOrDefault();
                        if (fermentationStep != null && fermentable.AddAfterBoil.ToLower() == "true")
                        {
                            var fermentableStepDto = GetFermentableStepDto(fermentable, fermentationStep);
                            fermentationStep.Ingredients.Add(fermentableStepDto);
                        }
                    }
                }
                //Hops
                if (source.Hops != null)
                {
                    foreach (var hop in source.Hops)
                    {
                        var time       = (int)double.Parse(hop.Time, CultureInfo.InvariantCulture);
                        var hopStepDto = GetHopStepDto(hop);
                        if (string.Equals(hop.Use, "Boil", StringComparison.OrdinalIgnoreCase) || hop.Use == "")
                        {
                            var boilStep = GetBoilStepDto(recipeDto, time);
                            if (hopStepDto != null)
                            {
                                boilStep.Ingredients.Add(hopStepDto);
                            }
                        }

                        if (string.Equals(hop.Use, "First Wort"))
                        {
                            //TODO: add support for first wort.
                        }

                        if (string.Equals(hop.Use, "Mash") && string.Equals(hop.Use, "Aroma"))
                        {
                            var mashStep = GetMashStepDto(recipeDto, time) ?? recipeDto.Steps.OfType <MashStepDto>().FirstOrDefault();
                            if (hopStepDto != null)
                            {
                                mashStep.Ingredients.Add(hopStepDto);
                            }
                        }

                        if (hop.Use == "Dry Hop")
                        {
                            var fermentationSteps = recipeDto.Steps.OfType <FermentationStepDto>();
                            var fermentationStep  = GetFermentationStepDto(recipeDto, time) ?? fermentationSteps.FirstOrDefault();
                            if (hopStepDto != null)
                            {
                                fermentationStep?.Ingredients.Add(hopStepDto);
                            }
                        }
                    }
                }

                if (source.Miscs != null)
                {
                    foreach (var misc in source.Miscs)
                    {
                        int time = 0;
                        if (misc.Time.Any())
                        {
                            time = (int)double.Parse(misc.Time, CultureInfo.InvariantCulture);
                        }
                        var othersStepDto = GetOthersStepDto(misc);
                        if (string.Equals(misc.Use, "Boil", StringComparison.OrdinalIgnoreCase))
                        {
                            var boilStep = GetBoilStepDto(recipeDto, time);
                            if (othersStepDto != null)
                            {
                                boilStep.Ingredients.Add(othersStepDto);
                            }
                        }
                        if (string.Equals(misc.Use, "Mash", StringComparison.OrdinalIgnoreCase))
                        {
                            var mashStep = GetMashStepDto(recipeDto, time) ?? recipeDto.Steps.OfType <MashStepDto>().FirstOrDefault();
                            if (othersStepDto != null)
                            {
                                mashStep.Ingredients.Add(othersStepDto);
                            }
                        }
                        if (string.Equals(misc.Use, "Primary", StringComparison.OrdinalIgnoreCase) || string.Equals(misc.Use, "Secondary", StringComparison.OrdinalIgnoreCase))
                        {
                            var fermentationSteps   = recipeDto.Steps.OfType <FermentationStepDto>();
                            var fermentationStepDto = GetFermentationStepDto(recipeDto, time) ?? fermentationSteps.FirstOrDefault();
                            if (othersStepDto != null)
                            {
                                fermentationStepDto.Ingredients.Add(othersStepDto);
                            }
                        }
                        if (string.Equals(misc.Use, "Bottling", StringComparison.OrdinalIgnoreCase))
                        {
                            //TODO: botteling step, beta shit.
                        }
                    }
                }

                if (source.Yeasts != null)
                {
                    foreach (var yeast in source.Yeasts)
                    {
                        var yeastStepDto      = GetYeastStepDto(yeast);
                        var fermentationSteps = recipeDto.Steps.OfType <FermentationStepDto>();
                        var inSecondary       = string.Equals(yeast.Add_To_Secondary, "false", StringComparison.OrdinalIgnoreCase);
                        if (!inSecondary)
                        {
                            var fermentationStepDto = (fermentationSteps.FirstOrDefault() ?? GetFermentationStepDto(recipeDto, 0)) ?? fermentationSteps.FirstOrDefault();
                            fermentationStepDto.Ingredients.Add(yeastStepDto);
                        }
                        else
                        {
                            var fermentationStepDto = (fermentationSteps.Skip(1).FirstOrDefault() ?? GetFermentationStepDto(recipeDto, 0)) ?? fermentationSteps.FirstOrDefault();
                            fermentationStepDto.Ingredients.Add(yeastStepDto);
                        }
                    }
                }

                SetStepNumber(recipeDto);

                return(recipeDto);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private FermentableStepDto GetFermentableStepDto(Model.BeerXml.Fermentable fermentable, MashStepDto mashStep)
        {
            var fermentableDto = _fermentableElasticsearch.Search(fermentable.Name, 0, 1).FirstOrDefault();

            if (fermentableDto == null)
            {
                {
                    return(null);
                };
            }
            var    fermentableStepDto = AutoMapper.Mapper.Map <FermentableDto, FermentableStepDto>(fermentableDto);
            double amount             = double.Parse(fermentable.Amount, CultureInfo.InvariantCulture);

            fermentableStepDto.Amount = (int)Math.Round(amount * 1000, 0);
            return(fermentableStepDto);
        }