aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs
blob: e0aff5be3676f8ec90fa1ee35d640c9fde05005a (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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Tango.Core.Commands;
using Tango.MachineStudio.Common;
using Tango.MachineStudio.UI.SupervisingController;
using Tango.SharedUI;

namespace Tango.MachineStudio.UI.ViewModels
{
    public class MainViewVM : ViewModel<IMainView>
    {
        public ObservableCollection<IStudioModule> Modules { get; set; }

        private IStudioModule _currentModule;

        public IStudioModule CurrentModule
        {
            get { return _currentModule; }
            set { _currentModule = value; RaisePropertyChangedAuto(); }
        }

        private bool _isMenuOpened;

        public bool IsMenuOpened
        {
            get { return _isMenuOpened; }
            set { _isMenuOpened = value; RaisePropertyChangedAuto(); }
        }

        public RelayCommand<IStudioModule> StartModuleCommand { get; set; }

        public RelayCommand HomeCommand { get; set; }

        public String Text { get; set; }

        public MainViewVM(IMainView view) : base(view)
        {
            Modules = new ObservableCollection<IStudioModule>();

            LoadModules();

            Text = "Hi ROy";

            StartModuleCommand = new RelayCommand<IStudioModule>(StartModule);

            HomeCommand = new RelayCommand(Home);
        }

        private void LoadModules()
        {
            string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            foreach (var file in Directory.GetFiles(assemblyFolder, "*.dll").Where(x => x.Contains("MachineStudio")))
            {
                try
                {
                    Assembly moduleAssembly = null;
                    moduleAssembly = Assembly.LoadFrom(file);

                    if (moduleAssembly != null)
                    {
                        foreach (var moduleType in moduleAssembly.GetTypes().Where(x => !x.IsInterface && typeof(IStudioModule).IsAssignableFrom(x)))
                        {
                            var module = Activator.CreateInstance(moduleType) as IStudioModule;
                            Modules.Add(module);
                        }
                    }
                }
                catch { }
            }
        }

        private void Home()
        {
            StartModule(null);
        }

        private void StartModule(IStudioModule module)
        {
            IsMenuOpened = false;
            CurrentModule = module;
        }

        protected override void OnViewAttached()
        {
            base.OnViewAttached();
        }
    }
}