diff --git a/src/PRo3D.Viewer/RemoteControlApp.fs b/src/PRo3D.Viewer/RemoteControlApp.fs index 8cd148bb..9677546a 100644 --- a/src/PRo3D.Viewer/RemoteControlApp.fs +++ b/src/PRo3D.Viewer/RemoteControlApp.fs @@ -11,6 +11,8 @@ open PRo3D.SimulatedViews open RemoteControlModel open MBrace + + type ClientStatistics = { session : System.Guid @@ -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 = - 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) @@ -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) @@ -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 -> @@ -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 diff --git a/src/PRo3D.Viewer/Utilities.fs b/src/PRo3D.Viewer/Utilities.fs index 01cc8207..b5da98d6 100644 --- a/src/PRo3D.Viewer/Utilities.fs +++ b/src/PRo3D.Viewer/Utilities.fs @@ -10,6 +10,8 @@ open OpcViewer.Base open PRo3D open PRo3D.Base.Annotation + +open System.Net.Http module Mod = open FSharp.Data.Adaptive @@ -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 = Pickler.unpickleOfJson jsonString - (wc, clientStats) + (httpClient, clientStats) namespace Aardvark.UI diff --git a/src/PRo3D.Viewer/Viewer/SceneConverter.fs b/src/PRo3D.Viewer/Viewer/SceneConverter.fs index 56bb24cc..513e8a05 100644 --- a/src/PRo3D.Viewer/Viewer/SceneConverter.fs +++ b/src/PRo3D.Viewer/Viewer/SceneConverter.fs @@ -3,6 +3,7 @@ open System open System.Diagnostics +open System.Net.Http // helper module for spawning processes module private Process = @@ -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