-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientCollection.cs
More file actions
81 lines (72 loc) · 2.4 KB
/
Copy pathClientCollection.cs
File metadata and controls
81 lines (72 loc) · 2.4 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
using RSNiniManager;
using System.Collections.Concurrent;
namespace GrpcServerConsole
{
public class ClientCollection : IDisposable
{
private ConcurrentDictionary<string, ClientCondition> _collection;
public delegate void OnCommandSendHandler(string message);
public event OnCommandSendHandler CommandSend;
public class ClientCondition
{
public string? response { get; set; }
public bool commandCondition { get; set; }
public string command { get; set; }
public ClientCondition()
{
}
public ClientCondition(string res, bool comm)
{
response = res;
commandCondition = comm;
}
}
public ClientCollection()
{
_collection = new ConcurrentDictionary<string, ClientCondition>();
}
public void TryAdd(string key, string res)
{
bool addet = _collection.TryAdd(key, new ClientCondition(res, false));
if (!addet)
{
_collection[key].response = res;
}
}
public ClientCondition Get(string key)
{
//var cond = new ClientCondition();
//bool hasValue = _collection.TryGetValue(key, out cond);
return _collection[key];
}
public void Update(string key, bool commandCondition, string command = null)
{
if (_collection.ContainsKey(key))
{
if (commandCondition)
{
CommandSend.Invoke($"command [bold {Colors.selectionColor}]{command}[/] [{Colors.infoColor}]added[/] to revit: {key}");
}
else
{
CommandSend.Invoke($"command [bold {Colors.selectionColor}]{command}[/] [{Colors.infoColor}]send[/] to revit: {key}");
}
var cond = Get(key);
cond.commandCondition = commandCondition;
if (command != null)
{
cond.command = command;
}
_collection[key] = cond;
}
}
public ConcurrentDictionary<string, ClientCondition> GetCollection()
{
return _collection;
}
public void Dispose()
{
_collection.Clear();
}
}
}