internal EventStoreSubscription(SubscriptionOperation subscriptionOperation, string streamId, long lastCommitPosition, int? lastEventNumber)
        {
            Ensure.NotNull(subscriptionOperation, "subscriptionOperation");

            _subscriptionOperation = subscriptionOperation;
            _streamId = streamId;
            LastCommitPosition = lastCommitPosition;
            LastEventNumber = lastEventNumber;
        }
        public SubscriptionItem(SubscriptionOperation operation, int maxRetries, TimeSpan timeout)
        {
            Ensure.NotNull(operation, "operation");

            Operation = operation;
            MaxRetries = maxRetries;
            Timeout = timeout;
            CreatedTime = DateTime.UtcNow;

            CorrelationId = Guid.NewGuid();
            RetryCount = 0;
            LastUpdated = DateTime.UtcNow;
        }
 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 SubscriptionOperation(_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));
     }
 }