aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/FSE/Modules/Tango.FSE.MachineConfiguration/ViewModels/MachineViewVM.cs
blob: 822f2cb80da7b2562b85c6cd5cd2842f548bb5c8 (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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-sty
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.BL.Entities;
using Tango.FSE.Common;
using Tango.FSE.Common.Navigation;
using Tango.FSE.MachineConfiguration.Messages;
using Tango.FSE.MachineConfiguration.Navigation;
using static Tango.FSE.BL.Services.MachineConfigurationService;
using static Tango.FSE.MachineConfiguration.ViewModels.MachineViewVM;

namespace Tango.FSE.MachineConfiguration.ViewModels
{
    public class MachineViewVM : ConfigurationViewModel, INavigationObjectReceiver<NavigationObject>
    {
        public class NavigationObject
        {
            public String MachineGuid { get; set; }
        }

        public enum NavigationView
        {
            SettingsView,
            DataStoreView,
        }

        private NavigationView _selectedView;
        public NavigationView SelectedView
        {
            get { return _selectedView; }
            set
            {
                if (value == NavigationView.DataStoreView)
                {
                    if (!CurrentUser.HasPermission(Tango.BL.Enumerations.Permissions.DataStoreRead))
                    {
                        Task.Delay(500).ContinueWith((x) =>
                        {
                            SelectedView = _selectedView;
                            NotificationProvider.ShowError("The current user profile does not allow accessing the data store.\nPlease contact your administrator.");
                        });
                        return;
                    }
                }

                _selectedView = value;
                RaisePropertyChangedAuto();
            }
        }

        private MachineEditingComposition _editingComposition;
        public MachineEditingComposition EditingComposition
        {
            get { return _editingComposition; }
            set { _editingComposition = value; RaisePropertyChangedAuto(); }
        }

        public void OnNavigatedToWithObject(NavigationObject obj)
        {
            SelectedView = NavigationView.SettingsView;
            LoadMachine(obj.MachineGuid);
        }

        private async void LoadMachine(String machineGuid)
        {
            using (NotificationProvider.PushTaskItem("Loading machine configuration..."))
            {
                try
                {
                    EditingComposition = await Services.MachineConfigurationService.GetMachineEditingComposition(machineGuid);
                    RaiseMessage(new EditingCompositionLoadedMessage() { EditingComposition = EditingComposition });
                }
                catch (Exception ex)
                {
                    LogManager.Log(ex, "Error loading machine.");
                    await Task.Delay(1000);
                    await ModularNavigationManager.NavigateBack();
                    await NotificationProvider.ShowError($"Error loading the selected machine.\n{ex.FlattenMessage()}");
                }
            }
        }
    }
}