Skip to content

Commit ab1f04b

Browse files
committed
Merge branch 'release-2.0'
2 parents 9c94583 + f70e4a6 commit ab1f04b

9 files changed

+182
-14
lines changed

BizTalkComponents.PipelineComponents.HttpDisassembler.sln

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@ EndProject
2020
Global
2121
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2222
Debug|Any CPU = Debug|Any CPU
23+
NugetRelease|Any CPU = NugetRelease|Any CPU
2324
Release|Any CPU = Release|Any CPU
2425
EndGlobalSection
2526
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2627
{4A6C8864-B06F-455E-A375-51F658673A72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2728
{4A6C8864-B06F-455E-A375-51F658673A72}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{4A6C8864-B06F-455E-A375-51F658673A72}.NugetRelease|Any CPU.ActiveCfg = NugetRelease|Any CPU
30+
{4A6C8864-B06F-455E-A375-51F658673A72}.NugetRelease|Any CPU.Build.0 = NugetRelease|Any CPU
2831
{4A6C8864-B06F-455E-A375-51F658673A72}.Release|Any CPU.ActiveCfg = Release|Any CPU
2932
{4A6C8864-B06F-455E-A375-51F658673A72}.Release|Any CPU.Build.0 = Release|Any CPU
3033
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3134
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.NugetRelease|Any CPU.ActiveCfg = NugetRelease|Any CPU
36+
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.NugetRelease|Any CPU.Build.0 = NugetRelease|Any CPU
3237
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.Release|Any CPU.ActiveCfg = Release|Any CPU
3338
{C52BFE1D-5760-4F69-BA03-43E34CA4F837}.Release|Any CPU.Build.0 = Release|Any CPU
3439
EndGlobalSection

Build/Build.proj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
<PropertyGroup>
66
<DestinationPath>.</DestinationPath>
77
<ApplicationName>BizTalkComponents.PipelineComponents.HttpDisassembler</ApplicationName>
8+
<Configuration></Configuration>
89
</PropertyGroup>
910
<ItemGroup>
10-
<Resource Include="..\Src\HttpDisassembler\bin\Debug\BizTalkComponents.PipelineComponents.HttpDisassembler.dll" />
11-
</ItemGroup>
11+
<Resource Include="..\Src\HttpDisassembler\bin\$(Configuration)\BizTalkComponents.PipelineComponents.HttpDisassembler.dll" />
12+
<Resource Include="..\packages\Microsoft.ApplicationInsights.2.0.1\lib\net45\Microsoft.ApplicationInsights.dll" />
13+
<Resource Include="..\packages\BizTalkComponents.Utilities.ComponentInstrumentation.1.0.0\lib\net45\BizTalkComponents.Utilities.ComponentInstrumentation.dll" />
14+
</ItemGroup>
1215
<Target Name="GetVersion">
13-
<MSBuild.ExtensionPack.Framework.Assembly TaskAction="GetInfo" NetAssembly="..\Src\HttpDisassembler\bin\Debug\BizTalkComponents.PipelineComponents.HttpDisassembler.dll">
16+
<MSBuild.ExtensionPack.Framework.Assembly TaskAction="GetInfo" NetAssembly="..\Src\HttpDisassembler\bin\$(Configuration)\BizTalkComponents.PipelineComponents.HttpDisassembler.dll">
1417
<Output TaskParameter="OutputItems" ItemName="Info"/>
1518
</MSBuild.ExtensionPack.Framework.Assembly>
1619
</Target>
@@ -23,4 +26,4 @@
2326
SourceLocation="C:\%(Info.AssemblyInformationalVersion)"
2427
Resources="@(Resource)" />
2528
</Target>
26-
</Project>
29+
</Project>

Src/HttpDisassembler/BizTalkComponents.PipelineComponents.HttpDisassembler.csproj

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>BizTalkComponents.PipelineComponents.HttpDisassembler</RootNamespace>
1111
<AssemblyName>BizTalkComponents.PipelineComponents.HttpDisassembler</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
1515
<RestorePackages>true</RestorePackages>
@@ -23,6 +23,7 @@
2323
<DefineConstants>DEBUG;TRACE</DefineConstants>
2424
<ErrorReport>prompt</ErrorReport>
2525
<WarningLevel>4</WarningLevel>
26+
<Prefer32Bit>false</Prefer32Bit>
2627
</PropertyGroup>
2728
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
2829
<DebugType>pdbonly</DebugType>
@@ -31,18 +32,40 @@
3132
<DefineConstants>TRACE</DefineConstants>
3233
<ErrorReport>prompt</ErrorReport>
3334
<WarningLevel>4</WarningLevel>
35+
<Prefer32Bit>false</Prefer32Bit>
3436
</PropertyGroup>
3537
<PropertyGroup>
3638
<SignAssembly>true</SignAssembly>
3739
</PropertyGroup>
3840
<PropertyGroup>
3941
<AssemblyOriginatorKeyFile>BizTalkComponents.HttpDisassembler.snk</AssemblyOriginatorKeyFile>
4042
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NugetRelease|AnyCPU'">
44+
<DebugSymbols>true</DebugSymbols>
45+
<OutputPath>bin\NugetRelease\</OutputPath>
46+
<DefineConstants>TRACE;DEBUG;tracking</DefineConstants>
47+
<DebugType>full</DebugType>
48+
<PlatformTarget>AnyCPU</PlatformTarget>
49+
<ErrorReport>prompt</ErrorReport>
50+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
51+
</PropertyGroup>
4152
<ItemGroup>
53+
<Reference Include="BizTalkComponents.Utilities.ComponentInstrumentation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8fc5a9041a4c00c5, processorArchitecture=MSIL">
54+
<HintPath>..\..\packages\BizTalkComponents.Utilities.ComponentInstrumentation.1.0.0\lib\net45\BizTalkComponents.Utilities.ComponentInstrumentation.dll</HintPath>
55+
<Private>True</Private>
56+
</Reference>
57+
<Reference Include="Microsoft.ApplicationInsights, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
58+
<HintPath>..\..\packages\Microsoft.ApplicationInsights.2.0.1\lib\net45\Microsoft.ApplicationInsights.dll</HintPath>
59+
<Private>True</Private>
60+
</Reference>
4261
<Reference Include="Microsoft.BizTalk.Pipeline, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4362
<SpecificVersion>False</SpecificVersion>
4463
<HintPath>..\..\..\..\..\Windows\assembly\GAC_MSIL\Microsoft.BizTalk.Pipeline\3.0.1.0__31bf3856ad364e35\Microsoft.BizTalk.Pipeline.dll</HintPath>
4564
</Reference>
65+
<Reference Include="Microsoft.BizTalk.Streaming, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
66+
<SpecificVersion>False</SpecificVersion>
67+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Microsoft BizTalk Server 2013\Microsoft.BizTalk.Streaming.dll</HintPath>
68+
</Reference>
4669
<Reference Include="Microsoft.XLANGs.RuntimeTypes, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
4770
<Reference Include="System" />
4871
<Reference Include="System.ComponentModel.DataAnnotations" />
@@ -67,6 +90,7 @@
6790
<ItemGroup>
6891
<None Include="BizTalkComponents.HttpDisassembler.snk" />
6992
<None Include="BizTalkComponents.PipelineComponents.HttpDisassembler.nuspec" />
93+
<None Include="packages.config" />
7094
</ItemGroup>
7195
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7296
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

Src/HttpDisassembler/BizTalkComponents.PipelineComponents.HttpDisassembler.nuspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
<releaseNotes>Initial release.</releaseNotes>
1111
<copyright>Copyright 2014</copyright>
1212
<tags>BizTalk</tags>
13+
<dependencies>
14+
<dependency id="BizTalkComponents.Utilities.ComponentInstrumentation" version="1.0" />
15+
</dependencies>
1316
</metadata>
1417
</package>

Src/HttpDisassembler/HttpDisassembler.cs

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,33 @@
99
using Microsoft.BizTalk.Message.Interop;
1010
using Microsoft.XLANGs.RuntimeTypes;
1111
using BizTalkComponents.Utils;
12+
using BizTalkComponents.Utilities.ComponentInstrumentation;
13+
using System.Runtime.InteropServices;
14+
using Microsoft.BizTalk.Streaming;
1215

1316
namespace BizTalkComponents.PipelineComponents.HttpDisassembler
1417
{
18+
1519
[System.Runtime.InteropServices.Guid("FE75A97A-EB7C-49AF-8778-136FA366A5F4")]
1620
[ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
1721
[ComponentCategory(CategoryTypes.CATID_DisassemblingParser)]
1822
public partial class HttpDisassembler : IBaseComponent, IPersistPropertyBag, IComponentUI, IDisassemblerComponent
1923
{
2024
private const string DocumentSpecNamePropertyName = "DocumentSpecName";
2125
private readonly Queue _outputQueue = new Queue();
26+
private readonly ComponentInstrumentationHelper _instrumentationHelper;
2227

28+
#if tracking
29+
public HttpDisassembler()
30+
{
31+
_instrumentationHelper = new ComponentInstrumentationHelper(new AppInsightsComponentTracker("insert key here"), Name);
32+
}
33+
#else
34+
public HttpDisassembler()
35+
{
36+
_instrumentationHelper = new ComponentInstrumentationHelper(new TraceComponentTracker(), Name);
37+
}
38+
#endif
2339
[RequiredRuntime]
2440
[DisplayName("DocumentSpecName")]
2541
[Description("DocumentSpec name of the schema to create an instance from.")]
@@ -31,11 +47,27 @@ public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
3147

3248
if (!Validate(out errorMessage))
3349
{
34-
throw new ArgumentException(errorMessage);
50+
var ex = new ArgumentException(errorMessage);
51+
_instrumentationHelper.TrackComponentError(ex);
52+
throw ex;
3553
}
3654

55+
var data = pInMsg.BodyPart.GetOriginalDataStream();
56+
57+
//Determine of the request body has any data. GET request will not have any body.
58+
var hasData = HasData(data);
59+
3760
//Get a reference to the BizTalk schema.
38-
var documentSpec = (DocumentSpec)pContext.GetDocumentSpecByName(DocumentSpecName);
61+
DocumentSpec documentSpec;
62+
try
63+
{
64+
documentSpec = (DocumentSpec)pContext.GetDocumentSpecByName(DocumentSpecName);
65+
}
66+
catch (COMException cex)
67+
{
68+
_instrumentationHelper.TrackComponentError(cex);
69+
throw cex;
70+
}
3971

4072
//Get a list of properties defined in the schema.
4173
var annotations = documentSpec.GetPropertyAnnotationEnumerator();
@@ -64,13 +96,29 @@ public void Disassemble(IPipelineContext pContext, IBaseMessage pInMsg)
6496
ms.Seek(0, SeekOrigin.Begin);
6597

6698
var outMsg = pInMsg;
67-
outMsg.BodyPart.Data = ms;
6899

69-
//Promote message type and SchemaStrongName
70-
outMsg.Context.Promote(new ContextProperty(SystemProperties.MessageType), documentSpec.DocType);
71-
outMsg.Context.Promote(new ContextProperty(SystemProperties.SchemaStrongName), documentSpec.DocSpecStrongName);
100+
//If the request has a body it should be preserved an the query parameters should be written to it's own message part.
101+
if (hasData)
102+
{
103+
outMsg = pInMsg;
104+
outMsg.BodyPart.Data = pInMsg.BodyPart.Data;
105+
outMsg.Context = PipelineUtil.CloneMessageContext(pInMsg.Context);
106+
var factory = pContext.GetMessageFactory();
107+
var queryPart = factory.CreateMessagePart();
108+
queryPart.Data = ms;
109+
110+
outMsg.AddPart("querypart", queryPart, false);
111+
}
112+
else
113+
{
114+
outMsg.BodyPart.Data = ms;
115+
//Promote message type and SchemaStrongName
116+
outMsg.Context.Promote(new ContextProperty(SystemProperties.MessageType), documentSpec.DocType);
117+
outMsg.Context.Promote(new ContextProperty(SystemProperties.SchemaStrongName), documentSpec.DocSpecStrongName);
118+
}
72119

73120
_outputQueue.Enqueue(outMsg);
121+
_instrumentationHelper.TrackComponentSuccess();
74122

75123
}
76124

@@ -93,5 +141,23 @@ public IBaseMessage GetNext(IPipelineContext pContext)
93141

94142
return null;
95143
}
144+
145+
private bool HasData(Stream data)
146+
{
147+
byte[] buffer= new byte[10];
148+
const int bufferSize = 0x280;
149+
const int thresholdSize = 0x100000;
150+
151+
if (!data.CanSeek || !data.CanRead)
152+
{
153+
data = new ReadOnlySeekableStream(data, new VirtualStream(bufferSize, thresholdSize), bufferSize);
154+
}
155+
156+
int num = data.Read(buffer, 0, buffer.Length);
157+
data.Seek(0, SeekOrigin.Begin);
158+
data.Position = 0;
159+
160+
return num > 0;
161+
}
96162
}
97163
}

