/// <summary>
        /// Creates a new <see cref="ActivityActorStateManager"/>.
        /// </summary>
        Task CreateStateManager()
        {
            state = new ActivityActorStateManager(this);

            state.Persisted = () =>
            {
                pump.Enqueue(async() =>
                {
                    await state.SaveAsync();
                    await SaveReminderAsync();
                    await actor.OnPersistedAsync();
                });
            };

            state.Completed = () =>
            {
                pump.Enqueue(async() =>
                {
                    await state.SaveAsync();
                    await SaveReminderAsync();
                });
            };

            return(Task.FromResult(true));
        }
        /// <summary>
        /// Attempts to load the workflow if possible.
        /// </summary>
        /// <returns></returns>
        async Task LoadWorkflow()
        {
            // might already be loaded somehow
            if (workflow == null)
            {
                // load state from actor
                await state.LoadAsync();

                // only continue if not already completed
                if (state.InstanceState != InstanceState.Completed)
                {
                    // generate owner ID
                    if (state.InstanceOwnerId == Guid.Empty)
                    {
                        state.InstanceOwnerId = Guid.NewGuid();
                    }

                    if (state.InstanceId == Guid.Empty)
                    {
                        // clear existing data
                        state.ClearInstanceData();
                        state.ClearInstanceMetadata();

                        // create workflow application
                        await CreateWorkflow(actor.CreateActivity(), actor.CreateActivityInputs() ?? new Dictionary <string, object>());

                        state.InstanceId = workflow.Id;
                        await InvokeAndPump(workflow.RunAsync);

                        await state.SaveAsync();
                    }
                    else
                    {
                        // create workflow application
                        await CreateWorkflow(actor.CreateActivity());
                        await InvokeAndPump(async() => await workflow.LoadAsync(state.InstanceId));
                        await InvokeAndPump(workflow.RunAsync);

                        await state.SaveAsync();
                    }
                }
            }
        }