static IMessage MakeMessageInternal( TextMessageCapture capture, IRegex headRe, IRegex bodyRe, ref IMatch bodyMatch, IFieldsProcessor fieldsProcessor, MakeMessageFlags makeMessageFlags, DateTime sourceTime, ITimeOffsets timeOffsets, MessagesBuilderCallback threadLocalCallbackImpl ) { if (bodyRe != null) { if (!bodyRe.Match(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength, ref bodyMatch)) { return(null); } } int idx = 0; Group[] groups; fieldsProcessor.Reset(); fieldsProcessor.SetSourceTime(sourceTime); fieldsProcessor.SetPosition(capture.BeginPosition); fieldsProcessor.SetTimeOffsets(timeOffsets); groups = capture.HeaderMatch.Groups; for (int i = 1; i < groups.Length; ++i) { var g = groups[i]; fieldsProcessor.SetInputField(idx++, new StringSlice(capture.HeaderBuffer, g.Index, g.Length)); } if (bodyRe != null) { groups = bodyMatch.Groups; for (int i = 1; i < groups.Length; ++i) { var g = groups[i]; fieldsProcessor.SetInputField(idx++, new StringSlice(capture.BodyBuffer, g.Index, g.Length)); } } else { fieldsProcessor.SetInputField(idx++, new StringSlice(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength)); } threadLocalCallbackImpl.SetCurrentPosition(capture.BeginPosition, capture.EndPosition); IMessage ret; ret = fieldsProcessor.MakeMessage(threadLocalCallbackImpl, makeMessageFlags); ret.SetRawText(StringSlice.Concat(capture.MessageHeaderSlice, capture.MessageBodySlice).Trim()); return(ret); }
private async void SetTimeOffsets(ITimeOffsets value) // todo: consider converting setter to a public function { var oldOffsets = provider.TimeOffsets; if (oldOffsets.Equals(value)) { return; } var savedBookmarks = bookmarks.Items .Where(b => b.GetLogSource() == this) .Select(b => new { bmk = b, threadId = b.Thread.ID }) .ToArray(); await provider.SetTimeOffsets(value, CancellationToken.None); var invserseOld = oldOffsets.Inverse(); bookmarks.PurgeBookmarksForDisposedThreads(); foreach (var b in savedBookmarks) { var newBmkTime = b.bmk.Time.Adjust(invserseOld).Adjust(value); bookmarks.ToggleBookmark(new Bookmark( newBmkTime, logSourceThreads.GetThread(new StringSlice(b.threadId)), b.bmk.DisplayName, b.bmk.Position, b.bmk.LineIndex)); } owner.OnTimeOffsetChanged(this); using (var s = OpenSettings(false)) { s.Data.Root.SetAttributeValue("timeOffset", value.ToString()); } }
public EventInfo(Event e, ITimeOffsets timeOffsets) { evt = e; var m = (TextLogEventTrigger)e.Trigger; timestamp = m.Timestamp.Adjust(timeOffsets).ToLocalDateTime(); }
Task ILogProvider.SetTimeOffsets(ITimeOffsets value, CancellationToken cancellation) { CheckDisposed(); var ret = new SetTimeOffsetsCommandHandler(this, value); Command cmd = new Command(Command.CommandType.SetTimeOffset, LogProviderCommandPriority.AsyncUserAction, tracer, cancellation, ret); PostCommand(cmd); return(ret.Task); }
public FactoryWriter( FieldsProcessor.IMessagesBuilderCallback callback, ITimeOffsets timeOffsets, int?maxLineLen ) { this.callback = callback; this.timeOffsets = timeOffsets; this.maxLineLen = maxLineLen; states.Push(WriteState.Content); }
public void AddEvents(ITimelinePostprocessorOutput postprocessorOutput, IEnumerable <Event> events, bool isLastEventsSet) { this.currentPostprocessorOutput = postprocessorOutput; this.currentIsLastEventsSet = isLastEventsSet; this.currentTimeOffsets = postprocessorOutput.LogSource.TimeOffsets; foreach (var e in events) { e.Visit(this); } this.currentPostprocessorOutput = null; this.currentTimeOffsets = null; this.currentIsLastEventsSet = false; }
public SetTimeOffsetsCommandHandler(IAsyncLogProvider owner, ITimeOffsets timeOffsets) { this.owner = owner; this.timeOffsets = timeOffsets; }
static IMessage MakeMessageInternal(TextMessageCapture capture, XmlFormatInfo formatInfo, IRegex bodyRe, ref IMatch bodyReMatch, MessagesBuilderCallback callback, XsltArgumentList transformArgs, DateTime sourceTime, ITimeOffsets timeOffsets) { int nrOfSequentialFailures = 0; int maxNrOfSequentialFailures = 10; for (; ;) { StringBuilder messageBuf = new StringBuilder(); messageBuf.AppendFormat("<root {0}>", formatInfo.NSDeclaration.ToString()); messageBuf.Append(capture.HeaderBuffer, capture.HeaderMatch.Index, capture.HeaderMatch.Length); if (bodyRe != null) { if (!bodyRe.Match(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength, ref bodyReMatch)) { return(null); } messageBuf.Append(capture.BodyBuffer, bodyReMatch.Index, bodyReMatch.Length); } else { messageBuf.Append(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength); } messageBuf.Append("</root>"); callback.SetCurrentPosition(capture.BeginPosition, capture.EndPosition); //this.owner.xslExt.SetSourceTime(this.owner.MediaLastModified); todo? string messageStr = messageBuf.ToString(); using (FactoryWriter factoryWriter = new FactoryWriter(callback, timeOffsets)) using (XmlReader xmlReader = XmlReader.Create(new StringReader(messageStr), xmlReaderSettings)) { try { if (formatInfo.IsNativeFormat) { factoryWriter.WriteNode(xmlReader, false); } else { formatInfo.Transform.Transform(xmlReader, transformArgs, factoryWriter); } nrOfSequentialFailures = 0; } catch (XmlException) { if (capture.IsLastMessage) { // There might be incomplete XML at the end of the stream. Ignore it. return(null); } else { if (nrOfSequentialFailures < maxNrOfSequentialFailures) { ++nrOfSequentialFailures; // Try to parse the next messsage if it's not the end of the stream continue; } else { throw; } } } var ret = factoryWriter.GetOutput(); if (ret == null) { throw new XsltException( "Normalization XSLT produced no output"); } if (formatInfo.ViewOptions.RawViewAllowed) { ret.SetRawText(StringSlice.Concat(capture.MessageHeaderSlice, capture.MessageBodySlice).Trim()); } if (formatInfo.ViewOptions.WrapLineLength.HasValue) { ret.WrapsTexts(formatInfo.ViewOptions.WrapLineLength.Value); } return(ret); } } }
public FactoryWriter(IMessagesBuilderCallback callback, ITimeOffsets timeOffsets) { this.callback = callback; this.timeOffsets = timeOffsets; states.Push(WriteState.Content); }
void IFieldsProcessor.SetTimeOffsets(ITimeOffsets value) { builder.__timeOffsets = value; }
static IMessage MakeMessageInternal(TextMessageCapture capture, JsonFormatInfo formatInfo, IRegex bodyRe, ref IMatch bodyReMatch, MessagesBuilderCallback callback, DateTime sourceTime, ITimeOffsets timeOffsets) { StringBuilder messageBuf = new StringBuilder(); messageBuf.Append(capture.HeaderBuffer, capture.HeaderMatch.Index, capture.HeaderMatch.Length); if (bodyRe != null) { if (!bodyRe.Match(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength, ref bodyReMatch)) { return(null); } messageBuf.Append(capture.BodyBuffer, bodyReMatch.Index, bodyReMatch.Length); } else { messageBuf.Append(capture.BodyBuffer, capture.BodyIndex, capture.BodyLength); } callback.SetCurrentPosition(capture.BeginPosition, capture.EndPosition); string messageStr = messageBuf.ToString(); var transfromed = JsonTransformer.Transform( formatInfo.Transform.DeepClone() as JObject, JObject.Parse(messageStr) ); var d = transfromed.Property("d")?.Value; DateTime date; if (d != null && d.Type == JTokenType.String) { date = DateTime.Parse(d.ToString(), null, System.Globalization.DateTimeStyles.RoundtripKind); } else if (d != null && d.Type == JTokenType.Date) { date = (DateTime)((JValue)d).Value; } else { throw new Exception("Bad time property \"d\""); } var t = transfromed.Property("t")?.Value?.ToString(); var m = transfromed.Property("m")?.Value; var msg = ""; if (m != null) { msg = m.ToString(); } var s = transfromed.Property("s")?.Value?.ToString(); var sev = !string.IsNullOrEmpty(s) ? char.ToLower(s[0]) : 'i'; IMessage ret = new Content( capture.BeginPosition, capture.EndPosition, callback.GetThread(new StringSlice(t ?? "")), new MessageTimestamp(date), new StringSlice(msg), sev == 'i' ? SeverityFlag.Info : sev == 'e' ? SeverityFlag.Error : sev == 'w' ? SeverityFlag.Warning : SeverityFlag.Info ); if (formatInfo.ViewOptions.RawViewAllowed) { ret.SetRawText(StringSlice.Concat(capture.MessageHeaderSlice, capture.MessageBodySlice).Trim()); } if (formatInfo.ViewOptions.WrapLineLength.HasValue) { ret.WrapsTexts(formatInfo.ViewOptions.WrapLineLength.Value); } return(ret); }
public MessageTimestamp Adjust(ITimeOffsets offsets) { return(new MessageTimestamp(offsets.Get(data))); }