Beispiel #1
0
        public static int ParseValueReadings(FileReadContainer fileReadContainer, int columnIndex, string timeSpan)
        {
            int      count = 0;
            DateTime?first = null;

            for (int i = fileReadContainer.CurrentLineCount; i > 0; i--)
            {
                if (fileReadContainer.Values[count] == null)
                {
                    fileReadContainer.Values[count] = new ValueReadingDto();
                }
                if (StringParser.TryParseLine(fileReadContainer.Lines[i - 1].Chars, columnIndex, fileReadContainer.Values[count]))
                {
                    DateTime dt = DateTime.Parse(fileReadContainer.Values[count].DateTime);
                    if (!first.HasValue)
                    {
                        first = dt;
                    }
                    if (!TimePeriods.IsDateWithinBoundry(dt, first.Value, timeSpan))
                    {
                        break;
                    }
                    count++;
                }
            }
            return(count);
        }
Beispiel #2
0
        private static void ReadLine(StreamReader reader, FileReadContainer fileReadContainer)
        {
            if (fileReadContainer.Lines[fileReadContainer.CurrentLineCount] == null)
            {
                fileReadContainer.Lines[fileReadContainer.CurrentLineCount] = new TextLine(fileReadContainer.ConstantLineLength);
            }
            int  charIndex = 0;
            char ch        = '\0';

            do
            {
                ch = (char)reader.Read();
                if (charIndex >= fileReadContainer.Lines[fileReadContainer.CurrentLineCount].Chars.Length)
                {
                    throw new Exception("Trying to read more chars than allocated by graph_line_length");
                }
                fileReadContainer.Lines[fileReadContainer.CurrentLineCount].Chars[charIndex++] = ch;
            } while (ch != NEWLINE);
        }
Beispiel #3
0
 private bool ReadAllLines(string filePath, FileReadContainer fileReadContainer)
 {
     try {
         using (var reader = new StreamReader(filePath)) {
             while (!reader.EndOfStream)
             {
                 ReadLine(reader, fileReadContainer);
                 fileReadContainer.CurrentLineCount++;
                 if (fileReadContainer.CurrentLineCount >= fileReadContainer.Lines.Length)
                 {
                     throw new Exception($"Trying to read more lines than allocated by graph_line_count for {filePath}.");
                 }
             }
             reader.Close();
             return(true);
         }
     } catch (Exception ex) {
         Console.WriteLine(ex);
     }
     return(false);
 }
Beispiel #4
0
        private static async Task <bool> ReadAllLinesToFileReadContainerAsync(string filePath, FileReadContainer fileReadContainer)
        {
            using var sourceStream =
                      new FileStream(
                          filePath,
                          FileMode.Open, FileAccess.Read, FileShare.Read,
                          bufferSize: 4096, useAsync: true);

            byte[] buffer = new byte[0x1000];
            int    numRead;
            int    currentCharPos = 0;

            while ((numRead = await sourceStream.ReadAsync(buffer, 0, buffer.Length)) != 0)
            {
                for (int i = 0; i < numRead; i++)
                {
                    char ch = Convert.ToChar(buffer[i]);
                    if (fileReadContainer.Lines[fileReadContainer.CurrentLineCount] == null)
                    {
                        fileReadContainer.Lines[fileReadContainer.CurrentLineCount] = new TextLine(fileReadContainer.ConstantLineLength);
                    }
                    fileReadContainer.Lines[fileReadContainer.CurrentLineCount].Chars[currentCharPos++] = ch;
                    if (currentCharPos >= fileReadContainer.Lines[fileReadContainer.CurrentLineCount].Chars.Length)
                    {
                        throw new Exception("Trying to read more chars than allocated by graph_line_length");
                    }
                    if (ch == '\n')
                    {
                        fileReadContainer.CurrentLineCount++;
                        currentCharPos = 0;
                    }
                }
            }
            return(true);
        }
Beispiel #5
0
 public Task <bool> ReadAllLinesAsync(string filePath, FileReadContainer fileReadContainer)
 {
     return(ReadAllLinesToFileReadContainerAsync(filePath, fileReadContainer));
 }