Ejemplo n.º 1
0
        public void TextWriterTraceListener_FindPrevMessagePositionTest()
        {
            var testLog =
                @"SampleApp Information: 0 : No free data file found. Going sleep.
  ProcessId=4756
  ThreadId=7
  DateTime=2011-07-12T12:10:00.0000000Z
SampleApp Information: 0 : Searching for data files
  ProcessId=4756
  ThreadId=7
  DateTime=2011-07-12T12:12:00.0000000Z
SampleApp Information: 0 : No free data file found. Going sleep.
  ProcessId=4756
  ThreadId=7
  DateTime=2011-07-12T12:14:00.0000000Z
";

            using (StringStreamMedia media = new StringStreamMedia(testLog, Encoding.ASCII))
                using (ILogSourceThreadsInternal threads = new LogSourceThreads())
                    using (IPositionedMessagesReader reader = CreateFactory().CreateMessagesReader(new MediaBasedReaderParams(threads, media, new TempFilesManager(), new TraceSourceFactory())))
                    {
                        reader.UpdateAvailableBounds(false);
                        long?prevMessagePos = PositionedMessagesUtils.FindPrevMessagePosition(reader, 0x0000004A);
                        Assert.IsTrue(prevMessagePos.HasValue);
                        Assert.AreEqual(0, prevMessagePos.Value);
                    }
        }
Ejemplo n.º 2
0
        public static void Test(IMediaBasedReaderFactory factory, ILogMedia media, ExpectedLog expectation)
        {
            using (ILogSourceThreadsInternal threads = new LogSourceThreads())
                using (IPositionedMessagesReader reader = factory.CreateMessagesReader(new MediaBasedReaderParams(threads, media, tempFilesManager, new TraceSourceFactory())))
                {
                    reader.UpdateAvailableBounds(false);

                    List <IMessage> msgs = new List <IMessage>();

                    using (var parser = reader.CreateParser(new CreateParserParams(reader.BeginPosition)))
                    {
                        for (; ;)
                        {
                            var msg = parser.ReadNext();
                            if (msg == null)
                            {
                                break;
                            }
                            msgs.Add(msg);
                        }
                    }

                    expectation.StartVerification();
                    for (int i = 0; i < msgs.Count; ++i)
                    {
                        expectation.Verify(i, msgs[i]);
                    }
                    expectation.FinishVerification();
                }
        }
Ejemplo n.º 3
0
        public static async Task Test(IMediaBasedReaderFactory factory, ILogMedia media, ExpectedLog expectation)
        {
            using (ILogSourceThreadsInternal threads = new LogSourceThreads())
                using (IPositionedMessagesReader reader = factory.CreateMessagesReader(new MediaBasedReaderParams(threads, media)))
                {
                    await reader.UpdateAvailableBounds(false);

                    List <IMessage> msgs = new List <IMessage>();

                    await DisposableAsync.Using(await reader.CreateParser(new CreateParserParams(reader.BeginPosition)), async parser =>
                    {
                        for (; ;)
                        {
                            var msg = await parser.ReadNext();
                            if (msg == null)
                            {
                                break;
                            }
                            msgs.Add(msg);
                        }
                    });

                    expectation.StartVerification();
                    for (int i = 0; i < msgs.Count; ++i)
                    {
                        expectation.Verify(i, msgs[i]);
                    }
                    expectation.FinishVerification();
                }
        }
        public static void Test(IMediaBasedReaderFactory factory, ILogMedia media, ExpectedLog expectation)
        {
            using (ILogSourceThreads threads = new LogSourceThreads())
                using (IPositionedMessagesReader reader = factory.CreateMessagesReader(new MediaBasedReaderParams(threads, media, tempFilesManager)))
                {
                    reader.UpdateAvailableBounds(false);

                    List <IMessage> msgs = new List <IMessage>();

                    using (var parser = reader.CreateParser(new CreateParserParams(reader.BeginPosition)))
                    {
                        for (; ;)
                        {
                            var msg = parser.ReadNext();
                            if (msg == null)
                            {
                                break;
                            }
                            msgs.Add(msg);
                        }
                    }

                    expectation.StartVerification();
                    int frameLevel = 0;
                    for (int i = 0; i < msgs.Count; ++i)
                    {
                        switch (msgs[i].Flags & MessageFlag.TypeMask)
                        {
                        case MessageFlag.StartFrame:
                            ++frameLevel;
                            break;

                        case MessageFlag.EndFrame:
                            --frameLevel;
                            break;
                        }

                        expectation.Verify(i, msgs[i], frameLevel);
                    }
                    expectation.FinishVerification();
                }
        }
