Esempio n. 1
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>();

            // Inputs
            var repositoryLocation   = RepositoryLocation.Get(context);
            var fileToUpload         = FileToUpload.Get(context);
            var commitMessage        = CommitMessage.Get(context);
            var repositoryUUIDOrSlug = RepositoryUUIDOrSlug.Get(context);
            var workspaceUUIDOrSlug  = WorkspaceUUIDOrSlug.Get(context);
            var branchName           = BranchName.Get(context);

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

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

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

            // Initialise and populate multipart content
            var multipartContent = new MultipartFormDataContent();

            multipartContent.Add(new ByteArrayContent(File.ReadAllBytes(fileToUpload)), repositoryLocation, Path.GetFileName(fileToUpload));
            multipartContent.Add(new StringContent(commitMessage), "message");

            // Check if optional branch name parameter provided. Add to request if not null.
            if (branchName != null)
            {
                multipartContent.Add(new StringContent(branchName), "branch");
            }

            // Execution Logic
            var response         = new JObject();
            var exceptionHandler = new ApiExceptionHandler();

            try
            {
                response = await AsyncRequests.PostRequest_WithBody(client, uri, cancellationToken, multipartContent);
            }
            catch (ApiException ex) // Catches any API exception and returns the message
            {
                await exceptionHandler.ParseExceptionAsync(ex);
            }

            // Outputs - API response as JObject
            return((ctx) =>
            {
                JsonResult.Set(ctx, response);
            });
        }
        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);
            });
        }
Esempio n. 3
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);
            });
        }
        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);
            var repositoryUUIDOrSlug = RepositoryUUIDOrSlug.Get(context);
            var requestType          = Enum.GetName(typeof(RequestTypes), (int)Action);

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

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

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

            // Initialise
            var response         = new JObject();
            var exceptionHandler = new ApiExceptionHandler();

            // Execution Logic for all types of API requests available for this endpoint
            try
            {
                switch (requestType)
                {
                case "GET":
                {
                    response = await AsyncRequests.GetRequest(client, uri, cancellationToken);

                    break;
                }

                case "POST":
                {
                    response = await AsyncRequests.PostRequest_NoBody(client, uri, cancellationToken);

                    break;
                }

                case "DELETE":
                {
                    response = await AsyncRequests.DeleteRequest(client, uri, cancellationToken);

                    break;
                }
                }
            }
            catch (ApiException ex) // Catches any API exception and returns the message
            {
                await exceptionHandler.ParseExceptionAsync(ex);
            }

            // Outputs - API response as JObject
            return((ctx) =>
            {
                JsonResult.Set(ctx, response);
            });
        }