Пример #1
0
        public static void SendTo(this SolarWindHub hub, HubId remoteHubId, object message, MessageId messageId = default)
        {
            if (hub.TryGetChannel(remoteHubId, out Channel channel))
            {
                channel.Post(message, messageId);
                return;
            }

            throw new InvalidOperationException($"Channel to '{remoteHubId}' was not found.");
        }
Пример #2
0
        private void OnConnected(Uri remoteUri, HubId remoteHubId, Connection connection)
        {
            Channel channel = _outChannels[remoteUri];

            channel.RemoteHubId = remoteHubId;
            var channelId = new ChannelId(_hubOptions.HubId, remoteHubId);

            _channels.TryAdd(channelId, channel);
            _remoteIndex.TryAdd(remoteHubId, channel);
            channel.OnReconnect(connection);
        }
Пример #3
0
        private void OnAccepted(HubId remoteHubId, Connection connection, BeforeChannelAccepted before, AfterChannelAccepted after)
        {
            var channelId = new ChannelId(_hubOptions.HubId, remoteHubId);

            Channel channel = _channels.GetOrAdd(channelId, id => new Channel(before(id.Remote), _hubOptions.LoggerFactory)
            {
                RemoteHubId = remoteHubId
            });

            _remoteIndex.TryAdd(remoteHubId, channel);
            after(channelId, channel);

            channel.OnReconnect(connection);
        }
Пример #4
0
 /// <summary>
 /// Looks up a channel by remote <see cref="HubId" />
 /// </summary>
 /// <param name="remoteHubId">An identifier of the remote hub.</param>
 /// <param name="channel">A channel to the remote hub.</param>
 /// <returns>True if hub is found and false otherwise.</returns>
 public bool TryGetChannel(HubId remoteHubId, out Channel channel)
 {
     EnsureNotDisposed();
     return(_remoteIndex.TryGetValue(remoteHubId, out channel));
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="ChannelId" /> structure
 /// </summary>
 /// <param name="local">Local hub identifier</param>
 /// <param name="remote">Remote hub identifier</param>
 public ChannelId(HubId local, HubId remote)
 {
     Local  = local;
     Remote = remote;
 }