Exemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log,
            CancellationToken token)
        {
            ITransformationProcess process;
            string id;
            Guid   processId;

            switch (req.Method)
            {
            // Trigger the transformation of a whole site
            case "POST":
                string target = "TargetSite";

                // Create the process
                process = await transformationExecutor.CreateTransformationProcessAsync(token);

                // Start to enqueue items
                await process.StartProcessAsync(
                    pnpContextFactory,
                    sourceContext,
                    target,
                    token);

                return(new OkObjectResult(new { process.Id }));

            // Get the status of a running transformation
            case "GET":
                id = req.Query["id"];
                if (!Guid.TryParse(id, out processId))
                {
                    return(new BadRequestResult());
                }

                process = await transformationExecutor.LoadTransformationProcessAsync(processId, token);

                var status = await process.GetStatusAsync(token);

                return(new OkObjectResult(status));

            // Cancel a running transformation
            case "DELETE":
                id = req.Query["id"];
                if (!Guid.TryParse(id, out processId))
                {
                    return(new BadRequestResult());
                }

                process = await transformationExecutor.LoadTransformationProcessAsync(processId, token);

                await process.StopProcessAsync(token);

                return(new OkResult());
            }

            return(new BadRequestResult());
        }
Exemplo n.º 2
0
        public async Task Run([QueueTrigger("%TasksQueueName%", Connection = "AzureWebJobsStorage")] TaskQueueItem item,
                              ILogger log,
                              CancellationToken token)
        {
            log.LogInformation($"Processing: {item.TaskId}");

            // Restore process info
            var process = await executor.LoadTransformationProcessAsync(item.ProcessId, token);

            if (!(process is LongRunningTransformationProcessBase p))
            {
                throw new NotSupportedException();
            }

            string target = "TargetSite";

            // Create SharePoint target context
            PnPContext targetContext = await pnpContextFactory.CreateAsync(target);

            // Configure the source item id and the data source provider
            var sourceItemId   = new SharePointSourceItemId(item.SourcePageUri);
            var sourceProvider = new SharePointSourceProvider(sourceContext);

            // Execute the actual transformatio task
            var task = new PageTransformationTask(item.TaskId, sourceProvider, sourceItemId, targetContext);
            await p.ProcessTaskAsync(task, token);
        }