I have a problem, I am trying to create an unzip pipeline in the pre-assemble stage of a Send Pipeline because i have to. This is my code:
[Guid("885186F0-8846-4AD1-BC3F-D0066844B871")]
[ComponentCategory(CategoryTypes.CATID_Any)]
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
public class UnzipperComponent : IBaseComponent, IComponent, IComponentUI, IPersistPropertyBag
{
private System.Collections.Queue inboundMsgQueue = new System.Collections.Queue();
IBaseMessage IComponent.Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
Stream currentPartSource = pInMsg.BodyPart.GetOriginalDataStream();
if (pInMsg.BodyPart != null && currentPartSource != null)
{
using (MemoryStream seekableStream = new MemoryStream())
{
// Copy the content of the non-seekable stream into a seekable stream
currentPartSource.CopyTo(seekableStream);
seekableStream.Seek(0, SeekOrigin.Begin);
string filename = "";
using (var unzipArchive = new ZipArchive(seekableStream, ZipArchiveMode.Read, true))
{
foreach (var entryStream in unzipArchive.Entries)
{
IBaseMessage inboundInstanceMessage;
filename = entryStream.FullName;
using (var outStream = new MemoryStream())
{
entryStream.Open().CopyTo(outStream);
var decompressedPartBuffer = outStream.ToArray();
MemoryStream messageInstanceStream = new MemoryStream(decompressedPartBuffer);
messageInstanceStream.Position = 0;
inboundInstanceMessage = pContext.GetMessageFactory().CreateMessage();
inboundInstanceMessage.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
inboundInstanceMessage.AddPart("Body", pContext.GetMessageFactory().CreateMessagePart(), true);
inboundInstanceMessage.BodyPart.Data = messageInstanceStream;
inboundInstanceMessage.BodyPart.Charset = "UTF-8";
inboundInstanceMessage.BodyPart.ContentType = "text";
DateTime time = new DateTime();
inboundInstanceMessage.Context.Promote("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", filename + time);
pInMsg.BodyPart.Data = messageInstanceStream;
}
}
}
}
}
return pInMsg;
}
The problem is that my method only outputs one of the messages to the send location even though all messages gets processed correctly through the pipeline. It does not matter if it's PDF,XML or TXT. If I have multiple messages, it only outputs one.
I have tried to read up on how messages is written to the pInMsg ibasemessage. I have tried to use a streamreader instead but cannot get it to work.
Basically you can't do that. You can only publish multiple messages from the Disassemble stage of the Receive Pipeline, so that is where your UnZip pipeline component needs to be. Then your send port could subscribe to that Receive Port and send the messages.
See
The other option as mentioned in the other answers is to have it in an Orchestration.