aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteAssistance/DefaultRemoteAssistanceProvider.cs
blob: c266ba7c0b14d62b4aef011ae349b5784b8f9dab (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Core.Components;
using Tango.PPC.Common.Connection;

namespace Tango.PPC.Common.RemoteAssistance
{
    /// <summary>
    /// Represents the default remote assistance provider.
    /// </summary>
    /// <seealso cref="Tango.Core.ExtendedObject" />
    /// <seealso cref="Tango.PPC.Common.RemoteAssistance.IRemoteAssistanceProvider" />
    public class DefaultRemoteAssistanceProvider : ExtendedObject, IRemoteAssistanceProvider
    {
        private IMachineProvider _machineProvider;
        private String _installer_path = "C:\\Installers\\TeamViewer_Host.msi";

        private bool _isEnabled;
        /// <summary>
        /// Gets a value indicating whether the remote assistance service is enabled.
        /// </summary>
        public bool IsEnabled
        {
            get { return _isEnabled; }
            private set { _isEnabled = value; RaisePropertyChangedAuto(); }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultRemoteAssistanceProvider"/> class.
        /// </summary>
        /// <param name="machineProvider">The machine provider.</param>
        public DefaultRemoteAssistanceProvider(IMachineProvider machineProvider)
        {
            _machineProvider = machineProvider;
        }

        /// <summary>
        /// Enables the remote assistance.
        /// </summary>
        /// <returns></returns>
        public async Task EnableRemoteAssistance()
        {
            if (!IsEnabled)
            {
                try
                {
                    CmdCommand command = new CmdCommand("sc.exe", "config TeamViewer start=auto");
                    command.Timeout = TimeSpan.FromSeconds(10);
                    await command.Run();

                    command = new CmdCommand("net", "start TeamViewer");
                    command.Timeout = TimeSpan.FromSeconds(10);
                    await command.Run();

                    IsEnabled = true;
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, "Error enabling remote assistance.");
                }
            }
        }

        /// <summary>
        /// Disables the remote assistance.
        /// </summary>
        /// <returns></returns>
        public async Task DisableRemoteAssistance()
        {
            if (IsEnabled)
            {
                try
                {
                    CmdCommand command = new CmdCommand("sc.exe", "config TeamViewer start=disabled");
                    command.Timeout = TimeSpan.FromSeconds(10);
                    await command.Run();

                    command = new CmdCommand("net", "stop TeamViewer");
                    command.Timeout = TimeSpan.FromSeconds(10);
                    await command.Run();
                    IsEnabled = false;
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, "Error disabling remote assistance.");
                }
            }
        }

        /// <summary>
        /// Installs the remote assistance.
        /// </summary>
        /// <param name="machineSerialNumber">The machine serial number.</param>
        /// <param name="group">The remote assistance group.</param>
        /// <param name="environment">The machine working environment.</param>
        /// <returns></returns>
        /// <exception cref="FileNotFoundException"></exception>
        /// <exception cref="ApplicationException">The remote assistance service was installed but could not be found.</exception>
        public async Task InstallRemoteAssistance(String machineSerialNumber, String group, String environment)
        {
            try
            {
                if (!File.Exists(_installer_path))
                {
                    throw new FileNotFoundException($"The remote assistance installer file could not be found at {_installer_path}.");
                }

                String q = "\"";
                //CmdCommand command = new CmdCommand("msiexec.exe", $"/i \"{_installer_path}\" /qn CUSTOMCONFIGID=ke43ann APITOKEN=4765529-gon1LwO1N1TTrlLI21ji ASSIGNMENTOPTIONS=\" --reassign --alias {"TANGO-" + machineSerialNumber}-{environment} --grant-easy-access\"");
                CmdCommand command = new CmdCommand("msiexec.exe", $"/i {q}{_installer_path}{q} /qn CUSTOMCONFIGID=ke43ann APITOKEN=4765529-gon1LwO1N1TTrlLI21ji ASSIGNMENTOPTIONS={q} --group {q}{q} {group} {q}{q} --reassign --alias TANGO-{machineSerialNumber}-{environment} --grant-easy-access{q}");
                command.Timeout = TimeSpan.FromSeconds(30);
                await command.Run();

                bool exist = await IsRemoteAssistanceInstalled();

                if (exist)
                {
                    await DisableRemoteAssistance();
                }
                else
                {
                    throw new ApplicationException("The remote assistance service was installed but could not be found.");
                }
            }
            catch (Exception ex)
            {
                LogManager.Log(ex, "Error installing remote assistance.");
                throw;
            }
        }

        /// <summary>
        /// Determines whether remote assistance is currently installed.
        /// </summary>
        /// <returns></returns>
        private async Task<bool> IsRemoteAssistanceInstalled()
        {
            bool exist = false;

            for (int i = 0; i < 6; i++)
            {
                LogManager.Log("Checking remote assistance service...");
                await Task.Delay(1000);
                CmdCommand command = new CmdCommand("sc.exe", "query TeamViewer");
                try
                {
                    await command.Run();
                    exist = true;
                    break;
                }
                catch { }
            }

            if (exist)
            {
                LogManager.Log("Remote assistance service found.");
            }
            else
            {
                LogManager.Log("Remote assistance service was not found.");
            }

            return exist;
        }
    }
}
span class="w"> } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary:&nbsp;</li> <li>Nested&nbsp;|&nbsp;</li> <li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li> <li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail:&nbsp;</li> <li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li> <li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_top"> <!-- --> </a></div> <!-- ========= END OF TOP NAVBAR ========= --> <!-- ======== START OF CLASS DATA ======== --> <div class="header"> <div class="subTitle">org.opencv.core</div> <h2 title="Class Rect" class="title">Class Rect</h2> </div> <div class="contentContainer"> <ul class="inheritance"> <li>java.lang.Object</li> <li> <ul class="inheritance"> <li>org.opencv.core.Rect</li> </ul> </li> </ul> <div class="description"> <ul class="blockList"> <li class="blockList"> <hr> <br> <pre>public class <span class="strong">Rect</span> extends java.lang.Object</pre> </li> </ul> </div> <div class="summary"> <ul class="blockList"> <li class="blockList"> <!-- =========== FIELD SUMMARY =========== --> <ul class="blockList"> <li class="blockList"><a name="field_summary"> <!-- --> </a> <h3>Field Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Field Summary table, listing fields, and an explanation"> <caption><span>Fields</span><span class="tabEnd">&nbsp;</span></caption> <tr> <th class="colFirst" scope="col">Modifier and Type</th> <th class="colLast" scope="col">Field and Description</th> </tr> <tr class="altColor"> <td class="colFirst"><code>int</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#height">height</a></strong></code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code>int</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#width">width</a></strong></code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code>int</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#x">x</a></strong></code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code>int</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#y">y</a></strong></code>&nbsp;</td> </tr> </table> </li> </ul> <!-- ======== CONSTRUCTOR SUMMARY ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor_summary"> <!-- --> </a> <h3>Constructor Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> <caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption> <tr> <th class="colOne" scope="col">Constructor and Description</th> </tr> <tr class="altColor"> <td class="colOne"><code><strong><a href="../../../org/opencv/core/Rect.html#Rect()">Rect</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colOne"><code><strong><a href="../../../org/opencv/core/Rect.html#Rect(double[])">Rect</a></strong>(double[]&nbsp;vals)</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colOne"><code><strong><a href="../../../org/opencv/core/Rect.html#Rect(int,%20int,%20int,%20int)">Rect</a></strong>(int&nbsp;x, int&nbsp;y, int&nbsp;width, int&nbsp;height)</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colOne"><code><strong><a href="../../../org/opencv/core/Rect.html#Rect(org.opencv.core.Point,%20org.opencv.core.Point)">Rect</a></strong>(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p1, <a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p2)</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colOne"><code><strong><a href="../../../org/opencv/core/Rect.html#Rect(org.opencv.core.Point,%20org.opencv.core.Size)">Rect</a></strong>(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p, <a href="../../../org/opencv/core/Size.html" title="class in org.opencv.core">Size</a>&nbsp;s)</code>&nbsp;</td> </tr> </table> </li> </ul> <!-- ========== METHOD SUMMARY =========== --> <ul class="blockList"> <li class="blockList"><a name="method_summary"> <!-- --> </a> <h3>Method Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> <caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption> <tr> <th class="colFirst" scope="col">Modifier and Type</th> <th class="colLast" scope="col">Method and Description</th> </tr> <tr class="altColor"> <td class="colFirst"><code>double</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#area()">area</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code><a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a></code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#br()">br</a></strong>()</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code><a href="../../../org/opencv/core/Rect.html" title="class in org.opencv.core">Rect</a></code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#clone()">clone</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code>boolean</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#contains(org.opencv.core.Point)">contains</a></strong>(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p)</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code>boolean</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#empty()">empty</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code>boolean</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#equals(java.lang.Object)">equals</a></strong>(java.lang.Object&nbsp;obj)</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code>int</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#hashCode()">hashCode</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#set(double[])">set</a></strong>(double[]&nbsp;vals)</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code><a href="../../../org/opencv/core/Size.html" title="class in org.opencv.core">Size</a></code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#size()">size</a></strong>()</code>&nbsp;</td> </tr> <tr class="rowColor"> <td class="colFirst"><code><a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a></code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#tl()">tl</a></strong>()</code>&nbsp;</td> </tr> <tr class="altColor"> <td class="colFirst"><code>java.lang.String</code></td> <td class="colLast"><code><strong><a href="../../../org/opencv/core/Rect.html#toString()">toString</a></strong>()</code>&nbsp;</td> </tr> </table> <ul class="blockList"> <li class="blockList"><a name="methods_inherited_from_class_java.lang.Object"> <!-- --> </a> <h3>Methods inherited from class&nbsp;java.lang.Object</h3> <code>getClass, notify, notifyAll, wait, wait, wait</code></li> </ul> </li> </ul> </li> </ul> </div> <div class="details"> <ul class="blockList"> <li class="blockList"> <!-- ============ FIELD DETAIL =========== --> <ul class="blockList"> <li class="blockList"><a name="field_detail"> <!-- --> </a> <h3>Field Detail</h3> <a name="height"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>height</h4> <pre>public&nbsp;int height</pre> </li> </ul> <a name="width"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>width</h4> <pre>public&nbsp;int width</pre> </li> </ul> <a name="x"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>x</h4> <pre>public&nbsp;int x</pre> </li> </ul> <a name="y"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>y</h4> <pre>public&nbsp;int y</pre> </li> </ul> </li> </ul> <!-- ========= CONSTRUCTOR DETAIL ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor_detail"> <!-- --> </a> <h3>Constructor Detail</h3> <a name="Rect()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>Rect</h4> <pre>public&nbsp;Rect()</pre> </li> </ul> <a name="Rect(double[])"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>Rect</h4> <pre>public&nbsp;Rect(double[]&nbsp;vals)</pre> </li> </ul> <a name="Rect(int, int, int, int)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>Rect</h4> <pre>public&nbsp;Rect(int&nbsp;x, int&nbsp;y, int&nbsp;width, int&nbsp;height)</pre> </li> </ul> <a name="Rect(org.opencv.core.Point, org.opencv.core.Point)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>Rect</h4> <pre>public&nbsp;Rect(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p1, <a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p2)</pre> </li> </ul> <a name="Rect(org.opencv.core.Point, org.opencv.core.Size)"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>Rect</h4> <pre>public&nbsp;Rect(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p, <a href="../../../org/opencv/core/Size.html" title="class in org.opencv.core">Size</a>&nbsp;s)</pre> </li> </ul> </li> </ul> <!-- ============ METHOD DETAIL ========== --> <ul class="blockList"> <li class="blockList"><a name="method_detail"> <!-- --> </a> <h3>Method Detail</h3> <a name="area()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>area</h4> <pre>public&nbsp;double&nbsp;area()</pre> </li> </ul> <a name="br()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>br</h4> <pre>public&nbsp;<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;br()</pre> </li> </ul> <a name="clone()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>clone</h4> <pre>public&nbsp;<a href="../../../org/opencv/core/Rect.html" title="class in org.opencv.core">Rect</a>&nbsp;clone()</pre> <dl> <dt><strong>Overrides:</strong></dt> <dd><code>clone</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd> </dl> </li> </ul> <a name="contains(org.opencv.core.Point)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>contains</h4> <pre>public&nbsp;boolean&nbsp;contains(<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;p)</pre> </li> </ul> <a name="empty()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>empty</h4> <pre>public&nbsp;boolean&nbsp;empty()</pre> </li> </ul> <a name="equals(java.lang.Object)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>equals</h4> <pre>public&nbsp;boolean&nbsp;equals(java.lang.Object&nbsp;obj)</pre> <dl> <dt><strong>Overrides:</strong></dt> <dd><code>equals</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd> </dl> </li> </ul> <a name="hashCode()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>hashCode</h4> <pre>public&nbsp;int&nbsp;hashCode()</pre> <dl> <dt><strong>Overrides:</strong></dt> <dd><code>hashCode</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd> </dl> </li> </ul> <a name="set(double[])"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>set</h4> <pre>public&nbsp;void&nbsp;set(double[]&nbsp;vals)</pre> </li> </ul> <a name="size()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>size</h4> <pre>public&nbsp;<a href="../../../org/opencv/core/Size.html" title="class in org.opencv.core">Size</a>&nbsp;size()</pre> </li> </ul> <a name="tl()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>tl</h4> <pre>public&nbsp;<a href="../../../org/opencv/core/Point.html" title="class in org.opencv.core">Point</a>&nbsp;tl()</pre> </li> </ul> <a name="toString()"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>toString</h4> <pre>public&nbsp;java.lang.String&nbsp;toString()</pre> <dl> <dt><strong>Overrides:</strong></dt> <dd><code>toString</code>&nbsp;in class&nbsp;<code>java.lang.Object</code></dd> </dl> </li> </ul> </li> </ul> </li> </ul> </div> </div> <!-- ========= END OF CLASS DATA ========= --> <!-- ======= START OF BOTTOM NAVBAR ====== --> <div class="bottomNav"><a name="navbar_bottom"> <!-- --> </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../../../overview-summary.html">Overview</a></li> <li><a href="package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../../../index-all.html">Index</a></li> <li><a href="../../../help-doc.html">Help</a></li> </ul> <div class="aboutLanguage"><em><a href="http://docs.opencv.org">OpenCV 3.3.0 Documentation</a></em></div> </div> <div class="subNav"> <ul class="navList"> <li><a href="../../../org/opencv/core/Range.html" title="class in org.opencv.core"><span class="strong">Prev Class</span></a></li> <li><a href="../../../org/opencv/core/Rect2d.html" title="class in org.opencv.core"><span class="strong">Next Class</span></a></li> </ul> <ul class="navList"> <li><a href="../../../index.html?org/opencv/core/Rect.html" target="_top">Frames</a></li> <li><a href="Rect.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_bottom"> <li><a href="../../../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_bottom"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary:&nbsp;</li> <li>Nested&nbsp;|&nbsp;</li> <li><a href="#field_summary">Field</a>&nbsp;|&nbsp;</li> <li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail:&nbsp;</li> <li><a href="#field_detail">Field</a>&nbsp;|&nbsp;</li> <li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_bottom"> <!-- --> </a></div> <!-- ======== END OF BOTTOM NAVBAR ======= --> </body> </html>