Example #1
0
        /// <summary>Returns user by peer.</summary>
        /// <param name="peer">Peer to find user.</param>
        /// <returns>User.</returns>
        public User GetUser(Peer peer)
        {
            if (peer == null) throw new ArgumentNullException("peer");
            if (!_map.ContainsValue(peer)) throw new InvalidOperationException(string.Format("Peer '{0}' is not stored.", peer));

            return _map.First(x => x.Value == peer).Key;
        }
Example #2
0
        /// <summary>Initializes a new instance of the RealmClient class using the specified protocol.</summary>
        /// <param name="protocol">Protocol.</param>
        public RealmClient(RealmProtocol protocol)
        {
            if (protocol == null) throw new ArgumentNullException("protocol", "Protocol can not be null");

            _peer = new Peer(protocol);
            _peer.ConnectionStateChanged += OnConnectionStateChanged;
            _peer.PacketReceived += OnPacketReceived;
        }
Example #3
0
        /// <summary>Maps user to peer.</summary>
        /// <param name="user">User to map.</param>
        /// <param name="peer">Peer to map.</param>
        public void Map(User user, Peer peer)
        {
            if (user == null) throw new ArgumentNullException("user", "User is null");
            if (peer == null) throw new ArgumentNullException("peer", "Peer is null");
            if (_map.ContainsKey(user)) throw new InvalidOperationException(string.Format("User '{0}' already mapped", user));
            if (_map.ContainsValue(peer)) throw new InvalidOperationException(string.Format("Peer '{0}' already mapped", peer));

            _map.Add(user, peer);
        }
Example #4
0
 public bool IsPeerStored(Peer peer)
 {
     return _map.ContainsValue(peer);
 }