Examples of Custom Configuration Schemas for Adapters
This section provides the following examples for how to customize configuration schemas for adapters:
Example 1 shows a complete custom XSD schema file representing an adapter property page using the baf:designer and baf:description extensions.
Example 2 also uses the baf:designer and baf:description extensions to show how to create a custom property value window for the BatchSize property that only accepts values between 1 and 99, inclusive.
Example 3 shows how to limit the baf:Password to 8 characters. By default, it allows 22 characters.
Example 4 shows how to implement pattern-matching constraints on property values because XSD patterns are not supported.
Example 1
This example shows a complete custom XSD schema. It represents an adapter property page using the baf:designer and baf:description extensions.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd"
xmlns:baf="BiztalkAdapterFramework.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:import namespace="BiztalkAdapterFramework.xsd" />
<xs:element name="Send">
<xs:complexType>
<xs:sequence>
<xs:element name="directory" type="xs:string" />
<xs:annotation>
<xs:appinfo>
<baf:designer>
<baf:description>Enter the directory that will receive sent files..
</baf:description>
</baf:designer>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="fileName" type="" />
<xs:element name="sendBatchSize" type="xs:int" />
<xs:element name="fileCopyMode" type="CopyMode" />
<xs:element name="uri" type="xs:string" >
<xs:annotation>
<xs:appinfo>
<baf:designer>
<baf:browsable show="false" />
</baf:designer>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="CopyMode">
<xs:restriction base="xs:string">
<xs:enumeration value="Append">
<xs:annotation>
<xs:documentation>= 0</xs:documentation>
</xs:annotation>
<xs:enumeration value="Create">
<xs:annotation>
<xs:documentation>= 1</xs:documentation>
</xs:annotation>
<xs:enumeration value="CreateNew">
<xs:annotation>
<xs:documentation>= 2</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Example 2
This example uses the baf:designer and baf:description extensions to show how to create a custom property value window for the BatchSize property that only accepts values between 1 and 99, inclusive.
<xs:element name="BatchSize">
<xs:simpleType>
<xs:annotation>
<xs:appinfo>
<baf:designer>
<baf:displayname>Batch Size</baf:displayname>
<baf:description>Enter the batch size (1-99)</baf:description>
</baf:designer>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
<xs:maxInclusive value="99" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Example 3
This example shows how to limit the baf:Password to 8 characters. By default, it allows 22 characters.
<xs:element name="AdapterPassword">
<xs:simpleType>
<xs:annotation>
<xs:appinfo>
<baf:designer>
<baf:displayname>Adapter Password</baf:displayname>
<baf:description>Enter the password (up to 8 characters)</baf:description>
<baf:editor assembly="%BTSROOT%\\Developer Tools\\Microsoft.BizTalk.Adapter.Framework.dll">Microsoft.BizTalk.Adapter.Framework.ComponentModel.PasswordUITypeEditor</baf:editor>
<baf:converter assembly="%BTSROOT%\\Developer Tools\\Microsoft.BizTalk.Adapter.Framework.dll">Microsoft.BizTalk.Adapter.Framework.ComponentModel.PasswordTypeConverter</baf:converter>
</baf:designer>
</xs:appinfo>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>
Example 4
This example shows how to implement pattern-matching constraints on property values because XSD patterns are not supported.
Fields such as ClientIdentifier are always a three-character numeric string. A property value of 10 is not valid, whereas 010 is valid. The following configuration schema fragment defines a ClientIdentifier property. The ClientIdentifierConverter class, implemented in your adapter assembly, implements pattern matching. In this case, the custom type converter restricts values to a string of exactly three digits (000 to 999). In the configuration schema, make sure the baf:converter node has the assembly and type full name set correctly. If the user attempts to enter a value that is not valid, an exception message pops up when a validation error occurs in the property page.
You can use the following code in the adapter property page configuration schemas.
<xs:element name="ClientIdentifier" type="xs:string">
<xs:annotation>
<xs:appinfo>
<baf:designer>
<baf:displayname>Adapter Client</baf:displayname>
<baf:description>Enter the Adapter Client (3 digit string)</baf:description>
<baf:converter assembly="%BTSROOT%\\Developer Tools\\Microsoft.BizTalk.TestAdapter.dll">Microsoft.BizTalk.TestAdapter.ClientIdentifierConverter</baf:converter>
</baf:designer>
</xs:appinfo>
</xs:annotation>
</xs:element>
You can place the following code in your adapter assembly.
using System;
using System.ComponentModel;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Microsoft.BizTalk.TestAdapter
{
/// <summary>
/// Summary description for ClientIdentifierConverter.
/// </summary>
public class ClientIdentifierConverter : System.ComponentModel.StringConverter
{
private void Validate(string value)
{
Regex regex = new Regex(@"^\d{3}$"); // ^=begin, \d=digit, {3}=exactly 3 occurrences, $=end
Match match = regex.Match((string)value);
if (!match.Success)
{
throw new ApplicationException("Value does not match pattern \"" + regex.ToString() + "\".");
}
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
this.Validate((string)value);
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (typeof(string) == destinationType && value is string)
{
this.Validate((string)value);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}