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


C# TextReader.ReadLineAsync方法代码示例

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


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

示例1: TryDecodeAsync

        public static async Task<PemData> TryDecodeAsync(TextReader input)
        {
            // Read the header
            var header = GetBarrierName(await input.ReadLineAsync());
            if (header == null)
            {
                return null;
            }

            // Read the data
            List<string> dataLines = new List<string>();
            string line;
            while (!(line = await input.ReadLineAsync()).StartsWith("-"))
            {
                dataLines.Add(line);
            }
            byte[] data;
            try
            {
                data = Convert.FromBase64String(String.Concat(dataLines));
            }
            catch
            {
                return null; // Invalid Base64 String!
            }

            // Read the footer
            var footer = GetBarrierName(line);
            return new PemData(header, data, footer);
        }
开发者ID:hishamco,项目名称:Signing,代码行数:30,代码来源:PemData.cs

示例2: ReadEventsFromReader

        private async Task ReadEventsFromReader(TextReader reader, IContext context)
        {
            try
            {
                string eventLine;
                while ((eventLine = await reader.ReadLineAsync()) != null)
                {
                    CheckIfCancelled();

                    if (eventLine.StartsWith("event: "))
                    {
                        string dataLine = await reader.ReadLineAsync();

                        cts.Token.ThrowIfCancellationRequested();

                        string eventName = ParseEventLine(eventLine);
                        string json = ParseEventLine(dataLine);
                        IJsonObject tree = context.Serializer.Deserialize(json);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Expected event but received: {eventLine}");
                    }
                }
            }
            catch (TaskCanceledException)
            {
                if (!disposed)
                    throw;
            }
        }
开发者ID:snargledorf,项目名称:Sharpbase,代码行数:31,代码来源:EventListenerRequest.cs

示例3: Read

        public static Attractions Read(TextReader reader)
        {
            // ReadOne the number of attractions followed by the time between attractions.
            reader.ReadLineAsync().Result.ParseInteger().VerifyTimesCount();

            var times = from t in reader.ReadLineAsync().Result.Split(' ') select t.ParseInteger();

            return new Attractions(times);
        }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:9,代码来源:Attractions.cs

示例4: ParseMetadataAsync

        private static async Task<Article> ParseMetadataAsync(TextReader textReader, FileSystemInfo fileInfo)
        {
            var line = await textReader.ReadLineAsync().ConfigureAwait(false);

            if (line == null || !line.Equals("<!--"))
            {
                throw new FormatException($"Cannot parse the file '{fileInfo.FullName}' to an article. The first line has to begin with an XML comment tag '<!--'.");
            }

            var article = new Article();

            while ((line = await textReader.ReadLineAsync().ConfigureAwait(false)) != null && line != "-->")
            {
                var pair = line.Split(new[] { ':' }, 2, StringSplitOptions.None);

                if (pair.Length != 2)
                    continue;

                var key = pair[0].Trim().ToLower();
                var value = pair[1].Trim();

                switch (key)
                {
                    case "title":
                        article.Title = value;
                        break;

                    case "author":
                        article.Author = value;
                        break;

                    case "published":
                        DateTime publishDateTime;
                        if (DateTime.TryParse(value, out publishDateTime))
                        {
                            article.PublishDateTime = publishDateTime;
                        }
                        break;

                    case "tags":
                        var tags = value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        article.Tags = tags;
                        break;
                }
            }

            if (line != "-->")
            {
                throw new FormatException($"Cannot parse the file '{fileInfo.FullName}' to an article. Couldn't find the closing tag of the meta data block.");
            }

            return article;
        }
开发者ID:zeshan-iqbal,项目名称:DustedCodes,代码行数:53,代码来源:ArticleParser.cs

示例5: ReadOne

        private static Plan ReadOne(TextReader reader, Attractions attractions)
        {
            var count = reader.ReadLineAsync().Result
                .ParseInteger().VerifyDestinationCount(attractions);

            var destinations
                = from a in reader.ReadLineAsync().Result.Split(' ')
                    select a.ParseInteger().VerifyDestination(attractions);

            // ReSharper disable once PossibleMultipleEnumeration
            destinations.Count().VerifyValue(count);

            // ReSharper disable once PossibleMultipleEnumeration
            return new Plan(attractions, destinations);
        }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:15,代码来源:Plan.cs

