Пример #1
0
        protected void ParallelWork(int n)
        {
            int i = 0;
            int m = (Count.HasValue ? Count.Value : Files.Length);
            ThreadStart work = () => {
                var p = new RagelParser();
                p.AddEvent((_) => { });
                while (i < m) {
                    Tuple<FileInfo, ArraySegment<byte>> tmp;
                    if (files.TryDequeue(out tmp)) {
                        ReadFile(p, tmp);
                        i++;
                    }
                }
            };

            Thread[] threads = new Thread[n];
            for (int j = 0; j < threads.Length; j++) {
                threads[j] = new Thread(work);
                threads[j].Start();
            }

            foreach (var thread in threads) {
                thread.Join();
            }
        }
Пример #2
0
 public override void ReadLine(RagelParser parser, ArraySegment<byte> line)
 {
     parser.Parse(line);
 }
Пример #3
0
Файл: Test.cs Проект: txdv/psi
 public override void ReadLine(RagelParser parser, ArraySegment<byte> line)
 {
     if (!parser.Parse(line)) {
         Console.WriteLine(Encoding.ASCII.GetString(line));
     }
 }
Пример #4
0
 protected virtual void ReadFile(RagelParser parser, Tuple<FileInfo, ArraySegment<byte>> data)
 {
     ReadFile(parser, data.Item1, data.Item2);
 }
Пример #5
0
 public abstract void ReadLine(RagelParser parser, ArraySegment<byte> line);
Пример #6
0
 protected virtual void ReadFile(RagelParser parser, FileInfo fi, ArraySegment<byte> file)
 {
     int start = file.Offset;
     int end = file.Offset + file.Count;
     int pos = start;
     byte[] data = file.Array;
     for (int j = start; j < end; j++) {
         if (data[j] == '\n') {
             ReadLine(parser, new ArraySegment<byte>(data, pos, j - pos));
             j++;
             pos = j;
         }
     }
 }