Src/HttpDisassembler/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
// [assembly: AssemblyVersion("1.0.*")]
3535
[assembly: AssemblyVersion("1.0.0.0")]
3636
[assembly: AssemblyFileVersion("1.0.0.0")]
37-
[assembly: AssemblyInformationalVersion("1.5.0.0")]
37+
[assembly: AssemblyInformationalVersion("2.0.0.0")]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="BizTalkComponents.Utilities.ComponentInstrumentation" version="1.0.0" targetFramework="net45" />
34
<package id="BizTalkComponents.Utils" version="2.1.0.4" targetFramework="net45" developmentDependency="true" />
5+
<package id="Microsoft.ApplicationInsights" version="2.0.1" targetFramework="net45" />
46
</packages>

Tests/UnitTests/BizTalkComponents.HttpDisassembler.Tests.UnitTests.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
55
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -18,6 +18,7 @@
1818
<TestProjectType>UnitTest</TestProjectType>
1919
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
2020
<RestorePackages>true</RestorePackages>
21+
<TargetFrameworkProfile />
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2324
<DebugSymbols>true</DebugSymbols>
@@ -36,6 +37,15 @@
3637
<ErrorReport>prompt</ErrorReport>
3738
<WarningLevel>4</WarningLevel>
3839
</PropertyGroup>
40+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'NugetRelease|AnyCPU'">
41+
<DebugSymbols>true</DebugSymbols>
42+
<OutputPath>bin\NugetRelease\</OutputPath>
43+
<DefineConstants>DEBUG;TRACE</DefineConstants>
44+
<DebugType>full</DebugType>
45+
<PlatformTarget>AnyCPU</PlatformTarget>
46+
<ErrorReport>prompt</ErrorReport>
47+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
48+
</PropertyGroup>
3949
<ItemGroup>
4050
<Reference Include="BizTalkComponents.Utils, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87c265fe42e38fa5, processorArchitecture=MSIL">
4151
<SpecificVersion>False</SpecificVersion>

