.txt文件,格式如下
1115151651515950000055 00012913702613000000000003000 139C0000007000000 1215151651121510000054 00022913803603000000000009000 000279A0000009000 1315115950000065516515 00032813104643000000000007000 000399B0000003000 121515160003290003290000010000000003000
前3行是身体元素,但身体部位的行数将是未知的(可能从1到无界)。身体部位没有标签标识符。文件中的最后一行始终是预告片。在解析之前要删除文件中的预告片,以便只需要解析记录。修复自定义管道组件以将标签添加到正文部分。 但是当我将工具箱中的组件添加到接收样式“管道组件负载()在IPersistPropertyBag实现上失败”时显示错误“
管道组件的代码是,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
namespace PipelinezTrailerPrj
{
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]
[System.Runtime.InteropServices.Guid("6118B8F0-8684-4ba2-87B4-8336D70BD4F7")]
public class CRemoveTrailer : IBaseComponent, IComponentUI, IComponent, IPersistPropertyBag
{
#region IBaseComponent
public string Description
{
get
{
return "Pipeline component used to delete the Trailer in The Incoming messages";
}
}
public string Name
{
get
{
return "CRemoveTrailer";
}
}
public string Version
{
get
{
return "1.0.0.0";
}
}
#endregion
#region IComponentUI
public IntPtr Icon
{
get
{
return new System.IntPtr();
}
}
public System.Collections.IEnumerator Validate(object projectSystem)
{
return null;
}
#endregion
#region IPersistPropertyBag
private string _NewNameSpace;
public string NewNameSpace
{
get { return _NewNameSpace; }
set { _NewNameSpace = value; }
}
public void GetClassID(out Guid classID)
{
classID = new Guid("ACC3F15A-C389-4a5d-8F8E-2A951CDC4C19");
}
public void InitNew()
{
}
public void Load(IPropertyBag propertyBag, int errorLog)
{
object val = null;
try
{
propertyBag.Read("PipelinezTrailerPrj", out val, 0);
}
catch (Exception ex)
{
throw new ApplicationException("Error reading propertybag: " + ex.Message);
}
if (val != null)
_NewNameSpace = (string)val;
else
_NewNameSpace = "http://PipelinezTrailerPrj";
}
public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
{
object val = (object)_NewNameSpace;
propertyBag.Write("PipelinezTrailerPrj", ref val);
}
#endregion
#region IComponent
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
{
if (pContext == null) throw new ArgumentNullException("pContext");
if (pInMsg == null) throw new ArgumentNullException("pInMsg");
IPipelineContext pipelineContext = pContext;
IBaseMessage baseMessage = pInMsg;
//Validate parameters
string partName;
for (int i = 0; i < baseMessage.PartCount; i++)
{
MemoryStream outStream = new MemoryStream();
partName = null;
IBaseMessagePart part = baseMessage.GetPartByIndex(i, out partName);
StreamReader reader = new StreamReader(part.GetOriginalDataStream());
string partBody = reader.ReadToEnd();
StreamWriter writer = new StreamWriter(outStream, new UTF8Encoding());
string[] separator = new string[] {"\r\n"};
string[] strArray = partBody.Split(separator, StringSplitOptions.None);
for (int n = 0; n < strArray.Length; n++)
{
//There will be a blank string in the last line of the array. So we don't need to add tag to the last 2 lines.
if (n < (strArray.Length - 2))
{
strArray[n] = "BODY" + strArray[n];
}
//Add the line break back.
writer.Write(strArray[n] + "\r\n");
}
writer.Flush();
outStream.Seek(0, SeekOrigin.Begin);
part.Data = outStream;
}
return baseMessage;
}
#endregion
}
}
答案 0 :(得分:0)
看看propertyBag.Read抛出一个异常然后你抓住它并抛出一个applicationException。
请参阅this article,与您的问题相同。建议的方法是
propertyBag.Read("System", strValue, errorLog)