public static bool Prefix(ref bool __result, Pawn getter, Pawn eater, bool desperate, ref Thing foodSource, ref ThingDef foodDef, bool canRefillDispenser, bool canUseInventory, bool allowForbidden, bool allowCorpse, bool allowSociallyImproper, bool allowHarvest, bool forceScanWholeMap) { #if DEBUG var traceOutput = new StringBuilder(); traceOutput.AppendLine($"Intercepting FoodUtility.TryFindBestFoodSourceFor getter={getter}|eater={eater}|desperate={desperate}|" + $"canRefillDispenser={canRefillDispenser}|canUseInventory={canUseInventory}|allowForbidden={allowForbidden}|" + $"allowCorpse={allowCorpse}|allowSociallyImproper={allowSociallyImproper}|allowHarvest={allowHarvest}|forceScanWholeMap={forceScanWholeMap}"); #endif try { var parameters = new FoodSearchParameters( getter: getter, eater: eater, desperate: desperate, canUseInventory: canUseInventory, maxPref: FoodPreferability.MealLavish, allowPlant: true, allowDrug: true, allowCorpse: allowCorpse, allowDispenserFull: true, allowDispenserEmpty: true, allowForbidden: allowForbidden, allowSociallyImproper: allowSociallyImproper, allowHarvest: allowHarvest, forceScanWholeMap: forceScanWholeMap); #if DEBUG var result = new FoodSearch(parameters, traceOutput).Find(); #else var result = new FoodSearch(parameters).Find(); #endif if (result.Success) { #if DEBUG traceOutput.AppendLine($"Found food {result.Thing?.Label ?? "(none)"} with def {result.Def?.label ?? "(none)"} for {eater}"); #endif __result = result.Thing != null; foodSource = result.Thing; foodDef = result.Def; return(false); } } catch (Exception ex) { Mod.LogError(ex.ToString() + Environment.NewLine + ex.StackTrace); } #if DEBUG finally { Mod.LogMessage(traceOutput.ToString()); } #endif // If failure, fall back to vanilla return(true); }
private static void FoodSearchExample() { var searchTerm = AskFor <string>("Enter a search term: "); if (foodSearch == null) { foodSearch = new FoodSearch(consumerKey, consumerSecret); } var response = foodSearch.GetResponseSynchronously(new FoodSearchRequest() { SearchExpression = searchTerm }); if (response.HasResults) { Console.WriteLine("Got " + response.foods.food.Count + " Results: \n\n"); var form = "id: {0}, \n - type: {1}, \n - name: {2}, \n - description: {3}"; foreach (var food in response.foods.food) { Console.WriteLine(String.Format(form, food.food_id, food.food_type, food.food_name, food.food_description)); } } else { Console.WriteLine("No results from term: " + searchTerm); } Console.WriteLine(""); Console.WriteLine(""); }
public List <FoodInfo> SearchFoods(string search) { var foodSearch = new FoodSearch(_consumerKey, _consumerSecret); var itemrequest = new FoodSearchRequest { SearchExpression = search }; var response = foodSearch.GetResponseSynchronously(itemrequest); if (response != null && response.HasResults) { return(response.foods.food); } return(null); }
public async Task <IIndexResponse> Index(FoodSearchViewModel item) { var model = new FoodSearch { Id = item.Id, Description = item.Description, FoodLocationId = item.FoodLocationId, FoodLocationName = item.FoodLocationName, Image = item.Image, Name = item.Name, Price = item.Price, PriceOld = item.PriceOld, Location = new GeoLocation(item.Latitude, item.Longitude), Category = item.Category, Tag = " " + item.Name.ToLower() + " " + convertToUnSign3(item.Name.ToLower()) + " ", CategoryLocation = item.CategoryLocation }; return(await _client.IndexAsync <FoodSearch>(model, i => i .Index("food") .Type("foodsearch") .Id(model.Id) .Refresh(Elasticsearch.Net.Refresh.True))); }
public string SearchFood(string searchExpression) { try { consumerKey = "your consumer Key"; consumerSecret = "your consumer Secret "; var searchTerm = searchExpression; foodSearch = new FoodSearch(consumerKey, consumerSecret); var response = foodSearch.GetResponseSynchronously(new FoodSearchRequest() { SearchExpression = searchTerm, MaxResults = 50, PageNumber = 0 }); if (response != null && response.HasResults) { return(new JavaScriptSerializer().Serialize(response)); } else { return(null); } } catch (Exception ex) { return(ex.Message); } }