public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg) { IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(0x280, 0x100000); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream, 0x280); string tempFile = Path.GetTempFileName(); using (FileStream fs = new FileStream(tempFile, FileMode.Open, FileAccess.Write, FileShare.Read)) { byte[] buffer = new byte[0x280]; int bytesRead = readOnlySeekableStream.Read(buffer, 0, buffer.Length); while (bytesRead != 0) { fs.Write(buffer, 0, bytesRead); fs.Flush(); bytesRead = readOnlySeekableStream.Read(buffer, 0, buffer.Length); } } VirtualStream outputStream = new VirtualStream(); using (XmlWriter xw = XmlWriter.Create(outputStream)) { const string NameSpace = "http://Codit.LFT.Schemas"; xw.WriteStartDocument(); xw.WriteStartElement("ns0", "LFT", NameSpace); xw.WriteElementString("TempFile", tempFile); xw.WriteEndDocument(); } outputStream.Position = 0; pContext.ResourceTracker.AddResource(outputStream); pInMsg.BodyPart.Data = outputStream; return pInMsg; }
public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage, string objectArgument) { var callToken = TraceProvider.Logger.TraceIn(this.Name); try { byte CR = 13; byte LF = 10; byte EQ = 61; // get original stream Stream messageStream = new ReadOnlySeekableStream(inputMessage.BodyPart.GetOriginalDataStream()); messageStream.Seek(0, SeekOrigin.Begin); pipelineContext.ResourceTracker.AddResource(messageStream); using (FileStream fs = new FileStream(string.Format("c:\\temp\\{0}.{1}.txt", Guid.NewGuid().ToString(), DateTime.Now.Ticks), FileMode.CreateNew)) { while (true) { byte[] buffer = new byte[1024]; int m = messageStream.Read(buffer, 0, 1024); if (m > 0) { for (int j = 0; j < m; j++) { int i = Convert.ToInt32(buffer[j]); List <byte> newBuffer = new List <byte>(); newBuffer.Add(buffer[j]); newBuffer.Add(EQ); newBuffer.AddRange(Encoding.UTF8.GetBytes("" + i).ToList <byte>()); newBuffer.Add(CR); fs.Write(newBuffer.ToArray(), 0, newBuffer.Count); } } else { break; } } } originalMessage = inputMessage; return(inputMessage); } catch (Exception ex) { // put component name as a source information in this exception, // so the event log in message could reflect this ex.Source = this.Name; TraceProvider.Logger.TraceError(ex); throw ex; } finally { TraceProvider.Logger.TraceOut(callToken, this.Name); } }
/// <summary> /// Output new IBaseMessage output from a file. /// </summary> /// <param name="pContext"></param> /// <param name="pInMsg"></param> /// <returns></returns> public Microsoft.BizTalk.Message.Interop.IBaseMessage Execute(IPipelineContext pContext, Microsoft.BizTalk.Message.Interop.IBaseMessage pInMsg) { IBaseMessagePart bodyPart = pInMsg.BodyPart; Stream inboundStream = bodyPart.GetOriginalDataStream(); VirtualStream virtualStream = new VirtualStream(0x280, 0x100000); ReadOnlySeekableStream readOnlySeekableStream = new ReadOnlySeekableStream(inboundStream, virtualStream, 0x280); string tempFile = Path.GetTempFileName(); using (FileStream fs = new FileStream(tempFile, FileMode.Open, FileAccess.Write, FileShare.Read)) { byte[] buffer = new byte[0x280]; int bytesRead = readOnlySeekableStream.Read(buffer, 0, buffer.Length); while (bytesRead != 0) { fs.Write(buffer, 0, bytesRead); fs.Flush(); bytesRead = readOnlySeekableStream.Read(buffer, 0, buffer.Length); } } VirtualStream outputStream = new VirtualStream(); using (XmlWriter xw = XmlWriter.Create(outputStream)) { const string NameSpace = "http://Codit.LFT.Schemas"; xw.WriteStartDocument(); xw.WriteStartElement("ns0", "LFT", NameSpace); xw.WriteElementString("TempFile", tempFile); xw.WriteEndDocument(); } outputStream.Position = 0; pContext.ResourceTracker.AddResource(outputStream); pInMsg.BodyPart.Data = outputStream; return(pInMsg); }