Exemple #1
0
        /// <inheritdoc />
        public Recipe Convert(RecipeDataContract value, object state)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "Precondition: value != null");
            }

            Recipe recipe;
            IConverter <RecipeDataContract, Recipe> converter;

            if (this.typeConverters.TryGetValue(value.Type, out converter))
            {
                recipe = converter.Convert(value, state);
            }
            else
            {
                recipe = new UnknownRecipe();
            }

            recipe.RecipeId        = value.Id;
            recipe.OutputItemId    = value.OutputItemId;
            recipe.OutputItemCount = value.OutputItemCount;
            recipe.MinimumRating   = value.MinRating;
            recipe.TimeToCraft     = TimeSpan.FromMilliseconds(value.TimeToCraftMs);

            var craftingDisciplines = value.Disciplines;

            if (craftingDisciplines != null)
            {
                recipe.CraftingDisciplines = this.converterForCraftingDisciplineCollection.Convert(craftingDisciplines, state);
            }

            var flags = value.Flags;

            if (flags != null)
            {
                recipe.Flags = this.converterForRecipeFlagCollection.Convert(flags, state);
            }

            var ingredients = value.Ingredients;

            if (ingredients != null)
            {
                recipe.Ingredients = this.converterForItemStackCollection.Convert(ingredients, state);
            }

            return(recipe);
        }
        /// <summary>Converts the given object of type <see cref="RecipeDataContract"/> to an object of type <see cref="Recipe"/>.</summary>
        /// <param name="value">The value to convert.</param>
        /// <param name="state"></param>
        /// <returns>The converted value.</returns>
        public Recipe Convert(RecipeDataContract value, object state)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "Precondition: value != null");
            }

            Recipe recipe;
            IConverter <RecipeDataContract, Recipe> converter;

            if (this.typeConverters.TryGetValue(value.Type, out converter))
            {
                recipe = converter.Convert(value, state);
            }
            else
            {
                recipe = new UnknownRecipe();
            }

            int recipeId;

            if (int.TryParse(value.RecipeId, out recipeId))
            {
                recipe.RecipeId = recipeId;
            }

            int outputItemId;

            if (int.TryParse(value.OutputItemId, out outputItemId))
            {
                recipe.OutputItemId = outputItemId;
            }

            int outputItemCount;

            if (int.TryParse(value.OutputItemCount, out outputItemCount))
            {
                recipe.OutputItemCount = outputItemCount;
            }

            int minimumRating;

            if (int.TryParse(value.MinimumRating, out minimumRating))
            {
                recipe.MinimumRating = minimumRating;
            }

            double timeToCraft;

            if (double.TryParse(value.TimeToCraft, out timeToCraft))
            {
                recipe.TimeToCraft = TimeSpan.FromMilliseconds(timeToCraft);
            }

            var craftingDisciplines = value.CraftingDisciplines;

            if (craftingDisciplines != null)
            {
                recipe.CraftingDisciplines = this.converterForCraftingDisciplineCollection.Convert(craftingDisciplines, state);
            }

            var flags = value.Flags;

            if (flags != null)
            {
                recipe.Flags = this.converterForRecipeFlagCollection.Convert(flags, state);
            }

            var ingredients = value.Ingredients;

            if (ingredients != null)
            {
                recipe.Ingredients = this.converterForItemQuantityCollection.Convert(ingredients, state);
            }

            return(recipe);
        }