Ejemplo n.º 1
0
        public static IEnumerable<GoogleCodeIssue> Parse(TextReader reader)
        {
            Debug.Assert(reader != null);

            var firstLine = reader.ReadLine();
            if (string.IsNullOrEmpty(firstLine))
                return Enumerable.Empty<GoogleCodeIssue>();

            var headers = ParseValues(firstLine).ToArray();

            var bindings = Enum.GetNames(typeof(GoogleCodeIssue.IssueField))
                .Select(n => Array.FindIndex(headers, h => n.Equals(h, StringComparison.OrdinalIgnoreCase)))
                .Select(i => (Func<IEnumerable<string>, string>)(values => values.ElementAtOrDefault(i) ?? string.Empty))
                .ToArray();

            return //...
                from line in reader.ReadLines()
                let values = ParseValues(line).ToArray()
                let id = ParseInteger(bindings[(int)GoogleCodeIssue.IssueField.Id](values), CultureInfo.InvariantCulture)
                where id != null && id.Value > 0
                let issue = new GoogleCodeIssue
                {
                    Id = id.Value,
                    Type = bindings[(int)GoogleCodeIssue.IssueField.Type](values),
                    Status = bindings[(int)GoogleCodeIssue.IssueField.Status](values),
                    Milestone = bindings[(int)GoogleCodeIssue.IssueField.Milestone](values),
                    Priority = bindings[(int)GoogleCodeIssue.IssueField.Priority](values),
                    Stars = bindings[(int)GoogleCodeIssue.IssueField.Stars](values),
                    Owner = bindings[(int)GoogleCodeIssue.IssueField.Owner](values),
                    Summary = bindings[(int)GoogleCodeIssue.IssueField.Summary](values)
                }
                select issue;
        }
Ejemplo n.º 2
0
 public static IEnumerable<VectorPairs> ParseFileText(TextReader stringReader)
 {
     return stringReader
         .ReadLines()
         .Skip(1)
         .ChunkBySize(3)
         .Select(problem => ParseProblem(problem[1], problem[2]));
 }
Ejemplo n.º 3
0
        /// <summary>
        ///   The method executes the passed delegate /lambda expression) for all lines of the text reader.
        /// </summary>
        /// <param name="reader"> The text reader. </param>
        /// <param name="action"> The action. </param>
        /// <example>
        /// <code>
        /// using(var reader = fileInfo.OpenText())
        /// {
        ///     reader.IterateLines(l => Console.WriteLine(l));
        /// }
        /// </code>
        /// </example>
        public static void ForEachReadLines(this TextReader reader, Action <String> action)
        {
            if (default(TextReader) == reader || default(Action <String>) == action)
            {
                return;
            }

            //foreach (var line in reader.ReadLines())
            //    action(line);
            // -------------------------------
            reader.ReadLines().ForEach(action);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Parses the TZDB time zone info file from the given reader and merges its information
 /// with the given database. The reader is not closed or disposed.
 /// </summary>
 /// <param name="reader">The reader to read.</param>
 /// <param name="database">The database to fill.</param>
 internal void Parse(TextReader reader, TzdbDatabase database)
 {
     string currentZone = null;
     foreach (var line in reader.ReadLines())
     {
         currentZone = ParseLine(line, currentZone, database);
     }
 }
Ejemplo n.º 5
0
 public static bool TryParseAsDynamic(TextReader textReader, out object dynamicValue)
 {
     HRONDynamicParseError[] errors;
     return HRONSerializer.TryParseDynamic(
         int.MaxValue,
         textReader.ReadLines().Select(s => s.ToSubString()),
         out dynamicValue,
         out errors
         );
 }
Ejemplo n.º 6
0
        public static bool TryParse(TextReader textReader, IVisitor visitor)
        {
            if (visitor == null)
            {
                return false;
            }

            var translatingVisitor = new TranslatingVisitor(visitor);
            HRONSerializer.Parse(
                int.MaxValue,
                textReader.ReadLines().Select(s => s.ToSubString()),
                translatingVisitor
                );
            return translatingVisitor.ErrorCount == 0;
        }