Product: PowerShell Universal Version: 5.2.1
Hello,
I have a PSU page in an app that simply shows a csv file in a table.
I would like to have a timer that checks the file last write time and reloads the file to the table if there was a change.
I already got it going using New-UDEndpointSchedule.
But the Endpoint stays forever.
Calling the page again will have me one more endpoint and so on.
And data exchange from that endpoint is only possible via $cache:.
Is there a way to do this just within the web page?
would work to reload the whole page, but that is disturbing.
I just like to reload the table.
Thanks
Recommended Answer
I always seem to open a topic, when I am close to find a solution…
Tried some other things, decided to wrap the button itself into a New-UdDynamic, since I am still working under the impression that long running processes should be there. Came up with this that does work under that idea. New-UDDashboard -Title 'PowerShell Web' -Content { New-UDElement -Tag 'div' -Id 'myElement' -Content {} New-UDdynamic -content { New-UDButton -Text 'Click Me' -OnClick { Set-UDElement -Id 'myElement' -Content { New-UDP…
That’s the right approach.
Here the code I put at the begin of the page:
New-UDdynamic -content {
while ($true) {
9..0 | %{
Set-UDElement -id "reload" -Properties @{text="Reload check in $_ seconds"}
start-sleep 1
}
$timestamp=(get-item $page:logs.csvfile).LastWriteTimeUtc.Tostring("yyyy-MM-dd HH:mm.ss")
if ($timestamp -ne $page:logs.timestamp) {
Show-UDToast -Message "Reloading ..."
$page:logs.csv=import-csv $page:logs.csvfile
$page:logs.timestamp=(get-item $page:logs.csvfile).LastWriteTimeUtc.Tostring("yyyy-MM-dd HH:mm.ss")
$page:logs.data=$page:logs.csv | sort-object datim -Descending
Set-UDElement -id timestamp -Properties @{value=$page:logs.timestamp}
Sync-UDElement -id "logstable" #-Wait
}
}
}I always seem to open a topic, when I am close to find a solution…
Tried some other things, decided to wrap the button itself into a New-UdDynamic, since I am still working under the impression that long running processes should be there. Came up with this that does work under that idea. New-UDDashboard -Title 'PowerShell Web' -Content { New-UDElement -Tag 'div' -Id 'myElement' -Content {} New-UDdynamic -content { New-UDButton -Text 'Click Me' -OnClick { Set-UDElement -Id 'myElement' -Content { New-UDP…
That’s the right approach.
Here the code I put at the begin of the page:
New-UDdynamic -content {
while ($true) {
9..0 | %{
Set-UDElement -id "reload" -Properties @{text="Reload check in $_ seconds"}
start-sleep 1
}
$timestamp=(get-item $page:logs.csvfile).LastWriteTimeUtc.Tostring("yyyy-MM-dd HH:mm.ss")
if ($timestamp -ne $page:logs.timestamp) {
Show-UDToast -Message "Reloading ..."
$page:logs.csv=import-csv $page:logs.csvfile
$page:logs.timestamp=(get-item $page:logs.csvfile).LastWriteTimeUtc.Tostring("yyyy-MM-dd HH:mm.ss")
$page:logs.data=$page:logs.csv | sort-object datim -Descending
Set-UDElement -id timestamp -Properties @{value=$page:logs.timestamp}
Sync-UDElement -id "logstable" #-Wait
}
}
}