-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStandardOutputPort.cs
More file actions
43 lines (34 loc) · 1.19 KB
/
Copy pathStandardOutputPort.cs
File metadata and controls
43 lines (34 loc) · 1.19 KB
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
using System;
using System.Collections.Generic;
namespace NTransit {
public class StandardOutputPort : IOutputPort {
public string Name { get; set; }
public Component Process { get; set; }
public bool HasCapacity { get { return connectedPort.HasCapacity; } }
public bool Connected { get { return connectedPort != null; } }
public bool Closed { get; private set; }
public bool ConnectedPortClosed { get { return Connected && connectedPort.Closed; } }
IInputPort connectedPort;
public StandardOutputPort(Component process) {
Process = process;
}
public void ConnectTo(IInputPort port) {
connectedPort = port;
}
public bool TrySend(InformationPacket ip) {
return TrySend(ip, false);
}
public bool TrySend(InformationPacket ip, bool ignoreClosed) {
if (!ignoreClosed && Closed) {
throw new InvalidOperationException(string.Format("Cannot send data on closed port '{0}.{1}'", Process.Name, Name));
}
if (!Connected) {
throw new InvalidOperationException(string.Format("Cannot send data on unconnected port '{0}.{1}'", Process.Name, Name));
}
return !connectedPort.Closed && connectedPort.TrySend(ip);
}
public void Close() {
Closed = true;
}
}
}