Skip to content

Commit 3a514fd

Browse files
committed
Merge branch 'release-1.6'
2 parents 25f967e + 91f2d32 commit 3a514fd

File tree

12 files changed

+129
-7
lines changed

12 files changed

+129
-7
lines changed

Src/SetProperty/BiztalkComponents.Utils/PropertyBagHelper.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ public static object ReadPropertyBag(IPropertyBag pb, string propName)
3939
return val;
4040
}
4141

42+
public static T ReadPropertyBag<T>(IPropertyBag pb, string propName)
43+
{
44+
try
45+
{
46+
object val;
47+
pb.Read(propName, out val, 0);
48+
49+
if (val == null)
50+
{
51+
return default(T);
52+
}
53+
54+
return (T)val;
55+
}
56+
catch (ArgumentException)
57+
{
58+
return default(T);
59+
}
60+
catch (InvalidCastException)
61+
{
62+
return default(T);
63+
}
64+
catch (Exception e)
65+
{
66+
throw new ApplicationException(e.Message);
67+
}
68+
}
69+
4270
/// <summary>
4371
/// Writes property values into a property bag.
4472
/// </summary>

Src/SetProperty/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("1.6.0.0")]

Src/SetProperty/SetProperty.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public partial class SetProperty : IComponent, IBaseComponent,
1616
{
1717
private const string PropertyPathPropertyName = "PropertyPath";
1818
private const string ValuePropertyName = "Value";
19+
private const string PromoteProperytName = "Promote";
1920

2021
[DisplayName("Property Path")]
2122
[Description("The property path where the specified value will be promoted to, i.e. http://temupuri.org#MyProperty.")]
@@ -29,6 +30,11 @@ public partial class SetProperty : IComponent, IBaseComponent,
2930
[RequiredRuntime]
3031
public string Value { get; set; }
3132

33+
[DisplayName("Promote Property")]
34+
[Description("Specifies whether the property should be promoted or just written to the context.")]
35+
[RequiredRuntime]
36+
public bool PromoteProperty { get; set; }
37+
3238
public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
3339
{
3440
string errorMessage;
@@ -38,21 +44,30 @@ public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
3844
throw new ArgumentException(errorMessage);
3945
}
4046

41-
pInMsg.Context.Promote(new ContextProperty(PropertyPath), Value);
47+
if (PromoteProperty)
48+
{
49+
pInMsg.Context.Promote(new ContextProperty(PropertyPath), Value);
50+
}
51+
else
52+
{
53+
pInMsg.Context.Write(new ContextProperty(PropertyPath), Value);
54+
}
4255

4356
return pInMsg;
4457
}
4558

4659
public void Load(IPropertyBag propertyBag, int errorLog)
4760
{
48-
PropertyPath = PropertyBagHelper.ToStringOrDefault(PropertyBagHelper.ReadPropertyBag(propertyBag, PropertyPathPropertyName), string.Empty);
49-
Value = PropertyBagHelper.ToStringOrDefault(PropertyBagHelper.ReadPropertyBag(propertyBag, ValuePropertyName), string.Empty);
61+
PropertyPath = PropertyBagHelper.ReadPropertyBag<string>(propertyBag, PropertyPathPropertyName);
62+
Value = PropertyBagHelper.ReadPropertyBag<string>(propertyBag, ValuePropertyName);
63+
PromoteProperty = PropertyBagHelper.ReadPropertyBag<bool>(propertyBag, PromoteProperytName);
5064
}
5165

5266
public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)
5367
{
5468
PropertyBagHelper.WritePropertyBag(propertyBag, PropertyPathPropertyName, PropertyPath);
5569
PropertyBagHelper.WritePropertyBag(propertyBag, ValuePropertyName, Value);
70+
PropertyBagHelper.WritePropertyBag(propertyBag, PromoteProperytName, PromoteProperty);
5671
}
5772
}
5873
}

Src/SetProperty/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="BizTalkComponents.Utils" version="2.1.0.4" targetFramework="net45" />
3+
<package id="BizTalkComponents.Utils" version="2.1.0.5" targetFramework="net40" />
44
</packages>

