最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PowerBi PowerBiClient : PostImportWithFileAsyncInGroup sometimes results in no datasets, while datasets are updated - Stack Over

programmeradmin2浏览0评论

I'm trying to upload a Symantic Model in a PowreBi Workspace, using the c# PowerBiClient. I'm using the following code:

public async Task<Import> UpsertDataSet(Guid groupId, string path, string displayName)
{
    var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);

    using var pbixStream = new FileStream(path, FileMode.Open, FileAccess.Read);
    var import = await pbiClient.Imports.PostImportWithFileAsyncInGroup(groupId, pbixStream, displayName, nameConflict: ImportConflictHandlerMode.CreateOrOverwrite);

    return await pbiClient.Imports.GetImportInGroupAsync(groupId, import.Id);
}

There are cases where the import.Datasets are not filled while the Model is uploaded.

I added and extra GetImportInGroupAsync to check if the model is updated. How come that the result is empty which the Model is updated

I'm trying to upload a Symantic Model in a PowreBi Workspace, using the c# PowerBiClient. I'm using the following code:

public async Task<Import> UpsertDataSet(Guid groupId, string path, string displayName)
{
    var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);

    using var pbixStream = new FileStream(path, FileMode.Open, FileAccess.Read);
    var import = await pbiClient.Imports.PostImportWithFileAsyncInGroup(groupId, pbixStream, displayName, nameConflict: ImportConflictHandlerMode.CreateOrOverwrite);

    return await pbiClient.Imports.GetImportInGroupAsync(groupId, import.Id);
}

There are cases where the import.Datasets are not filled while the Model is uploaded.

I added and extra GetImportInGroupAsync to check if the model is updated. How come that the result is empty which the Model is updated

Share Improve this question asked Mar 31 at 14:26 BartBart 3253 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Apperently the PostImportWithFileAsyncInGroup returns directly and there is a need for polling the importstate

public async Task<Import> UpsertDataSet(Guid groupId, string path, string displayName)
{
    var pbiClient = await GetPowerBIClient() ?? throw new PowerBiException(PowerBiClientIsNull);

    using var pbixStream = new FileStream(path, FileMode.Open, FileAccess.Read);
    var import = await pbiClient.Imports.PostImportWithFileAsyncInGroup(groupId, pbixStream,
        datasetDisplayName: displayName,
        nameConflict: ImportConflictHandlerMode.CreateOrOverwrite,
        overrideModelLabel: true,
        overrideReportLabel: true);

    var importId = import.Id;
    var retry = 0;

    while (retry++ < MaxRetries)
    {
        var importState = ParseImportState(import.ImportState);

        if (importState is ImportState.Succeeded)
        {
            logger.LogInformation("Dataset updated: - {Name} (Id: {Id})", import.Name, import.Id);
            return import;
        }

        if (importState is ImportState.Failed)
        {
            throw new PowerBiException(ImportFailed);
        }

        await Task.Delay(500);

        import = await pbiClient.Imports.GetImportInGroupAsync(groupId, importId);
    }

    throw new PowerBiException(ImportFailed);
}
private static ImportState ParseImportState(string state)
{
    return state switch
    {
        "Succeeded" => ImportState.Succeeded,
        "Failed" => ImportState.Failed,
        "Publishing" => ImportState.Publishing,
        _ => ImportState.Unknown
    };
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论