Esempio n. 1
0
        private void StartSubscription(StartSubscriptionMessage msg)
        {
            switch (_state)
            {
            case ConnectionState.Init:
                msg.Source.SetException(new InvalidOperationException(string.Format("EventStoreConnection '{0}' is not active.", _esConnection.ConnectionName)));
                break;

            case ConnectionState.Connecting:
            case ConnectionState.Connected:
                var operation = new VolatileSubscriptionOperation(_settings.Log, msg.Source, msg.StreamId, msg.ResolveLinkTos,
                                                                  msg.UserCredentials, msg.EventAppeared, msg.SubscriptionDropped,
                                                                  _settings.VerboseLogging, () => _connection);
                LogDebug("StartSubscription {4} {0}, {1}, {2}, {3}.", operation.GetType().Name, operation, msg.MaxRetries, msg.Timeout, _state == ConnectionState.Connected ? "fire" : "enqueue");
                var subscription = new SubscriptionItem(operation, msg.MaxRetries, msg.Timeout);
                if (_state == ConnectionState.Connecting)
                {
                    _subscriptions.EnqueueSubscription(subscription);
                }
                else
                {
                    _subscriptions.StartSubscription(subscription, _connection);
                }
                break;

            case ConnectionState.Closed:
                msg.Source.SetException(new ObjectDisposedException(_esConnection.ConnectionName));
                break;

            default: throw new Exception(string.Format("Unknown state: {0}.", _state));
            }
        }
 private void StartSubscription(StartSubscriptionMessage msg)
 {
     switch (_state)
     {
         case ConnectionState.Init:
             msg.Source.SetException(new InvalidOperationException(string.Format("EventStoreConnection '{0}' is not active.", _esConnection.ConnectionName)));
             break;
         case ConnectionState.Connecting:
         case ConnectionState.Connected:
             var operation = new VolatileSubscriptionOperation(_settings.Log, msg.Source, msg.StreamId, msg.ResolveLinkTos,
                                                       msg.UserCredentials, msg.EventAppeared, msg.SubscriptionDropped,
                                                       _settings.VerboseLogging, () => _connection);
             LogDebug("StartSubscription {4} {0}, {1}, {2}, {3}.", operation.GetType().Name, operation, msg.MaxRetries, msg.Timeout, _state == ConnectionState.Connected ? "fire" : "enqueue");
             var subscription = new SubscriptionItem(operation, msg.MaxRetries, msg.Timeout);
             if (_state == ConnectionState.Connecting)
                 _subscriptions.EnqueueSubscription(subscription);
             else
                 _subscriptions.StartSubscription(subscription, _connection);
             break;
         case ConnectionState.Closed:
             msg.Source.SetException(new ObjectDisposedException(_esConnection.ConnectionName));
             break;
         default: throw new Exception(string.Format("Unknown state: {0}.", _state));
     }
 }