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

            return(new Dictionary <string, string>());
        }
コード例 #2
0
        private async Task AssertResourceGroupAsync(ProviderProjectUpdateCommand command)
        {
            var resourceGroup = await AzureResourceService
                                .GetResourceGroupAsync(ResourceGroupSubscriptionId.Value, ResourceGroupName, true)
                                .ConfigureAwait(false);

            var resources = await resourceGroup.GetResourcesAsync()
                            .ToListAsync()
                            .ConfigureAwait(false);

            var resource = resources
                           .SingleOrDefault(resource => resource.ResourceId.ResourceTypeFullName.Equals("microsoft.insights/components", StringComparison.OrdinalIgnoreCase));

            Assert.NotNull(resource);

            foreach (var user in command.Payload.Users)
            {
                switch (user.ProjectMembership(command.Payload.Id.ToString()).Role)
                {
                case ProjectUserRole.Owner:

                    await resource
                    .ShouldHaveRoleAssignmentAsync(user, AzureRoleDefinition.Contributor)
                    .ConfigureAwait(false);

                    break;

                case ProjectUserRole.Member:

                    await resource
                    .ShouldHaveRoleAssignmentAsync(user, AzureRoleDefinition.Reader)
                    .ConfigureAwait(false);

                    break;

                case ProjectUserRole.None:

                    await resource
                    .ShouldHaveNoRoleAssignmentAsync(user)
                    .ConfigureAwait(false);

                    break;
                }
                ;
            }
        }
コード例 #3
0
        public static Dictionary <string, string> RunActivity(
            [ActivityTrigger] ProviderProjectUpdateCommand 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(ProviderProjectUpdateCommand)} failed: {exc.Message}");

                    throw exc.AsSerializable();
                }
            }
        }
コード例 #4
0
        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 <OrchestratorProjectUpdateCommand>();
            var commandResult = command.CreateResult();

            using (log.BeginCommandScope(command))
            {
                var project = commandResult.Result = command.Payload;

                try
                {
                    var projectUsers = project.Users.ToList();

                    using (await functionContext.LockContainerDocumentAsync(project).ConfigureAwait(true))
                    {
                        functionContext.SetCustomStatus($"Updating project", log);

                        project = commandResult.Result = await functionContext
                                                         .SetProjectAsync(project)
                                                         .ConfigureAwait(true);

                        functionContext.SetCustomStatus($"Adding users", log);

                        project.Users = await Task
                                        .WhenAll(projectUsers.Select(user => functionContext.SetUserProjectMembershipAsync(user, project.Id, allowUnsafe: true)))
                                        .ConfigureAwait(true);
                    }

                    functionContext.SetCustomStatus("Waiting on providers to update project resources.", log);

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

                    var providerResults = await functionContext
                                          .SendProviderCommandAsync <ProviderProjectUpdateCommand, ProviderProjectUpdateCommandResult>(providerCommand, project)
                                          .ConfigureAwait(true);
                }
                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: {commandException.Message}", log, commandException);
                    }

                    functionContext.SetOutput(commandResult);
                }
            }
        }