ConnectionConsumerAttribute 클래스

정의

웹 파트 연결에서 소비자 역할을 하는 서버 컨트롤의 콜백 메서드를 식별하고 개발자가 소비자의 연결 지점에 대한 세부 사항을 지정할 수 있도록 합니다.

public ref class ConnectionConsumerAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public class ConnectionConsumerAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type ConnectionConsumerAttribute = class
    inherit Attribute
Public Class ConnectionConsumerAttribute
Inherits Attribute
상속
ConnectionConsumerAttribute
특성

예제

다음 코드 예제에서는 소비자 컨트롤의 ConnectionConsumerAttribute 콜백 메서드에서 메타데이터 요소를 선언 ConnectionConsumerAttribute 하는 방법을 보여 줌으로써 클래스를 사용하는 방법을 보여 줍니다. 생성자의 가장 간단한 오버로드가 사용됩니다. displayName 매개 변수 값만 제공됩니다.

[ConnectionConsumer("Row")]
public void SetConnectionInterface(IWebPartRow provider) 
{
    _provider = provider;
}
    <ConnectionConsumer("Row")> _
    Public Sub SetConnectionInterface(ByVal provider As IWebPartRow)
        _provider = provider

    End Sub
End Class

다음 코드 예제에서는 클래스를 사용 하 여 WebPartConnection 두 웹 파트 컨트롤 간에 기본 정적 연결을 만드는 방법을 보여 줍니다. 공급자 및 소비자 코드 파일을 App_Code 폴더.aspx 페이지를 포함 하는 애플리케이션 폴더에 넣어야 합니다.

첫 번째 예제에서는 공급자 역할을 하는 클래스를 보여줍니다.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web.UI;
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 row data.
namespace My 
{
    public sealed class RowProviderWebPart : WebPart, IWebPartRow 
    {

        private DataTable _table;

        public RowProviderWebPart() 
        {
            _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);
        }
        [ConnectionProvider("Row")]
        public IWebPartRow GetConnectionInterface()
        {
            return new RowProviderWebPart();
        }
        public PropertyDescriptorCollection Schema 
        {
            get {
                return TypeDescriptor.GetProperties(_table.DefaultView[0]);
                }
        }
        public void GetRowData(RowCallback callback)
        {
            callback(_table.Rows);
        }
    }
}
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Reflection
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

'This sample code creates a Web Parts control that acts as a provider of row data.
Namespace MyCustomWebPart

    Public NotInheritable Class RowProviderWebPart
        Inherits WebPart
        Implements IWebPartRow

        Private _table As DataTable


        Public Sub New()
            _table = New DataTable()

            Dim col As New DataColumn()
            col.DataType = GetType(String)
            col.ColumnName = "Name"
            _table.Columns.Add(col)

            col = New DataColumn()
            col.DataType = GetType(String)
            col.ColumnName = "Address"
            _table.Columns.Add(col)

            col = New DataColumn()
            col.DataType = GetType(Integer)
            col.ColumnName = "ZIP Code"
            _table.Columns.Add(col)

            Dim row As DataRow = _table.NewRow()
            row("Name") = "John Q. Public"
            row("Address") = "123 Main Street"
            row("ZIP Code") = 98000
            _table.Rows.Add(row)

        End Sub

        <ConnectionProvider("Row")> _
        Public Function GetConnectionInterface() As IWebPartRow
            Return New RowProviderWebPart()

        End Function 'GetConnectionInterface

        Public ReadOnly Property Schema() As PropertyDescriptorCollection _
            Implements IWebPartRow.Schema
            Get
                Return TypeDescriptor.GetProperties(_table.DefaultView(0))
            End Get
        End Property

        Public Sub GetRowData(ByVal callback As RowCallback) _
            Implements IWebPartRow.GetRowData
            callback(_table.Rows)

        End Sub
    End Class

두 번째 예제에서는 소비자 역할을 하는 클래스를 보여줍니다. 메서드는 메타데이터 요소를 사용하여 콜백 메서드로 ConnectionConsumerAttribute 지정됩니다.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
// This sample code creates a Web Parts control that acts as a consumer of row data.
namespace My 
{

    public sealed class RowConsumerWebPart : WebPart {
        private IWebPartRow _provider;
        private ICollection _tableData;
    
