示例#1
0
        public static async Task <Dictionary <string, string> > RunActivity(
            [ActivityTrigger] ProviderProjectDeleteCommand command,
            ILogger log)
        {
            if (command is null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            return(new Dictionary <string, string>());
        }
        public static Dictionary <string, string> RunActivity(
            [ActivityTrigger] ProviderProjectDeleteCommand command,
            ILogger log)
        {
            if (command is null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            using (log.BeginCommandScope(command))
            {
                try
                {
                    return(new Dictionary <string, string>());
                }
                catch (Exception exc)
                {
                    log.LogError(exc, $"{nameof(ProjectDeleteActivity)} failed: {exc.Message}");

                    throw exc.AsSerializable();
                }
            }
        }
示例#3
0
        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 <OrchestratorProjectDeleteCommand>();
            var commandResult = command.CreateResult();

            using (log.BeginCommandScope(command))
            {
                orchestrationContext.SetCustomStatus($"Refreshing project", log);

                var project = commandResult.Result = (await orchestrationContext
                                                      .GetProjectAsync(command.ProjectId, allowUnsafe: true)
                                                      .ConfigureAwait(true)) ?? command.Payload;

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

                        var providerCommand = new ProviderProjectDeleteCommand
                                              (
                            command.User.PopulateExternalModel(),
                            project.PopulateExternalModel(),
                            command.CommandId
                                              );

                        var providerResults = await orchestrationContext
                                              .SendProviderCommandAsync <ProviderProjectDeleteCommand, ProviderProjectDeleteCommandResult>(providerCommand, project)
                                              .ConfigureAwait(true);
                    }
                    finally
                    {
                        orchestrationContext.SetCustomStatus("Deleting project", log);

                        await orchestrationContext
                        .DeleteProjectAsync(project)
                        .ConfigureAwait(true);

                        orchestrationContext.SetCustomStatus($"Deleting project identity", log);

                        await orchestrationContext
                        .CallActivityWithRetryAsync(nameof(ProjectIdentityDeleteActivity), project)
                        .ConfigureAwait(true);

                        orchestrationContext.SetCustomStatus("Deleting resources", log);

                        await orchestrationContext.DeleteResourcesAsync
                        (
                            false, // we are not going to wait for this operation
                            GetResourceGroupId(project?.ResourceGroup?.Id)
                        )
                        .ConfigureAwait(true);
                    }
                }
                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: {commandException.Message}", log, commandException);
                    }

                    orchestrationContext.SetOutput(commandResult);
                }
            }
        }