다음을 통해 공유


어댑터에 대한 사용자 지정 구성 스키마 예제

이 섹션에서는 어댑터용 구성 스키마를 사용자 지정하는 방법을 보여 주는 다음 예를 제공합니다.

  • 예제 1 에서는 baf:designer 및 baf:description 확장을 사용하여 어댑터 속성 페이지를 나타내는 전체 사용자 지정 XSD 스키마 파일을 보여 줍니다.

  • 또한 예제 2 에서는 baf:designer 및 baf:description 확장을 사용하여 1에서 99 사이의 값만 허용하는 BatchSize 속성에 대한 사용자 지정 속성 값 창을 만드는 방법을 보여 줍니다.

  • 예제 3 에서는 baf:Password를 8자로 제한하는 방법을 보여줍니다. 기본적으로 최대 22자까지 허용됩니다.

  • 예제 4 에서는 XSD 패턴이 지원되지 않으므로 속성 값에 패턴 일치 제약 조건을 구현하는 방법을 보여 줍니다.

예 1

이 예에서는 전체 사용자 지정 XSD 스키마를 보여 줍니다. 또한 baf:designer 및 baf:description 확장을 사용하여 어댑터 속성 페이지를 나타냅니다.

<?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>  

예 2

이 예제에서는 baf:designer 및 baf:description 확장을 사용하여 1에서 99 사이의 값만 허용하는 BatchSize 속성에 대한 사용자 지정 속성 값 창을 만드는 방법을 보여 줍니다.

   <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>  

예제 3

이 예에서는 baf:Password를 8자로 제한하는 방법을 보여 줍니다. 기본적으로 최대 22자까지 허용됩니다.

<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>  

예제 4

이 예에서는 XSD 패턴이 지원되지 않으므로 속성 값에 패턴 일치 제약 조건을 구현하는 방법을 보여 줍니다.

ClientIdentifier와 같은 필드는 항상 3자 숫자 문자열입니다. 속성 값 10은 올바르지 않지만 010은 유효합니다. 다음 구성 스키마 조각은 ClientIdentifier 속성을 정의합니다. 어댑터 어셈블리에 구현된 ClientIdentifierConverter 클래스는 패턴 일치를 구현합니다. 이 경우 사용자 지정 유형 변환기는 값을 정확히 3자리 문자열(000-999)로 제한합니다. 구성 스키마의 baf:converter 노드에서 어셈블리와 유형 전체 이름이 올바르게 설정되었는지 확인합니다. 사용자가 잘못된 값을 입력하면 속성 페이지에서 유효성 검사 오류가 발생할 때 예외 메시지가 표시됩니다.

어댑터 속성 페이지 구성 스키마에 다음 코드를 사용할 수 있습니다.

        <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>  

어댑터 어셈블리에 다음 코드를 배치할 수 있습니다.

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);  
              }  
       }  
}  

참고 항목

어댑터 프레임워크 구성 스키마 확장