Partager via


Current propriété

Gets the current LogProvider element in the collection.

Espace de noms :  Microsoft.SqlServer.Dts.Runtime
Assembly :  Microsoft.SqlServer.ManagedDTS (dans Microsoft.SqlServer.ManagedDTS.dll)

Syntaxe

'Déclaration
Public ReadOnly Property Current As LogProvider
    Get
'Utilisation
Dim instance As LogProviderEnumerator
Dim value As LogProvider

value = instance.Current
public LogProvider Current { get; }
public:
property LogProvider^ Current {
    LogProvider^ get ();
}
member Current : LogProvider
function get Current () : LogProvider

Valeur de la propriété

Type : Microsoft.SqlServer.Dts.Runtime. . :: . .LogProvider
The current LogProvider element in the collection.

Notes

After an enumerator is created, or after a call to the Reset method, the MoveNext method must be called to advance the enumerator to the first element of the collection before the enumerator can read the value of the Current property; otherwise, Current is undefined and throws an exception.

Current also throws an exception if the last call to MoveNext returned false, which indicates the end of the collection.

Current does not move the position of the enumerator, and consecutive calls to Current return the same object until either MoveNext or Reset is called.

An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is invalidated and becomes irrecoverable; thus, the next call to MoveNext or Reset throws an InvalidOperationException. However, if the collection is modified between calls to MoveNext and Current, Current returns the element that it is set to, even if the enumerator has been invalidated.

Exemples

The following code example adds and removes log providers for the package, in addition to creating an enumerator by using the GetEnumerator method, and then uses the.Current and MoveNext methods to navigate over the collection.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace Microsoft.SqlServer.SSIS.Samples
{
    class Program
    {
        static void Main(string[] args)
        {
            Package pkg = new Package();
            // Make several log providers available to the package.
            LogProvider log1 = pkg.LogProviders.Add("DTS.LogProviderEventLog.2");
            LogProvider log2 = pkg.LogProviders.Add("DTS.LogProviderSQLProfiler.2");
            LogProvider log3 = pkg.LogProviders.Add("DTS.LogProviderTextFile.2");
            LogProvider log4 = pkg.LogProviders.Add("DTS.LogProviderTextFile.2");
            // Show the log providers available to the package.
            Console.WriteLine("Log providers available in the Package:");
            LogProviders logs = pkg.LogProviders;
            foreach (LogProvider lp in logs)
                Console.WriteLine(lp.CreationName);

            // Pick a log provider for the package.
            pkg.LoggingOptions.SelectedLogProviders.Add(log4);
            pkg.LoggingOptions.SelectedLogProviders.Add(log1);
            SelectedLogProviders provs = pkg.LoggingOptions.SelectedLogProviders;
            Console.WriteLine();
            Console.WriteLine("Selected Log Providers for Package: {0}", provs.Count);

            foreach (LogProvider lp in provs)
                Console.WriteLine(lp.CreationName);

            pkg.LoggingOptions.SelectedLogProviders.Remove(0);
            Console.WriteLine();
            Console.WriteLine("Count after one has been removed {0}", provs.Count);

            // Test both the indexer and Contains method.
            if (logs.Contains(0))
                Console.WriteLine("Index zero in collection contains:  {0}", logs[0].CreationName);
            else
                throw new Exception();

            // Show the use of the GetEnumerator.
            LogProviderEnumerator myEnum = pkg.LogProviders.GetEnumerator();
            Console.WriteLine("The collection contains the following values:");
            while ((myEnum.MoveNext()) && (myEnum.Current != null))
                Console.WriteLine("{0}", myEnum.Current.Name);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace Microsoft.SqlServer.SSIS.Samples
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim pkg As Package =  New Package() 
            ' Make several log providers available to the package.
            Dim log1 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderEventLog.2") 
            Dim log2 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderSQLProfiler.2") 
            Dim log3 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderTextFile.2") 
            Dim log4 As LogProvider =  pkg.LogProviders.Add("DTS.LogProviderTextFile.2") 
            ' Show the log providers available to the package.
            Console.WriteLine("Log providers available in the Package:")
            Dim logs As LogProviders =  pkg.LogProviders 
            Dim lp As LogProvider
            For Each lp In logs
                Console.WriteLine(lp.CreationName)
            Next
 
            ' Pick a log provider for the package.
            pkg.LoggingOptions.SelectedLogProviders.Add(log4)
            pkg.LoggingOptions.SelectedLogProviders.Add(log1)
            Dim provs As SelectedLogProviders =  pkg.LoggingOptions.SelectedLogProviders 
            Console.WriteLine()
            Console.WriteLine("Selected Log Providers for Package: {0}", provs.Count)
 
            Dim lp As LogProvider
            For Each lp In provs
                Console.WriteLine(lp.CreationName)
            Next
 
            pkg.LoggingOptions.SelectedLogProviders.Remove(0)
            Console.WriteLine()
            Console.WriteLine("Count after one has been removed {0}", provs.Count)
 
            ' Test both the indexer and Contains method.
            If logs.Contains(0) Then
                Console.WriteLine("Index zero in collection contains:  {0}", logs(0).CreationName)
            Else 
                Throw New Exception()
            End If
 
            ' Show the use of the GetEnumerator.
            Dim myEnum As LogProviderEnumerator =  pkg.LogProviders.GetEnumerator() 
            Console.WriteLine("The collection contains the following values:")
            While (myEnum.MoveNext()) &&(myEnum.Current <> Nothing)
                Console.WriteLine("{0}", myEnum.Current.Name)
            End While
        End Sub
    End Class
End Namespace

Sample Output:

Log providers available in the Package:

DTS.LogProviderTextFile.2

DTS.LogProviderSQLProfiler.2

DTS.LogProviderEventLog.2

DTS.LogProviderTextFile.2

Selected Log Providers for Package: 2

DTS.LogProviderTextFile.2

DTS.LogProviderEventLog.2

Count after one has been removed 1

Index zero in collection contains: DTS.LogProviderTextFile.2

The collection contains the following values:

{9A4FD6D3-7DE2-43AD-8B02-CE9B02E7504B}

{AB1C156F-8018-4063-A1A5-48E122CE6FFD}

{B8E93B36-36FE-4E65-9814-9752915E9E15}

{E586A867-86EC-4901-8F5A-C945D4469C46}