Beispiel #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);
                    }
        }
Beispiel #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();
                }
        }
        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 bool Update()
            {
                using (owner.trace.NewNamedFrame("Updating {0}", this.fileName))
                {
                    CheckDisposed();

                    try
                    {
                        if (simpleMedia == null)
                        {
                            owner.trace.Info("SimpleMedia object not created yet. Creating");
                            simpleMedia = new SimpleFileMedia(
                                owner.fileSystem,
                                SimpleFileMedia.CreateConnectionParamsFromFileName(Path.Combine(owner.baseDirectory, FileName))
                                );
                        }

                        owner.trace.Info("Updating simple media");
                        simpleMedia.Update();

                        if (!simpleMedia.IsAvailable)
                        {
                            owner.trace.Info("File is not avaliable (i.e. has been deleted)");
                            return(false);
                        }

                        if (firstMessageTime == null)
                        {
                            owner.trace.Info("First message time is unknown. Calcalating it");
                            using (IPositionedMessagesReader reader = (IPositionedMessagesReader)Activator.CreateInstance(
                                       owner.logReaderType, new MediaBasedReaderParams(owner.tempThreads, SimpleMedia, owner.tempFilesManager), owner.logFormatInfo))
                            {
                                owner.trace.Info("Reader created");

                                reader.UpdateAvailableBounds(false);
                                owner.trace.Info("Bounds found");

                                IMessage first = PositionedMessagesUtils.ReadNearestMessage(reader, reader.BeginPosition);
                                if (first == null)
                                {
                                    owner.trace.Warning("No messages found");
                                    return(false);
                                }

                                owner.trace.Info("First message: {0} '{1}'", first.Time, first.Text);
                                firstMessageTime = first.Time;
                            }
                        }

                        owner.trace.Info("Part updated OK");
                        return(true);
                    }
                    catch (Exception e)
                    {
                        owner.trace.Error(e, "Failure during part update");
                        return(false);
                    }
                }
            }
        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();
                }
        }