From 2ab54573d10ca59351100ab8416178be2223fc91 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 27 Feb 2019 16:49:42 +0200 Subject: Added support for caching on machine studio. --- .../MachineStudioSettings.cs | 13 +++++++++++++ .../MachineStudio/Tango.MachineStudio.UI/App.xaml.cs | 20 ++++++++++++++++++++ .../Tango.MachineStudio.UI/Views/AboutView.xaml | 7 +++++++ 3 files changed, 40 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs index f7c05c1a8..e5fe63d87 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/MachineStudioSettings.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using Tango.BL; using Tango.Logging; using Tango.PMR.Printing; using Tango.Settings; @@ -107,6 +108,16 @@ namespace Tango.MachineStudio.Common /// public bool ByPassEnvironmentVersionCheck { get; set; } + /// + /// Gets or sets a value indicating whether to enable database entity caching. + /// + public ObservablesContextInMemoryCachingMode CachingMode { get; set; } + + /// + /// Gets or sets the maximum cache time for a single entity (when CachingMode is set Absolute or Relative). + /// + public TimeSpan MaximumCacheTime { get; set; } + /// /// Gets the machine service address. /// @@ -136,6 +147,8 @@ namespace Tango.MachineStudio.Common Environment = WorkingEnvironment.Remote; DeploymentSlot = DeploymentSlot.DEV; JobUploadStrategy = JobUploadStrategy.Default; + MaximumCacheTime = TimeSpan.FromMinutes(5); + CachingMode = ObservablesContextInMemoryCachingMode.None; } } } diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs index d4598867c..2e2b1a014 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/App.xaml.cs @@ -84,6 +84,26 @@ namespace Tango.MachineStudio.UI exceptionTrapper = new WpfGlobalExceptionTrapper(); exceptionTrapper.Initialize(this); exceptionTrapper.ApplicationCrashed += ExceptionTrapper_ApplicationCrashed; + + //Apply Caching + if (settings.CachingMode != ObservablesContextInMemoryCachingMode.None) + { + LogManager.Log("EF Caching is enabled."); + LogManager.Log($"EF Caching mode is: {settings.CachingMode}."); + LogManager.Log($"EF Caching timeout: {settings.MaximumCacheTime.ToString()}"); + try + { + ObservablesContext.EnableInMemoryCache(settings.MaximumCacheTime, settings.CachingMode); + } + catch (Exception ex) + { + LogManager.Log(ex, "Error while trying to activate EF caching."); + } + } + else + { + LogManager.Log("EF Caching is disabled"); + } } #region Global Exception Trapping diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml index 640c3c1df..54a8349e6 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/AboutView.xaml @@ -6,6 +6,7 @@ xmlns:vm="clr-namespace:Tango.MachineStudio.UI.ViewModels" xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI" xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" + xmlns:bl="clr-namespace:Tango.BL;assembly=Tango.BL" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Width="600" Height="700" Background="White" d:DataContext="{d:DesignInstance Type=vm:AboutViewVM, IsDesignTimeCreatable=False}" DataContext="{Binding AboutViewVM, Source={StaticResource Locator}}"> @@ -13,6 +14,7 @@ + @@ -60,6 +62,11 @@ () + Caching Mode: + + + (Requires restart) + -- cgit v1.3.1