-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSubscriptions.cs
68 lines (59 loc) · 1.95 KB
/
Subscriptions.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
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Fleck;
using Net.DDP.Server;
namespace Net.DDP.Server
{
/*
An IEnumerable collection of clients subscribed to publications.
*/
public class Subscriptions : IEnumerable<Subscription>
{
private readonly Dictionary<string, Subscription> _subscriptions;
internal Subscriptions()
{
_subscriptions = new Dictionary<string, Subscription>();
}
/// <summary>
/// Subscribes a client websocket connection to a publication
/// </summary>
/// <param name="subscription"></param>
public void Subscribe(Subscription subscription)
{
_subscriptions.Add(subscription.Id, subscription);
}
/// <summary>
/// Removes a client websocket connection from a subscription to a publication
/// </summary>
/// <param name="id"></param>
/// <param name="name"></param>
/// <param name="connection"></param>
public void Unsubscribe(string id, string name, IWebSocketConnection connection)
{
_subscriptions.Remove(id);
}
/// <summary>
/// Returns an IEnumerable collection of subscriptions to publication
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public IEnumerable<Subscription> GetSubscriptions(string name)
{
return _subscriptions.Where(subscription => subscription.Value.Name == name).Select(x => x.Value);
}
public IEnumerator<Subscription> GetEnumerator()
{
return _subscriptions.Select(subscription => subscription.Value).GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}