Ejemplo n.º 1
0
        public object Parse(string value, object argument)
        {
            var bytes = Encoding.UTF8.GetBytes(value.ToCharArray());
            using (var ms = new MemoryStream(bytes)) {
                var scanner = new Scanner(ms);
                var parser = new Parser(scanner);
                parser.Parse();

                var sn = int.Parse(Regex.Match(value, @"(\d+)$").Value);
                return MessageInfo.FromBodyPart(parser.Root, sn, value);
            }
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            if (!File.Exists("log.txt")) {
                File.Create("log.txt");
            } else {
                var date = DateTime.Now;
                // copy old log
                File.Copy("log.txt", "log.txt " + date.ToString("'('yyyy'.'MM'.'dd HH'.'mm'.'ss'Z'')'"));
                // clearing old file
                File.WriteAllText("log.txt", string.Empty);
            }
            const string name = "1000 structures.txt";
            using (var fs = new FileStream(name, FileMode.Open)) {
                using (var sr = new StreamReader(fs)) {
                    Console.SetBufferSize(800, 600);
                    while (true) {
                        var line = sr.ReadLine();
                        if (line == null) {
                            break;
                        }

                        // * 1 FETCH (BODYSTRUCTURE (...) )
                        Console.WriteLine(line);
                        using (var sfs = File.Open("log.txt", FileMode.Append, FileAccess.Write)) {
                            using (var sw = new StreamWriter(sfs)) {
                                sw.WriteLine(line);
                            }
                        }

                        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(line))) {
                            ms.Seek(0, SeekOrigin.Begin);
                            var scanner = new Scanner(ms);
                            var parser = new Parser(scanner) {errors = {errorStream = new StreamWriter(new FileStream("log.txt", FileMode.Append, FileAccess.Write, FileShare.Read))}};
                            try {
                                parser.Parse();
                                parser.errors.errorStream.Close();
                            }
                            catch (Exception ex) {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            Console.ReadKey(true);
        }
Ejemplo n.º 3
0
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
     errors = new Errors();
 }