Skip to content

Commit cf22e1d

Browse files
committed
Merge branch 'feature-newutilsversion'
2 parents 714dbf1 + b3bc374 commit cf22e1d

File tree

7 files changed

+127
-34
lines changed

7 files changed

+127
-34
lines changed

Src/ContextRegExParseAndPromote/BizTalkComponents.PipelineComponents.ContextRegExParseAndPromote.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
<AssemblyOriginatorKeyFile>BizTalkComponents.PipelineComponents.ContextRegExParseAndPromote.snk</AssemblyOriginatorKeyFile>
4040
</PropertyGroup>
4141
<ItemGroup>
42+
<Reference Include="Microsoft.BizTalk.GlobalPropertySchemas, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
4243
<Reference Include="Microsoft.BizTalk.Pipeline, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
4344
<SpecificVersion>False</SpecificVersion>
4445
<HintPath>..\..\..\..\Windows\assembly\GAC_MSIL\Microsoft.BizTalk.Pipeline\3.0.1.0__31bf3856ad364e35\Microsoft.BizTalk.Pipeline.dll</HintPath>
4546
</Reference>
47+
<Reference Include="Microsoft.XLANGs.BaseTypes, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
4648
<Reference Include="System" />
4749
<Reference Include="System.ComponentModel.DataAnnotations" />
4850
<Reference Include="System.Core" />