            private void GetRowData(object rowData)
            {
                _tableData = (ICollection)rowData;
            }

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

        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("Row")]
        public void SetConnectionInterface(IWebPartRow provider) 
        {
            _provider = provider;
        }
         }
    }
//}
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Reflection
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts

' This sample code creates a Web Parts control that acts as a consumer of row data.
Namespace MyCustomWebPart

    Public NotInheritable Class RowConsumerWebPart
        Inherits WebPart
        Private _provider As IWebPartRow
        Private _tableData As ICollection


        Private Sub GetRowData(ByVal rowData As Object)
            _tableData = CType(rowData, ICollection)

        End Sub


        Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
            If Not (_provider Is Nothing) Then
                '        _provider.GetRowData(AddressOf (New RowCallback(GetRowData)))
                _provider.GetRowData(AddressOf GetRowData)
                '    _provider.GetRowData(New RowCallback(AddressOf GetRowData))
            End If

        End Sub



        Protected Overrides Sub RenderContents(ByVal writer As HtmlTextWriter)
            If Not (_provider Is Nothing) Then
                Dim props As PropertyDescriptorCollection = _provider.Schema
                Dim count As Integer = 0
                If Not (props Is Nothing) AndAlso props.Count > 0 AndAlso Not (_tableData Is Nothing) Then
                    Dim prop As PropertyDescriptor
                    For Each prop In props
                        Dim o As DataRow
                        For Each o In _tableData
                            writer.Write(prop.DisplayName & ": " & o(count))
                            writer.WriteBreak()
                            writer.WriteLine()
                            count = count + 1
                        Next o
                    Next prop
                Else
                    writer.Write("No data")
                End If
            Else
                writer.Write("Not connected")
            End If

        End Sub

        <ConnectionConsumer("Row")> _
        Public Sub SetConnectionInterface(ByVal provider As IWebPartRow)
            _provider = provider

        End Sub
    End Class

마지막 예제에서는 두 컨트롤이 포함된 ASP.NET 페이지를 보여 줍니다.

<%@ page language="C#" %>
<%@ register TagPrefix="my" Namespace="My" %>

<!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>IRow Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!-- A static or dynamic connection is required to link two Web Parts controls. --->
        <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>
                <!-- The following two lines specify the two connected controls. --->
                <my:RowProviderWebPart ID="provider1" runat="server" ToolTip="Row Provider Control" />
                <my:RowConsumerWebPart ID="consumer1" runat="server" ToolTip="Row Consumer Control" />
            </ZoneTemplate>
        </asp:webpartzone>
    </div>
    </form>
</body>
</html>
<%@ page language="VB" %>
<%@ Register TagPrefix="my" Namespace="MyCustomWebPart" %>

<!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>IRow Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <!-- A static or dynamic connection is required to link two Web Parts controls. --->
        <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>
                <my:RowProviderWebPart ID="provider1" runat="server" ToolTip="Row Provider Control" />
                <my:RowConsumerWebPart ID="consumer1" runat="server" ToolTip="Row Consumer Control" />
           </ZoneTemplate>
        </asp:webpartzone>
    </div>
    </form>
</body>
</html>

설명

웹 파트 연결은 한 영역에 상주하고 WebPartZoneBase 한 컨트롤에서 다른 컨트롤로 전달되는 인터페이스 인스턴스를 통해 데이터를 공유하는 두 개의 서버 컨트롤로 구성됩니다. 인터페이스 인스턴스를 제공하는 컨트롤을 공급자라고 하며, 인터페이스 인스턴스를 수신하고 데이터를 처리하거나 표시하는 컨트롤을 소비자라고 합니다. 연결에 대한 자세한 내용은 클래스 및 웹 파트 연결 개요를 참조 WebPartConnection 하세요.

연결의 소비자 컨트롤은 컨트롤 또는 모든 유형의 서버 또는 사용자 컨트롤일 수 WebPart 있지만 콜백 메서드로 지정된 메서드가 있어야 합니다. 콜백 메서드는 연결 프로세스 중에 호출되며, 그 목적은 공급자로부터 데이터를 포함하는 인터페이스 인스턴스를 수신하는 것입니다. 소비자에서 콜백 메서드 역할을 하는 메서드를 지정하려면 메서드에 메타데이터 요소를 추가 ConnectionConsumerAttribute 해야 합니다(요소는 클래스를 기반으로 ConnectionConsumerAttribute 합니다).

