-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
95 lines (84 loc) · 4.47 KB
/
Program.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Threading.Tasks.Dataflow;
namespace mega_bank_corp_tpl_demo
{
class Program
{
static void Main(string[] args)
{
var openAccountBlock = new BroadcastBlock<ApplicantDetails>(null);
var creditCheckBlock = new TransformBlock<ApplicantDetails, PerformCheck>(applicantDetails =>
{
Console.WriteLine($"Credit check - {applicantDetails.NationalIdNumber}");
return new PerformCheck
{
Account = applicantDetails,
Success = true
};
});
var dbsCheck = new TransformBlock<ApplicantDetails, PerformCheck>(applicantDetails =>
{
Console.WriteLine($"DBS Check- {applicantDetails.NationalIdNumber}");
return new PerformCheck
{
Account = applicantDetails,
Success = true
};
});
var sendEmailSuccessAction = new TransformBlock<ApplicantDetails, ApplicantDetails>(applicantDetails =>
{
Console.WriteLine($"Send Email (Success) - {applicantDetails.NationalIdNumber}");
return applicantDetails;
});
var sendPostSuccessActionBlock = new TransformBlock<ApplicantDetails, ApplicantDetails>(applicantDetails =>
{
Console.WriteLine($"Send Post (Success) - {applicantDetails.NationalIdNumber}");
return applicantDetails;
});
var notifyCardIssueDeptAction = new TransformBlock<ApplicantDetails, ApplicantDetails>(applicantDetails =>
{
Console.WriteLine($"Notify card issue department - {applicantDetails.NationalIdNumber}");
return applicantDetails;
});
var openAccount = new TransformBlock<ApplicantDetails, ApplicantDetails>(applicantDetails =>
{
Console.WriteLine($"openeing account- {applicantDetails.NationalIdNumber}");
sendEmailSuccessAction.Post(applicantDetails);
sendPostSuccessActionBlock.Post(applicantDetails);
notifyCardIssueDeptAction.Post(applicantDetails);
return applicantDetails;
});
var checksCompletedBlock = new JoinBlock<PerformCheck, PerformCheck>(new GroupingDataflowBlockOptions { Greedy = false });
var checksDesicionBlock = new ActionBlock<Tuple<PerformCheck, PerformCheck>>(tuple =>
{
Console.WriteLine($"Checks completed - {tuple.Item1.Account.NationalIdNumber}");
if (tuple.Item1.Success && tuple.Item2.Success)
{
openAccount.Post(tuple.Item1.Account);
}
});
var postAccountOpenedActionsBlock = new JoinBlock<ApplicantDetails, ApplicantDetails, ApplicantDetails>(new GroupingDataflowBlockOptions { Greedy = false});
var audidCompletedBlock = new ActionBlock<Tuple<ApplicantDetails, ApplicantDetails, ApplicantDetails>>(tuple =>
{
Console.WriteLine($"Audit completed successfully - {tuple.Item1.NationalIdNumber}");
Console.WriteLine("");
});
openAccountBlock.LinkTo(creditCheckBlock, new DataflowLinkOptions());
openAccountBlock.LinkTo(dbsCheck, new DataflowLinkOptions());
creditCheckBlock.LinkTo(checksCompletedBlock.Target1); // first input of Join block
dbsCheck.LinkTo(checksCompletedBlock.Target2); // second input of Join block
checksCompletedBlock.LinkTo(checksDesicionBlock);
sendEmailSuccessAction.LinkTo(postAccountOpenedActionsBlock.Target1);
sendPostSuccessActionBlock.LinkTo(postAccountOpenedActionsBlock.Target2);
notifyCardIssueDeptAction.LinkTo(postAccountOpenedActionsBlock.Target3);
postAccountOpenedActionsBlock.LinkTo(audidCompletedBlock);
Console.WriteLine("Create a new MEGA Bank corp ");
Console.WriteLine("Enter National ID number to begin application:");
while (true)
{
var userId = Console.ReadLine();
openAccountBlock.Post(new ApplicantDetails(userId));
}
}
}
}