USDADataImport.USDAImport.AddTranslationForSeveralIngredients C# (CSharp) Method

AddTranslationForSeveralIngredients() public method

public AddTranslationForSeveralIngredients ( int startNDBNo, int count ) : void
startNDBNo int
count int
return void
        public void AddTranslationForSeveralIngredients(int startNDBNo, int count)
        {
            log.InfoFormat("[AddTranslationForSeveralIngredients] startIndex={0}, count={1}.", startNDBNo, count);
            List<Ingredient> list = serviceLayer.GetAllIngredients();
            int ingrCount = 0;
            int ingrNDBNo = 0;
            foreach (Ingredient tempIngr in list)
            {
                if (tempIngr.USDA_NDB_No >= startNDBNo && (ingrCount++ <= count || count == -1))
                {

                    AddTranslationForIngredient(tempIngr);
                    ingrNDBNo = tempIngr.USDA_NDB_No;
                    //string text = (tempIngr.LongDesc != null && tempIngr.LongDesc.GetDescription() != null) ? tempIngr.LongDesc.GetDescription() : "";
                    //log.InfoFormat("[AddTranslationForSeveralIngredients] Ingredient.LongDescription={0}, translation={1}", text, tempIngr.LongDesc.GetDescription("he"));
                }
                else
                {
                    if (ingrCount > count)
                    {
                        log.InfoFormat("[AddTranslationForSeveralIngredients] Last translated Ingredient NDB_No={0}.", ingrNDBNo);
                        break;
                    }
                }
            }
            log.InfoFormat("[AddTranslationForSeveralIngredients] Total characters count={0}, ingredientCount={1}.", charsCount, IngredientCount);
        }

Usage Example

Ejemplo n.º 1
0
        public static void AddTranslationForIngredient()
        {
            try
            {
                Console.WriteLine("Add translation for ingredients");
                Console.WriteLine("Enter strart NDB No:");
                string NDBNoStr = Console.ReadLine();
                int startNDBNo = 0, count = 0;
                if (NDBNoStr != null)
                {
                    startNDBNo = int.Parse(NDBNoStr);
                    if (startNDBNo < 1001 || startNDBNo > 93600)
                    {
                        log.WarnFormat("[AddTranslationForIngredient] Incorrect strart NDB No = {0}.", NDBNoStr);
                        return;
                    }

                }

                Console.WriteLine("Enter count of ingredients:");
                NDBNoStr = Console.ReadLine();
                if (NDBNoStr != null)
                {
                    count = int.Parse(NDBNoStr);
                    if (count < -1 || count > 8463)
                    {
                        log.WarnFormat("[AddTranslationForIngredient] Incorrect count = {0}.", NDBNoStr);
                        return;
                    }

                }
                log.InfoFormat("[AddTranslationForIngredient] strart NDB No = {0}, count = {1}.", startNDBNo, count);
                USDAImport usdaImport = new USDAImport();
                usdaImport.AddTranslationForSeveralIngredients(startNDBNo, count);
            }
            catch (Exception e)
            {
                log.ErrorFormat("[AddTranslationForIngredient] Exception={0}", e);
            }
        }