private void RemoveSubscription(string id, ref int subscriptions) { object o; if (Subscribers.TryRemove(id, out o)) { if (!Subscribers.Any()) { var variable = new List <string> { Name }; var parent = Parent; while (parent != null) { variable.Insert(0, parent.Name); parent = parent.Parent; } using (var guard = new ReaderGuard(_papperLock)) { _papper.SetActiveState(false, variable.FirstOrDefault(), variable.Skip(1).Aggregate((a, b) => $"{a}.{b}")); _papper.UnsubscribeDataChanges(Name, OnDataChanged); } } Interlocked.Decrement(ref subscriptions); } foreach (var child in Childs) { child.Value.RemoveSubscription(id, ref subscriptions); } }
public async Task SubscribeAsync(IMqttSubscriber subscriber, string topic, MqttQualityOfServiceLevel mqttQosLevel) { if (!Subscribers.Any(e => e.Key == topic)) { Subscribers.Add(new KeyValuePair <string, List <IMqttSubscriber> >(topic, new List <IMqttSubscriber>())); } var topicSubscribers = Subscribers.First(e => e.Key == topic).Value; // client already subscribed to this topic if (!topicSubscribers.Contains(subscriber)) { await MqttClient.SubscribeAsync(topic, mqttQosLevel); topicSubscribers.Add(subscriber); } }
public void AddToFriends(User subscriber) { if (Id == subscriber.Id) { throw new Exception("You can not add to friend yourself"); } if (!Subscribers.Any(sub => sub.Subscriber.Id == subscriber.Id)) { throw new Exception("This user is not your subscriber"); } if (UserFriends.Any(friend => friend.Friend.Id == subscriber.Id)) { throw new Exception("This user already your friend"); } UserFriends.Add(new UserFriend(Id, subscriber.Id)); RemoveFromSubscribers(subscriber.Id); }
public override void EnsureSeeded() { Log.Debug("seeding..."); if (!MasterFacilities.Any()) { var data = SeedDataReader.ReadCsv <MasterFacility>(typeof(MnchContext).Assembly, "Seed", "|"); MasterFacilities.AddRange(data); } if (!Dockets.Any()) { var data = SeedDataReader.ReadCsv <Docket>(typeof(MnchContext).Assembly, "Seed", "|"); Dockets.AddRange(data); } if (!Subscribers.Any()) { var data = SeedDataReader.ReadCsv <Subscriber>(typeof(MnchContext).Assembly, "Seed", "|"); Subscribers.AddRange(data); } SaveChanges(); Log.Debug("seeding DONE"); }