英文:
BizTalk Server 2016: Receive a zip file and unzip it
问题
我按照以下博客中提供的确切步骤操作,但输出文件仍然是zip格式,文件大小增加,文件损坏。
请告诉我出了什么问题,以及接收管道中解压接收文件的其他方法。这是管道中使用的代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
using Ionic.Zip;
namespace UnzipMessages
{
// 类的属性
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_DisassemblingParser]
// 生成唯一标识符
[System.Runtime.InteropServices.Guid("9ABA4232-1F8E-4a45-B12D-9BE50160464B")]
public class UnzipMessageDisassembler : IBaseComponent,
IComponentUI,
IDisassemblerComponent,
IPersistPropertyBag
{
// 实现接口
// ...
public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
{
// 解压逻辑
// ...
}
public IBaseMessage GetNext(IPipelineContext pContext)
{
// 获取下一个消息
// ...
}
}
}
请提醒您,我只提供了代码部分的翻译。如果您需要关于此代码的更多帮助或解释,请随时告诉我。
英文:
I followed the exact same steps given in the following blog, but the output file is still in zip format with increase in file size and file gets corrupted.
Please tell me what is going wrong and any other ways to unzip a received file in receive pipeline. This is the code used in pipeline.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.BizTalk.Message.Interop;
using Microsoft.BizTalk.Component.Interop;
using Ionic.Zip;
namespace UnzipMessages
{
//Attributes of class
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
[ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]
//Generate unique identifier
[System.Runtime.InteropServices.Guid("9ABA4232-1F8E-4a45-B12D-9BE50160464B")]
public class UnzipMessageDisassembler:IBaseComponent,
IComponentUI,
IDisassemblerComponent,
IPersistPropertyBag
{
//Implementing Interfaces
#region IBaseComponent
private const string description = "UnzipMessages pipeline component";
private const string name = "UnzipMessageDisaasembler";
private const string version = "1.0.0.0";
public string Description
{
get
{
return description;
}
}
public string Name
{
get
{
return name;
}
}
public string Version
{
get
{
return version;
}
}
#endregion
#region IComponentUI
private IntPtr icon = new IntPtr();
public IntPtr Icon
{
get
{
return icon;
}
}
public System.Collections.IEnumerator Validate(object projectsystem)
{
return null;
}
#endregion
#region IPersistPropertyBag
public void GetClassID(out Guid classid)
{
classid = new System.Guid("9ABA4232-1F8E-4a45-B12D-9BE50160464B");
}
public void InitNew()
{
}
public void Load(IPropertyBag propertyBag, int errorlog)
{
}
public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
{
}
#endregion
#region IDisassemblerComponent
// This component will read the zipped input message as a stream and with the help
// of Zip library the message will unzipped and stored in the Queue.
private System.Collections.Queue OutFiles = new System.Collections.Queue();
public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
{
IBaseMessagePart msgBodyPart = pInMsg.BodyPart;
if (msgBodyPart != null)
{
Stream msgBodyPartStream = msgBodyPart.GetOriginalDataStream();
if (msgBodyPartStream != null)
{
using (ZipInputStream zipInputStream = new ZipInputStream(msgBodyPartStream))
{
ZipEntry entry = zipInputStream.GetNextEntry();
while (entry != null)
{
MemoryStream memStream = new MemoryStream();
byte[] buffer = new Byte[1024];
int bytesRead = 1024;
while (bytesRead != 0)
{
bytesRead = zipInputStream.Read(buffer, 0, buffer.Length);
memStream.Write(buffer, 0, bytesRead);
}
//Creating outMessage
IBaseMessage outMessage;
outMessage = pContext.GetMessageFactory().CreateMessage();
outMessage.AddPart("Body", pContext.GetMessageFactory().CreateMessagePart(), true);
memStream.Position = 0;
outMessage.BodyPart.Data = memStream;
//Creating custom context property to hold extension of file
string extension = string.Empty;
extension = entry.FileName.Substring(entry.FileName.IndexOf("."));
//Promoting the custom property
pInMsg.Context.Promote("Extension","https://DemoZip.ZipMessageProperties", extension);
outMessage.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
//Add outMessage to queue
OutFiles.Enqueue(outMessage);
entry = zipInputStream.GetNextEntry();
}
}
}
}
}
public IBaseMessage GetNext(IPipelineContext pContext)
{
if (OutFiles.Count > 0)
return (IBaseMessage)OutFiles.Dequeue();
else
return null;
}
#endregion
}
}
Thanks.
答案1
得分: 0
这是来自GitHub源的另一个示例链接:
https://github.com/BizTalkCommunity/BizTalk-PipelineComponents-Extensions-UtilityPack/blob/master/BTS2016/BizTalk.PipelineComponents.ZipFile/ZipFile.cs
英文:
here's another example from github source:
https://github.com/BizTalkCommunity/BizTalk-PipelineComponents-Extensions-UtilityPack/blob/master/BTS2016/BizTalk.PipelineComponents.ZipFile/ZipFile.cs
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论