SinkProviderData 类

定义

为接收器提供程序存储接收器提供程序数据。

public ref class SinkProviderData
public class SinkProviderData
[System.Runtime.InteropServices.ComVisible(true)]
public class SinkProviderData
type SinkProviderData = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type SinkProviderData = class
Public Class SinkProviderData
继承
SinkProviderData
属性

示例

public class MySinkProviderData : IServerChannelSinkProvider
{
    private IServerChannelSinkProvider myIServerChannelSinkProviderNew;

    private bool myAcceptMode = true;
    private ICollection myCollectionData = null;

    public MySinkProviderData()
    {
    }

    public MySinkProviderData(IDictionary properties, ICollection providerData)
    {
        String myMode = (String)properties["mode"];
        if (String.Compare(myMode, "accept", true) == 0)
            myAcceptMode = true;
        else
            if (String.Compare(myMode, "reject", true) == 0)
            myAcceptMode = false;
        myCollectionData = providerData;
    }

    public void GetChannelData(IChannelDataStore myLocalChannelData)
    {
    }
    
    public IServerChannelSink CreateSink(IChannelReceiver myChannel)
    {
        IServerChannelSink myIServerChannelSink_nextSink = null;
        if (myIServerChannelSinkProviderNew != null)
            myIServerChannelSink_nextSink = myIServerChannelSinkProviderNew.CreateSink(myChannel);
        MyIPFilterChannelSink mySink = new MyIPFilterChannelSink(myAcceptMode,
            myIServerChannelSink_nextSink);
        // Create and initialize a new ArrayList.
        ArrayList myArrayList = new ArrayList();

        // Add filters.
        foreach (SinkProviderData mySinkData in myCollectionData)
        {
            // The SinkProviderData properties are added to the ArrayList.
            myArrayList.Add(mySinkData.Children);
            myArrayList.Add(mySinkData.Name);

            String myMaskString = (String)mySinkData.Properties["mask"];
            String myIPString = (String)mySinkData.Properties["ip"];
            String myMachineString = (String)mySinkData.Properties["machine"];

            IPAddress mask = null;
            IPAddress ip = null;

            if (myIPString != null)
            {
                mask = IPAddress.Parse(myMaskString);
                ip = IPAddress.Parse(myIPString);
            }
            else
            {
                mask = IPAddress.Parse("255.255.255.255");
                ip = Dns.Resolve(myMachineString).AddressList[0];
            }

            mySink.AddFilter(mask, ip);
        }
        Console.WriteLine("The Count of the ArrayList is  :"+ myArrayList.Count);
        Console.WriteLine("The values in the SinkProviderData collection are:");

        // Call the PrintValues function to enumerate and print values to the console.
        PrintValues( myArrayList );

        return mySink;
    }

    public IServerChannelSinkProvider Next
    {
        get
        {
            return myIServerChannelSinkProviderNew;
        }
        set
        {
            myIServerChannelSinkProviderNew = value;
        }
    }

    public FilterMode Mode
    {
        get
        {
            return (myAcceptMode ? FilterMode.Accept : FilterMode.Reject);
        }
        set
        {
            myAcceptMode = (value == FilterMode.Accept);
        }
    }

    public static void PrintValues( IEnumerable myList )
    {
        IEnumerator myEnumerator = myList.GetEnumerator();
        while ( myEnumerator.MoveNext() )
            Console.Write( "\t{0}", myEnumerator.Current );
        Console.WriteLine();
    }
} // class MySinkProviderData

   Public Class MySinkProviderData
      Implements IServerChannelSinkProvider
      Private myIServerChannelSinkProviderNew As IServerChannelSinkProvider

      Private myAcceptMode As Boolean = True
      Private myCollectionData As ICollection = Nothing

      Public Sub New()
      End Sub

      Public Sub New(properties As IDictionary, providerData As ICollection)
         Dim myMode As String = CType(properties("mode"), String)
         If String.Compare(myMode, "accept", True) = 0 Then
            myAcceptMode = True
         Else
            If String.Compare(myMode, "reject", True) = 0 Then
               myAcceptMode = False
            End If
         End If
         myCollectionData = providerData
      End Sub

