public bool Subscribe(Guid correlationId, TcpPackageConnection connection) { Ensure.NotNull(connection, "connection"); if (_subscription != null || _unsubscribed != 0) return false; _correlationId = correlationId; connection.EnqueueSend(CreateSubscriptionPackage()); return true; }
internal void DropSubscription(SubscriptionDropReason reason, Exception exc, TcpPackageConnection connection = null) { if (Interlocked.CompareExchange(ref _unsubscribed, 1, 0) == 0) { if (_verboseLogging) _log.Debug("Subscription {0:B} to {1}: closing subscription, reason: {2}, exception: {3}...", _correlationId, _streamId == string.Empty ? "<all>" : _streamId, reason, exc); if (reason != SubscriptionDropReason.UserInitiated) { if (exc == null) throw new Exception(string.Format("No exception provided for subscription drop reason '{0}", reason)); _source.TrySetException(exc); } if (reason == SubscriptionDropReason.UserInitiated && _subscription != null && connection != null) connection.EnqueueSend(CreateUnsubscriptionPackage()); if (_subscription != null) ExecuteActionAsync(() => _subscriptionDropped(_subscription, reason, exc)); } }