From 5c58e6499306b3087015758c1054497dccc407e6 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 21 Aug 2018 13:05:37 +0300 Subject: Done with Developer Module. Implemented DB auth using Azure Active Directory Interactive! --- .../Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index 50caced63..f9d803aed 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -119,7 +119,7 @@ namespace Tango.MachineStudio.Logging.ViewModels { if (msg.Machine != null) { - _connectedMachine = ObservablesEntitiesAdapter.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); + _connectedMachine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); SelectedMachine = _connectedMachine; } else -- cgit v1.3.1 From 9e7f301df8d5114249d74aaceddff801170d3e44 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 21 Aug 2018 16:21:23 +0300 Subject: Logging module working OK. --- Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 15400960 -> 15400960 bytes .../ViewModels/EventsViewVM.cs | 75 +++++++++++---------- 3 files changed, 40 insertions(+), 35 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels') diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 6d427fd5e..598de983a 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 38010497b..1505d16bb 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index f9d803aed..20eba4b8e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -14,6 +14,7 @@ using Tango.MachineStudio.Common.StudioApplication; using Tango.MachineStudio.Logging.Navigation; using Tango.MachineStudio.Logging.Views; using Tango.SharedUI; +using System.Data.Entity; namespace Tango.MachineStudio.Logging.ViewModels { @@ -23,15 +24,22 @@ namespace Tango.MachineStudio.Logging.ViewModels private IStudioApplicationManager _application; private IEventLogger _eventLogger; private ObservableCollection _realTimeEvents; - private Machine _connectedMachine; private LoggingNavigationManager _navigation; private bool _dialog_shown; + private ObservablesContext _db; + private List _history_events; private Machine _selectedMachine; public Machine SelectedMachine { get { return _selectedMachine; } - set { _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); } + set + { + if (_selectedMachine != value) + { + _selectedMachine = value; RaisePropertyChangedAuto(); OnSelectedMachineChanged(); + } + } } private ObservableCollection _events; @@ -76,7 +84,6 @@ namespace Tango.MachineStudio.Logging.ViewModels set { _maxDate = value; RaisePropertyChangedAuto(); } } - private bool _isRealTime; public bool IsRealTime { @@ -109,25 +116,11 @@ namespace Tango.MachineStudio.Logging.ViewModels _realTimeEvents = new ObservableCollection(); _eventLogger.NewLog += _eventLogger_NewLog; - RegisterMessage(OnMachineConnectionChanged); DisplayTimelineCommand = new RelayCommand(DisplayTimeline); NavigateToEventsCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.EventsView)); NavigateToHomeCommand = new RelayCommand(() => _navigation.NavigateTo(LoggingNavigationView.HomeView)); } - private void OnMachineConnectionChanged(MachineConnectionChangedMessage msg) - { - if (msg.Machine != null) - { - _connectedMachine = ObservablesStaticCollections.Instance.Machines.SingleOrDefault(x => x.SerialNumber == msg.Machine.SerialNumber); - SelectedMachine = _connectedMachine; - } - else - { - _connectedMachine = null; - } - } - private void _eventLogger_NewLog(object sender, MachinesEvent machineEvent) { InvokeUI(() => @@ -136,29 +129,41 @@ namespace Tango.MachineStudio.Logging.ViewModels }); } - private void OnSelectedMachineChanged() + private async void OnSelectedMachineChanged() { if (SelectedMachine != null) { - Dates = new ObservableCollection(); - - if (SelectedMachine == _connectedMachine) + using (_notification.PushTaskItem("Loading machine events...")) { - IsRealTime = true; - } + await Task.Factory.StartNew(() => + { + _db = ObservablesContext.CreateDefault(); + _db.Configuration.LazyLoadingEnabled = false; - foreach (var day in SelectedMachine.MachinesEvents.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) - { - Dates.Add(day); - } + _db.EventTypes.Load(); + _db.EventTypesCategories.Load(); + _db.EventTypesGroups.Load(); - if (Dates.Count > 0) - { - MinDate = Dates.Min(); - MaxDate = Dates.Max(); - } + DateTime now = DateTime.UtcNow.AddMonths(-1); - SelectedDate = Dates.FirstOrDefault(); + _history_events = _db.MachinesEvents.Where(x => x.MachineGuid == SelectedMachine.Guid && x.DateTime > now).ToList(); + + Dates = new ObservableCollection(); + + foreach (var day in _history_events.GroupBy(x => x.DateTime.DayOfYear).Select(x => x.First().DateTime).OrderByDescending(x => x)) + { + Dates.Add(day); + } + + if (Dates.Count > 0) + { + MinDate = Dates.Min(); + MaxDate = Dates.Max(); + } + + SelectedDate = Dates.FirstOrDefault(); + }); + } } } @@ -170,9 +175,9 @@ namespace Tango.MachineStudio.Logging.ViewModels { Events = _realTimeEvents; } - else + else if (_history_events != null) { - Events = SelectedMachine.MachinesEvents.Where(x => x.DateTime.DayOfYear == SelectedDate.Date.DayOfYear).OrderByDescending(x => x.DateTime).ToObservableCollection(); + Events = _history_events.Where(x => x.DateTime.DayOfYear == SelectedDate.Date.DayOfYear).OrderByDescending(x => x.DateTime).ToObservableCollection(); } } } -- cgit v1.3.1 From ea97f593f82a1176125901c257c8e81c45c23b67 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Thu, 23 Aug 2018 11:17:23 +0300 Subject: ObservablesContext is now LazyLoading = 'false' by default. --- .../ViewModels/MainViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 2 -- .../ViewModels/MainViewVM.cs | 3 --- .../ViewModels/EventsViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 1 - .../ViewModels/MainViewVM.cs | 3 --- .../EventLogging/DefaultEventLogger.cs | 1 - .../Authentication/DefaultAuthenticationProvider.cs | 1 - .../EventLogging/DefaultEventLogger.cs | 1 - Software/Visual_Studio/Tango.BL/ObservableEntity.cs | 21 ++++++++++++++++++++- .../Tango.BL/ObservablesContextExtension.cs | 1 + .../Tango.BL/ObservablesEntitiesAdapter.cs | 1 + .../Tango.BL/ObservablesStaticCollections.cs | 2 -- 13 files changed, 22 insertions(+), 17 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs index 1811ea7c7..02f496b1f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ColorLab/ViewModels/MainViewVM.cs @@ -281,7 +281,6 @@ namespace Tango.MachineStudio.ColorLab.ViewModels Task.Factory.StartNew(() => { _dbContext = ObservablesContext.CreateDefault(); - _dbContext.Configuration.LazyLoadingEnabled = false; Machines = _dbContext.Machines.ToObservableCollection(); ColorSpaces = _dbContext.ColorSpaces.ToObservableCollection(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 6178ae30a..60c2e65f9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -732,7 +732,6 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Initializing machine Db context..."); _machineDbContext = ObservablesContext.CreateDefault(); - _machineDbContext.Configuration.LazyLoadingEnabled = false; if (_settings.LastSelectedMachineGuid != null) { @@ -1498,7 +1497,6 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Creating active job DB context..."); _activeJobDbContext = ObservablesContext.CreateDefault(); - _activeJobDbContext.Configuration.LazyLoadingEnabled = false; LogManager.Log("Initializing available color spaces, RMLs & Winding methods..."); 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 54b954745..6ba28cb72 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 @@ -102,7 +102,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels if (_db != null) _db.Dispose(); _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; CurrentVersion.HardwareMotors = _db.HardwareMotorTypes.ToList().Select(x => new HardwareMotor() { HardwareMotorType = x }).ToObservableCollection(); CurrentVersion.HardwareDancers = _db.HardwareDancerTypes.ToList().Select(x => new HardwareDancer() { HardwareDancerType = x }).ToObservableCollection(); @@ -117,7 +116,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels { using (var db = ObservablesContext.CreateDefault()) { - db.Configuration.LazyLoadingEnabled = false; _hardwareVersions = db.HardwareVersions.ToObservableCollection(); InvokeUI(() => { @@ -131,7 +129,6 @@ namespace Tango.MachineStudio.HardwareDesigner.ViewModels if (_db != null) _db.Dispose(); _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; CurrentVersion = _db.Adapter.GetHardwareVersion(x => x.Guid == selectedVersion.Guid); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs index 20eba4b8e..68094d91f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Logging/ViewModels/EventsViewVM.cs @@ -138,7 +138,6 @@ namespace Tango.MachineStudio.Logging.ViewModels await Task.Factory.StartNew(() => { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.EventTypes.Load(); _db.EventTypesCategories.Load(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index 183cdb247..de9a8de4a 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -218,7 +218,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels CanWork = false; _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; Adapter = new ObservablesStaticCollections(); Adapter.ApplicationDisplayPanelVersions = _db.ApplicationDisplayPanelVersions.ToObservableCollection(); 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 0def388d3..db312b78f 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 @@ -199,7 +199,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels await Task.Factory.StartNew(() => { _userContext = ObservablesContext.CreateDefault(); - _userContext.Configuration.LazyLoadingEnabled = false; Roles = _userContext.Roles.ToObservableCollection(); ManagedUser = _userContext.Adapter.GetUser(SelectedUser.Guid); @@ -256,7 +255,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels await Task.Factory.StartNew(() => { _manageContext = ObservablesContext.CreateDefault(); - _manageContext.Configuration.LazyLoadingEnabled = false; ManagedOrganization = _manageContext.Adapter.GetOrganizationAndUsers(SelectedOrganization.Guid); }); @@ -270,7 +268,6 @@ namespace Tango.MachineStudio.UsersAndRoles.ViewModels Task.Factory.StartNew(() => { _organizationsContext = ObservablesContext.CreateDefault(); - _organizationsContext.Configuration.LazyLoadingEnabled = false; Organizations = _organizationsContext.Organizations .Include(x => x.Machines) diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index c5b9c63cb..cb4611cad 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -81,7 +81,6 @@ namespace Tango.MachineStudio.Common.EventLogging try { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.ActionTypes.ToList(); _db.EventTypesActions.ToList(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs index de84e43e8..c16f76449 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Authentication/DefaultAuthenticationProvider.cs @@ -51,7 +51,6 @@ namespace Tango.MachineStudio.UI.Authentication { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - db.Configuration.LazyLoadingEnabled = false; String hash = User.GetPasswordHash(password); diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs index d981723be..adf99e3a3 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/EventLogging/DefaultEventLogger.cs @@ -80,7 +80,6 @@ namespace Tango.PPC.Common.EventLogging try { _db = ObservablesContext.CreateDefault(); - _db.Configuration.LazyLoadingEnabled = false; _db.ActionTypes.ToList(); _db.EventTypesActions.ToList(); diff --git a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs index d6cdcfb16..1b69a8bdb 100644 --- a/Software/Visual_Studio/Tango.BL/ObservableEntity.cs +++ b/Software/Visual_Studio/Tango.BL/ObservableEntity.cs @@ -157,7 +157,26 @@ namespace Tango.BL /// public virtual void Save(ObservablesContext context) { - context.SaveChanges(); + if (context == ObservablesEntitiesAdapter.Instance.Context) + { + var tableName = this.GetType().GetCustomAttribute().Name; + + String propName = tableName.FromDalNameToTitleCase(); + + DbSet set = ObservablesEntitiesAdapter.Instance.Context.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(context) as DbSet; + ObservableCollection obs = ObservablesEntitiesAdapter.Instance.GetType().GetProperty(propName, BindingFlags.Instance | BindingFlags.Public).GetValue(ObservablesEntitiesAdapter.Instance) as ObservableCollection; + + if (!obs.Contains(this as T)) + { + set.Add(this as T); + } + + ObservablesEntitiesAdapter.Instance.SaveChanges(); + } + else + { + context.SaveChanges(); + } } /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index 49c80695f..f387bd1e1 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -34,6 +34,7 @@ namespace Tango.BL public ObservablesContext(DataSource dataSource) : base(dataSource.ToConnection(), true) { Database.SetInitializer(null); + Configuration.LazyLoadingEnabled = false; _adapter = new ObservablesContextAdapter(this); } diff --git a/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs b/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs index fdc359da0..4fdaf9071 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesEntitiesAdapter.cs @@ -69,6 +69,7 @@ namespace Tango.BL private ObservablesEntitiesAdapter() { Context = ObservablesContext.CreateDefault(); + Context.Configuration.LazyLoadingEnabled = true; } /// diff --git a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs index db5faef4b..4820c784b 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesStaticCollections.cs @@ -42,8 +42,6 @@ namespace Tango.BL { db = ObservablesContext.CreateDefault(); - db.Configuration.LazyLoadingEnabled = false; - WindingMethods = db.WindingMethods.ToObservableCollection(); ColorSpaces = db.ColorSpaces.ToObservableCollection(); SpoolTypes = db.SpoolTypes.ToObservableCollection(); -- cgit v1.3.1