Beispiel #1
0
    public int Match(DishSummary dishSummary)
    {
        int weight = 0;

        foreach (KeyValuePair <String, ICondition> kvp in propertyConditionDictionary)
        {
            String     propertyName = kvp.Key;
            ICondition condition    = kvp.Value;

            IDishProperty dishProperty = dishSummary.GetDishProperty(propertyName);

            bool propertyNotFound = (dishProperty == null);

            if (propertyNotFound)
            {
                return(0);
            }

            bool valueMatched = condition.IsTrue(dishProperty.value);

            if (valueMatched)
            {
                weight += (dishProperty.value > 0) ? dishProperty.value : 1;
            }
            else
            {
                return(0);
            }
        }

        return(weight);
    }
Beispiel #2
0
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        IDishProperty dishProperty = value as IDishProperty;

        JObject jobject = new JObject();

        jobject.Add("Name", new JValue(dishProperty.name));
        jobject.Add("Value", new JValue(dishProperty.value));

        bool needToWriteIngredientInfo = (dishProperty.ingredientInfo != null);

        if (needToWriteIngredientInfo)
        {
            jobject.Add("IngredientInfo", JObject.FromObject(dishProperty.ingredientInfo));
        }

        jobject.WriteTo(writer);
    }
Beispiel #3
0
    private void ReadDishTupleFromJsonObject(ref Tuple <String, IReadOnlyCollection <IDishProperty>, int> dishTuple, String dishTupleName, JObject jobject)
    {
        JObject dishTupleJObject = jobject.GetValue(dishTupleName).ToObject <JObject>();

        String recipeName         = dishTupleJObject.GetValue("RecipeName").ToObject <String>();
        int    dishPropertyCount  = dishTupleJObject.GetValue("DishPropertyCount").ToObject <int>();
        JArray dishPropertyJArray = dishTupleJObject.GetValue("DishProperties").ToObject <JArray>();

        List <IDishProperty> dishPropertyList = new List <IDishProperty>(dishPropertyCount);

        foreach (JToken dishPropertyToken in dishPropertyJArray.Children())
        {
            IDishProperty dishProperty = dishPropertyToken.ToObject <IDishProperty>();

            dishPropertyList.Add(dishProperty);
        }

        IReadOnlyCollection <IDishProperty> dishProperties = dishPropertyList;

        int dishScore = dishTupleJObject.GetValue("DishScore").ToObject <int>();

        dishTuple = Tuple.Create(recipeName, dishProperties, dishScore);
    }
 private bool IsIngredientProperty(IDishProperty dishProperty)
 {
     return(dishProperty.ingredientInfo != null);
 }