Esempio n. 1
0
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            LeakReader lr = new LeakReader(3, @"D:\leaks");

            tsc = new CancellationTokenSource();
            InputProgress prog;

            using (LeakSaver ls = new LeakSaver(3, @"D:\leaks"))
            {
                li = new LeakInput(@"D:\dropbox", ls, lr);
                Task <InputProgress> inputTask = li.SortAllAsync(tsc.Token);
                Console.ReadLine();
                tsc.Cancel();
                Console.WriteLine("Stopping");
                prog = await inputTask;
                Console.WriteLine("Stopped inputing waiting for flush");
            }

            if (prog.IsDone)
            {
                System.Collections.Generic.IEnumerable <string> res = await lr.Lookup("ric");
            }
            else
            {
                Console.WriteLine("Progress: {0}%\t Done: {1}\tinMB: {2}", prog.Percentage * 100, prog.Completed, prog.Completed / 1000 / 1000);
                Console.Read();
            }
        }
Esempio n. 2
0
        public LeakInput(string path, LeakSaver leakSaver, LeakReader lr) : this(path, leakSaver)
        {
            //hack to get around no use of async await
            Task t = Task.Run(async() =>
            {
                //do a 'binary search' in the stream
                long lowerBound    = 0;
                long upperBound    = streamReader.BaseStream.Length;
                const long minDist = 5 * 1000;//start looking line by line at 5kb
                while (upperBound - lowerBound > minDist)
                {
                    long middle = (lowerBound + upperBound) / 2;

                    // print a nice graphic
                    const long glen         = 100;
                    long maxLen             = streamReader.BaseStream.Length;
                    long gLpos              = (glen * lowerBound) / maxLen;
                    long gMpos              = (glen * middle) / maxLen;
                    long gUpos              = (glen * upperBound) / maxLen;
                    char[] gdata            = new string(' ', (int)glen + 2).ToCharArray();
                    gdata[0]                = '[';
                    gdata[gdata.Length - 1] = ']';
                    if (gLpos != gMpos && gMpos != gUpos)
                    {
                        gdata[gLpos + 1] = '<';
                        gdata[gMpos + 1] = '.';
                        gdata[gUpos + 1] = '>';
                        Console.WriteLine(new string(gdata));
                    }


                    streamReader.BaseStream.Position = middle;
                    streamReader.DiscardBufferedData();
                    // read partial line
                    await streamReader.ReadLineAsync();
                    string line = await streamReader.ReadLineAsync();
                    if (await lr.HasResult(line))
                    {
                        lowerBound = middle - 1000; // offset because partial lines
                    }
                    else
                    {
                        upperBound = middle + 1000; // offset because partial lines
                    }
                }
                streamReader.BaseStream.Position = lowerBound;
                streamReader.DiscardBufferedData();
                await streamReader.ReadLineAsync();

                while (true)
                {
                    string line = await streamReader.ReadLineAsync();
                    if (!(await lr.HasResult(line)))
                    {
                        await leakSaver.SaveLine(line);
                        break;
                    }
                }
                Console.WriteLine("Skipped aprox. {0}MB", streamReader.BaseStream.Position / (1000 * 1000));
            });

            t.Wait();
        }