void EmitBuildParameter(LogRotateOptionsBuilder builder, string line) { var match = Regex.Match(line, @"^\s*(?<name>\S+)(\s+(?<val>.*?))?\s*$"); if (!match.Success) { throw new InvalidOperationException("invalid config " + line); } var name = match.Groups["name"].Value; var value = match.Groups["val"].Value.TrimEnd(); builder.AddBuildParameter(name, string.IsNullOrEmpty(value) ? null : value); }
private LogRotateOptionsBuilder ParseBuilder(StreamReader reader, string line) { var root = ReadRootLine(line); var builder = new LogRotateOptionsBuilder(root); bool eof = false, pre = false, post = false; while (!eof && !reader.EndOfStream) { line = reader.ReadLine(); eof = Regex.IsMatch(line, @"^\s*}\s*$"); if (!eof && !IsCommentOrEmpty(line)) { var instruction = line.Trim().ToLower(); switch (instruction) { case "endscript": pre = post = false; break; case "prerotate": pre = true; break; case "postrotate": post = true; break; default: if (pre) { builder.AddPreScripts(line); } else if (post) { builder.AddPostScripts(line); } else { EmitBuildParameter(builder, line); } break; } } } if (!eof) { throw new InvalidOperationException("missing eof }"); } return(builder); }