コード例 #1
0
ファイル: LogReader.cs プロジェクト: mookid8000/Kafkaesque
        IEnumerable <LogEvent> ReadUsing(StreamReader reader, string filePath, CancellationToken cancellationToken, bool throwWhenCancelled)
        {
            var fileNumber  = FileSnap.Create(filePath).FileNumber;
            var lineCounter = 0;

            try
            {
                using (reader)
                {
                    string line;

                    var firstIteration = true;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (throwWhenCancelled)
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                        }
                        else if (cancellationToken.IsCancellationRequested)
                        {
                            yield break;
                        }

                        if (!line.EndsWith("#"))
                        {
                            _logger.Verbose($"Line {line} did not end with #");
                            yield break;
                        }

                        lineCounter++;

                        if (firstIteration)
                        {
                            _logger.Verbose($"Successfully initiated read operation from file {filePath}");
                            firstIteration = false;
                        }

                        var position = reader.GetBytePosition();
                        var data     = Convert.FromBase64String(line.Substring(0, line.Length - 1));

                        yield return(new LogEvent(data, fileNumber, position));
                    }
                }
            }
            finally
            {
                if (lineCounter > 0)
                {
                    _logger.Verbose($"Successfully read {lineCounter} lines from file {filePath}");
                }
            }
        }
コード例 #2
0
ファイル: LogWriter.cs プロジェクト: mookid8000/Kafkaesque
        async Task DeleteFile(FileSnap file, CancellationToken cancellationToken)
        {
            var filePath = file.FilePath;

            try
            {
                File.Delete(filePath);
                _logger.Verbose($"Deleted file {filePath}");
            }
            catch (Exception exception)
            {
                throw new IOException($"Could not delete file {filePath}", exception);
            }
        }