ConnectionProviderAttribute クラス

定義

Web パーツ接続でプロバイダーとして機能するサーバー コントロールのコールバック メソッドを識別し、開発者がプロバイダーのコネクション ポイントの詳細を指定できるようにします。

public ref class ConnectionProviderAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Method)]
public class ConnectionProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Method)>]
type ConnectionProviderAttribute = class
    inherit Attribute
Public Class ConnectionProviderAttribute
Inherits Attribute
継承
ConnectionProviderAttribute
属性

次のコード例では、 クラスを ConnectionProviderAttribute 使用して、プロバイダー コントロールのコールバック メソッドでメタデータ要素を宣言 ConnectionProviderAttribute する方法を示します。 コンストラクターの最も単純なオーバーロードが使用されることに注意してください。 displayName パラメーター値のみが指定されます。

[ConnectionProvider("Row")]
public IWebPartRow GetConnectionInterface()
{
    return new RowProviderWebPart();
}
<ConnectionProvider("Row")> _
Public Function GetConnectionInterface() As IWebPartRow
    Return New RowProviderWebPart()

End Function 'GetConnectionInterface

次のコード例では、 クラスを使用して 2 つの Web パーツ コントロール間に基本的な静的接続を作成する方法を WebPartConnection 示します。 プロバイダーとコンシューマー のコード ファイルは、.aspx ページを含むアプリケーション フォルダーの下の App_Code フォルダーに配置する必要があります。

最初の例は、プロバイダーとして機能するクラスを示しています。 メソッドがメタデータ要素を持つコールバック メソッドとして指定されていることに ConnectionProviderAttribute 注意してください。

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

2 番目の例は、コンシューマーとして機能するクラスを示しています。

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

最後の例では、2 つのコントロールを含む 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>

注釈

Web パーツ接続は、1 つのゾーンに WebPartZoneBase 存在する 2 つのサーバー コントロールで構成され、一方のコントロールから他方のコントロールに渡されるインターフェイス インスタンスを使用してデータを共有します。 インターフェイス インスタンスを提供するコントロールはプロバイダーと呼ばれ、インターフェイス インスタンスを受け取ってデータを処理または表示するコントロールはコンシューマーと呼ばれます。 接続の詳細については、 クラスと Web パーツ接続WebPartConnection概要に関するページを参照してください。

接続 WebPart 内のプロバイダー コントロールは、コントロールまたは任意の種類のサーバーコントロールまたはユーザー コントロールにすることができますが、コールバック メソッドとして指定されたメソッドが必要です。 コールバック メソッドは接続プロセス中に呼び出され、その目的は、データを含むインターフェイス インスタンスをコンシューマーに返すものです。 プロバイダーでコールバック メソッドとして機能するメソッドを指定するには、メタデータ要素を メソッドに追加 ConnectionProviderAttribute する必要があります (要素は クラスに ConnectionProviderAttribute 基づいています)。

オブジェクトでは、プロバイダーでコールバック メソッドを指定するだけでなく、 ConnectionProviderAttribute プロバイダーの接続ポイントに関する特定の詳細を指定することもできます。 プロバイダー接続ポイントは、接続を確立するために必要なプロバイダーに関するすべての詳細 (プロバイダーのコントロールの種類、同時に複数のコンシューマーに接続できるかどうか、プロバイダーがコンシューマーに提供するインターフェイスの種類、コールバック メソッドの詳細、およびユーザー インターフェイス (UI) のプロバイダー接続ポイントを表す表示名など) をカプセル化する クラスのインスタンス ProviderConnectionPoint です。 すべての Web パーツ接続には、プロバイダー コントロールに関連付けられているプロバイダー接続ポイントが含まれます。

プロバイダーの ConnectionProviderAttribute コールバック メソッドにメタデータ要素を追加する場合は、プロバイダー接続ポイントに関する次の詳細を指定することもできます。接続ポイントの表示名 (詳細については、 プロパティを参照してください DisplayName )、プロバイダーが同時に複数のコンシューマーに接続できるかどうか (詳細については、 プロパティを AllowsMultipleConnections 参照) 接続ポイントの ID (詳細については、 プロパティを ID 参照)、およびプロバイダーが使用する接続ポイントの種類 (詳細については、 プロパティを ConnectionPointType 参照してください)。 クラスのコンストラクター ConnectionProviderAttribute の 4 つのオーバーロードには、クラスの新しいインスタンスが作成されるときに、これらの接続ポイントプロパティの 1 つ以上の値を指定できるパラメーターがあります。 プロバイダー接続ポイントのほとんどのプロパティは、プログラムで設定することもできます。要素を ConnectionProviderAttribute 使用して設定することは省略可能です。

注意

プロバイダーの ConnectionProviderAttribute コールバック メソッドにメタデータ要素を追加する場合、常に指定する必要がある唯一の必須パラメーターは パラメーターです displayName (詳細については、コンストラクターのオーバーロードを ConnectionProviderAttribute(String) 参照してください)。 このパラメーターの値は プロパティに DisplayName 割り当てられ、ユーザーが接続 UI (コントロールによって ConnectionsZone 作成) を開くと、表示名は UI のプロバイダー接続ポイントを表します。 プロバイダー コントロールで複数のコールバック メソッドを指定する場合は、選択できる接続ポイントが複数存在し、各コールバック メソッドにメタデータ要素を追加 ConnectionProviderAttribute するときは、 パラメーターの値 id も指定して、各プロバイダー接続ポイントに既知の一意の識別子が設定されるようにする必要があります。

コンストラクター

ConnectionProviderAttribute(String)

プロバイダー コネクション ポイントの表示名を指定して、ConnectionProviderAttribute クラスの新しいインスタンスを初期化します。

ConnectionProviderAttribute(String, String)

プロバイダー コネクション ポイントの表示名と ID を指定して、ConnectionProviderAttribute クラスの新しいインスタンスを初期化します。

ConnectionProviderAttribute(String, String, Type)

プロバイダー接続ポイントに使用する接続ポイント オブジェクトの表示名、ID、および特定の型を指定して、ConnectionProviderAttribute クラスの新しいインスタンスを初期化します。

ConnectionProviderAttribute(String, Type)

プロバイダー コネクション ポイントに使用する表示名と特定のコネクション ポイント オブジェクトの型を指定して、ConnectionProviderAttribute クラスの新しいインスタンスを初期化します。

プロパティ

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)

適用対象

こちらもご覧ください