Current 속성
Gets the current PrecedenceConstraint element in the collection.
네임스페이스: Microsoft.SqlServer.Dts.Runtime
어셈블리: Microsoft.SqlServer.ManagedDTS(Microsoft.SqlServer.ManagedDTS.dll)
구문
‘선언
Public ReadOnly Property Current As PrecedenceConstraint
Get
‘사용 방법
Dim instance As PrecedenceConstraintEnumerator
Dim value As PrecedenceConstraint
value = instance.Current
public PrecedenceConstraint Current { get; }
public:
property PrecedenceConstraint^ Current {
PrecedenceConstraint^ get ();
}
member Current : PrecedenceConstraint
function get Current () : PrecedenceConstraint
속성 값
유형: Microsoft.SqlServer.Dts.Runtime. . :: . .PrecedenceConstraint
The current PrecedenceConstraint object.
주의
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. 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.
예
The following code example creates two precedence constraints. It then uses Contains to verify the existence of a specific constraint, counts the number of constraints before and after the use of the Remove method, and shows how to use the GetEnumerator to iterate over the collection, using the Item syntax of pConsts[i].ID to return the ID of the constraint.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.FileSystemTask;
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask;
namespace PrecedenceConst
{
class Program
{
static void Main(string[] args)
{
Package pkg = new Package();
// Add a File System task.
Executable eFileTask1 = pkg.Executables.Add("STOCK:FileSystemTask");
TaskHost thFileTask1 = eFileTask1 as TaskHost;
// Add a second File System task.
Executable eFileTask2 = pkg.Executables.Add("STOCK:FileSystemTask");
TaskHost thFileTask2 = eFileTask2 as TaskHost;
// Add a Bulk Insert task.
Executable eBulkInsert = pkg.Executables.Add("STOCK:BulkInsertTask");
TaskHost thBulkInsert = eBulkInsert as TaskHost;
// Add a precedence constraint between eFileTask1 and eFileTask2.
// Set the constraint to be that eFileTask2 cannot run
// until eFileTask1 completes.
PrecedenceConstraint pcFileTasks = pkg.PrecedenceConstraints.Add(eFileTask1, eFileTask2);
pcFileTasks.Name = "constraint between File System Tasks";
// Add another precedence constraint. Add it between eFileTask2 and BulkInsert.
// Again, set the constraint to be that BulkInsert cannot run
// until eFileTask2 completes.
PrecedenceConstraint pcFiletoBulk = pkg.PrecedenceConstraints.Add(eFileTask2, eBulkInsert);
pcFileTasks.Name = "constraint between File System and Bulk Insert Tasks";
// Obtain the precedence constraint collection.
PrecedenceConstraints pConsts = pkg.PrecedenceConstraints;
Boolean containsConstraint = pkg.PrecedenceConstraints.Contains("constraint between File System and Bulk Insert Tasks");
Console.WriteLine("Contains the constraint between File System and Bulk Insert Tasks? {0}", containsConstraint);
// Create the enumerator.
PrecedenceConstraintEnumerator myEnumerator = pConsts.GetEnumerator();
// Iterate over the collection, and remove the Bulk Insert task.
int i = 0;
while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))
{
Console.WriteLine("ID {0}", pConsts[i].ID);
}
Console.WriteLine("Number of constraints {0}", pConsts.Count);
// Remove the second contstraint.
pConsts.Remove(1);
// Verify that one has been removed.
Console.WriteLine("Number of constraints {0}", pConsts.Count);
Console.WriteLine();
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.FileSystemTask
Imports Microsoft.SqlServer.Dts.Tasks.BulkInsertTask
Namespace PrecedenceConst
Class Program
Shared Sub Main(ByVal args() As String)
Dim pkg As Package = New Package()
' Add a File System task.
Dim eFileTask1 As Executable = pkg.Executables.Add("STOCK:FileSystemTask")
Dim thFileTask1 As TaskHost = eFileTask1 as TaskHost
' Add a second File System task.
Dim eFileTask2 As Executable = pkg.Executables.Add("STOCK:FileSystemTask")
Dim thFileTask2 As TaskHost = eFileTask2 as TaskHost
' Add a Bulk Insert task.
Dim eBulkInsert As Executable = pkg.Executables.Add("STOCK:BulkInsertTask")
Dim thBulkInsert As TaskHost = eBulkInsert as TaskHost
' Add a precedence constraint between eFileTask1 and eFileTask2.
' Set the constraint to be that eFileTask2 cannot run
' until eFileTask1 completes.
Dim pcFileTasks As PrecedenceConstraint = pkg.PrecedenceConstraints.Add(eFileTask1,eFileTask2)
pcFileTasks.Name = "constraint between File System Tasks"
' Add another precedence constraint. Add it between eFileTask2 and BulkInsert.
' Again, set the constraint to be that BulkInsert cannot run
' until eFileTask2 completes.
Dim pcFiletoBulk As PrecedenceConstraint = pkg.PrecedenceConstraints.Add(eFileTask2,eBulkInsert)
pcFileTasks.Name = "constraint between File System and Bulk Insert Tasks"
' Obtain the precedence constraint collection.
Dim pConsts As PrecedenceConstraints = pkg.PrecedenceConstraints
Dim containsConstraint As Boolean = pkg.PrecedenceConstraints.Contains("constraint between File System and Bulk Insert Tasks")
Console.WriteLine("Contains the constraint between File System and Bulk Insert Tasks? {0}", containsConstraint)
' Create the enumerator.
Dim myEnumerator As PrecedenceConstraintEnumerator = pConsts.GetEnumerator()
' Iterate over the collection, and remove the Bulk Insert task.
Dim i As Integer = 0
While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)
Console.WriteLine("ID {0}", pConsts(i).ID)
End While
Console.WriteLine("Number of constraints {0}", pConsts.Count)
' Remove the second contstraint.
pConsts.Remove(1)
' Verify that one has been removed.
Console.WriteLine("Number of constraints {0}", pConsts.Count)
Console.WriteLine()
End Sub
End Class
End Namespace
Sample Output:
Contains the constraint between File System and Bulk Insert Tasks? True
ID {BA42AF32-3AC1-4CB6-85A2-289760ADBFA4}
ID {BA42AF32-3AC1-4CB6-85A2-289760ADBFA4}
Number of constraints 2
Number of constraints 1