public void Handle(ClientMessage.DeletePersistentSubscription message)
        {
            if (!_started)
            {
                return;
            }
            Log.Debug("delete subscription " + message.GroupName);
            var streamAccess = _readIndex.CheckStreamAccess(SystemStreams.SettingsStream, StreamAccessType.Write, message.User);

            if (!streamAccess.Granted)
            {
                message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(message.CorrelationId,
                                                                                                   ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.AccessDenied,
                                                                                                   "You do not have permissions to create streams"));
                return;
            }
            var key = BuildSubscriptionGroupKey(message.EventStreamId, message.GroupName);
            PersistentSubscription subscription;

            if (!_subscriptionsById.TryGetValue(key, out subscription))
            {
                message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(message.CorrelationId,
                                                                                                   ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.DoesNotExist,
                                                                                                   "Group '" + message.GroupName + "' does not exist."));
                return;
            }
            if (!_subscriptionTopics.ContainsKey(message.EventStreamId))
            {
                message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(message.CorrelationId,
                                                                                                   ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Fail,
                                                                                                   "Group '" + message.GroupName + "' does not exist."));
                return;
            }
            RemoveSubscription(message.EventStreamId, message.GroupName);
            RemoveSubscriptionConfig(message.User.Identity.Name, message.EventStreamId, message.GroupName);
            subscription.Delete();
            SaveConfiguration(() => message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(message.CorrelationId,
                                                                                                                       ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Success, "")));
        }
        public void Handle(ClientMessage.DeletePersistentSubscription message)
        {
            if (!_started)
            {
                return;
            }
            var key = BuildSubscriptionGroupKey(message.EventStreamId, message.GroupName);

            Log.Debug("Deleting persistent subscription {subscriptionKey}", key);

            PersistentSubscription subscription;

            if (!_subscriptionsById.TryGetValue(key, out subscription))
            {
                message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(
                                               message.CorrelationId,
                                               ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.DoesNotExist,
                                               "Group '" + message.GroupName + "' does not exist."));
                return;
            }

            if (!_subscriptionTopics.ContainsKey(message.EventStreamId))
            {
                message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(
                                               message.CorrelationId,
                                               ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Fail,
                                               "Group '" + message.GroupName + "' does not exist."));
                return;
            }

            RemoveSubscription(message.EventStreamId, message.GroupName);
            RemoveSubscriptionConfig(message.User.Identity.Name, message.EventStreamId, message.GroupName);
            subscription.Delete();
            SaveConfiguration(() => message.Envelope.ReplyWith(new ClientMessage.DeletePersistentSubscriptionCompleted(
                                                                   message.CorrelationId,
                                                                   ClientMessage.DeletePersistentSubscriptionCompleted.DeletePersistentSubscriptionResult.Success, "")));
        }