forked from tompaana/bot-message-routing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalRoutingDataManager.cs
More file actions
183 lines (160 loc) · 5.72 KB
/
LocalRoutingDataManager.cs
File metadata and controls
183 lines (160 loc) · 5.72 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System;
using System.Collections.Generic;
using Underscore.Bot.Models;
using Underscore.Bot.Utils;
namespace Underscore.Bot.MessageRouting.DataStore.Local
{
/// <summary>
/// Routing data manager that stores the data locally.
///
/// NOTE: USE THIS CLASS ONLY FOR TESTING!
/// Storing the data like this in production would not work since the bot can and likely will
/// have multiple instances.
///
/// See IRoutingDataManager and AbstractRoutingDataManager for general documentation of
/// properties and methods.
/// </summary>
[Serializable]
public class LocalRoutingDataManager : AbstractRoutingDataManager
{
/// <summary>
/// Parties that are users (not this bot).
/// </summary>
protected IList<Party> UserParties
{
get;
set;
}
/// <summary>
/// If the bot is addressed from different channels, its identity in terms of ID and name
/// can vary. Those different identities are stored in this list.
/// </summary>
protected IList<Party> BotParties
{
get;
set;
}
/// <summary>
/// Represents the channels (and the specific conversations e.g. specific channel in Slack),
/// where the chat requests are directed. For instance, a channel could be where the
/// customer service agents accept customer chat requests.
/// </summary>
protected IList<Party> AggregationParties
{
get;
set;
}
/// <summary>
/// The list of parties waiting for their (conversation) requests to be accepted.
/// </summary>
protected List<Party> PendingRequests
{
get;
set;
}
/// <summary>
/// Contains 1:1 associations between parties i.e. parties connected in a conversation.
/// Furthermore, the key party is considered to be the conversation owner e.g. in
/// a customer service situation the customer service agent.
/// </summary>
protected Dictionary<Party, Party> ConnectedParties
{
get;
set;
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="globalTimeProvider">The global time provider for providing the current
/// time for various events such as when a connection is requested.</param>
public LocalRoutingDataManager(GlobalTimeProvider globalTimeProvider = null)
: base(globalTimeProvider)
{
AggregationParties = new List<Party>();
UserParties = new List<Party>();
BotParties = new List<Party>();
PendingRequests = new List<Party>();
ConnectedParties = new Dictionary<Party, Party>();
}
public override IList<Party> GetUserParties()
{
List<Party> userPartiesAsList = UserParties as List<Party>;
return userPartiesAsList?.AsReadOnly();
}
public override IList<Party> GetBotParties()
{
List<Party> botPartiesAsList = BotParties as List<Party>;
return botPartiesAsList?.AsReadOnly();
}
public override IList<Party> GetAggregationParties()
{
List<Party> aggregationPartiesAsList = AggregationParties as List<Party>;
return aggregationPartiesAsList?.AsReadOnly();
}
public override IList<Party> GetPendingRequests()
{
List<Party> pendingRequestsAsList = PendingRequests as List<Party>;
return pendingRequestsAsList?.AsReadOnly();
}
public override Dictionary<Party, Party> GetConnectedParties()
{
return ConnectedParties;
}
public override void DeleteAll()
{
base.DeleteAll();
AggregationParties.Clear();
UserParties.Clear();
BotParties.Clear();
PendingRequests.Clear();
ConnectedParties.Clear();
}
protected override bool ExecuteAddParty(Party partyToAdd, bool isUser)
{
if (isUser)
{
UserParties.Add(partyToAdd);
}
else
{
BotParties.Add(partyToAdd);
}
return true;
}
protected override bool ExecuteRemoveParty(Party partyToRemove, bool isUser)
{
if (isUser)
{
return UserParties.Remove(partyToRemove);
}
return BotParties.Remove(partyToRemove);
}
protected override bool ExecuteAddAggregationParty(Party aggregationPartyToAdd)
{
AggregationParties.Add(aggregationPartyToAdd);
return true;
}
protected override bool ExecuteRemoveAggregationParty(Party aggregationPartyToRemove)
{
return AggregationParties.Remove(aggregationPartyToRemove);
}
protected override bool ExecuteAddPendingRequest(Party requestorParty)
{
PendingRequests.Add(requestorParty);
return true;
}
protected override bool ExecuteRemovePendingRequest(Party requestorParty)
{
return PendingRequests.Remove(requestorParty);
}
protected override bool ExecuteAddConnection(Party conversationOwnerParty, Party conversationClientParty)
{
ConnectedParties.Add(conversationOwnerParty, conversationClientParty);
return true;
}
protected override bool ExecuteRemoveConnection(Party conversationOwnerParty)
{
return ConnectedParties.Remove(conversationOwnerParty);
}
}
}