From bbbf67be9caac01ccb671bf3f737200a7320d3e0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 19 Feb 2019 19:48:24 +0200 Subject: Implemented safe guard for corrupted EF Model Cache. --- .../Build/Shortcuts/Machine Studio.lnk | Bin 1532 -> 1516 bytes .../Tango.BL/ObservablesContextConfiguration.cs | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk index 21b63193d..cd233d031 100644 Binary files a/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk and b/Software/Visual_Studio/Build/Shortcuts/Machine Studio.lnk differ diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs index 90d78f6bc..07c3f5306 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextConfiguration.cs @@ -5,6 +5,7 @@ using System.Data.Entity.Infrastructure; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Tango.Core.Helpers; @@ -22,7 +23,25 @@ namespace Tango.BL public ObservablesContextConfiguration() : base() { Directory.CreateDirectory(FolderPath); - SetModelStore(new DefaultDbModelStore(FolderPath)); + var modelStore = new DefaultDbModelStore(FolderPath); + + try + { + modelStore.TryLoad(typeof(ObservablesContext)); + } + catch + { + try + { + Directory.Delete(FolderPath, true); + Thread.Sleep(1000); + Directory.CreateDirectory(FolderPath); + } + catch { } + modelStore = new DefaultDbModelStore(FolderPath); + } + + SetModelStore(modelStore); } public static void ClearModelStore() -- cgit v1.3.1