Tests/UnitTests/SetPropertyTests.cs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ namespace BizTalkComponents.PipelineComponents.SetProperty.Tests.UnitTests
77
public class SetPropertyTests
88
{
99
[TestMethod]
10-
public void TestSetProperty()
10+
public void TestSetPropertyPromote()
1111
{
1212
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
1313
var component = new SetProperty
1414
{
1515
PropertyPath = "http://tempuri.org#MyProp",
16-
Value = "Test"
16+
Value = "Test",
17+
PromoteProperty = true
1718
};
1819

1920
pipeline.AddComponent(component, PipelineStage.Decode);
@@ -29,5 +30,55 @@ public void TestSetProperty()
2930

3031
Assert.IsTrue(output[0].Context.IsPromoted("MyProp", "http://tempuri.org"));
3132
}
33+
34+
35+
[TestMethod]
36+
public void TestSetPropertyWrite()
37+
{
38+
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
39+
var component = new SetProperty
40+
{
41+
PropertyPath = "http://tempuri.org#MyProp",
42+
Value = "Test",
43+
PromoteProperty = false
44+
};
45+
46+
pipeline.AddComponent(component, PipelineStage.Decode);
47+
48+
var message = MessageHelper.Create("<test></test>");
49+
50+
51+
Assert.IsNull(message.Context.Read("MyProp", "http://tempuri.org"));
52+
53+
var output = pipeline.Execute(message);
54+
55+
Assert.AreEqual(1, output.Count);
56+
57+
Assert.IsFalse(output[0].Context.IsPromoted("MyProp", "http://tempuri.org"));
58+
}
59+
60+
[TestMethod]
61+
public void TestSetPropertyPromotePropertyNotSet()
62+
{
63+
var pipeline = PipelineFactory.CreateEmptyReceivePipeline();
64+
var component = new SetProperty
65+
{
66+
PropertyPath = "http://tempuri.org#MyProp",
67+
Value = "Test"
68+
};
69+
70+
pipeline.AddComponent(component, PipelineStage.Decode);
71+
72+
var message = MessageHelper.Create("<test></test>");
73+
74+
75+
Assert.IsNull(message.Context.Read("MyProp", "http://tempuri.org"));
76+
77+
var output = pipeline.Execute(message);
78+
79+
Assert.AreEqual(1, output.Count);
80+
81+
Assert.IsFalse(output[0].Context.IsPromoted("MyProp", "http://tempuri.org"));
82+
}
3283
}
3384
}

packages/BizTalkComponents.Utils.2.1.0.4/BizTalkComponents.Utils.2.1.0.4.nupkg renamed to packages/BizTalkComponents.Utils.2.1.0.5/BizTalkComponents.Utils.2.1.0.5.nupkg

6.36 KB
Binary file not shown.

packages/BizTalkComponents.Utils.2.1.0.4/content/BiztalkComponents.Utils/ContextExtensions.cs renamed to packages/BizTalkComponents.Utils.2.1.0.5/content/BiztalkComponents.Utils/ContextExtensions.cs

File renamed without changes.

packages/BizTalkComponents.Utils.2.1.0.4/content/BiztalkComponents.Utils/ContextProperties.cs renamed to packages/BizTalkComponents.Utils.2.1.0.5/content/BiztalkComponents.Utils/ContextProperties.cs

File renamed without changes.

packages/BizTalkComponents.Utils.2.1.0.4/content/BiztalkComponents.Utils/ContextProperty.cs renamed to packages/BizTalkComponents.Utils.2.1.0.5/content/BiztalkComponents.Utils/ContextProperty.cs

File renamed without changes.

packages/BizTalkComponents.Utils.2.1.0.4/content/BiztalkComponents.Utils/PropertyBagHelper.cs renamed to packages/BizTalkComponents.Utils.2.1.0.5/content/BiztalkComponents.Utils/PropertyBagHelper.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ public static object ReadPropertyBag(IPropertyBag pb, string propName)
3939
return val;
4040
}
4141

42+
public static T ReadPropertyBag<T>(IPropertyBag pb, string propName)
43+
{
44+
try
45+
{
46+
object val;
47+
pb.Read(propName, out val, 0);
48+
49+
if (val == null)
50+
{
51+
return default(T);
52+
}
53+
54+
return (T)val;
55+
}
56+
catch (ArgumentException)
57+
{
58+
return default(T);
59+
}
60+
catch (InvalidCastException)
61+
{
62+
return default(T);
63+
}
64+
catch (Exception e)
65+
{
66+
throw new ApplicationException(e.Message);
67+
}
68+
}
69+
4270
/// <summary>
4371
/// Writes property values into a property bag.
4472
/// </summary>

0 commit comments

Comments
 (0)