コード例 #1
0
        /// <summary>
        /// Sets the miscs on the recipe
        /// </summary>
        void SetMiscs(Recipe recipe, XElement entryPoint)
        {
            var allMiscs = this.BrewDataService.GetUsableIngredients <Adjunct>(this.UserId);

            recipe.Adjuncts = new List <RecipeAdjunct>();

            if (entryPoint.Element("MISCS") != null)
            {
                foreach (var miscElement in entryPoint.Element("MISCS").Elements("MISC"))
                {
                    var misc = new RecipeAdjunct();

                    var matchingAdjunct = allMiscs.FirstOrDefault(x => x.Name.Trim().ToLower() == miscElement.Element("NAME").Value.Trim().ToLower());
                    if (matchingAdjunct != null)
                    {
                        misc.IngredientId = matchingAdjunct.IngredientId;
                        misc.Adjunct      = matchingAdjunct;
                    }
                    else
                    {
                        misc.IngredientId = 0;
                        misc.Adjunct      = new Adjunct();
                        misc.Adjunct.Name = miscElement.Element("NAME").Value;
                    }

                    // Detect Unit
                    if (miscElement.Element("amount_is_weight") != null)
                    {
                        misc.Unit = (miscElement.Element("amount_is_weight").Value.ToLower() == "true") ? "oz" : "floz";
                    }

                    misc.Amount = Math.Round((misc.Unit == "oz" ?
                                              this.RecipeUnitConverter.ConvertKilogramsToOunces(Convert.ToDouble(miscElement.Element("AMOUNT").Value)) :
                                              this.RecipeUnitConverter.ConvertLitersToFluidOunces(Convert.ToDouble(miscElement.Element("AMOUNT").Value))) * 10000) / 10000;

                    misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Boil;
                    var usageType = miscElement.Element("use").Value.ToLower();
                    if (usageType == "mash")
                    {
                        misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Mash;
                    }
                    else if (usageType == "primary")
                    {
                        misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Primary;
                    }
                    else if (usageType == "secondary")
                    {
                        misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Secondary;
                    }
                    else if (usageType == "bottling")
                    {
                        misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Bottle;
                    }

                    recipe.Adjuncts.Add(misc);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets the Adjunct Amount Elements
        /// </summary>
        object GetAdjuctAmountElements(RecipeAdjunct recipeAdjunct)
        {
            // Weight use KG, Liquid use L

            switch (recipeAdjunct.Unit.ToLower())
            {
            case "each":
                return(new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "lb":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertPoundsToKilograms(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "true") });

            case "oz":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertOuncesToKilograms(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "true") });

            case "floz":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertFluidOuncesToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "gal":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertGallonsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "pt":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertPintsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "qt":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertQuartsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "tbsp":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertTbspToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "tsp":
                return(new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertTspToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "kg":
                return(new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "true") });

            case "l":
                return(new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "false") });

            case "ml":
                return(new[] { new XElement("AMOUNT", recipeAdjunct.Amount * 1000), new XElement("AMOUNT_IS_WEIGHT", "false") });

            default:
                return(null);
            }
        }
コード例 #3
0
        /// <summary>
        /// Gets an adjunct usage element
        /// </summary>
        XElement GetAdjunctUsageElement(RecipeAdjunct recipeAdjunct)
        {
            switch ((AdjunctUsageType)recipeAdjunct.AdjunctUsageTypeId)
            {
            case AdjunctUsageType.Boil:
                return(new XElement("use", "boil"));

            case AdjunctUsageType.Mash:
                return(new XElement("use", "mash"));

            case AdjunctUsageType.Primary:
                return(new XElement("use", "primary"));

            case AdjunctUsageType.Secondary:
                return(new XElement("use", "secondary"));

            case AdjunctUsageType.Bottle:
                return(new XElement("use", "bottling"));

            default:
                return(new XElement("use", "boil"));
            }
        }
