Skip to content

Commit

Permalink
Remove deprecated webclient in PRo3D Viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Pichler authored and Sophie Pichler committed Jan 15, 2025
1 parent 4789971 commit 609f485
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
43 changes: 7 additions & 36 deletions src/PRo3D.Viewer/RemoteControlApp.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ open PRo3D.SimulatedViews
open RemoteControlModel
open MBrace



type ClientStatistics =
{
session : System.Guid
Expand All @@ -26,37 +28,9 @@ module RemoteControlApp =

let jsonSerializer = FsPickler.Json.JsonSerializer(indent=true)



let fromDate (dt : DateTime) =
dt.ToString("yyyymmdd_hhmmss")

let takeScreenshot baseAddress (width:int) (height:int) name folder =
let wc = new System.Net.WebClient()
let path = "screenshots"
if System.IO.Directory.Exists path |> not then
System.IO.Directory.CreateDirectory path |> ignore
let clientStatistic =
let path = sprintf "%s/rendering/stats.json" baseAddress
Log.line "[RemoteControl] querying rendering stats at: %s" path
let result = wc.DownloadString(path)
let clientBla : list<ClientStatistics> =
Pickler.unpickleOfJson result
match clientBla with
| [] -> failwith "no client bla"
| x::[] -> x
| _ -> failwith "doent know"
let screenshot =
sprintf "%s/rendering/screenshot/%s?w=%d&h=%d&samples=8" baseAddress clientStatistic.name width height
Log.line "[RemoteControl] Running screenshot on: %s" screenshot

match System.IO.Directory.Exists folder with
| true -> ()
| false -> System.IO.Directory.CreateDirectory folder |> ignore

let filename = System.IO.Path.ChangeExtension (name,".jpg")
wc.DownloadFile(screenshot,Path.combine [folder; filename])

let mkInstrumetnWps m =
let pShots =
m.shots |> IndexList.choose(fun x -> PlatformShot.froAdaptiveRoverModel m.Rover x)
Expand Down Expand Up @@ -108,14 +82,12 @@ module RemoteControlApp =
| CaptureShot sh ->
let view = sh |> Shot.getViewSpec
view |> RemoteAction.SetView |> send

try Utilities.takeScreenshot baseAddress sh.col sh.row sh.id sh.folder ".png" with e -> printfn "error: %A" e
try Utilities.takeScreenshot baseAddress sh.col sh.row sh.id sh.folder ".png" with e -> printfn "error: %A" e
m
| CapturePlatform psh ->
let view = PlatformShot.getViewSpec m.Rover psh
view |> RemoteAction.SetView |> send

try Utilities.takeScreenshot baseAddress view.resolution.X view.resolution.Y psh.id psh.folder ".png" with e -> printfn "error: %A" e
try Utilities.takeScreenshot baseAddress view.resolution.X view.resolution.Y psh.id psh.folder ".png" with e -> printfn "error: %A" e
m
| UpdateCameraTest sh ->
send <| RemoteAction.SetCameraView (sh |> Shot.getCamera)
Expand All @@ -127,8 +99,7 @@ module RemoteControlApp =

let view = PlatformShot.getViewSpec m.Rover p
view |> RemoteAction.SetView |> send

try Utilities.takeScreenshot baseAddress view.resolution.X view.resolution.Y sh.id sh.folder ".png" with e -> printfn "error: %A" e
try Utilities.takeScreenshot baseAddress view.resolution.X view.resolution.Y sh.id sh.folder ".png" with e -> printfn "error: %A" e
m
| None -> m
| SelectShot sh ->
Expand All @@ -138,8 +109,8 @@ module RemoteControlApp =
{ m with selectedShot = Some sh }
| Play ->
for sh in m.shots do
send <| RemoteAction.SetCameraView (sh |> Shot.getCamera)
try Utilities.takeScreenshot baseAddress sh.col sh.row sh.id sh.folder ".png" with e -> printfn "error: %A" e
send <| RemoteAction.SetCameraView (sh |> Shot.getCamera)
try Utilities.takeScreenshot baseAddress sh.col sh.row sh.id sh.folder ".png" with e -> printfn "error: %A" e
m
| Load ->
loadData m
Expand Down
16 changes: 11 additions & 5 deletions src/PRo3D.Viewer/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ open OpcViewer.Base

open PRo3D
open PRo3D.Base.Annotation

open System.Net.Http

module Mod =
open FSharp.Data.Adaptive
Expand All @@ -30,24 +32,28 @@ module Net =
open System.Threading
open Aardvark.UI
let getClient () =
let downloadString_ (httpClient: HttpClient) (path: string) = async {
let! result = httpClient.GetStringAsync(path) |> Async.AwaitTask
return result
}
use cancelToken = new CancellationTokenSource()
let waitForClient =
async {
for i in 1..100 do
let wc = new System.Net.WebClient()
let httpClient = new HttpClient()
try
let lst = wc.DownloadString("http://localhost:54321/rendering/stats.json")
let lst = downloadString_ httpClient "http://localhost:54321/rendering/stats.json" |> Async.RunSynchronously
match String.length lst > 3 with
| true -> cancelToken.Cancel ()
| false -> do! Async.Sleep 1000
with ex -> do! Async.Sleep 1000
}
try Async.RunSynchronously (waitForClient, -1, cancelToken.Token) with e -> ()
let wc = new System.Net.WebClient()
let jsonString = wc.DownloadString("http://localhost:54321/rendering/stats.json")
let httpClient = new HttpClient()
let jsonString = downloadString_ httpClient "http://localhost:54321/rendering/stats.json" |> Async.RunSynchronously
let clientStats : list<PRo3D.Base.Utilities.ClientStatistics> =
Pickler.unpickleOfJson jsonString
(wc, clientStats)
(httpClient, clientStats)


namespace Aardvark.UI
Expand Down
11 changes: 9 additions & 2 deletions src/PRo3D.Viewer/Viewer/SceneConverter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System
open System.Diagnostics

open System.Net.Http

// helper module for spawning processes
module private Process =
Expand Down Expand Up @@ -71,11 +72,17 @@ module SceneLoading =

let mutable DownloadPath = "http://download.vrvis.at/acquisition/pro3d/49a0d346a7ecd7f8eca596a7d895da7cb38ed8c0.zip"

let downloadFile_ (url: string) (fileStream: FileStream) (client : HttpClient) = async {
let! responseStream = client.GetStreamAsync(url) |> Async.AwaitTask
do! responseStream.CopyToAsync(fileStream) |> Async.AwaitTask
}

let downloadConverter () =
use wc = new WebClient()
use httpClient = new HttpClient()
let temp = Path.GetTempFileName()
Log.line "Downloading converter from: %s" DownloadPath
wc.DownloadFile(DownloadPath, temp)
use fileStream = File.Create(DownloadPath)
downloadFile_ temp fileStream httpClient |> Async.RunSynchronously
if Directory.Exists ConverterPath then Directory.Delete(ConverterPath, true)
Directory.CreateDirectory ConverterPath |> ignore
Log.line "unpacking to: %s" ConverterPath
Expand Down

0 comments on commit 609f485

Please sign in to comment.