Esempio n. 1
0
        public IEnumerable <BSGrainBill> GetGrainBill(string aRecepieName)
        {
            var    ret    = new List <BSGrainBill>();
            string errMsg = null;

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

            var gs = r.XPathSelectElements(XPATH_FOR_GRAINS);

            foreach (XElement g in gs)
            {
                float f;
                var   gb = new BSGrainBill();
                if (float.TryParse(g.Element("F_G_PERCENT").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                {
                    gb.AmountPercent = (int)(Math.Round(f));
                }
                else
                {
                    errMsg = "Unable to parse one grain percentage in the grainbill";
                }

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

                gb.FermentableName = g.Element("F_G_NAME").Value;
                ret.Add(gb);
            }

            return(ret);
        }
Esempio n. 2
0
        public IEnumerable<BSGrainBill> GetGrainBill(string aRecepieName)
        {
            var ret = new List<BSGrainBill>();
            string errMsg = null;

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

            var gs = r.XPathSelectElements(XPATH_FOR_GRAINS);
            foreach (XElement g in gs)
            {
                float f;
                var gb = new BSGrainBill();
                if (float.TryParse(g.Element("F_G_PERCENT").Value, NumberStyles.AllowDecimalPoint, CultureInfo.CreateSpecificCulture("en-US"), out f))
                    gb.AmountPercent = (int)(Math.Round(f));
                else
                    errMsg = "Unable to parse one grain percentage in the grainbill";

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

                gb.FermentableName = g.Element("F_G_NAME").Value;
                ret.Add(gb);
            }

            return ret;
        }