public static QuantityAndUnit Parse(string quantityAndUnit) { if (string.IsNullOrEmpty(quantityAndUnit)) { return(null); } QuantityAndUnit value; quantityAndUnit = quantityAndUnit.Trim(); value = QuantityAndUnit.Parse(quantityAndUnit, " kg"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, " g"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, " gr"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, " l"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, " ml"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, "kg"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, "g"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, "gr"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, "l"); if (value != null) { return(value); } value = QuantityAndUnit.Parse(quantityAndUnit, "ml"); if (value != null) { return(value); } return(null); }
private void SearchAndShowArticle(string eanCode) { /* * foodInfo.product = new FoodInformation.Product(); * foodInfo.product.image_url = "https://static.openfoodfacts.org/images/products/20005016/front_fr.4.400.jpg"; * foodInfo.product.image_small_url = "https://static.openfoodfacts.org/images/products/20005016/front_fr.4.200.jpg"; */ //eanCode = "22120649"; // Kartoffeleintopf Mit Würstchen Und Rauchspeck, mit Mengenangabe, und KCal/100g //eanCode = "88888888888"; // Not Found //eanCode = "4000462810052"; // Goldpuder Weizenmehl Type 405 1 KG //eanCode = "5410673854001"; // Reis, mit Einheit und Nährstoff string title = string.Empty; string info = string.Empty; InternetDatabaseSearchActivity.picture = null; this.formatedResponseFromServer = string.Empty; this.foodInfo = null; this.foodSize = null; this.kcalPer100 = null; var eanCodeView = FindViewById <TextView>(Resource.Id.InternetDatabaseResult_EanCode); var progressText = FindViewById <TextView>(Resource.Id.InternetDatabaseResult_ProgressText); var progressBar = FindViewById <ProgressBar>(Resource.Id.InternetDatabaseResult_Progress); try { string[] eanCodeList = eanCode.Split(","); foreach (string ean in eanCodeList) { RunOnUiThread(() => eanCodeView.Text = "EAN Code: " + ean); this.foodInfo = this.GetFoodInformation(ean); if (foodInfo.status == 1) // Artikelangaben gefunden? { break; } } } catch (Exception ex) { TRACE(ex); title = ex.Message; } RunOnUiThread(() => { eanCodeView.Text = string.Empty; if (this.foodInfo != null) { title = string.Format("EAN Code: {0}", this.foodInfo.code); if (this.foodInfo.status == 1) { info += string.Format("Produkt:\n{0}\n\n", this.foodInfo.product.GetProduktName()); info += string.Format("Hersteller:\n{0}\n\n", this.foodInfo.product.brands); this.foodSize = QuantityAndUnit.Parse(this.foodInfo.product.quantity); if (this.foodSize != null) { info += string.Format("Menge: {0} {1}", this.foodSize.Quantity, this.foodSize.Unit); } else { info += string.Format("Menge mit Einheit nicht erkannt: {0}", this.foodInfo.product.quantity); } if (foodInfo.product.nutriments != null) { /* * info += string.Format("Nährwert: {0} {1} pro 100g\n", * this.foodInfo.product.nutriments.energy_100g, * this.foodInfo.product.nutriments.energy_unit); */ if (string.Compare(this.foodInfo.product.nutriments.energy_unit, "kcal", true) == 0) { this.kcalPer100 = this.foodInfo.product.nutriments.energy_value; info += "\n\n"; info += string.Format("Nährwert: {0} kcal pro 100g", this.kcalPer100); } if (string.Compare(this.foodInfo.product.nutriments.energy_unit, "kJ", true) == 0) { // kcal = kJ / 4,184 dividieren this.kcalPer100 = this.foodInfo.product.nutriments.energy_100g / 4.184m; this.kcalPer100 = Math.Round(this.kcalPer100.Value, 0); info += "\n\n"; info += string.Format("Nährwert: {0} kcal pro 100g", this.kcalPer100); } } eanCodeView.Text = "Link: https://de.openfoodfacts.org/produkt/" + this.foodInfo.code; } else { info += string.Format("Status: {0} - {1}\n\n", this.foodInfo.status, this.foodInfo.status_verbose); info += string.Format("Response: {0}", this.formatedResponseFromServer); } } progressText.Text = title; progressBar.Visibility = ViewStates.Gone; var textView = FindViewById <TextView>(Resource.Id.InternetDatabaseResult_Text); if (textView == null) { return; } textView.Text = info; if (this.foodInfo?.product != null) { InternetDatabaseSearchActivity.picture = this.GetUrlPicture(this.foodInfo.product.image_url); var imageView = FindViewById <ImageView>(Resource.Id.InternetDatabaseResult_Image); imageView.SetImageBitmap(InternetDatabaseSearchActivity.picture); } }); }