protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(BitbucketAPIScope.ParentContainerPropertyTag);
            var client          = objectContainer.Get <FluentClient>();

            // Inputs
            var workspaceUUIDOrSlug = WorkspaceUUIDOrSlug.Get(context);

            // Validate whether Workspace UUID or Slug provided (assume name will never be a GUID format)
            if (Validation.IsUUID(workspaceUUIDOrSlug))
            {
                HttpUtility.UrlEncode(workspaceUUIDOrSlug);
            }

            // Create request URI
            var uri = "repositories/" + workspaceUUIDOrSlug;

            // Initialsie
            var response           = new JObject();
            var repositorySlugList = new List <string>();
            var repositoryUUIDList = new List <string>();
            var exceptionHandler   = new ApiExceptionHandler();

            try
            {
                // Perform request
                response = await AsyncRequests.GetRequest(client, uri, cancellationToken);

                // Create slug list
                repositorySlugList = JObjectParser.JObjectToSlugList(response);

                // Create UUID list
                repositoryUUIDList = JObjectParser.JObjectToUUIDList(response);
            }
            catch (ApiException ex) // Catches any API exception and returns the message
            {
                await exceptionHandler.ParseExceptionAsync(ex);
            }

            // Outputs
            return((ctx) =>
            {
                RepositoriesJObject.Set(ctx, response);
                RepositoriesSlugList.Set(ctx, repositorySlugList);
                RepositoriesUUIDList.Set(ctx, repositoryUUIDList);
            });
        }
Beispiel #2
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(BitbucketAPIScope.ParentContainerPropertyTag);
            var client          = objectContainer.Get <FluentClient>();

            // Create request URI
            var uri = "workspaces";

            // Initialsie
            var response          = new JObject();
            var workspaceSlugList = new List <string>();
            var workspaceUUIDList = new List <string>();
            var exceptionHandler  = new ApiExceptionHandler();

            try
            {
                // Perform request
                response = await AsyncRequests.GetRequest(client, uri, cancellationToken);

                // Create slug list
                workspaceSlugList = JObjectParser.JObjectToSlugList(response);

                // Create UUID list
                workspaceUUIDList = JObjectParser.JObjectToUUIDList(response);
            }
            catch (ApiException ex) // Catches any API exception and returns the message
            {
                await exceptionHandler.ParseExceptionAsync(ex);
            }

            // Outputs
            return((ctx) =>
            {
                WorkspacesJObject.Set(ctx, response);
                WorkspacesSlugList.Set(ctx, workspaceSlugList);
                WorkspacesUUIDList.Set(ctx, workspaceUUIDList);
            });
        }