Example #1
0
        public IEnumerable <BSHops> GetBoilHops(string aRecepieName)
        {
            var    ret    = new List <BSHops>();
            string errMsg = null;

            var xrs = XDoc.XPathSelectElements(XPATH_FOR_RECIPIES);
            var r   = xrs.FirstOrDefault(x => x.Element(RECIPE_NAME_ELEMENT).Value.Equals(aRecepieName));

            var hs = r.XPathSelectElements(XPATH_FOR_HOPS);

            foreach (XElement h in hs)
            {
                double f;
                var    gb = new BSHops();

                if (double.TryParse(h.Element("F_H_AMOUNT").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.Amount = Math.Round(ConvertUsOuncesToGrams(f), 1);
                }
                else
                {
                    errMsg = "Unable to parse hops amount";
                }


                if (double.TryParse(h.Element("F_H_ALPHA").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.AlphaAcid = f;
                }
                else
                {
                    errMsg = "Unable to parse hops alpha acid";
                }

                if (double.TryParse(h.Element("F_H_BOIL_TIME").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.BoilTime = (int)(Math.Round(f));
                }
                else
                {
                    errMsg = "Unable to parse hop boil time";
                }

                if (double.TryParse(h.Element("F_H_DRY_HOP_TIME").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.DryHopDay = f;
                }
                else
                {
                    errMsg = "Unable to parse hops dry hops days";
                }

                if (errMsg != null)
                {
                    throw new ArgumentException(errMsg);
                }

                gb.Name = h.Element("F_H_NAME").Value;
                ret.Add(gb);
            }

            return(ret);
        }
Example #2
0
        public IEnumerable<BSHops> GetBoilHops(string aRecepieName)
        {
            var ret = new List<BSHops>();
            string errMsg = null;

            var xrs = XDoc.XPathSelectElements(XPATH_FOR_RECIPIES);
            var r = xrs.FirstOrDefault(x => x.Element(RECIPE_NAME_ELEMENT).Value.Equals(aRecepieName));

            var hs = r.XPathSelectElements(XPATH_FOR_HOPS);
            foreach (XElement h in hs)
            {
                double f;
                var gb = new BSHops();

                if (double.TryParse(h.Element("F_H_AMOUNT").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.Amount = Math.Round(ConvertUsOuncesToGrams(f), 1);
                }
                else
                    errMsg = "Unable to parse hops amount";


                if (double.TryParse(h.Element("F_H_ALPHA").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                    gb.AlphaAcid = f;
                else
                    errMsg = "Unable to parse hops alpha acid";

                if (double.TryParse(h.Element("F_H_BOIL_TIME").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                    gb.BoilTime = (int)(Math.Round(f));
                else
                    errMsg = "Unable to parse hop boil time";

                if (double.TryParse(h.Element("F_H_DRY_HOP_TIME").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                    gb.DryHopDay = f;
                else
                    errMsg = "Unable to parse hops dry hops days";

                if (errMsg != null)
                    throw new ArgumentException(errMsg);

                gb.Name = h.Element("F_H_NAME").Value;
                ret.Add(gb);
            }

            return ret;
        }