aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.RemoteDesktop/ScreenCaptureFrame.cs
blob: 12d749954180455700da0cd3aecd987c3797df6d (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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using Tango.RemoteDesktop.Frames;

namespace Tango.RemoteDesktop
{
    /// <summary>
    /// Represents a screen capture frame for holding the original bitmap and difference frame.
    /// </summary>
    /// <typeparam name="TFrame">The type of the frame.</typeparam>
    /// <seealso cref="Tango.RemoteDesktop.Frames.RasterFrame" />
    /// <seealso cref="System.IDisposable" />
    public class ScreenCaptureFrame<TFrame> : RasterFrame, IDisposable where TFrame : IFrame
    {
        private TFrame _diffFrame;

        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenCaptureFrame{TFrame}"/> class.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        public ScreenCaptureFrame(Bitmap bitmap) : base(bitmap)
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ScreenCaptureFrame{TFrame}"/> class.
        /// </summary>
        /// <param name="bitmap">The bitmap.</param>
        /// <param name="diffFrame">The difference frame.</param>
        public ScreenCaptureFrame(Bitmap bitmap, TFrame diffFrame) : this(bitmap)
        {
            _diffFrame = diffFrame;
        }

        /// <summary>
        /// Gets a value indicating whether a difference frame is available.
        /// </summary>
        public bool DifferenceAvailable
        {
            get { return _diffFrame != null; }
        }

        /// <summary>
        /// Gets or sets the number differences.
        /// </summary>
        public uint DifferenceCount { get; set; }

        /// <summary>
        /// Returns the difference frame.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">No difference is available at this point. Please use the 'DifferenceAvailable' property before attempting to get the difference.</exception>
        public TFrame ToDifference()
        {
            if (!DifferenceAvailable)
            {
                throw new InvalidOperationException("No difference is available at this point. Please use the 'DifferenceAvailable' property before attempting to get the difference.");
            }

            return _diffFrame;
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();

            if (_diffFrame != null)
            {
                _diffFrame.Dispose();
            }
        }
    }
}
"w"> = new List<RunningJobUpdateClient>(); MachineProvider.MachineOperator.PrintingStarted += MachineOperator_PrintingStarted; } private async void MachineOperator_PrintingStarted(object sender, Integration.Operation.PrintingEventArgs e) { _handler = e.JobHandler; e.JobHandler.StatusChanged += JobHandler_StatusChanged; e.JobHandler.Stopped += JobHandler_Stopped; _currentJobDTO = JobDTO.FromObservable(e.Job); _currentJobProcessParameters = ProcessParametersTableDTO.FromObservable(_handler.ProcessParameters); foreach (var client in _clients.ToList()) { try { RemoteJobProgress progress = new RemoteJobProgress(); progress.Stage = RemoteJobStage.Started; progress.JobStatus = _handler.JobStatus; await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse() { Job = _currentJobDTO, ProcessParameters = _currentJobProcessParameters, Progress = progress }, client.Token); client.JobSent = true; } catch { } } } private async void JobHandler_StatusChanged(object sender, RunningJobStatus e) { foreach (var client in _clients.ToList()) { if (client.JobSent) { try { await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse() { Progress = GetJobProgress(_handler) }, client.Token); } catch { } } else { try { RemoteJobProgress progress = new RemoteJobProgress(); progress.Stage = RemoteJobStage.Started; progress.JobStatus = _handler.JobStatus; await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse() { Job = _currentJobDTO, ProcessParameters = _currentJobProcessParameters, Progress = progress }, client.Token); client.JobSent = true; } catch { } } } } private async void JobHandler_Stopped(object sender, EventArgs e) { foreach (var client in _clients.ToList().Where(x => x.JobSent)) { try { await client.Receiver.SendGenericResponse(new RemoteJobUpdateResponse() { Progress = GetJobProgress(_handler), }, client.Token); client.JobSent = false; } catch { } } } private RemoteJobProgress GetJobProgress(JobHandler handler) { RemoteJobStage stage = RemoteJobStage.Running; if (_handler.Status.IsCanceled) { stage = RemoteJobStage.Aborted; } else if (_handler.Status.IsCompleted) { stage = RemoteJobStage.Completed; } else if (_handler.Status.IsFailed) { stage = RemoteJobStage.Failed; } return new RemoteJobProgress() { Stage = stage, JobStatus = handler.JobStatus, }; } [ExternalBridgeRequestHandlerMethod(typeof(RemoteJobUpdateRequest), RequestHandlerLoggingMode.LogRequestName)] public async Task OnRunningJobUpdateRequest(RemoteJobUpdateRequest request, String token, ExternalBridgeReceiver receiver) { this.ThrowIfDisabled(); if (!_clients.ToList().Exists(x => x.Receiver == receiver)) { _clients.Add(new RunningJobUpdateClient() { Receiver = receiver, Token = token }); } await receiver.SendGenericResponse(new RemoteJobUpdateResponse(), token); } public void OnReceiverDisconnected(ExternalBridgeReceiver receiver) { _clients.RemoveAll(x => x.Receiver == receiver); } } }