aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-08-22 17:36:01 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-08-22 17:36:01 +0300
commitf3ed76912f8dc895023b2afb92d605ddde1f0c42 (patch)
treeb59bd703db5c2ab55e560853837a05299788ead5 /Software/Visual_Studio/MachineStudio/Modules
parent5baedef34343452e3b3e17bcc5b4987e0521453e (diff)
downloadTango-f3ed76912f8dc895023b2afb92d605ddde1f0c42.tar.gz
Tango-f3ed76912f8dc895023b2afb92d605ddde1f0c42.zip
DB Module with lazy loading working...
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/MainViewVM.cs32
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml14
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs88
-rw-r--r--Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs22
4 files changed, 105 insertions, 51 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..2f3419d67 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;
@@ -16,9 +17,40 @@ namespace Tango.MachineStudio.DB.ViewModels
{
public class MainViewVM : StudioViewModel<DBModule>
{
+ 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 RelayCommand LoadCommand { get; set; }
+
public MainViewVM() : base()
{
+ NotLoaded = true;
+ LoadCommand = new RelayCommand(LoadAdapter,() => !IsLoading);
+ }
+
+ private async void LoadAdapter()
+ {
+ IsLoading = true;
+ InvalidateRelayCommands();
+
+ await Task.Factory.StartNew(() =>
+ {
+ ObservablesEntitiesAdapter.Instance.Initialize();
+ });
+ IsLoading = false;
+ NotLoaded = false;
}
public override void OnModuleRequest(params object[] args)
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml
index a6edd80da..050ce5f31 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml
@@ -6,6 +6,7 @@
xmlns:dockablz="clr-namespace:Dragablz.Dockablz;assembly=Dragablz"
xmlns:dragablz="clr-namespace:Dragablz;assembly=Dragablz"
xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
+ xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:managers="clr-namespace:Tango.MachineStudio.DB.Managers"
@@ -154,5 +155,18 @@
<Thumb HorizontalAlignment="Left" Opacity="0" Width="5" VerticalAlignment="Stretch" Cursor="SizeWE" DragDelta="Thumb_DragDelta"></Thumb>
</Grid>
+
+ <Grid Background="#C9000000" Visibility="{Binding NotLoaded,Converter={StaticResource BoolToVisConverter}}">
+ <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0 20 0 0">
+ <TextBlock TextAlignment="Center" FontSize="16" Foreground="Gainsboro">
+ <Run>The Database module is considered obsolete and will be removed in the future.</Run>
+ <LineBreak/>
+ <Run>Loading the module will require some time and memory.</Run>
+ </TextBlock>
+
+ <Button Height="50" Width="200" Margin="0 40 0 0" Command="{Binding LoadCommand}">LOAD</Button>
+ <mahapps:ProgressRing Margin="0 20 0 0" IsActive="{Binding IsLoading}" />
+ </StackPanel>
+ </Grid>
</Grid>
</UserControl>
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
index ab2b99dbd..9e67c247b 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.HardwareDesigner/ViewModels/MainViewVM.cs
@@ -137,75 +137,79 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
CurrentVersion = _db.GetHardwareVersion(x => x.Guid == selectedVersion.Guid);
- ObservablesStaticCollections.Instance.HardwareMotorTypes.Where(x => !CurrentVersion.HardwareMotors.ToList().Exists(y => y.HardwareMotorType.Code == x.Code)).ToList().ForEach(x =>
+
+ InvokeUINow(() =>
{
- CurrentVersion.HardwareMotors.Add(new HardwareMotor()
+ ObservablesStaticCollections.Instance.HardwareMotorTypes.Where(x => !CurrentVersion.HardwareMotors.ToList().Exists(y => y.HardwareMotorType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareMotorType = _db.HardwareMotorTypes.SingleOrDefault(y => y.Code == x.Code),
+ CurrentVersion.HardwareMotors.Add(new HardwareMotor()
+ {
+ HardwareMotorType = _db.HardwareMotorTypes.SingleOrDefault(y => y.Code == x.Code),
+ });
});
- });
- CurrentVersion.HardwareMotors = CurrentVersion.HardwareMotors.OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection();
+ CurrentVersion.HardwareMotors = CurrentVersion.HardwareMotors.OrderBy(x => x.HardwareMotorType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwareDancerTypes.Where(x => !CurrentVersion.HardwareDancers.ToList().Exists(y => y.HardwareDancerType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwareDancers.Add(new HardwareDancer()
+ ObservablesStaticCollections.Instance.HardwareDancerTypes.Where(x => !CurrentVersion.HardwareDancers.ToList().Exists(y => y.HardwareDancerType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareDancerType = _db.HardwareDancerTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwareDancers.Add(new HardwareDancer()
+ {
+ HardwareDancerType = _db.HardwareDancerTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwareDancers = CurrentVersion.HardwareDancers.OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection();
+ CurrentVersion.HardwareDancers = CurrentVersion.HardwareDancers.OrderBy(x => x.HardwareDancerType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwarePidControlTypes.Where(x => !CurrentVersion.HardwarePidControls.ToList().Exists(y => y.HardwarePidControlType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwarePidControls.Add(new HardwarePidControl()
+ ObservablesStaticCollections.Instance.HardwarePidControlTypes.Where(x => !CurrentVersion.HardwarePidControls.ToList().Exists(y => y.HardwarePidControlType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwarePidControlType = _db.HardwarePidControlTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwarePidControls.Add(new HardwarePidControl()
+ {
+ HardwarePidControlType = _db.HardwarePidControlTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwarePidControls = CurrentVersion.HardwarePidControls.OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection();
+ CurrentVersion.HardwarePidControls = CurrentVersion.HardwarePidControls.OrderBy(x => x.HardwarePidControlType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwareWinderTypes.Where(x => !CurrentVersion.HardwareWinders.ToList().Exists(y => y.HardwareWinderType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwareWinders.Add(new HardwareWinder()
+ ObservablesStaticCollections.Instance.HardwareWinderTypes.Where(x => !CurrentVersion.HardwareWinders.ToList().Exists(y => y.HardwareWinderType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareWinderType = _db.HardwareWinderTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwareWinders.Add(new HardwareWinder()
+ {
+ HardwareWinderType = _db.HardwareWinderTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwareWinders = CurrentVersion.HardwareWinders.OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection();
+ CurrentVersion.HardwareWinders = CurrentVersion.HardwareWinders.OrderBy(x => x.HardwareWinderType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwareSpeedSensorTypes.Where(x => !CurrentVersion.HardwareSpeedSensors.ToList().Exists(y => y.HardwareSpeedSensorType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwareSpeedSensors.Add(new HardwareSpeedSensor()
+ ObservablesStaticCollections.Instance.HardwareSpeedSensorTypes.Where(x => !CurrentVersion.HardwareSpeedSensors.ToList().Exists(y => y.HardwareSpeedSensorType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareSpeedSensorType = _db.HardwareSpeedSensorTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwareSpeedSensors.Add(new HardwareSpeedSensor()
+ {
+ HardwareSpeedSensorType = _db.HardwareSpeedSensorTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwareSpeedSensors = CurrentVersion.HardwareSpeedSensors.OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection();
+ CurrentVersion.HardwareSpeedSensors = CurrentVersion.HardwareSpeedSensors.OrderBy(x => x.HardwareSpeedSensorType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwareBlowerTypes.Where(x => !CurrentVersion.HardwareBlowers.ToList().Exists(y => y.HardwareBlowerType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwareBlowers.Add(new HardwareBlower()
+ ObservablesStaticCollections.Instance.HardwareBlowerTypes.Where(x => !CurrentVersion.HardwareBlowers.ToList().Exists(y => y.HardwareBlowerType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareBlowerType = _db.HardwareBlowerTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwareBlowers.Add(new HardwareBlower()
+ {
+ HardwareBlowerType = _db.HardwareBlowerTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwareBlowers = CurrentVersion.HardwareBlowers.OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection();
+ CurrentVersion.HardwareBlowers = CurrentVersion.HardwareBlowers.OrderBy(x => x.HardwareBlowerType.Code).ToObservableCollection();
- ObservablesStaticCollections.Instance.HardwareBreakSensorTypes.Where(x => !CurrentVersion.HardwareBreakSensors.ToList().Exists(y => y.HardwareBreakSensorType.Code == x.Code)).ToList().ForEach(x =>
- {
- CurrentVersion.HardwareBreakSensors.Add(new HardwareBreakSensor()
+ ObservablesStaticCollections.Instance.HardwareBreakSensorTypes.Where(x => !CurrentVersion.HardwareBreakSensors.ToList().Exists(y => y.HardwareBreakSensorType.Code == x.Code)).ToList().ForEach(x =>
{
- HardwareBreakSensorType = _db.HardwareBreakSensorTypes.SingleOrDefault(y => y.Code == x.Code)
+ CurrentVersion.HardwareBreakSensors.Add(new HardwareBreakSensor()
+ {
+ HardwareBreakSensorType = _db.HardwareBreakSensorTypes.SingleOrDefault(y => y.Code == x.Code)
+ });
});
- });
- CurrentVersion.HardwareBreakSensors = CurrentVersion.HardwareBreakSensors.OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection();
+ CurrentVersion.HardwareBreakSensors = CurrentVersion.HardwareBreakSensors.OrderBy(x => x.HardwareBreakSensorType.Code).ToObservableCollection();
+ });
}
private async void OnSelectedVersionChanged()
@@ -240,7 +244,7 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels
if (!String.IsNullOrWhiteSpace(name))
{
- using (_notification.PushTaskItem("Creating new machine versions..."))
+ using (_notification.PushTaskItem("Creating new machine version..."))
{
await Task.Factory.StartNew(() =>
{
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs
index 344d677ff..56888e631 100644
--- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs
+++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.UsersAndRoles/ViewModels/MainViewVM.cs
@@ -193,19 +193,21 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels
}
}
- private void LoadSelectedUser()
+ private async void LoadSelectedUser()
{
using (_notification.PushTaskItem("Loading user details..."))
{
- Task.Factory.StartNew(() =>
+ await Task.Factory.StartNew(() =>
{
_userContext = ObservablesContext.CreateDefault();
+ _userContext.Configuration.LazyLoadingEnabled = false;
+
Roles = _userContext.Roles.ToObservableCollection();
- ManagedUser = _userContext.Users.SingleOrDefault(x => x.Guid == SelectedUser.Guid);
+ ManagedUser = _userContext.GetUser(SelectedUser.Guid);
ManagedUserRoles = ManagedUser.Roles.ToObservableCollection();
-
- InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView));
});
+
+ _navigation.NavigateTo(UsersAndRolesNavigationView.UserManagementView);
}
}
@@ -248,17 +250,19 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels
}
}
- private void LoadSelectedOrganization()
+ private async void LoadSelectedOrganization()
{
using (_notification.PushTaskItem("Loading organization..."))
{
- Task.Factory.StartNew(() =>
+ await Task.Factory.StartNew(() =>
{
_manageContext = ObservablesContext.CreateDefault();
- ManagedOrganization = _manageContext.Organizations.SingleOrDefault(x => x.Guid == SelectedOrganization.Guid);
+ _manageContext.Configuration.LazyLoadingEnabled = false;
- InvokeUI(() => _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView));
+ ManagedOrganization = _manageContext.GetOrganizationAndUsers(SelectedOrganization.Guid);
});
+
+ _navigation.NavigateTo(UsersAndRolesNavigationView.OrganizationManagementView);
}
}