示例6: ParseLabReport

        public static async Task<IEnumerable<Lab>> ParseLabReport(TextReader reader)
        {
            var labs = new List<Lab>();
            var lineNumber = 1;

            var line = await reader.ReadLineAsync();
            do
            {
                if (line != null)
                    labs.Add(await ParseLabBlock(reader, () => lineNumber, (ln) => lineNumber = ln, line));
                lineNumber++;
            }
            while ((line = await reader.ReadLineAsync()) != null);

            return labs;
        }
开发者ID:pjlammertyn,项目名称:MediDocParser,代码行数:16,代码来源:Parser.cs

示例7: ParseTextReport

        public static async Task<IEnumerable<ExecutingDoctor>> ParseTextReport(TextReader reader)
        {
            var executingDoctors = new List<ExecutingDoctor>();
            var lineNumber = 1;

            var line = await reader.ReadLineAsync();
            do
            {
                if (line != null)
                    executingDoctors.Add(await ParseTextReportDoctorBlock(reader, () => lineNumber, (ln) => lineNumber = ln, line));
                lineNumber++;
            }
            while ((line = await reader.ReadLineAsync()) != null);

            return executingDoctors;
        }
开发者ID:pjlammertyn,项目名称:MediDocParser,代码行数:16,代码来源:Parser.cs

示例8: ReadAll

        private static Frequencies ReadAll(TextReader reader, int count, Frequencies frequencies)
        {
            /* The order in which these are read can be peculiar. Watch for the roll over of the
             * clock to happen when the value is suddenly less than the former minimum. And even
             * this is not a great way of doing it without also incorporating some notion of the
             * date itself. */

            const int minutesPerDay = Constants.MinutesPerDay;

            int? previousTimeMinutes = null;

            while (count-- > 0)
            {
                var line = reader.ReadLineAsync().Result;

                var parts = line.Split(' ');

                var startingTimeMinutes = parts[0].ToMinutes();

                // Normalize when the previous was greater than this one.
                if (previousTimeMinutes > startingTimeMinutes)
                    startingTimeMinutes += minutesPerDay;

                var waitTimeMinutes = parts[1].ParseInteger();

                frequencies.Entries[startingTimeMinutes] = waitTimeMinutes;

                previousTimeMinutes = startingTimeMinutes;
            }

            return frequencies;
        }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:32,代码来源:Frequencies.cs

示例9: ReadAll

        public static IEnumerable<Plan> ReadAll(TextReader reader, Attractions attractions)
        {
            // Read the attraction queries.
            var count = reader.ReadLineAsync().Result.ParseInteger().VerifyQueryCount();

            while (count-- > 0)
                yield return ReadOne(reader, attractions);
        }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:8,代码来源:Plan.cs

示例10: ReadOne

 private static Patron ReadOne(TextReader reader)
 {
     var line = reader.ReadLineAsync().Result;
     // Accounting for discrepancies in the input file where Count > the actual Count(Patron)
     if (string.IsNullOrEmpty(line)) return null;
     var parts = line.Split(' ');
     var timeOfDayMinutes = parts[0].ToMinutes();
     var stopNumber = parts[1].ParseInteger();
     var direction = TripConstraint.Directions[parts[2][0]];
     return new Patron(timeOfDayMinutes, stopNumber, direction);
 }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:11,代码来源:Patron.cs

示例11: Read

        public static ThemePark Read(TextReader reader)
        {
            var values = from x in reader.ReadLineAsync().Result.Split(' ')
                select x.ParseInteger();

            // ReSharper disable once PossibleMultipleEnumeration
            var attractionCount = values.ElementAt(0);

            // ReSharper disable once PossibleMultipleEnumeration
            var maxHoursPerDay = values.ElementAt(1);

            var attractions = Attraction.ReadAll(reader, attractionCount).ToList();

            var result = new ThemePark(attractions, maxHoursPerDay);

            var queryCount = reader.ReadLineAsync().Result.ParseInteger();

            result.Guests = Guest.ReadAll(reader, queryCount, result).ToList();

            return result;
        }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:21,代码来源:ThemePark.cs

示例12: ReadAll

 public static IEnumerable<Patron> ReadAll(TextReader reader)
 {
     var line = reader.ReadLineAsync().Result;
     var count = line.ParseInteger();
     var result = new List<Patron>();
     while (count-- > 0)
     {
         var patron = ReadOne(reader);
         // Accounting for an error in the input file.
         if (patron == null) break;
         result.Add(patron);
     }
     return result;
 }
