当前位置: 首页>>代码示例>>C#>>正文


C# System.IO.StringReader.ReadLineAsync方法代码示例

本文整理汇总了C#中System.IO.StringReader.ReadLineAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.StringReader.ReadLineAsync方法的具体用法?C# System.IO.StringReader.ReadLineAsync怎么用?C# System.IO.StringReader.ReadLineAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StringReader的用法示例。


在下文中一共展示了System.IO.StringReader.ReadLineAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportIngredientsData

        private async void ImportIngredientsData(string fileContent)
        {
            string line = "";
            using (System.IO.StringReader stringReader = new System.IO.StringReader(fileContent))
            {
                while ((line = await stringReader.ReadLineAsync()) != null)
                {
                    IngredientViewModel ingredient = new IngredientViewModel();

                    string[] ingredientAndManufacturer = line.Split(';');
                    ingredient.Name = ingredientAndManufacturer[0].TrimEnd();
                    //ingredient.Manufacturer = ingredientAndManufacturer[1].TrimEnd();
                    ingredient.Category = "Metzgerei";
                    ingredient.UnitOfMeasure = 1;
                    ingredient.SaveIngredientCheckExisting(ingredient);
                }
            }
        }
开发者ID:mhebestadt,项目名称:CateringKingCalculator,代码行数:18,代码来源:StartPage.xaml.cs

示例2: ReadSettings

        static async Task<Dictionary<string, string>> ReadSettings(string settingsIni)
        {
            Dictionary<string, string> Settings = new Dictionary<string, string>();

            try
            {
                System.IO.StringReader strReader = new System.IO.StringReader(settingsIni);
                string line = null;

                while ((line = await strReader.ReadLineAsync()) != null)
                {
                    if (line.Length < 1 || line.StartsWith("#") || line.StartsWith("["))
                    {
                        continue;
                    }

                    int delimiterIndex = line.IndexOf("=");

                    if (delimiterIndex != -1)
                    {
                        string key = line.Substring(0, delimiterIndex);
                        string val = line.Substring(delimiterIndex + 1);

                        try
                        {
                            Settings.Add(key, val);
                        }
                        catch
                        {
                        }
                    }
                }

                strReader.Close();
            }
            catch (Exception e)
            {
                Out.WriteLine("Error #2 loading app.ini: " + e.Message, "Azure.Boot", ConsoleColor.Red);
                Console.ReadKey();
                Environment.Exit(0);
            }

            return Settings;
        }
开发者ID:53SPARTA53,项目名称:DoPs,代码行数:44,代码来源:Program.cs

示例3: ImportMealItemsData

        private async void ImportMealItemsData(string fileContent, string mealItemCategory)
        {
            string line = "";
            string[] mealItemsRaw = fileContent.Split('|');
            char[] trimChar = {'\n','\r'};
            bool mealItemExists = false;

            foreach(var mealItemRaw in mealItemsRaw)
            {
                if (mealItemRaw.ToString().Length == 0) { continue; }
                string mealItemInfo = mealItemRaw.TrimStart(trimChar);
                using (System.IO.StringReader stringReader = new System.IO.StringReader(mealItemInfo))
                {
                    int lineNo = 0;
                    string mealItemName = "";
                    float grossWeight = 0;
                    float divisionFactor = 0;
                    string grossWeightUnitOfMeasure = "";
                    List<string> rawIngredients = new List<string>();

                    while ((line = await stringReader.ReadLineAsync()) != null)
                    {
                        // At 0 this should be the name
                        if (lineNo == 0)
                        {
                            mealItemName = CleanMealItemName(line);
                            MealItemViewModel mealItemView = new MealItemViewModel();
                            // In case the meal item exists we move on to the next
                            if (mealItemView.MealItemExists(mealItemName) == true) { mealItemExists = true; break; }
                            lineNo++;
                            continue;
                        }

                        if (line.Contains("Personen"))
                        {
                            string _grossWeight;
                            string _divisionFactor;
                            GetGrossWeightAndDivisionFactor(line, out _grossWeight, 
                                out grossWeightUnitOfMeasure, out _divisionFactor);
                            _divisionFactor = _divisionFactor.Replace(',', '.');
                            _grossWeight = _grossWeight.Replace(',', '.');
                            divisionFactor = float.Parse(_divisionFactor, CultureInfo.InvariantCulture.NumberFormat);
                            grossWeight = float.Parse(_grossWeight, CultureInfo.InvariantCulture.NumberFormat) / divisionFactor;
                            
                            lineNo++;
                            continue;
                        }

                        rawIngredients = InterpretIngredientDefinition(line);
                        lineNo++;
                    }

                    // Let's see if there was an inner break
                    if (mealItemExists) { mealItemExists = false; continue; }

                    // if go this far it means a new meal item
                    MealItemViewModel mealItem = new MealItemViewModel();
                    IngredientViewModel ingredient = null;
                    foreach (var rawIngredient in rawIngredients)
                    {
                        string amount;
                        string unitOfMeasure;
                        ingredient = GetIngredientDetails(rawIngredient, out amount, out unitOfMeasure);

                        if (ingredient != null)
                        {
                            UnitOfMeasureViewModel unitOfMeasureModel = new UnitOfMeasureViewModel();
                            unitOfMeasureModel = unitOfMeasureModel.GetUnitOfMeasure(ingredient.UnitOfMeasure);
                            amount = amount.Replace(',', '.');
                            float floatAmount = float.Parse(amount, CultureInfo.InvariantCulture.NumberFormat);

                            // Recalculating kilogramms and liters
                            if ((unitOfMeasure.Equals("kg", StringComparison.CurrentCultureIgnoreCase)) ||
                                    (unitOfMeasure.Equals("Ltr", StringComparison.CurrentCultureIgnoreCase)))
                                floatAmount = floatAmount * 1000;
                            // Devive by the number of people all amounts were calculated for
                            floatAmount = floatAmount / divisionFactor;
                            mealItem.IngredientIDsWithTotalAmount.Add(ingredient.Id, floatAmount);
                        }
                    }

                    mealItem.Name = mealItemName;
                    if (grossWeightUnitOfMeasure.Equals("Ltr", StringComparison.CurrentCultureIgnoreCase) ||
                        grossWeightUnitOfMeasure.Equals("kg", StringComparison.CurrentCultureIgnoreCase))
                        grossWeight = grossWeight * 1000;

                    if (grossWeightUnitOfMeasure.Equals("kg", StringComparison.CurrentCultureIgnoreCase) ||
                        grossWeightUnitOfMeasure.Equals("g", StringComparison.CurrentCultureIgnoreCase))
                        mealItem.TotalAmountUnitOfMeasure = 1;

                    if (grossWeightUnitOfMeasure.Equals("Ltr", StringComparison.CurrentCultureIgnoreCase) ||
                        grossWeightUnitOfMeasure.Equals("ml", StringComparison.CurrentCultureIgnoreCase))
                        mealItem.TotalAmountUnitOfMeasure = 2;

                    mealItem.TotalAmount = grossWeight;
                    FoodCategoryViewModel mealItemCategoryModel = new FoodCategoryViewModel();
                    mealItemCategoryModel = mealItemCategoryModel.GetFoodCategoryByName(mealItemCategory);
                    if (mealItemCategoryModel != null) { mealItem.CategoryId = mealItemCategoryModel.Id; }
                    _mealItems.Add(mealItem);
                     
//.........这里部分代码省略.........
开发者ID:mhebestadt,项目名称:CateringKingCalculator,代码行数:101,代码来源:StartPage.xaml.cs


注:本文中的System.IO.StringReader.ReadLineAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。