Share via


ProviderConnectionPoint 생성자

정의

ProviderConnectionPoint 클래스의 새 인스턴스를 초기화합니다.

public:
 ProviderConnectionPoint(System::Reflection::MethodInfo ^ callbackMethod, Type ^ interfaceType, Type ^ controlType, System::String ^ displayName, System::String ^ id, bool allowsMultipleConnections);
public ProviderConnectionPoint (System.Reflection.MethodInfo callbackMethod, Type interfaceType, Type controlType, string displayName, string id, bool allowsMultipleConnections);
new System.Web.UI.WebControls.WebParts.ProviderConnectionPoint : System.Reflection.MethodInfo * Type * Type * string * string * bool -> System.Web.UI.WebControls.WebParts.ProviderConnectionPoint
Public Sub New (callbackMethod As MethodInfo, interfaceType As Type, controlType As Type, displayName As String, id As String, allowsMultipleConnections As Boolean)

매개 변수

callbackMethod
MethodInfo

연결을 설정하기 위해 소비자에게 인터페이스 인스턴스를 반환하는 공급자 컨트롤의 메서드입니다.

interfaceType
Type

공급자가 소비자에게 제공하는 인터페이스의 Type입니다.

controlType
Type

공급자 연결 지점과 관련된 공급자 컨트롤의 Type입니다.

displayName
String

연결 UI(사용자 인터페이스)에서 사용자에게 표시되는 공급자 연결 지점의 표시 이름입니다.

id
String

공급자 연결 지점의 고유 식별자입니다.

allowsMultipleConnections
Boolean

공급자 연결 지점에 소비자와의 연결이 동시에 여러 개 있을 수 있는지 여부를 나타내는 부울 값입니다.

예외

callbackMethod이(가) null인 경우

또는 interfaceType이(가) null인 경우

또는 controlType이(가) null인 경우

또는 displayNamenull 또는 빈 문자열("")인 경우

controlType이 공급자 컨트롤 또는 이 컨트롤에서 파생된 유효한 클래스의 형식과 동일하지 않은 경우

예제

다음 코드 예제에서는 클래스에서 ProviderConnectionPoint 파생하여 사용자 지정 공급자 연결 지점을 만드는 방법을 보여 줍니다.

이 코드 예제는 세 부분으로 구성 합니다.

  • 공급자 WebPart 컨트롤, 소비자 WebPart 컨트롤 및 사용자 지정 ProviderConnectionPoint 개체를 포함하는 소스 파일입니다.

  • 정적 연결에서 컨트롤을 호스트하는 웹 페이지입니다.

  • 예제 코드를 실행하는 방법에 대한 설명입니다.

코드 예제의 첫 번째 부분은 공급자 및 소비자 WebPart 컨트롤의 소스와 이름이 지정된 TableProviderConnectionPoint사용자 지정 ProviderConnectionPoint 클래스입니다. 클래스의 TableProviderConnectionPoint 생성자는 매개 변수 섹션에 표시된 대로 필수 매개 변수를 전달하여 기본 생성자를 호출합니다. 또한 클래스 GetConnectionInterface 에서 TableProviderWebPart 메서드는 연결에 대한 콜백 메서드로 지정되고 특성은 ConnectionProvider 사용자 지정 TableProviderConnectionPoint 을 매개 변수로 선언합니다. 사용자 지정 공급자 연결 지점을 만든 다음 공급자 컨트롤과 연결하는 방법을 보여 줍니다. 이 예제에서는 소스 코드를 동적으로 컴파일할 소스 코드 파일을 웹 애플리케이션의 App_Code 하위 폴더에 배치 해야 하므로

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