コード例 #4
0
		/// <summary>
		/// Sets the miscs on the recipe
		/// </summary>
		void SetMiscs(Recipe recipe, XElement entryPoint)
		{
			var allMiscs = this.BrewDataService.GetUsableIngredients<Adjunct>(this.UserId);
			recipe.Adjuncts = new List<RecipeAdjunct>();

			if (entryPoint.Element("MISCS") != null)
			{
				foreach (var miscElement in entryPoint.Element("MISCS").Elements("MISC"))
				{
					var misc = new RecipeAdjunct();

					var matchingAdjunct = allMiscs.FirstOrDefault(x => x.Name.Trim().ToLower() == miscElement.Element("NAME").Value.Trim().ToLower());
					if (matchingAdjunct != null)
					{
						misc.IngredientId = matchingAdjunct.IngredientId;
						misc.Adjunct = matchingAdjunct;
					}
					else
					{
						misc.IngredientId = 0;
						misc.Adjunct = new Adjunct();
						misc.Adjunct.Name = miscElement.Element("NAME").Value;
					}

					// Detect Unit
					if (miscElement.Element("amount_is_weight") != null)
					{
						misc.Unit = (miscElement.Element("amount_is_weight").Value.ToLower() == "true") ? "oz" : "floz";
					}

					misc.Amount = Math.Round((misc.Unit == "oz" ?
						this.RecipeUnitConverter.ConvertKilogramsToOunces(Convert.ToDouble(miscElement.Element("AMOUNT").Value)) :
						this.RecipeUnitConverter.ConvertLitersToFluidOunces(Convert.ToDouble(miscElement.Element("AMOUNT").Value))) * 10000) / 10000;

					misc.AdjunctUsageTypeId = (int)AdjunctUsageType.Boil;
					var usageType = miscElement.Element("use").Value.ToLower();
					if (usageType == "mash")
					{
						misc.AdjunctUsageTypeId = (int) AdjunctUsageType.Mash;
					} 
					else if (usageType == "primary")
					{
						misc.AdjunctUsageTypeId = (int) AdjunctUsageType.Primary;
					}
					else if (usageType == "secondary")
					{
						misc.AdjunctUsageTypeId = (int) AdjunctUsageType.Secondary;
					}
					else if (usageType == "bottling")
					{
						misc.AdjunctUsageTypeId = (int) AdjunctUsageType.Bottle;
					}

					recipe.Adjuncts.Add(misc);
				}
			}
		}
コード例 #5
0
		/// <summary>
		/// Gets the Adjunct Amount Elements
		/// </summary>
		object GetAdjuctAmountElements(RecipeAdjunct recipeAdjunct)
		{
			// Weight use KG, Liquid use L

			switch (recipeAdjunct.Unit.ToLower())
			{				
				case "each":
					return new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "lb":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertPoundsToKilograms(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "true") };
				case "oz":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertOuncesToKilograms(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "true") };
				case "floz":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertFluidOuncesToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "gal":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertGallonsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "pt":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertPintsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "qt":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertQuartsToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "tbsp":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertTbspToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "tsp":
					return new[] { new XElement("AMOUNT", RecipeUnitConverter.ConvertTspToLiters(recipeAdjunct.Amount)), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "kg":
					return new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "true") };
				case "l":
					return new[] { new XElement("AMOUNT", recipeAdjunct.Amount), new XElement("AMOUNT_IS_WEIGHT", "false") };
				case "ml":
					return new[] { new XElement("AMOUNT", recipeAdjunct.Amount * 1000), new XElement("AMOUNT_IS_WEIGHT", "false") };
				default:
					return null;
			}
		}
コード例 #6
0
		/// <summary>
		/// Gets an adjunct usage element
		/// </summary>
		XElement GetAdjunctUsageElement(RecipeAdjunct recipeAdjunct)
		{
			switch((AdjunctUsageType)recipeAdjunct.AdjunctUsageTypeId)
			{
				case AdjunctUsageType.Boil:
					return new XElement("use", "boil");
				case AdjunctUsageType.Mash:
					return new XElement("use", "mash");
				case AdjunctUsageType.Primary:
					return new XElement("use", "primary");
				case AdjunctUsageType.Secondary:
					return new XElement("use", "secondary");
				case AdjunctUsageType.Bottle:
					return new XElement("use", "bottling");
				default:
					return new XElement("use", "boil");
			}
		}