diff options
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs index 727436306..9503e4c38 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Windows; using Tango.BL; using Tango.BL.Entities; +using Tango.Core.Commands; using Tango.Core.DI; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.StudioApplication; @@ -14,36 +15,72 @@ using Tango.SharedUI; namespace Tango.MachineStudio.DB.ViewModels { - public class MainViewVM : StudioViewModel<DBModule> + public class MainViewVM : StudioViewModel { - public MainViewVM() : base() + private bool _isLoading; + public bool IsLoading { + get { return _isLoading; } + set { _isLoading = value; RaisePropertyChangedAuto(); } + } + private bool _notLoaded; + public bool NotLoaded + { + get { return _notLoaded; } + set { _notLoaded = value; RaisePropertyChangedAuto(); } } - public override void OnModuleRequest(params object[] args) + public RelayCommand LoadCommand { get; set; } + + public MainViewVM() : base() { - if (args != null && args.Length > 0 && args[0] is IObservableEntity) - { - var arg = args[0]; + NotLoaded = true; + LoadCommand = new RelayCommand(LoadAdapter,() => !IsLoading); + } - String vmName = arg.GetType().Name + "sViewVM"; + private async void LoadAdapter() + { + IsLoading = true; + InvalidateRelayCommands(); - Type vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); + await Task.Factory.StartNew(() => + { + ObservablesEntitiesAdapter.Instance.Initialize(); + }); - if (vmType == null) - { - vmName = arg.GetType().BaseType.Name + "sViewVM"; - vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); - } + IsLoading = false; + NotLoaded = false; + } - if (vmType != null) - { - var vm = TangoIOC.Default.GetInstance(vmType); - vmType.GetProperty("SelectedEntity").SetValue(vm, arg); - vmType.GetMethod("OnEdit", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(vm, new object[] { }); - } - } + public override void OnApplicationReady() + { + } + + //public override void OnModuleRequest(params object[] args) + //{ + // if (args != null && args.Length > 0 && args[0] is IObservableEntity) + // { + // var arg = args[0]; + + // String vmName = arg.GetType().Name + "sViewVM"; + + // Type vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); + + // if (vmType == null) + // { + // vmName = arg.GetType().BaseType.Name + "sViewVM"; + // vmType = Assembly.GetAssembly(typeof(MainViewVM)).GetTypes().SingleOrDefault(x => x.Name == vmName); + // } + + // if (vmType != null) + // { + // var vm = TangoIOC.Default.GetInstance(vmType); + // vmType.GetProperty("SelectedEntity").SetValue(vm, arg); + // vmType.GetMethod("OnEdit", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(vm, new object[] { }); + // } + // } + //} } } |