//This sample code creates a Web Parts control that acts as a provider of table data.
namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
    public sealed class TableProviderWebPart : WebPart, IWebPartTable
    {
        DataTable _table;

        public TableProviderWebPart()
        {
            _table = new DataTable();

            DataColumn col = new DataColumn();
            col.DataType = typeof(string);
            col.ColumnName = "Name";
            _table.Columns.Add(col);

            col = new DataColumn();
            col.DataType = typeof(string);
            col.ColumnName = "Address";
            _table.Columns.Add(col);

            col = new DataColumn();
            col.DataType = typeof(int);
            col.ColumnName = "ZIP Code";
            _table.Columns.Add(col);

            DataRow row = _table.NewRow();
            row["Name"] = "John Q. Public";
            row["Address"] = "123 Main Street";
            row["ZIP Code"] = 98000;
            _table.Rows.Add(row);
        }

        public PropertyDescriptorCollection Schema
        {
            get
            {
                return TypeDescriptor.GetProperties(_table.DefaultView[0]);
            }
        }
        public void GetTableData(TableCallback callback)
        {
                callback(_table.Rows);
        }

        public bool ConnectionPointEnabled
        {
            get
            {
                object o = ViewState["ConnectionPointEnabled"];
                return (o != null) ? (bool)o : true;
            }
            set
            {
                ViewState["ConnectionPointEnabled"] = value;
            }
        }

        [ConnectionProvider("Table", typeof(TableProviderConnectionPoint), AllowsMultipleConnections = true)]
        public IWebPartTable GetConnectionInterface()
        {
            return new TableProviderWebPart();
        }

        public class TableProviderConnectionPoint : ProviderConnectionPoint
        {
            public TableProviderConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
            string name, string id, bool allowsMultipleConnections) : base(
                callbackMethod, interfaceType, controlType,
                name, id, allowsMultipleConnections)
            {
            }
            public override bool GetEnabled(Control control)
            {
                return ((TableProviderWebPart)control).ConnectionPointEnabled;
            }
        }
    }
    
    // This code sample demonstrates a custom WebPart controls that acts as 
    // a consumer in a Web Parts connection.
  [AspNetHostingPermission(SecurityAction.Demand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  [AspNetHostingPermission(SecurityAction.InheritanceDemand,
    Level = AspNetHostingPermissionLevel.Minimal)]
  public class TableConsumer : WebPart
  {
    private IWebPartTable _provider;
    private ICollection _tableData;

    private void GetTableData(object tableData)
    {
      _tableData = (ICollection)tableData;
    }

    protected override void OnPreRender(EventArgs e)
    {
      if (_provider != null)
      {
        _provider.GetTableData(new TableCallback(GetTableData));
      }
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
      if (_provider != null)
      {
        PropertyDescriptorCollection props = _provider.Schema;
        int count = 0;
        if (props != null && props.Count > 0 && _tableData != null)
        {
          foreach (PropertyDescriptor prop in props)
          {
            foreach (DataRow o in _tableData)
            {
              writer.Write(prop.DisplayName + ": " + o[count]);
            }
            writer.WriteBreak();
            writer.WriteLine();
            count = count + 1;
          }
        }
        else
        {
          writer.Write("No data");
        }
      }
      else
      {
        writer.Write("Not connected");
      }
    }
    [ConnectionConsumer("Table")]
    public void SetConnectionInterface(IWebPartTable provider)
    {
      _provider = provider;
    }

    public class TableConsumerConnectionPoint : ConsumerConnectionPoint
    {
      public TableConsumerConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
      string name, string id, bool allowsMultipleConnections)
        : base(
        callbackMethod, interfaceType, controlType,
        name, id, allowsMultipleConnections)
      {
      }
    }
  }
}

코드 예제의 두 번째 부분은 정적 웹 파트 연결에서 사용자 지정 컨트롤을 호스트하는 웹 페이지입니다. 페이지 맨 위에는 Register 사용자 지정 컨트롤의 접두사 및 네임스페이스를 선언하는 지시문이 있습니다. 연결은 요소를 사용하여 <asp:webpartconnection> 선언되고 공급자 및 소비자 컨트롤은 요소 내에서 <asp:webpartzone> 선언됩니다.

<%@ page language="C#" %>
<%@ register tagprefix="aspSample" 
    namespace="Samples.AspNet.CS.Controls" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>IField Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:webpartmanager id="WebPartManager1" runat="server">
            <StaticConnections>
                <asp:WebPartConnection id="wp1" ProviderID="provider1" ConsumerID="consumer1">
                </asp:WebPartConnection>
            </StaticConnections>
        </asp:webpartmanager>
        <asp:webpartzone id="WebPartZone1" runat="server">
          <zoneTemplate>
            <aspSample:TableProviderWebPart ID="provider1" runat="server" 
              ToolTip="Web Parts Table Provider Control" />
            <aspSample:TableConsumer ID="consumer1" runat="server" 
              ToolTip="Web Parts Table Consumer Control"/>
          </zoneTemplate>
        </asp:webpartzone>
    </div>
    </form>
</body>
</html>

브라우저에서 페이지를 로드 합니다. 컨트롤 간의 연결이 이미 있으며, 연결이 페이지에서 정적 연결로 선언되었기 때문에 소비자는 공급자의 데이터를 표시합니다.

설명

ProviderConnectionPoint 클래스의 ProviderConnectionPoint 생성자는 단순히 기본 생성자를 호출하여 다양한 매개 변수로 전달하고 기본 클래스를 초기화합니다.

기본 클래스 생성자는 연결점에 대한 여러 매개 변수를 확인하고 몇 가지 예외를 throw할 수 있습니다. 가능한 예외 목록은 예외 섹션을 참조하세요.

생성자를 호출 ProviderConnectionPoint 하여 클래스의 고유한 인스턴스를 ProviderConnectionPoint 만들 수 있습니다. 그러나 단순히 연결을 설정하고 클래스를 확장하지 않는 경우 메서드를 호출 GetProviderConnectionPoints 하여 공급자에서 기존 연결 지점 개체를 반환해야 합니다.

적용 대상

추가 정보