Tableau Migration SDK 5.1.1
  • Articles
  • Code Samples
  • Python API Reference
  • C# API Reference
Show / Hide Table of Contents
  • Filters
    • Filter projects by name
    • Filter users by SiteRole
    • Filter Custom Views by 'Shared' flag
  • Mappings
    • Username email
    • Rename projects
    • Change projects
  • Transformers
    • Add tags to content
    • Encrypt Extracts
    • Adjust 'Start At' to Scheduled Tasks
    • Change default users for Custom Views
    • Action URL XML Transformer
  • Post-Publish Hooks
    • Update permissions
  • Bulk Post-Publish Hooks
    • Bulk logging
  • Batch Migration Completed Hooks
    • Batch migration logging
  • Migration Action Completed Hooks
    • Migration action logging

Sample: Bulk logging

In the following example, a bulk post-publish hook logs published items.

  • Python
  • C#

Bulk Post-Publish Hook Class

import logging
from tableau_migration import (
    BulkPostPublishHookBase,
    BulkPostPublishContext,
    IDataSource)


class BulkLoggingHookForDataSources(BulkPostPublishHookBase[IDataSource]):
    def __init__(self) -> None:
        super().__init__()
        
        # Create a logger for this class
        self._logger = logging.getLogger(__name__)
        
    def execute(self, ctx: BulkPostPublishContext[IDataSource]) -> BulkPostPublishContext[IDataSource]:
        # Log the number of items published in the batch.
        self._logger.info("Published %d IDataSource item(s).", ctx.published_items.count)
        return None
    

Registration

Learn more.

plan_builder.hooks.add(BulkLoggingHookForDataSources)

Bulk Post-Publish Hook Class

public class BulkLoggingHook<T> : BulkPostPublishHookBase<T>
{
    private readonly ILogger<BulkLoggingHook<T>> _logger;

    public BulkLoggingHook(ILogger<BulkLoggingHook<T>> logger)
    {
        _logger = logger;
    }

    public override Task<BulkPostPublishContext<T>?> ExecuteAsync(BulkPostPublishContext<T> ctx, CancellationToken cancel)
    {
        // Log the number of items published in the batch.
        _logger.LogInformation(
            "Published {Count} {ContentType} item(s).",
            ctx.PublishedItems.Count,
            typeof(T).Name);

        return Task.FromResult<BulkPostPublishContext<T>?>(ctx);
    }
}

Registration

Learn more.

_planBuilder.Hooks.Add<BulkLoggingHook<IUser>>();

Dependency Injection

Learn more.

services.AddScoped(typeof(BulkLoggingHook<>));
  • Edit this page
In this article