aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs')
-rw-r--r--Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs96
1 files changed, 96 insertions, 0 deletions
diff --git a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
index 32a85ada6..eb5d57447 100644
--- a/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
+++ b/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
@@ -1,13 +1,109 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
+using System.Drawing;
+using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+using Tango.Core.Commands;
+using Tango.Core.Threading;
using Tango.FSE.Common;
+using Tango.RemoteDesktop.Frames;
+using Tango.RemoteDesktop.Network;
namespace Tango.FSE.PPCConsole.ViewModels
{
public class RemoteDesktopViewVM : FSEViewModel
{
+ private RasterFrame _currentFrame;
+
+ private BitmapSource _source;
+ public BitmapSource Source
+ {
+ get { return _source; }
+ set { _source = value; RaisePropertyChangedAuto(); }
+ }
+
+ public RelayCommand StartCommand { get; set; }
+ public RelayCommand StopCommand { get; set; }
+
+ public RemoteDesktopViewVM()
+ {
+ StartCommand = new RelayCommand(StartRemoteDesktop, () => MachineProvider.IsConnected);
+ StopCommand = new RelayCommand(StopRemoteDesktop);
+ }
+
+ public override void OnApplicationStarted()
+ {
+ base.OnApplicationStarted();
+
+ MachineProvider.MachineConnected += (_, __) => InvalidateRelayCommands();
+ MachineProvider.MachineDisconnected += (_, __) => InvalidateRelayCommands();
+ }
+
+ private void StartRemoteDesktop()
+ {
+ SequencerThread<StartRemoteDesktopSessionResponse> sequencer = null;
+ sequencer = new SequencerThread<StartRemoteDesktopSessionResponse>((response) =>
+ {
+ if (response.Packet == null)
+ {
+ sequencer.FrameRate = 1000 / response.FrameRate;
+ return; //Returned just to notice that there was no timeout..
+ }
+
+ try
+ {
+ if (!response.Packet.IsPartial)
+ {
+ using (MemoryStream ms = new MemoryStream(response.Packet.Bitmap))
+ {
+ if (_currentFrame != null)
+ {
+ _currentFrame.Dispose();
+ }
+
+ _currentFrame = new RasterFrame(new Bitmap(ms));
+ }
+ }
+ else
+ {
+ using (MemoryStream ms = new MemoryStream(response.Packet.Bitmap))
+ {
+ var diffFrame = new RasterFrame(new Bitmap(ms), response.Packet.PartialRegion.Left, response.Packet.PartialRegion.Top);
+ diffFrame.Apply(_currentFrame);
+ diffFrame.Dispose();
+ }
+ }
+
+ Source = _currentFrame.ToBitmapSource();
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine($"Error on remote desktop packet received: {ex.Message}");
+ }
+ });
+
+ sequencer.Start();
+
+ MachineProvider.MachineOperator.SendGenericContinuousRequest<StartRemoteDesktopSessionRequest, StartRemoteDesktopSessionResponse>(new StartRemoteDesktopSessionRequest() { }, new Transport.TransportContinuousRequestConfig()
+ {
+ ContinuousTimeout = TimeSpan.FromSeconds(30),
+ }).Subscribe((response) =>
+ {
+ sequencer.Push(response);
+
+ }, (ex) =>
+ {
+ Debug.WriteLine(ex);
+ }, () => { });
+ }
+
+ private void StopRemoteDesktop()
+ {
+
+ }
}
}