<SecurityPermission(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure)> _
      Public Sub GetChannelData(myLocalChannelData As IChannelDataStore) Implements _
                                       IServerChannelSinkProvider.GetChannelData
      End Sub

<SecurityPermission(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure)> _
      Public Function CreateSink(myChannel As IChannelReceiver) As IServerChannelSink Implements _
                                                         IServerChannelSinkProvider.CreateSink
         Dim myIServerChannelSink_nextSink As IServerChannelSink = Nothing
         If Not (myIServerChannelSinkProviderNew Is Nothing) Then
            myIServerChannelSink_nextSink = myIServerChannelSinkProviderNew.CreateSink(myChannel)
         End If
         Dim mySink As New MyIPFilterChannelSink(myAcceptMode, myIServerChannelSink_nextSink)
         ' Create and initialize a new ArrayList.
         Dim myArrayList As New ArrayList()

         ' Add filters.
         Dim mySinkData As SinkProviderData
         For Each mySinkData In  myCollectionData
            ' The SinkProviderData properties are added to the ArrayList.
            myArrayList.Add(mySinkData.Children)
            myArrayList.Add(mySinkData.Name)

            Dim myMaskString As String = CType(mySinkData.Properties("mask"), String)
            Dim myIPString As String = CType(mySinkData.Properties("ip"), String)
            Dim myMachineString As String = CType(mySinkData.Properties("machine"), String)

            Dim mask As IPAddress = Nothing
            Dim ip As IPAddress = Nothing

            If Not (myIPString Is Nothing) Then
               mask = IPAddress.Parse(myMaskString)
               ip = IPAddress.Parse(myIPString)
            Else
               mask = IPAddress.Parse("255.255.255.255")
               ip = Dns.Resolve(myMachineString).AddressList(0)
            End If

            mySink.AddFilter(mask, ip)
         Next mySinkData
         Console.WriteLine("The Count of the ArrayList is  :" + myArrayList.Count.ToString())
         Console.WriteLine("The values in the SinkProviderData collection are:")

         ' Call the PrintValues function to enumerate and print values to the console.
         PrintValues(myArrayList)

         Return mySink
      End Function 'CreateSink

      Public Property [Next]() As IServerChannelSinkProvider Implements _
                                                            IServerChannelSinkProvider.Next
<SecurityPermission(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure)> _
         Get
            Return myIServerChannelSinkProviderNew
         End Get
<SecurityPermission(SecurityAction.Demand, Flags := SecurityPermissionFlag.Infrastructure)> _
         Set
            myIServerChannelSinkProviderNew = value
         End Set
      End Property

      Public Property Mode() As FilterMode
         Get
            Return(IIf(myAcceptMode ,FilterMode.Accept ,FilterMode.Reject))
         End Get
         Set(ByVal Value As FilterMode)
             If Value = FilterMode.Accept Then
                 myAcceptMode = Value
             End If
         End Set
      End Property

      Public Shared Sub PrintValues(myList As IEnumerable)
         Dim myEnumerator As IEnumerator = myList.GetEnumerator()
         While myEnumerator.MoveNext()
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
         End While
         Console.WriteLine()
      End Sub
   End Class
     ' class MySinkProviderData

注解

接收器提供程序数据是元素 (模板) 配置节点中<provider>存储的配置信息的树结构。 所有接收器提供程序必须具有一个构造函数, IDictionary 如果想要从配置文件使用属性和其中一个 ICollection 结构。

构造函数

SinkProviderData(String)

初始化 SinkProviderData 类的新实例。

属性

Children

获取一个子 SinkProviderData 节点的列表。

Name

获取与当前 SinkProviderData 对象中的数据关联的接收器提供程序的名称。

Properties

获取可以通过其访问接收器提供程序上属性的字典。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于