blob: de8649c138ca596e098baef078a995777effc35f (
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
|
using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tango.Core.Helpers;
using Tango.MachineStudio.Common.StudioApplication;
using Tango.MachineStudio.Common.Navigation;
using GalaSoft.MvvmLight.Ioc;
using System.Reflection;
using System.Collections;
using Tango.Integration.Services;
using Tango.Core;
using Tango.Logging;
namespace Tango.MachineStudio.UI.StudioApplication
{
public class DefaultStudioApplicationManager : ExtendedObject, IStudioApplicationManager
{
private INavigationManager _navigationManager;
public DefaultStudioApplicationManager(INavigationManager navigationManager)
{
_navigationManager = navigationManager;
}
public bool IsShuttingDown { get; private set; }
private IExternalBridgeClient _connectedMachine;
public IExternalBridgeClient ConnectedMachine
{
get { return _connectedMachine; }
set
{
_connectedMachine = value;
RaisePropertyChangedAuto();
RaisePropertyChanged(nameof(IsMachineConnected));
RaisePropertyChanged(nameof(IsMachineConnectedViaTCP));
if (_connectedMachine != null)
{
_connectedMachine.StateChanged -= ConnectedMachine_StateChanged;
_connectedMachine.StateChanged += ConnectedMachine_StateChanged;
}
}
}
public bool IsMachineConnectedViaTCP
{
get { return IsMachineConnected && ConnectedMachine.Type != ExternalBridgeClientType.USB; }
}
private void ConnectedMachine_StateChanged(object sender, Transport.TransportComponentState e)
{
if (e == Transport.TransportComponentState.Disconnected || e == Transport.TransportComponentState.Failed)
{
ConnectedMachine = null;
}
}
public bool IsMachineConnected
{
get { return ConnectedMachine != null; }
}
public async void ShutDown()
{
if (IsShuttingDown) return;
IsShuttingDown = true;
await Task.Factory.StartNew(async () =>
{
try
{
if (ConnectedMachine != null)
{
ConnectedMachine.Disconnect().Wait();
}
}
catch (Exception ex)
{
LogManager.Log(ex, "Error disconnecting from machine.");
}
//Do Shutdown Procedures...
foreach (var vm in ServiceLocator.Current.GetAllInstancesByBase<IShutdownRequestBlocker>())
{
var result = await vm.OnShutdownRequest();
if (!result)
{
IsShuttingDown = false;
return;
}
}
_navigationManager.NavigateTo(NavigationView.ShutdownView);
Thread.Sleep(3000);
Environment.Exit(0);
});
}
}
}
|