소비자에서 콜백 메서드를 지정하는 것 외에도 개체를 사용하면 소비자 ConnectionConsumerAttribute 의 연결점에 대한 특정 세부 정보를 지정할 수 있습니다. 소비자 연결 지점은 소비자의 ConsumerConnectionPoint 제어 유형, 동시에 여러 공급자에 연결할 수 있는지 여부, 소비자가 공급자로부터 받을 수 있는 인터페이스 유형, 콜백 메서드에 대한 세부 정보 및 사용자 인터페이스(UI)의 소비자 연결 지점을 나타내는 표시 이름을 포함하여 연결을 설정하는 데 필요한 소비자에 대한 모든 세부 정보를 캡슐화하는 클래스의 인스턴스입니다. 모든 웹 파트 연결에는 소비자 제어와 연결된 소비자 연결 지점이 포함됩니다.

소비자의 ConnectionConsumerAttribute 콜백 메서드에 메타데이터 요소를 추가하는 경우 소비자 연결점에 대한 다음 세부 정보를 지정하는 데 사용할 수도 있습니다. 연결점에 대한 표시 이름(자세한 내용은 속성 참조 DisplayName ), 소비자가 동시에 여러 공급자에 연결할 수 있는지 여부(자세한 내용은 속성 참조 AllowsMultipleConnections ). 연결점에 대한 ID(자세한 내용은 속성 참조 ID ) 및 소비자가 사용하는 연결 지점의 유형(자세한 내용은 속성 참조 ConnectionPointType )입니다. 클래스에 대한 ConnectionConsumerAttribute 생성자의 4개 오버로드에는 각각 클래스의 새 인스턴스를 만들 때 이러한 연결점 속성 중 하나 이상의 값을 지정할 수 있는 매개 변수가 있습니다. 소비자 연결 지점에 대한 대부분의 속성을 프로그래밍 방식으로 설정할 수도 있습니다. 요소를 사용하여 설정은 ConnectionConsumerAttribute 선택 사항입니다.

참고

소비자의 ConnectionConsumerAttribute 콜백 메서드에 메타데이터 요소를 추가하는 경우 항상 지정해야 하는 유일한 필수 매개 변수는 매개 변수입니다 displayName (자세한 내용은 생성자 오버로드 참조 ConnectionConsumerAttribute(String) ). 이 매개 변수의 값이 속성에 DisplayName 할당되고 사용자가 연결 UI를 열면(컨트롤에서 ConnectionsZone 만든) 표시 이름은 UI의 소비자 연결 지점을 나타냅니다. 소비자 컨트롤에서 여러 콜백 메서드를 지정하는 경우 선택할 수 있는 여러 연결점이 있으며, 각 콜백 메서드에 메타데이터 요소를 추가할 ConnectionConsumerAttribute 때 각 소비자 연결 지점에 알려진 고유 식별자가 있도록 매개 변수 값 id 도 지정해야 합니다.

생성자

ConnectionConsumerAttribute(String)

소비자 연결 지점의 표시 이름을 지정하여 ConnectionConsumerAttribute 클래스의 새 인스턴스를 초기화합니다.

ConnectionConsumerAttribute(String, String)

소비자 연결 지점의 표시 이름과 ID를 지정하여 ConnectionConsumerAttribute 클래스의 새 인스턴스를 초기화합니다.

ConnectionConsumerAttribute(String, String, Type)

소비자 연결 지점에 사용할 연결 지점 개체의 표시 이름, ID 및 특정 형식을 지정하는 ConnectionConsumerAttribute 클래스의 새 인스턴스를 초기화합니다.

ConnectionConsumerAttribute(String, Type)

소비자 연결 지점에 사용할 표시 이름 및 연결 지점 개체의 특정 형식을 지정하여 ConnectionConsumerAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

AllowsMultipleConnections

연결 지점에서 여러 연결이 허용되는지 여부를 나타내는 값을 가져오거나 설정합니다.

ConnectionPointType

소비자 연결 지점의 연결 지점 형식을 가져옵니다.

DisplayName

소비자 연결 지점의 이름을 가져옵니다.

DisplayNameValue

지역화 시나리오에서 사용할 경우 DisplayName 속성 값으로 사용되는 문자열을 가져오거나 설정합니다.

ID

소비자 연결 지점의 고유 ID를 나타내는 문자열을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보