Src/ContextRegExParseAndPromote/BiztalkComponents.Utils/ContextExtensions.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@ namespace BizTalkComponents.Utils
55
{
66
public static class ContextExtensions
77
{
8-
public static bool TryRead(this IBaseMessageContext ctx ,ContextProperty property, out object val)
8+
public static bool TryRead<T>(this IBaseMessageContext ctx, ContextProperty property, out T val)
99
{
1010
if (property == null)
1111
{
1212
throw new ArgumentNullException("property");
1313
}
14+
object content = ctx.Read(property.PropertyName, property.PropertyNamespace);
15+
if (content is T)
16+
{
17+
val = (T)content;
18+
return true;
19+
}
20+
else
21+
{
22+
val = default(T);
23+
return false;
24+
}
25+
}
1426

15-
return ((val = ctx.Read(property.PropertyName, property.PropertyNamespace)) != null);
27+
public static bool TryRead(this IBaseMessageContext ctx, ContextProperty property, out object val)
28+
{
29+
return TryRead<object>(ctx, property, out val);
1630
}
1731

1832
public static bool TryRead(this IBaseMessageContext ctx, ContextProperty property, out string val)
1933
{
20-
if (property == null)
21-
{
22-
throw new ArgumentNullException("property");
23-
}
24-
25-
val = ctx.Read(property.PropertyName, property.PropertyNamespace) as string;
34+
TryRead<string>(ctx, property, out val);
2635

2736
return !string.IsNullOrWhiteSpace(val);
2837
}
Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,72 @@
1-
namespace BizTalkComponents.Utils
1+
using Microsoft.XLANGs.BaseTypes;
2+
3+
namespace BizTalkComponents.Utils
24
{
35
public class FileProperties
46
{
5-
public const string ReceivedFileName = "http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName";
7+
/// <summary>
8+
/// http://schemas.microsoft.com/BizTalk/2003/file-properties#ReceivedFileName
9+
/// </summary>
10+
public static readonly string ReceivedFileName = SystemProperties.GetFullyQualifiedName(new FILE.ReceivedFileName());
611
}
712

813
public class SSOTicketProperties
914
{
10-
public const string SSOTicket = "http://schemas.microsoft.com/BizTalk/2003/system-properties#SSOTicket";
15+
/// <summary>
16+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#SSOTicket
17+
/// </summary>
18+
public static readonly string SSOTicket = SystemProperties.GetFullyQualifiedName(new BTS.SSOTicket());
1119
}
1220

1321
public class SystemProperties
1422
{
15-
public const string MessageType = "http://schemas.microsoft.com/BizTalk/2003/system-properties#MessageType";
16-
public const string SchemaStrongName = "http://schemas.microsoft.com/BizTalk/2003/system-properties#SchemaStrongName";
23+
/// <summary>
24+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#MessageType
25+
/// </summary>
26+
public static readonly string MessageType = GetFullyQualifiedName(new BTS.MessageType());
27+
28+
/// <summary>
29+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#SchemaStrongName
30+
/// </summary>
31+
public static readonly string SchemaStrongName = GetFullyQualifiedName(new BTS.SchemaStrongName());
32+
33+
/// <summary>
34+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#RouteDirectToTP
35+
/// </summary>
36+
public static readonly string RouteDirectToTP = GetFullyQualifiedName(new BTS.RouteDirectToTP());
1737

18-
public const string RouteDirectToTP =
19-
"http://schemas.microsoft.com/BizTalk/2003/system-properties#RouteDirectToTP";
38+
/// <summary>
39+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#EpmRRCorrelationToken
40+
/// </summary>
41+
public static readonly string EpmRRCorrelationToken = GetFullyQualifiedName(new BTS.EpmRRCorrelationToken());
2042

21-
public const string EpmRRCorrelationToken =
22-
"http://schemas.microsoft.com/BizTalk/2003/system-properties#EpmRRCorrelationToken";
43+
/// <summary>
44+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#CorrelationToken
45+
/// </summary>
46+
public static readonly string CorrelationToken = GetFullyQualifiedName(new BTS.CorrelationToken());
2347

24-
public const string CorrelationToken =
25-
"http://schemas.microsoft.com/BizTalk/2003/system-properties#CorrelationToken";
48+
/// <summary>
49+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#IsRequestResponse
50+
/// </summary>
51+
public static readonly string IsRequestResponse = GetFullyQualifiedName(new BTS.IsRequestResponse());
2652

27-
public const string IsRequestResponse =
28-
"http://schemas.microsoft.com/BizTalk/2003/system-properties#IsRequestResponse";
53+
/// <summary>
54+
/// http://schemas.microsoft.com/BizTalk/2003/system-properties#ReqRespTransmitPipelineID
55+
/// </summary>
56+
public static readonly string ReqRespTransmitPipelineID = GetFullyQualifiedName(new BTS.ReqRespTransmitPipelineID());
2957

30-
public const string ReqRespTransmitPipelineID =
31-
"http://schemas.microsoft.com/BizTalk/2003/system-properties#ReqRespTransmitPipelineID";
58+
public static string GetFullyQualifiedName(PropertyBase propertyBase)
59+
{
60+
var qName = propertyBase.QName;
61+
return qName.Namespace + "#" + qName.Name;
62+
}
3263
}
3364

3465
public class WCFProperties
3566
{
36-
public const string OutboundHttpStatusCode =
37-
"http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties#OutboundHttpStatusCode";
67+
/// <summary>
68+
/// http://schemas.microsoft.com/BizTalk/2006/01/Adapters/WCF-properties#OutboundHttpStatusCode
69+
/// </summary>
70+
public static readonly string OutboundHttpStatusCode = SystemProperties.GetFullyQualifiedName(new WCF.OutboundHttpStatusCode());
3871
}
3972
}

Src/ContextRegExParseAndPromote/BiztalkComponents.Utils/PropertyBagHelper.cs

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
24
using Microsoft.BizTalk.Component.Interop;
35

46
namespace BizTalkComponents.Utils
@@ -21,6 +23,7 @@ public static string ToStringOrDefault(object property, string defaultValue)
2123
/// <param name="pb">Property bag</param>
2224
/// <param name="propName">Name of property</param>
2325
/// <returns>Value of the property</returns>
26+
[Obsolete("Use ReadPropertyBag<T>(IPropertyBag pb, stringPropName, T oldValue instead.")]
2427
public static object ReadPropertyBag(IPropertyBag pb, string propName)
2528
{
2629
object val = null;
@@ -39,19 +42,39 @@ public static object ReadPropertyBag(IPropertyBag pb, string propName)
3942
return val;
4043
}
4144

45+
[Obsolete("Use ReadPropertyBag<T>(IPropertyBag pb, stringPropName, T oldValue instead.")]
4246
public static T ReadPropertyBag<T>(IPropertyBag pb, string propName)
4347
{
4448
try
4549
{
4650
object val;
4751
pb.Read(propName, out val, 0);
4852

53+
return val is T ? (T)val : default(T);
54+
}
55+
catch (ArgumentException)
56+
{
57+
return default(T);
58+
}
59+
catch (Exception e)
60+
{
61+
throw new ApplicationException(e.Message);
62+
}
63+
}
64+
65+
public static T ReadPropertyBag<T>(IPropertyBag pb, string propName, T oldValue)
66+
{
67+
try
68+
{
69+
object val;
70+
pb.Read(propName, out val, 0);
71+
4972
if (val == null)
5073
{
51-
return default(T);
74+
return oldValue;
5275
}
53-
54-
return (T)val;
76+
77+
return val is T ? (T)val : default(T);
5578
}
5679
catch (ArgumentException)
5780
{
@@ -84,5 +107,31 @@ public static void WritePropertyBag(IPropertyBag pb, string propName, object val
84107
throw new ApplicationException(e.Message);
85108
}
86109
}
110+
111+
public static void WriteAll(IPropertyBag pb, object instance)
112+
{
113+
var props = GetPipelineComponentProperties(instance);
114+
115+
foreach (var prop in props)
116+
{
117+
WritePropertyBag(pb, prop.Name, prop.GetValue(instance,null));
118+
}
119+
}
120+
121+
public static void ReadAll(IPropertyBag pb, object instance)
122+
{
123+
var props = GetPipelineComponentProperties(instance);
124+
125+
foreach (var prop in props)
126+
{
127+
var oldValue = prop.GetValue(instance, null);
128+
prop.SetValue(instance, ReadPropertyBag(pb, prop.Name, oldValue), null);
129+
}
130+
}
131+
132+
private static IEnumerable<PropertyInfo> GetPipelineComponentProperties(object instance)
133+
{
134+
return instance.GetType().GetProperties();
135+
}
87136
}
88137
}

Src/ContextRegExParseAndPromote/ContextRegExParseAndPromote.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
8282

8383
public void Load(IPropertyBag propertyBag, int errorLog)
8484
{
85-
PropertyToParse = PropertyBagHelper.ReadPropertyBag<string>(propertyBag, PropertyToParsePropertyName);
86-
RegExPattern = PropertyBagHelper.ReadPropertyBag<string>(propertyBag, RegExPatternPropertyName);
87-
DestinationProperty = PropertyBagHelper.ReadPropertyBag<string>(propertyBag, DestinationPropertyPropertyName);
88-
ThrowIfNoMatch = PropertyBagHelper.ReadPropertyBag<bool>(propertyBag, ThrowIfNoMatchPropertyName);
85+
PropertyToParse = PropertyBagHelper.ReadPropertyBag(propertyBag, PropertyToParsePropertyName, PropertyToParse);
86+
RegExPattern = PropertyBagHelper.ReadPropertyBag(propertyBag, RegExPatternPropertyName, RegExPattern);
87+
DestinationProperty = PropertyBagHelper.ReadPropertyBag(propertyBag, DestinationPropertyPropertyName, DestinationProperty);
88+
ThrowIfNoMatch = PropertyBagHelper.ReadPropertyBag(propertyBag, ThrowIfNoMatchPropertyName, ThrowIfNoMatch);
8989
}
9090

9191
public void Save(IPropertyBag propertyBag, bool clearDirty, bool saveAllProperties)

Src/ContextRegExParseAndPromote/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.0.1.0")]
37+
[assembly: AssemblyInformationalVersion("1.1.0.0")]
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.5" targetFramework="net45" developmentDependency="true"/>
3+
<package id="BizTalkComponents.Utils" version="2.4.0" targetFramework="net40" developmentDependency="true" />
44
</packages>

0 commit comments

Comments
 (0)