-
Notifications
You must be signed in to change notification settings - Fork 30
/
DirectorManager.cs
85 lines (64 loc) · 2.34 KB
/
DirectorManager.cs
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
using Garry.Control4.Jailbreak.Utility;
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Garry.Control4.Jailbreak
{
public class DirectorManager
{
private IPAddress address;
SoapClient Soap;
ConnectionInfo SshConnectionInfo;
public string SystemName { get; private set; }
public string CommonName { get; private set; }
public string Version { get; private set; }
public DirectorManager( IPAddress address )
{
this.address = address;
SshConnectionInfo = new ConnectionInfo( address.ToString(), "jailbreak", new PasswordAuthenticationMethod( "jailbreak", "jailbreak" ) );
SshConnectionInfo.RetryAttempts = 1;
SshConnectionInfo.Timeout = TimeSpan.FromSeconds( 2 );
}
public ScpClient ScpClient => new ScpClient( SshConnectionInfo );
public SshClient SshClient => new SshClient( SshConnectionInfo );
public async Task<bool> TryInitialize()
{
//
// Since 3.1.1 Soap doesn't work, we probably need a certificate or something
//
//Soap = new SoapClient( address );
//var getItems = await Soap.Call<Soap.GetItems>( "GetItems", "filter", "1" );
//var getVersionInfo = await Soap.Call<Soap.GetVersionInfo>( "GetVersionInfo" );
//var getCommonName = await Soap.Call<Soap.GetCommonName>( "GetCommonName" );
//SystemName = getItems.SystemItems.All.FirstOrDefault( x => x.Type == 1 ).Name;
//CommonName = getCommonName.CommonName;
//Version = getVersionInfo.Versions.All.Single( x => x.Name == "Director" ).VersionNumber;
Trace.WriteLine( $"Version is {Version}" );
return true;
}
internal async void Reboot( LogWindow log )
{
log.WriteNormal( $"\nRebooting Director\n\n" );
using ( var ssh = SshClient )
{
log.WriteTrace( $"\nConnecting via SSH.. " );
ssh.Connect();
log.WriteTrace( $"\n .. connected!" );
log.WriteSuccess( $"\n\nYour director is now rebooting. This can take a few minutes and it's a nervous wait - I know.\n" );
log.WriteSuccess( $"But nothing we've done here will stop your director from booting up, so don't worry.\n" );
var cmd = ssh.CreateCommand( "sysman reboot" );
var task = cmd.BeginExecute();
while( !task.IsCompleted )
{
await Task.Delay( 10 );
}
}
}
}
}