public NativeXMLFormatFactory(ITempFilesManager tempFiles, IRegexFactory regexFactory, ITraceSourceFactory traceSourceFactory) { this.tempFiles = tempFiles; this.regexFactory = regexFactory; this.traceSourceFactory = traceSourceFactory; this.nativeFormatInfo = XmlFormatInfo.MakeNativeFormatInfo("utf-8", null, new FormatViewOptions(), regexFactory); }
public MessagesReader(MediaBasedReaderParams readerParams, XmlFormatInfo fmt) : base(readerParams.Media, fmt.BeginFinder, fmt.EndFinder, fmt.ExtensionsInitData, fmt.TextStreamPositioningParams, readerParams.Flags, readerParams.SettingsAccessor) { this.formatInfo = fmt; this.threads = readerParams.Threads; this.transformArgs = new XsltArgumentList(); this.xslExt = new LogJointXSLExtension(); transformArgs.AddExtensionObject(Properties.LogJointNS, this.xslExt); foreach (MessagesReaderExtensions.ExtensionData extInfo in this.Extensions.Items) { transformArgs.AddExtensionObject(Properties.LogJointNS + extInfo.Name, extInfo.Instance()); } }
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); } } }