Loading data from external sources

When I load data from an external powershell module, the page does not load before this completes. I tried using a backdrop to cover this however I still get the same issue. How do I do this process in the background?

Page displays as follows when loading content before showing the actual page:

Anythoughts on this?

Can you share a little of the script you are running? My first suggestion is to use New-UDDynamic to load sections that require background data but I would need to see some code to help further.

Sure

New-UDDashboard -Title ‘Home’ -theme $theme -Content {
New-UDAppBar -Position fixed -Children {
New-UDGrid -Container -Content{
New-UDGrid -Item -ExtraSmallSize 1 -Content{
New-UDImage -Id “logoImage” -URL “/themes/small.png”
}
New-UDGrid -Item -ExtraSmallSize 11 -Content{
New-UDElement -Id “logoText” -Tag ‘h1’ -Content {“Home”}
}
}
}
New-UDBackdrop -Id ‘backdrop’ -Content {
New-UDTypography -id ‘backdroptext’ -Text “Loading Devolutions Data…” -Variant h2
Import-Module RemoteDesktopManager.PowerShellModule
$session:DevolutionsVaults = Get-RDMVault #This is the line that causes the issue!
New-UDTypography -id ‘backdroptext’ -Text “Compleated! Click to continue” -Variant h2
} -Open -OnClick {
Set-UDElement -Id ‘backdrop’ -Properties @{
open = $false
}
}
#New-UDTabs -RenderOnActive -Tabs {
# foreach ($Devolutions_Tab in (Get-ChildItem “$UDScriptRoot\Tabs” -Recurse -filter *.ps1)) {
# New-UDTab -Text $Devolutions_Tab.name.split(’.’)[0] -Content {. $Devolutions_Tab.fullname}
# }
#}

} -DefaultTheme dark -Stylesheets @("/themes/theme.css")

I didn’t test this but this should give you the general idea.

New-UDDashboard -Title ‘Home’ -theme $theme -Content {
    New-UDAppBar -Position fixed -Children {
        New-UDGrid -Container -Content {
            New-UDGrid -Item -ExtraSmallSize 1 -Content {
                New-UDImage -Id “logoImage” -URL “/themes/small.png”
            }
            New-UDGrid -Item -ExtraSmallSize 11 -Content {
                New-UDElement -Id “logoText” -Tag ‘h1’ -Content { “Home” }
            }
        }
    }

    New-UDDynamic -Id 'background' -Content {
        if ($session:DevolutionsVaults -eq $null) {
            Import-Module RemoteDesktopManager.PowerShellModule
            $session:DevolutionsVaults = Get-RDMVault #This is the line that causes the issue!
            Sync-UDElement -Id 'content'
        }
    }

    New-UDDynamic -Id 'content' -Content {
        if ($session:DevolutionsVaults -eq $null) {
            New-UDBackdrop -Id ‘backdrop’ -Content {
                New-UDTypography -id ‘backdroptext’ -Text “Loading Devolutions Data…” -Variant h2
            } -Open
        }
        else {
            #New-UDTabs -RenderOnActive -Tabs {
            # foreach ($Devolutions_Tab in (Get-ChildItem “$UDScriptRoot\Tabs” -Recurse -filter *.ps1)) {
            # New-UDTab -Text $Devolutions_Tab.name.split(’.’)[0] -Content {. $Devolutions_Tab.fullname}
            # }
            #}
        } 
    }
} -DefaultTheme dark -Stylesheets @("/themes/theme.css")

Great ill try that out and report back.

That seems to work. whats the best way to check if the data is loaded and then close the backdrop?

New-UDDynamic -Id ‘content’ -Content {
while ($session:DevolutionsVaults -eq $null) {
New-UDBackdrop -Id ‘backdrop’ -Content {
New-UDTypography -id ‘backdroptext’ -Text “Loading Devolutions Data…” -Variant h2
} -Open
}
else {
Set-UDElement -Id ‘backdrop’ -Properties @{
open = $false
}
#New-UDTabs -RenderOnActive -Tabs {
# foreach ($Devolutions_Tab in (Get-ChildItem “$UDScriptRoot\Tabs” -Recurse -filter *.ps1)) {
# New-UDTab -Text $Devolutions_Tab.name.split(’.’)[0] -Content {. $Devolutions_Tab.fullname}
# }
#}
}
}

Trying this but it does not show the backdrop

Maybe try to close it when you finish loading the module.

    New-UDDynamic -Id 'background' -Content {
        if ($session:DevolutionsVaults -eq $null) {
            Import-Module RemoteDesktopManager.PowerShellModule
            $session:DevolutionsVaults = Get-RDMVault #This is the line that causes the issue!
            Set-UDElement -Id ‘backdrop’ -Properties @{
                open = $false
            }
            Sync-UDElement -Id 'content'
        }
    }

That does not seem to work either. Bug?

Maybe. I’ll have to play with it.

Thanks

This seems to work fine for me.

    New-UDDynamic -Id 'background' -Content {
        if ($session:DevolutionsVaults -eq $null) {
            Start-Sleep 3
            $session:DevolutionsVaults = "Cool"
            Set-UDElement -Id ‘backdrop’ -Properties @{
                open = $false
            }
            Sync-UDElement -Id 'content'
        }
    }

    New-UDDynamic -Id 'content' -Content {
        if ($session:DevolutionsVaults -eq $null) {
            New-UDBackdrop -Id ‘backdrop’ -Content {
                New-UDTypography -id ‘backdroptext’ -Text “Loading Devolutions Data” -Variant h2
            } -Open
        }
        else {
            New-UDTypography "Loaded"
        } 
    }

Thanks @adam maybe the powershell line is not working for me.

Yeah looks like the powershell function is not working. Out of interest in the laters version of PU and framework when calling external powershell commands does it run under the service context? If I run the commands in powershell from a powershell window it works but running under PU it does not seem to work. So dont know if its the application side or the context side.

Thanks

If you are running PSU as a service, it will run under the service context for all the dashboard commands.

Ok cool just double checking as that is what i thought

Looks like its trying to run under the pc context not the user account as the logs on the application are showing the computer account as the username.

Any ideas on that?

You’ll have to change the service account the service is running under. Right now, it’s likely running on Local System or something similar and that’s why it’s the computer’s account name.

Its running as a user account. Maybe when the upgrade happened that broke. Ill reset it and see if that works.

Yea when upgrading PU it wipes the service back, but services.msc does not reflect this so displays wrong without a manual refresh :smiley:

And its working :smiley:

1 Like