summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Instance/RemoteInstance.cs
blob: bfefb6cafb2ef27ea6c778d92b9aec52b1a07aa3 (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
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoteInstance.cs" company="HandBrake Project (http://handbrake.fr)">
//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
//   An Implementation of IEncodeInstance that works with a remote process rather than locally in-process.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace HandBrakeWPF.Instance
{
    using System;
    using System.Diagnostics;

    using HandBrake.Interop.Interop.EventArgs;
    using HandBrake.Interop.Interop.Interfaces;
    using HandBrake.Interop.Interop.Json.Encode;

    public class RemoteInstance : IEncodeInstance
    {
        private Process workerProcess;

        public event EventHandler<EncodeCompletedEventArgs> EncodeCompleted;

        public event EventHandler<EncodeProgressEventArgs> EncodeProgress;

        public void PauseEncode()
        {
            throw new NotImplementedException();
        }

        public void ResumeEncode()
        {
            throw new NotImplementedException();
        }

        public void StartEncode(JsonEncodeObject jobToStart)
        {
            throw new NotImplementedException();
        }

        public void StopEncode()
        {
            throw new NotImplementedException();
        }

        protected virtual void OnEncodeCompleted(EncodeCompletedEventArgs e)
        {
            this.EncodeCompleted?.Invoke(this, e);
        }

        protected virtual void OnEncodeProgress(EncodeProgressEventArgs e)
        {
            this.EncodeProgress?.Invoke(this, e);
        }

        private void StartServer()
        {
            if (this.workerProcess == null || this.workerProcess.HasExited)
            {
                this.workerProcess = new Process();

                // TODO Take default port from preferences, then find a usable port thereafter.
                this.workerProcess.StartInfo =
                    new ProcessStartInfo("HandBrake.Worker.exe", "--port=8080")
                        {
                            WindowStyle = ProcessWindowStyle.Normal
                        };

                this.workerProcess.Start();
                this.workerProcess.Exited += this.WorkerProcess_Exited;
            }
        }

        private void WorkerProcess_Exited(object sender, EventArgs e)
        {
            Debug.WriteLine("Worker Process has exited");
        }

        private void StopServer()
        {
            if (this.workerProcess != null && !this.workerProcess.HasExited)
            {
                this.workerProcess.Kill();
            }
        }
    }
}