开发者ID:mwpowellhtx,项目名称:challenge-parks-and-transportation,代码行数:14,代码来源:Patron.cs

示例13: ReadHeaderAsync

        private static async Task<string> ReadHeaderAsync(TextReader reader, string headerName)
        {
            string line = await reader.ReadLineAsync().ConfigureAwait(false);
            if (string.IsNullOrEmpty(line))
            {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "{0} header is expected.", headerName));
            }

            string[] parts = line.Split(':');
            if (parts.Length != 2)
            {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Unexpected header format. {0} header is expected. Actual header: {1}", headerName, line));
            }

            if (parts[0] != headerName)
            {
                throw new FormatException(string.Format(CultureInfo.InvariantCulture, "{0} header is expected. Actual header: {1}", headerName, line));
            }

            return parts[1].Trim();
        }
开发者ID:JoseCarlosMM,项目名称:ApplicationInsights-dotnet,代码行数:21,代码来源:StorageTransmission.cs

示例14: ParseTextResultBlock

        static async Task<TextResult> ParseTextResultBlock(TextReader reader, Func<int> lineNumberGetter, Action<int> lineNumberSetter, IDictionary<int, IList<string>> parserErrors)
        {
            //(lijn 1:)#Rb positie 1-3:duidt begin aan van verslag)
            var result = new TextResult();
            var lineNumber = lineNumberGetter();

            //(lijn 2:) evt identificatie van de analyse (positie 1-56)
            //formaat: '!'gevolgd door trefwoord
            lineNumber++;
            var line = await reader.ReadLineAsync();
            if (line.StartsWith(@"!"))
            {
                result.Name = line?.Trim();
                lineNumber++;
                line = await reader.ReadLineAsync();
            }

            //(lijn 3: vanaf hier begint het eigenlijke verslag)
            var sb = new StringBuilder();
            do
            {
                sb.AppendLine(line);
                lineNumber++;
            }
            while ((line = (await reader.ReadLineAsync())) != null && !line.StartsWith(@"#R/"));
            result.Text = sb.Length > 0 ? sb.ToString() : null;

            lineNumberSetter(lineNumber);
            return result;
        }
开发者ID:pjlammertyn,项目名称:MediDocParser,代码行数:30,代码来源:Parser.cs

示例15: ParseAsync

        public static async Task<SourceInformationCollection> ParseAsync(TextReader reader, CancellationToken cancellationToken)
        {
            const int State_Start = 0;
            const int State_Ini = 1;
            const int State_Vars = 2;
            const int State_Files = 3;

            var vars = new Dictionary<string, SrcSrvExpression>(StringComparer.OrdinalIgnoreCase);
            var lineVars = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            var result = new SourceInformationCollection();

            var state = State_Start;
            string line;
            while ((line = await reader.ReadLineAsync()) != null)
            {
                cancellationToken.ThrowIfCancellationRequested();

                switch (state)
                {
                    case State_Start:
                        if (line.StartsWith("SRCSRV: ini"))
                            state = State_Ini;
                        break;
                    case State_Ini:
                        if (line.StartsWith("SRCSRV: variables"))
                            state = State_Vars;
                        break;
                    case State_Vars:
                        if (line.StartsWith("SRCSRV: source files"))
                        {
                            if (!vars.ContainsKey("SRCSRVTRG")) return null;
                            state = State_Files;
                        }
                        else
                        {
                            var index = line.IndexOf('=');
                            if (index > 0)
                            {
                                var var = ParseVariable(line.Substring(index + 1));
                                if (var == null) return null;
                                vars.Add(line.Substring(0, index), var);
                            }
                        }

                        break;
                    case State_Files:
                        var split = line.Split('*');
                        if (!string.IsNullOrWhiteSpace(line) && split.Length > 0)
                        {
                            lineVars.Clear();
                            for (var i = 0; i < split.Length; i++)
                                lineVars[string.Format(CultureInfo.InvariantCulture, "VAR{0}", i + 1)] = split[i];
                            var trg = vars["SRCSRVTRG"].Evaluate(vars, lineVars);
                            result.Add(new SourceInformation(split[0], trg));
                        }

                        break;
                }
            }

            return result;
        }
开发者ID:tmr232,项目名称:symblr,代码行数:62,代码来源:SrcSrvParser.cs


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