Ejemplo n.º 5
0
        async Task <PreprocessingStepParams> ExecuteInternal(IPreprocessingStepCallback callback)
        {
            await callback.BecomeLongRunning();

            string factoryName = @params.Argument;

            callback.TempFilesCleanupList.Add(@params.Location);
            Action <double?> setStepDescription = prctComplete =>
            {
                var str = new StringBuilder();
                str.Append(@params.FullPath);
                str.Append(": fixing timestamp anomalies...");
                if (prctComplete != null)
                {
                    str.AppendFormat(" {0}%", (int)(prctComplete.Value * 100));
                }
                callback.SetStepDescription(str.ToString());
            };

            setStepDescription(null);

            string tmpFileName = callback.TempFilesManager.GenerateNewName();

            var factoryNameSplit = factoryName.Split('\\');

            if (factoryNameSplit.Length != 2)
            {
                throw new InvalidFormatException();
            }
            var factory = logProviderFactoryRegistry.Find(factoryNameSplit[0], factoryNameSplit[1]);

            if (factory == null)
            {
                throw new InvalidDataException("factory not found: " + factoryName);
            }
            var readerFactory = factory as IMediaBasedReaderFactory;

            if (readerFactory == null)
            {
                throw new InvalidDataException("bad factory: " + factoryName);
            }
            using (ILogMedia fileMedia = await SimpleFileMedia.Create(fileSystem,
                                                                      SimpleFileMedia.CreateConnectionParamsFromFileName(@params.Location)))
                using (ILogSourceThreadsInternal threads = new LogSourceThreads())
                    using (var reader = readerFactory.CreateMessagesReader(
                               new MediaBasedReaderParams(threads, fileMedia)))
                    {
                        var readerImpl = reader as MediaBasedPositionedMessagesReader;         // todo: do not use real classes; have stream encoding in an interface.
                        if (readerImpl == null)
                        {
                            throw new InvalidDataException("bad reader was made by factory " + factoryName);
                        }
                        await reader.UpdateAvailableBounds(false);

                        var    range    = new FileRange.Range(reader.BeginPosition, reader.EndPosition);
                        double rangeLen = range.Length;
                        using (var progress = progressAggregator.CreateProgressSink())
                            using (var writer = new StreamWriter(tmpFileName, false, readerImpl.StreamEncoding))
                                await DisposableAsync.Using(await reader.CreateParser(new CreateParserParams(reader.BeginPosition,
                                                                                                             flags: MessagesParserFlag.DisableDejitter | MessagesParserFlag.HintParserWillBeUsedForMassiveSequentialReading)), async parser =>
                                {
                                    var queue = new VCSKicksCollection.PriorityQueue <IMessage>(
                                        new MessagesComparer(ignoreConnectionIds: true));
                                    Action dequeue          = () => writer.WriteLine(queue.Dequeue().RawText.ToString());
                                    double lastPrctComplete = 0;
                                    var cancellation        = callback.Cancellation;
                                    for (long msgIdx = 0;; ++msgIdx)
                                    {
                                        if (cancellation.IsCancellationRequested)
                                        {
                                            break;
                                        }
                                        var msg = await parser.ReadNext();
                                        if (msg == null)
                                        {
                                            break;
                                        }
                                        if ((msgIdx % progressUpdateThreshold) == 0 && rangeLen > 0)
                                        {
                                            var prctComplete = (double)(msg.Position - range.Begin) / rangeLen;
                                            progress.SetValue(prctComplete);
                                            if (prctComplete - lastPrctComplete > 0.05)
                                            {
                                                setStepDescription(prctComplete);
                                                lastPrctComplete = prctComplete;
                                            }
                                        }
                                        queue.Enqueue(msg);
                                        if (queue.Count > queueSize)
                                        {
                                            dequeue();
                                        }
                                    }
                                    while (queue.Count > 0)
                                    {
                                        dequeue();
                                    }
                                });
                    }

            return(new PreprocessingStepParams(
                       tmpFileName,
                       @params.FullPath + " (reordered)",
                       @params.PreprocessingHistory.Add(new PreprocessingHistoryItem(name, factoryName))
                       ));
        }