DtsEnumerator 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
定义了一个抽象基类,实现IEnumerator方法。
public ref class DtsEnumerator abstract : System::Collections::IEnumerator
public abstract class DtsEnumerator : System.Collections.IEnumerator
type DtsEnumerator = class
interface IEnumerator
Public MustInherit Class DtsEnumerator
Implements IEnumerator
- 继承
-
DtsEnumerator
- 派生
- 实现
示例
以下代码示例是将任务添加到一个包中,然后运行该包。 警告集合通过创建一个 WarningEnumerator继承自该 DtsEnumerator 类的 ,并显示每个警告描述。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask;
namespace Microsoft.SqlServer.SSIS.Samples
{
class Program
{
static void Main(string[] args)
{
Package package = new Package();
Console.WriteLine("Package warnings count before running: {0}", package.Warnings.Count);
TaskHost taskH2 = (TaskHost)package.Executables.Add("STOCK:SendMailTask");
taskH2.FailPackageOnFailure = false;
taskH2.FailParentOnFailure = false;
Console.WriteLine("SendMailTask: {0}", taskH2.ID);
// Test that warnings were successfully added to the collection.
package.MaximumErrorCount = 100;
package.FailPackageOnFailure = false;
package.FailParentOnFailure = false;
package.DelayValidation = true;
package.Execute();
Console.WriteLine("Package warnings count after running the package: {0}", package.Warnings.Count);
// Create the enumerator.
WarningEnumerator myEnumerator = package.Warnings.GetEnumerator();
Console.WriteLine("The collection contains the following values:");
int i = 0;
while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))
Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Description);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask
Namespace Microsoft.SqlServer.SSIS.Samples
Class Program
Shared Sub Main(ByVal args() As String)
Dim package As Package = New Package()
Console.WriteLine("Package warnings count before running: {0}", package.Warnings.Count)
Dim taskH2 As TaskHost = CType(package.Executables.Add("STOCK:SendMailTask"), TaskHost)
taskH2.FailPackageOnFailure = False
taskH2.FailParentOnFailure = False
Console.WriteLine("SendMailTask: {0}", taskH2.ID)
' Test that warnings were successfully added to the collection.
package.MaximumErrorCount = 100
package.FailPackageOnFailure = False
package.FailParentOnFailure = False
package.DelayValidation = True
package.Execute()
Console.WriteLine("Package warnings count after running the package: {0}", package.Warnings.Count)
' Create the enumerator.
Dim myEnumerator As WarningEnumerator = package.Warnings.GetEnumerator()
Console.WriteLine("The collection contains the following values:")
Dim i As Integer = 0
While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)
Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
End While
End Sub
End Class
End Namespace
示例输出:
包裹警告在运行前计数:0
SendMailTask: {34CAEFF9-64BF-401D-B646-C88B705DB971}
包裹警告在运行包后计入:2
该集合包含以下数值:
[0] 发件人行中的地址未正确生成。 缺少@或无效。
[1] 主语为空
注解
DtsEnumerator 是所有枚举器的基础接口。 它 DtsEnumerator 只允许读取集合中的数据,不用于修改底层集合。
最初,枚举器位于集合中的第一个元素之前。 Reset 还将枚举器带回此位置。 在此位置,调用 Current 将引发异常。 因此,在读取值MoveNext之前,必须调用Current枚举器将枚举器提升到集合的第一个元素。
Current返回相同的对象,直到调用或MoveNextReset调用。 MoveNext 设置为 Current 下一个元素。
传递集合末尾后,枚举器将定位在集合中的最后一个元素之后,并调用 MoveNext 返回 false。 如果返回MoveNext的最后一次调用false,则调用Current将引发异常。 若要再次设置为 Current 集合的第一个元素,可以调用 Reset 后跟 MoveNext。
只要集合保持不变,枚举器就保持有效。 如果对集合进行了更改(例如添加、修改或删除元素),枚举器将不可恢复地失效,并且下次调用 MoveNext 或 Reset 时会引发 InvalidOperationException 异常。 如果集合在两MoveNext者之间Current进行了修改,Current将返回它设置为的元素,即使枚举器已失效。
普查员没有对该收藏的独家访问权限;因此,通过集合枚举并非线程安全的过程。 即使集合同步,其他线程仍可以修改集合,这会导致枚举器引发异常。 为了保证枚举过程中的线程安全,你可以在整个枚举过程中锁定集合,或捕捉其他线程更改导致的异常。
构造函数
| 名称 | 说明 |
|---|---|
| DtsEnumerator(IEnumerator, DTSReadOnlyCollectionBase) |
初始化 DtsEnumerator 类的新实例。 |
属性
| 名称 | 说明 |
|---|---|
| Current |
获取集合中的当前元素。 |
方法
| 名称 | 说明 |
|---|---|
| MoveNext() |
将枚举器推进到集合的下一个元素。 |
| Reset() |
将枚举器设置为其初始位置,该位置位于集合中的第一个元素之前。 |