Tests/UnitTests/HttpDisassemblerTest.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.VisualStudio.TestTools.UnitTesting;
44
using Winterdom.BizTalk.PipelineTesting;
55
using BizTalkComponents.Utils.ContextPropertyHelpers;
6+
using System.Runtime.InteropServices;
67

78
namespace BizTalkComponents.HttpDisassembler.Tests.UnitTests
89
{
@@ -30,11 +31,65 @@ public void CreateMessageTest()
3031
var result = pipeline.Execute(message);
3132

3233
Assert.AreEqual(1, result.Count);
34+
Assert.AreEqual(1, result[0].PartCount);
3335

3436
var doc = XDocument.Load(result[0].BodyPart.GetOriginalDataStream());
3537

3638
Assert.AreEqual("value1", doc.Descendants("TestElement1").Single().Value);
3739
Assert.AreEqual("value2", doc.Descendants("TestElement2").Single().Value);
3840
}
41+
42+
[TestMethod]
43+
public void CreateMessageWithBodyTest()
44+
{
45+
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
46+
47+
pipeline.AddDocSpec(typeof(TestSchema));
48+
49+
var disassembler = new PipelineComponents.HttpDisassembler.HttpDisassembler
50+
{
51+
DocumentSpecName = "BizTalkComponents.HttpDisassembler.Tests.UnitTests.TestSchema"
52+
};
53+
string testMessage = "<testmessage></testmessage>";
54+
var message = MessageHelper.CreateFromString(testMessage);
55+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty1"), "value1");
56+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty2"), "value2");
57+
58+
pipeline.AddComponent(disassembler, PipelineStage.Disassemble);
59+
60+
var result = pipeline.Execute(message);
61+
62+
Assert.AreEqual(1, result.Count);
63+
Assert.AreEqual(2, result[0].PartCount);
64+
65+
var doc = XDocument.Load(result[0].GetPart("querypart").GetOriginalDataStream());
66+
var bodyDoc = XDocument.Load(result[0].BodyPart.GetOriginalDataStream());
67+
68+
Assert.AreEqual("value1", doc.Descendants("TestElement1").Single().Value);
69+
Assert.AreEqual("value2", doc.Descendants("TestElement2").Single().Value);
70+
Assert.AreEqual(testMessage, bodyDoc.ToString());
71+
}
72+
73+
[TestMethod]
74+
[ExpectedException(typeof(COMException))]
75+
public void UnknownDocType()
76+
{
77+
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
78+
79+
pipeline.AddDocSpec(typeof(TestSchema));
80+
81+
var disassembler = new PipelineComponents.HttpDisassembler.HttpDisassembler
82+
{
83+
DocumentSpecName = "Schema"
84+
};
85+
86+
var message = MessageHelper.CreateFromString(string.Empty);
87+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty1"), "value1");
88+
message.Context.Promote(new ContextProperty("http://BiztalkComponents.PropertySchema#TestProperty2"), "value2");
89+
90+
pipeline.AddComponent(disassembler, PipelineStage.Disassemble);
91+
92+
var result = pipeline.Execute(message);
93+
}
3994
}
4095
}

0 commit comments

Comments
 (0)