aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.PPCConsole/ViewModels/RemoteDesktopViewVM.cs
blob: c8365af3b415c6b74795eca7b56f52ce3a0a4cfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using Tango.Core.Commands;
using Tango.Core.Threading;
using Tango.FSE.Common;
using Tango.FSE.Common.RemoteDesktop;
using Tango.RemoteDesktop.Frames;
using Tango.RemoteDesktop.Network;

namespace Tango.FSE.PPCConsole.ViewModels
{
    public class RemoteDesktopViewVM : FSEViewModel
    {
        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);
            StopCommand = new RelayCommand(StopRemoteDesktop);
        }

        public override void OnApplicationStarted()
        {
            base.OnApplicationStarted();

            RemoteDesktopProvider.FrameReceived += RemoteDesktopProvider_FrameReceived;
        }

        private async void StartRemoteDesktop()
        {
            try
            {
                await RemoteDesktopProvider.StartSession();
            }
            catch (Exception ex)
            {
                await NotificationProvider.ShowError($"Error starting remote desktop session.\n{ex.FlattenMessage()}");
            }
        }

        private async void StopRemoteDesktop()
        {
            try
            {
                await RemoteDesktopProvider.EndSession();
            }
            catch (Exception ex)
            {
                await NotificationProvider.ShowError($"Error stopping remote desktop session.\n{ex.FlattenMessage()}");
            }
        }

        private void RemoteDesktopProvider_FrameReceived(object sender, DesktopFrameReceivedEventArgs e)
        {
            Source = e.Source;
        }

        #region Mouse & Keyboard Handlers From View

        public void OnMouseDown(MouseButton changedButton, System.Windows.Point point, System.Windows.Size size)
        {
            RemoteDesktopProvider.MouseDown(changedButton, point, size);
        }

        public void OnMouseUp(MouseButton changedButton, System.Windows.Point point, System.Windows.Size size)
        {
            RemoteDesktopProvider.MouseUp(changedButton, point, size);
        }

        public void OnMouseMove(System.Windows.Point point, System.Windows.Size size)
        {
            //RemoteDesktopProvider.MouseMove(point, size);
        }

        public void OnMouseDoubleClick(MouseButton changedButton, System.Windows.Point point, System.Windows.Size size)
        {
            RemoteDesktopProvider.MouseDoubleClick(changedButton, point, size);
        }

        public void OnKeyboardDown(Key key, bool ctrlDown, bool shitDown, bool altDown)
        {
            throw new NotImplementedException();
        }

        public void OnKeyboardUp(Key key, bool ctrlDown, bool shitDown, bool altDown)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}