aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/TechnicianModule.cs
blob: ae423c938be9193cbf8803741f482d217f40176d (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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
using Tango.BL.Entities;
using Tango.BL.Enumerations;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.Technician.Views;
using Tango.SharedUI.Helpers;

namespace Tango.MachineStudio.Technician
{
    /// <summary>
    /// Represents a machine studio technician module.
    /// </summary>
    /// <seealso cref="Tango.MachineStudio.Common.IStudioModule" />
    [StudioModule(1)]
    public class TechnicianModule : StudioModuleBase
    {
        /// <summary>
        /// Gets the module name.
        /// </summary>
        public override string Name => "Tech Board";

        /// <summary>
        /// Gets the module description.
        /// </summary>
        public override string Description => "Provides access to low level machine components by exposing diagnostics and profiling tools.";

        /// <summary>
        /// Gets the module cover image.
        /// </summary>
        public override BitmapSource Image => ResourceHelper.GetImageFromResources("Images/technician.jpg");

        /// <summary>
        /// Gets the module entry point view type.
        /// </summary>
        public override Type MainViewType
        {
            get
            {
                return typeof(MachineTechView);
            }
        }

        /// <summary>
        /// Gets the permission required to see and load this module.
        /// </summary>
        public override Permissions Permission => Permissions.RunTechnicianModule;

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public override void Dispose()
        {
            
        }
    }
}
class="o"><InternalModule>(nameof(PowerOffView)); }; AbortCommand = new RelayCommand(AbortPowerOff); } public override void OnApplicationStarted() { } public override void OnApplicationReady() { base.OnApplicationReady(); MachineProvider.MachineOperator.PowerDownStarted += MachineOperator_PowerDownStarted; } private void MachineOperator_PowerDownStarted(object sender, PowerDownStartedEventArgs e) { _abortTries = 0; _handler = e.Handler; _handler.StatusChanged += OnStatusChanged; _handler.Failed += OnFailed; _handler.Completed += OnCompleted; InvokeUI(async () => { await NavigationManager.NavigateTo<InternalModule>(nameof(PowerOffView)); NotificationProvider.PushAppBarItem(_appBarItem); }); } private void OnStatusChanged(object sender, PowerDownStatusChangedEventArgs e) { Status = e.Status; _appBarItem.Status = Status; } private void OnCompleted(object sender, EventArgs e) { InvokeUI(async () => { if (IsVisible) { await NavigationManager.NavigateBack(); } NotificationProvider.PopAppBarItem(_appBarItem); }); } private void OnFailed(object sender, Exception ex) { InvokeUI(async () => { await NotificationProvider.ShowError($"An error occurred while powering off the machine.\n{ex.FlattenMessage()}"); if (IsVisible) { await NavigationManager.NavigateBack(); } NotificationProvider.PopAppBarItem(_appBarItem); }); } private async void AbortPowerOff() { try { NotificationProvider.SetGlobalBusyMessage("Aborting machine power off..."); await _handler.Abort(); await NavigationManager.NavigateBack(); NotificationProvider.PopAppBarItem(_appBarItem); } catch (Exception ex) { _abortTries++; LogManager.Log(ex, "Power down abort error."); NotificationProvider.ReleaseGlobalBusyMessage(); await NotificationProvider.ShowError($"An error occurred while trying to abort the power off sequence.\n{ex.FlattenMessage()}"); if (_abortTries > 2) { if (IsVisible) { await NavigationManager.NavigateBack(); } NotificationProvider.PopAppBarItem(_appBarItem); } } finally { NotificationProvider.ReleaseGlobalBusyMessage(); } } } }