forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessEdgeBuilder.cs
54 lines (44 loc) · 1.65 KB
/
ProcessEdgeBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft. All rights reserved.
using System;
namespace Microsoft.SemanticKernel;
/// <summary>
/// Provides functionality for incrementally defining a process edge.
/// </summary>
public sealed class ProcessEdgeBuilder
{
internal ProcessFunctionTargetBuilder? Target { get; set; }
/// <summary>
/// The event Id that the edge fires on.
/// </summary>
internal string EventId { get; }
/// <summary>
/// The source step of the edge.
/// </summary>
internal ProcessBuilder Source { get; }
/// <summary>
/// Initializes a new instance of the <see cref="ProcessEdgeBuilder"/> class.
/// </summary>
/// <param name="source">The source step.</param>
/// <param name="eventId">The Id of the event.</param>
internal ProcessEdgeBuilder(ProcessBuilder source, string eventId)
{
Verify.NotNull(source, nameof(source));
Verify.NotNullOrWhiteSpace(eventId, nameof(eventId));
this.Source = source;
this.EventId = eventId;
}
/// <summary>
/// Sends the output of the source step to the specified target when the associated event fires.
/// </summary>
public ProcessEdgeBuilder SendEventTo(ProcessFunctionTargetBuilder target)
{
if (this.Target is not null)
{
throw new InvalidOperationException("An output target has already been set.");
}
this.Target = target;
ProcessStepEdgeBuilder edgeBuilder = new(this.Source, this.EventId, this.EventId) { Target = this.Target };
this.Source.LinkTo(this.EventId, edgeBuilder);
return new ProcessEdgeBuilder(this.Source, this.EventId);
}
}