-
Notifications
You must be signed in to change notification settings - Fork 23
/
InMemoryRoutingDataStore.cs
181 lines (158 loc) · 6.07 KB
/
InMemoryRoutingDataStore.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
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
using Microsoft.Bot.Schema;
using System;
using System.Collections.Generic;
using Underscore.Bot.MessageRouting.Models;
namespace Underscore.Bot.MessageRouting.DataStore.Local
{
/// <summary>
/// Routing data store 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 the IRoutingDataStore interface for the general documentation of properties and methods.
/// </summary>
[Serializable]
public class InMemoryRoutingDataStore : IRoutingDataStore
{
/// <summary>
/// The list of users (identities).
/// </summary>
protected IList<ConversationReference> Users
{
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<ConversationReference> BotInstances
{
get;
set;
}
/// <summary>
/// Represents the channels (and the specific conversations e.g. specific channel in Teams),
/// where the chat requests are directed. For instance, a channel could be where the
/// customer service agents accept customer chat requests.
/// </summary>
protected IList<ConversationReference> AggregationChannels
{
get;
set;
}
/// <summary>
/// The list of connections.
/// </summary>
protected IList<Connection> Connections
{
get;
set;
}
/// <summary>
/// The list of connections requests waiting to be accepted/rejected.
/// </summary>
protected List<ConnectionRequest> ConnectionRequests
{
get;
set;
}
/// <summary>
/// Constructor.
/// </summary>
public InMemoryRoutingDataStore()
{
Users = new List<ConversationReference>();
BotInstances = new List<ConversationReference>();
AggregationChannels = new List<ConversationReference>();
ConnectionRequests = new List<ConnectionRequest>();
Connections = new List<Connection>();
}
public IList<ConversationReference> GetUsers()
{
List<ConversationReference> userPartiesAsList = Users as List<ConversationReference>;
return userPartiesAsList?.AsReadOnly();
}
public IList<ConversationReference> GetBotInstances()
{
List<ConversationReference> botPartiesAsList = BotInstances as List<ConversationReference>;
return botPartiesAsList?.AsReadOnly();
}
public bool AddConversationReference(ConversationReference conversationReferenceToAdd)
{
if (conversationReferenceToAdd.User != null)
{
Users.Add(conversationReferenceToAdd);
return true;
}
if (conversationReferenceToAdd.Bot != null)
{
BotInstances.Add(conversationReferenceToAdd);
return true;
}
return false;
}
public bool RemoveConversationReference(ConversationReference conversationReferenceToRemove)
{
if (conversationReferenceToRemove.User != null)
{
return ((Users as List<ConversationReference>)
.RemoveAll(conversationReference =>
RoutingDataManager.Match(conversationReference, conversationReferenceToRemove)) > 0);
}
if (conversationReferenceToRemove.Bot != null)
{
return ((BotInstances as List<ConversationReference>)
.RemoveAll(conversationReference =>
RoutingDataManager.Match(conversationReference, conversationReferenceToRemove)) > 0);
}
return false;
}
public IList<ConversationReference> GetAggregationChannels()
{
List<ConversationReference> aggregationPartiesAsList = AggregationChannels as List<ConversationReference>;
return aggregationPartiesAsList?.AsReadOnly();
}
public bool AddAggregationChannel(ConversationReference aggregationChannelToAdd)
{
AggregationChannels.Add(aggregationChannelToAdd);
return true;
}
public bool RemoveAggregationChannel(ConversationReference aggregationConversationReferenceToRemove)
{
return ((AggregationChannels as List<ConversationReference>)
.RemoveAll(conversationReference =>
RoutingDataManager.Match(conversationReference, aggregationConversationReferenceToRemove)) > 0);
}
public IList<ConnectionRequest> GetConnectionRequests()
{
List<ConnectionRequest> connectionRequestsAsList = ConnectionRequests as List<ConnectionRequest>;
return connectionRequestsAsList?.AsReadOnly();
}
public bool AddConnectionRequest(ConnectionRequest requestorConversationReference)
{
ConnectionRequests.Add(requestorConversationReference);
return true;
}
public bool RemoveConnectionRequest(ConnectionRequest requestorConversationReference)
{
return ConnectionRequests.Remove(requestorConversationReference);
}
public IList<Connection> GetConnections()
{
List<Connection> connectionsAsList = Connections as List<Connection>;
return connectionsAsList?.AsReadOnly();
}
public bool AddConnection(Connection connectionToAdd)
{
Connections.Add(connectionToAdd);
return true;
}
public bool RemoveConnection(Connection connectionToRemove)
{
return Connections.Remove(connectionToRemove);
}
}
}