private void BeginCreatePrepared(ProjectionConfig config, Action onPrepared)
        {
            _onPrepared = onPrepared;
            if (config == null) throw new ArgumentNullException("config");

            //TODO: which states are allowed here?
            if (_state >= ManagedProjectionState.Preparing)
            {
                DisposeCoreProjection();
                _state = ManagedProjectionState.Loaded;
            }

            //TODO: load configuration from the definition

            if (_persistedState.SourceDefinition == null)
                throw new Exception(
                    "The projection cannot be loaded as stopped as it was stored in the old format.  Update the projection query text to force prepare");

            var createProjectionMessage =
                new CoreProjectionManagementMessage.CreatePrepared(
                    new PublishEnvelope(_inputQueue), Id, _name,
                    new ProjectionVersion(_projectionId, _persistedState.Epoch ?? 0, _persistedState.Version ?? 1),
                    config, _persistedState.SourceDefinition, HandlerType, Query);

            //note: set running before start as coreProjection.start() can respond with faulted
            _state = ManagedProjectionState.Preparing;
            _coreQueue.Publish(createProjectionMessage);
        }
        private CoreProjectionManagementMessage.CreatePrepared CreatePreparedMessage(ProjectionConfig config)
        {
            if (PersistedProjectionState.SourceDefinition == null)
                throw new Exception(
                    "The projection cannot be loaded as stopped as it was stored in the old format.  Update the projection query text to force prepare");

            var createProjectionMessage = new CoreProjectionManagementMessage.CreatePrepared(
                Id,
                _workerId,
                _name,
                new ProjectionVersion(_projectionId, PersistedProjectionState.Epoch ?? 0, PersistedProjectionState.Version ?? 1),
                config,
                QuerySourcesDefinition.From(PersistedProjectionState.SourceDefinition),
                HandlerType,
                Query);
            return createProjectionMessage;
        }