public static async Task RunOrchestration(
            [OrchestrationTrigger] IDurableOrchestrationContext functionContext,
            ILogger log)
        {
            if (functionContext is null)
            {
                throw new ArgumentNullException(nameof(functionContext));
            }

            if (log is null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            var command        = functionContext.GetInput <OrchestratorProjectUserDeleteCommand>();
            var commandResult  = command.CreateResult();
            var commandProject = default(Project);

            using (log.BeginCommandScope(command))
            {
                try
                {
                    functionContext.SetCustomStatus($"Deleting user", log);

                    using (await functionContext.LockAsync <Project>(command.ProjectId.ToString()).ConfigureAwait(true))
                    {
                        commandProject = await functionContext
                                         .GetProjectAsync(command.ProjectId.GetValueOrDefault())
                                         .ConfigureAwait(true);

                        if (commandProject.Users.Remove(command.Payload))
                        {
                            commandProject = await functionContext
                                             .SetProjectAsync(commandProject)
                                             .ConfigureAwait(true);
                        }
                    }

                    functionContext.SetCustomStatus("Sending commands", log);

                    var providerCommand = new ProviderProjectUserDeleteCommand
                                          (
                        command.User,
                        command.Payload,
                        commandProject.Id,
                        command.CommandId
                                          );

                    var providerResults = await functionContext
                                          .SendCommandAsync <ProviderProjectUserDeleteCommand>(providerCommand, commandProject)
                                          .ConfigureAwait(true);

                    var providerException = providerResults.Values?
                                            .SelectMany(result => result.Errors ?? new List <CommandError>())
                                            .ToException();

                    if (providerException != null)
                    {
                        throw providerException;
                    }
                }
                catch (Exception exc)
                {
                    commandResult ??= command.CreateResult();
                    commandResult.Errors.Add(exc);

                    throw;
                }
                finally
                {
                    var commandException = commandResult.Errors?.ToException();

                    if (commandException is null)
                    {
                        functionContext.SetCustomStatus($"Command succeeded", log);
                    }
                    else
                    {
                        functionContext.SetCustomStatus($"Command failed", log, commandException);
                    }

                    commandResult.Result = command.Payload;

                    functionContext.SetOutput(commandResult);
                }
            }
        }
        public static async Task RunOrchestration(
            [OrchestrationTrigger] IDurableOrchestrationContext orchestrationContext,
            ILogger log)
        {
            if (orchestrationContext is null)
            {
                throw new ArgumentNullException(nameof(orchestrationContext));
            }

            if (log is null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            var command       = orchestrationContext.GetInput <OrchestratorProjectUserDeleteCommand>();
            var commandResult = command.CreateResult();
            var user          = command.Payload;

            using (log.BeginCommandScope(command))
            {
                try
                {
                    orchestrationContext.SetCustomStatus($"Deleting user", log);

                    using (await orchestrationContext.LockContainerDocumentAsync(user).ConfigureAwait(true))
                    {
                        user = await orchestrationContext
                               .DeleteUserProjectMembershipAsync(user, command.ProjectId)
                               .ConfigureAwait(true);
                    }

                    orchestrationContext.SetCustomStatus("Sending commands", log);

                    var providerCommand = new ProviderProjectUserDeleteCommand
                                          (
                        command.User.PopulateExternalModel(),
                        user.PopulateExternalModel(),
                        command.ProjectId,
                        command.CommandId
                                          );

                    var providerResults = await orchestrationContext
                                          .SendProviderCommandAsync(providerCommand, null)
                                          .ConfigureAwait(true);

                    var providerException = providerResults.Values?
                                            .SelectMany(result => result.Errors ?? new List <CommandError>())
                                            .ToException();

                    if (providerException != null)
                    {
                        throw providerException;
                    }
                }
                catch (Exception exc)
                {
                    commandResult ??= command.CreateResult();
                    commandResult.Errors.Add(exc);
                }
                finally
                {
                    var commandException = commandResult.Errors?.ToException();

                    if (commandException is null)
                    {
                        orchestrationContext.SetCustomStatus($"Command succeeded", log);
                    }
                    else
                    {
                        orchestrationContext.SetCustomStatus($"Command failed", log, commandException);
                    }

                    commandResult.Result = user;

                    orchestrationContext.SetOutput(commandResult);
                }
            }
        }