-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
103 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,62 @@ | ||
using System; | ||
using Microsoft.BizTalk.Streaming; | ||
using System; | ||
using System.IO; | ||
using ICSharpCode.SharpZipLib.Core; | ||
using ICSharpCode.SharpZipLib.Zip; | ||
using Microsoft.BizTalk.Message.Interop; | ||
using System.IO.Compression; | ||
|
||
namespace BizTalkComponents.PipelineComponents.CompressMessage.Utils | ||
{ | ||
public class CompressionUtil | ||
public class CompressionUtil : IDisposable | ||
{ | ||
private readonly ZipOutputStream _zipStream; | ||
private readonly MemoryStream _outputMemStream; | ||
private readonly ZipArchive _zipArchive; | ||
private readonly Stream _outputStream; | ||
|
||
public CompressionUtil() | ||
{ | ||
_outputMemStream = new MemoryStream(); | ||
_zipStream = new ZipOutputStream(_outputMemStream); | ||
_zipStream.SetLevel(3); | ||
_outputStream = new VirtualStream(); | ||
_zipArchive = new ZipArchive(_outputStream, ZipArchiveMode.Create, true); | ||
} | ||
|
||
public void AddMessage(Stream msg, string filename) | ||
public void AddMessage(Stream msg, string filename, CompressionLevel compressionLevel = CompressionLevel.Optimal) | ||
{ | ||
var entry = new ZipEntry(filename) {DateTime = DateTime.Now}; | ||
var entry = _zipArchive.CreateEntry(filename, compressionLevel); | ||
|
||
using (var entryStream = entry.Open()) | ||
{ | ||
msg.CopyTo(entryStream); | ||
} | ||
|
||
_zipStream.PutNextEntry(entry); | ||
StreamUtils.Copy(msg, _zipStream, new byte[4096]); | ||
_zipStream.CloseEntry(); | ||
} | ||
|
||
public MemoryStream GetZip() | ||
public Stream GetZip() | ||
{ | ||
_zipStream.IsStreamOwner = false; | ||
_zipStream.Close(); | ||
_outputMemStream.Position = 0; | ||
Dispose(); | ||
_outputStream.Position = 0; | ||
|
||
return _outputStream; | ||
} | ||
|
||
return _outputMemStream; | ||
#region IDisposable Support | ||
private bool disposedValue = false; // To detect redundant calls | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
_zipArchive.Dispose(); | ||
} | ||
|
||
disposedValue = true; | ||
} | ||
} | ||
|
||
// This code added to correctly implement the disposable pattern. | ||
public void Dispose() | ||
{ | ||
// Do not change this code. Put cleanup code in Dispose(bool disposing) above. | ||
Dispose(true); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="BizTalkComponents.Utils" version="2.2.1.0" targetFramework="net45" developmentDependency="true"/> | ||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45"/> | ||
<package id="BizTalkComponents.Utils" version="2.2.1.0" targetFramework="net45" developmentDependency="true" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" /> | ||
<package id="Winterdom.BizTalk.PipelineTesting" version="1.2.2.0" targetFramework="net45" /> | ||
</packages> |