Class Generators
Factory methods for constructing finite stream generators.
Inheritance
Namespace: Microsoft.Psi
Assembly: Microsoft.Psi.dll
Syntax
public static class Generators : object
Methods
View SourceOnce<T>(Pipeline, T, String)
Generates stream containing a single message, and keeps the stream open afterwards.
Declaration
public static IProducer<T> Once<T>(Pipeline pipeline, T value, string name = "Once")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | value | The value to publish. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of value to publish. |
Remarks
The generated stream stays open until the pipeline is shut down.
Range(Pipeline, Int32, Int32, TimeSpan, Nullable<DateTime>, Boolean, String)
Generates a stream of a finite range of integer values published at a regular interval.
Declaration
public static IProducer<int> Range(Pipeline pipeline, int start, int count, TimeSpan interval, DateTime? alignDateTime = null, bool keepOpen = false, string name = "Range")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
System. |
start | The starting value. |
System. |
count | The number of messages to publish. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with the specified time. |
System. |
keepOpen | Indicates whether the stream should be kept open after the specified number of messages have been posted. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<System. |
A stream of consecutive integers. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.
Repeat<T>(Pipeline, T, Int32, TimeSpan, Nullable<DateTime>, Boolean, String)
Generates a finite stream of constant values published at a regular interval.
Declaration
public static IProducer<T> Repeat<T>(Pipeline pipeline, T value, int count, TimeSpan interval, DateTime? alignmentDateTime = null, bool keepOpen = false, string name = "Repeat")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | value | The value to publish. |
System. |
count | The number of messages to publish. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignmentDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time. |
System. |
keepOpen | Indicates whether the stream should be kept open after the specified number of messages have been posted. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline. The generated stream closes once the specified number of messages has been published.
Repeat<T>(Pipeline, T, TimeSpan, Nullable<DateTime>, String)
Generates an infinite stream of constant values published at a regular interval.
Declaration
public static IProducer<T> Repeat<T>(Pipeline pipeline, T value, TimeSpan interval, DateTime? alignmentDateTime = null, string name = "Repeat")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | value | The value to publish. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignmentDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.
Return<T>(Pipeline, T, String)
Generates stream containing a single message, and closes the stream afterwards.
Declaration
public static IProducer<T> Return<T>(Pipeline pipeline, T value, string name = "Return")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | value | The value to publish. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream containing one value of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of value to publish. |
Remarks
The generated stream closes after the message is published.
Sequence<T>(Pipeline, T, Func<T, T>, Int32, TimeSpan, Nullable<DateTime>, Boolean, String)
Generates a finite stream of values published at a regular interval from a user-provided function.
Declaration
public static IProducer<T> Sequence<T>(Pipeline pipeline, T initialValue, Func<T, T> generateNext, int count, TimeSpan interval, DateTime? alignmentDateTime = null, bool keepOpen = false, string name = "Sequence")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | initialValue | The initial value. |
Func<T, T> | generateNext | The function that generates a new value based on the previous value. |
System. |
count | The number of messages to publish. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignmentDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time. |
System. |
keepOpen | Indicates whether the stream should be kept open after all messages in the sequence have been posted. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.
Sequence<T>(Pipeline, T, Func<T, T>, TimeSpan, Nullable<DateTime>, String)
Generates an infinite stream of values published at a regular interval from a user-provided function.
Declaration
public static IProducer<T> Sequence<T>(Pipeline pipeline, T initialValue, Func<T, T> generateNext, TimeSpan interval, DateTime? alignmentDateTime = null, string name = "Sequence")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
T | initialValue | The initial value. |
Func<T, T> | generateNext | The function that generates a new value based on the previous value. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignmentDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.
Sequence<T>(Pipeline, IEnumerable<T>, TimeSpan, Nullable<DateTime>, Boolean, String)
Generates a stream of values published at a regular interval from a specified enumerable.
Declaration
public static IProducer<T> Sequence<T>(Pipeline pipeline, IEnumerable<T> enumerable, TimeSpan interval, DateTime? alignmentDateTime = null, bool keepOpen = false, string name = "Sequence")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
IEnumerable<T> | enumerable | The sequence to publish. |
Time |
interval | The desired time interval between consecutive messages. Defaults to 1 tick. |
System. |
alignmentDateTime | If non-null, this parameter specifies a time to align the generator messages with. If the parameter is non-null, the messages will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time. |
System. |
keepOpen | Indicates whether the stream should be kept open after all messages in the sequence have been posted. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.
Sequence<T>(Pipeline, IEnumerable<(T, DateTime)>, Nullable<DateTime>, Boolean, String)
Generates a stream of values from a specified enumerable that provides the values and corresponding originating times.
Declaration
public static IProducer<T> Sequence<T>(Pipeline pipeline, IEnumerable<(T, DateTime)> enumerable, DateTime? startTime = null, bool keepOpen = false, string name = "Sequence")
Parameters
Type | Name | Description |
---|---|---|
Pipeline | pipeline | The pipeline to add the component to. |
IEnumerable<System. |
enumerable | An enumerable sequence of (data, originating time) pairs. |
System. |
startTime | The explicit start time of the data in the enumeration. Supply this parameter when the enumeration contains data values with absolute originating times (e.g. [value, time] pairs read from a file), and you want to propose a pipeline replay time to take this into account. Otherwise, pipeline playback will be determined by the prevailing replay descriptor (taking into account any other components in the pipeline which may have proposed replay times). |
System. |
keepOpen | Indicates whether the stream should be kept open after all the messages in the enumerable have been posted. |
System. |
name | An optional name for the stream generator. |
Returns
Type | Description |
---|---|
IProducer<T> | A stream of values of type T. |
Type Parameters
Name | Description |
---|---|
T | The type of data in the sequence. |
Remarks
When the pipeline is in replay mode, the timing of the messages complies with the speed of the pipeline.