| Devon Cochenour 2005-04-27, 5:52 pm |
| I have created a custom disassembler that is being used to do some work on a
large XML file that is received and then parsed into many smaller docs, some
work done on those docs and then sent back to bts as many small docs.
I have gotten the code to run successfully, but all that ever happens is
that I only ever get ONE document back. Its the first one of the batch of
smaller documents, but thats it. I am at a loss as to what I am missing.
The code looks like this.
public IBaseMessage GetNext(IPipelineContext pContext)
{
return disassembler.GetNext(pContext);
}
public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
{
if (null == pContext)
throw new ArgumentNullException("pContext");
if (null == pInMsg)
throw new ArgumentNullException("pInMsg");
// Check whether input message doesn't have a body part or it is set to
null, fail probe in those cases
if (null == pInMsg.BodyPart || null ==
pInMsg.BodyPart.GetOriginalDataStream())
throw new ArgumentNullException("pInMessage","The inbound message has no
message body");
Stream sourceStream = pInMsg.BodyPart.GetOriginalDataStream();
try
{
IDocumentSpec documentSpec =
pContext.GetDocumentSpecByType("urn:mdWebService#ResponseRecord");
pInMsg.Context.Write(DocumentSpecNamePropertyName, "urn:mdWebService",
documentSpec.DocSpecStrongName);
originalMsgContext = PipelineUtil.CloneMessageContext(pInMsg.Context);
xmlDoc.Load(sourceStream);
if (xmlDoc != null)
{
XmlNodeList xmlNodeList = xmlDoc.GetElementsByTagName("ResponseRecord");
string sNodeData;
sNodeData = xmlNodeList.Item(i).OuterXml;
while(i<xmlNodeList.Count)
{
XmlDocument xmlNewDoc = new XmlDocument();
xmlNewDoc.LoadXml(sNodeData);
EventLog.WriteEntry("CASS_Orchestration",xmlNewDoc.OuterXml.ToString());
MemoryStream newStream = new MemoryStream();
byte[] bData = System.Text.Encoding.UTF8.GetBytes(sNodeData);
newStream.Flush();
newStream.Write(bData,0,bData.Length);
newStream.Seek(0,SeekOrigin.Begin);
newMsg = pContext.GetMessageFactory().CreateMessage();
IBaseMessagePart newMsgPart =
pContext.GetMessageFactory().CreateMessagePart();
newMsgPart.Charset = "UTF-8";
newMsgPart.Data = newStream;
newMsg.AddPart("body", newMsgPart, true);
for (int iProp = 0; iProp < originalMsgContext.CountProperties; iProp++)
{
string strName;
string strNSpace;
object val = originalMsgContext.ReadAt(iProp, out strName, out
strNSpace);
if (originalMsgContext.IsPromoted(strName, strNSpace))
newMsg.Context.Promote(strName, strNSpace, val);
else
newMsg.Context.Write(strName, strNSpace, val);
}
pContext.ResourceTracker.AddResource(newStream);
i++;
disassembler.Disassemble(pContext,newMsg);
}
sourceStream.Seek(0,SeekOrigin.End);
}
}
--
Devon Cochenour
MCSD, MCT MSF Master Trainer
|