private void Read(string value) { if (value == null || value.Length == 0) { return; } var x = value.Split(new char[] { '|' }); for (int i = 0; i < x.Length; i++) { if (x[i].Length > 2) { values[Property.GetProperty(x[i].Substring(0, 2))] = Floats.ParseStorage(x[i].Substring(2)); } } }
public static Amount ParseEquivalent(string text) { try{ if (string.IsNullOrEmpty(text)) { return(Amount.Zero); } if (text.EndsWith("g") || text.EndsWith("ml")) { return(Parse(text)); } if (char.IsNumber(text, text.Length - 1)) { return(FromGram(Floats.ParseStorage(text))); } } catch (Exception ex) { LittleWatson.ReportException(ex, text); } return(Parse(text)); }
public static void LoadDay(DateTime date, String Xml) { if (Xml != null) { Serializer s = Serializer.FromXML(Xml); foreach (var p in s.Select("Period")) { Period period = p.Key.ParsePeriod(); List <Entry> entries = new List <Entry> (); DateTime modified = DateTime.MinValue; if (p.Read("LastChanged") != null) { modified = DateTime.Parse(p.Read("LastChanged")); } String note = p.Read("Note"); String time = p.Read("Time"); foreach (var e in p.Select("Entry")) { var NewEntry = new Entry(date, period, e.Key); NewEntry.AmountSelectedDB = e.Read("Amount"); NewEntry.AmountScaleDB = Floats.ParseStorage(e.Read("AmountScale")); NewEntry.Date = date; NewEntry.Period = period; FoodItem item = new FoodItem(e.Key, true); item.NutritionDB = e.Read("Properties"); item.ServingSizesDB = e.Read("Amount") + "=" + e.Read("Grams"); Cache.MergeItem(item); entries.Add(NewEntry); } Cache.MergeMeal(date, period, entries, modified, note, time); } } }
public override FoodItem MakeItem() { FoodItem result = new FoodItem(Text, false);//, Text + " - Powered by Nutritionix API"); string servingsize_qty = ""; string servingsize_unit = ""; string grams = ""; foreach (var field in token.Children()) { string column = ((JProperty)field).Name; if (((JProperty)field).Value.Type != JTokenType.Null) { string value = ((JProperty)field).Value.ToString(); if (map.ContainsKey(column)) { result.Values[map[column]] = Floats.ParseStorage(value.Replace(",", ".")); } switch (column) { //case "item_id": result.ServiceId = value; break; //case "nf_ingredient_statement": result.Description = value; break; //case "nf_servings_per_container": result.ServingsPerContainer = value; break; case "nf_serving_size_qty": servingsize_qty = value; break; case "nf_serving_size_unit": servingsize_unit = value; break; case "nf_serving_weight_grams": grams = value; break; } } } string servingsize; servingsize = string.Format("{0} {1}", servingsize_qty, servingsize_unit); Single divamounts = 0; if (servingsize_unit == "g" || servingsize_unit == "gram" || servingsize_unit == "grams") { grams = null; divamounts = (Amount)servingsize / "100g"; } if (grams != null) { result.ServingSizes.Add(servingsize, grams + " g"); divamounts = (Amount)(grams + " g") / "100g"; } else { result.ServingSizes.Add(servingsize); } if (divamounts > 0 && divamounts != 1) { result.Values.DivideAllValues(divamounts); } return(result); }