From 036938d9d9f0368e9d71008311e97a8abf41f053 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 8 Jun 2017 17:12:52 +0000 Subject: [PATCH] B2016-115 the comparison of the contents of RO.FST files would also be seen as different (and loading into memory) even when user created a new RO.fst without making any RO changes. We needed to skip past the RO.FST header information in the file which contains the date/time the FST was created. Also needed to do a garbage collection. --- .../Extension/DocVersionExt.cs | 40 ++----------------- .../Extension/ROFSTExt.cs | 35 ++++++++++++++++ 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs index aa032e30..f829701c 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/DocVersionExt.cs @@ -61,23 +61,8 @@ namespace VEPROMS.CSLA.Library if (fiRofst.Length != roFstInfo.ROLookup.Length) return fiRofst.LastWriteTimeUtc > roFstInfo.DTS; // if we can't tell by the DTS or size, compare the contents. Get all of the rodb's - // rofsts of the size of the file & compare bytes. If - ROFstInfoList fstList = ROFstInfoList.GetBySize(rdi.RODbID, (int)fiRofst.Length); - if (fstList.Count > 0) - { - FileStream fsIn = new FileStream(rofstPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - // Create an instance of StreamReader that can read characters from the FileStream. - BinaryReader r = new BinaryReader(fsIn); - byte[] ab = r.ReadBytes((int)fsIn.Length); - fsIn.Close(); - foreach (ROFstInfo irofst in fstList) - { - // compare contents by comparing each byte. - for (int i = 0; i < fiRofst.Length; i++) - if (ab[i] != irofst.ROLookup[i]) return true; - } - } - return false; + // rofsts of the size of the file & compare bytes. + return ROFstInfoList.ROFstDiffBySize(rofstPath, rdi.RODbID, (int)fiRofst.Length); } } #region VersionType @@ -244,25 +229,8 @@ namespace VEPROMS.CSLA.Library if (fiRofst.Length != roFstInfo.ROLookup.Length) return AddToRoFstLookup(key,fiRofst.LastWriteTimeUtc > roFstInfo.DTS); // if we can't tell by the DTS or size, compare the contents. Get all of the rodb's - // rofsts of the size of the file & compare bytes. If - ROFstInfoList fstList = ROFstInfoList.GetBySize(rdi.RODbID, (int)fiRofst.Length); - if (fstList.Count > 0) - { - // B2017-078 WCN users with Read only access to the RO FST file where not able to open the file for reading when - // another user was accessing the file. Changed FileShare from Read to ReadWrite - FileStream fsIn = new FileStream(rofstPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - // Create an instance of StreamReader that can read characters from the FileStream. - BinaryReader r = new BinaryReader(fsIn); - byte[] ab = r.ReadBytes((int)fsIn.Length); - fsIn.Close(); - foreach (ROFstInfo irofst in fstList) - { - // compare contents by comparing each byte. - for (int i = 0; i < fiRofst.Length; i++) - if (ab[i] != irofst.ROLookup[i]) return AddToRoFstLookup(key,true); - } - } - return AddToRoFstLookup(key,false); + // rofsts of the size of the file & compare bytes. + return AddToRoFstLookup(key, ROFstInfoList.ROFstDiffBySize(rofstPath, rdi.RODbID, (int)fiRofst.Length)); } } diff --git a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs index e5214689..b366dfa1 100644 --- a/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs +++ b/PROMS/VEPROMS.CSLA.Library/Extension/ROFSTExt.cs @@ -1079,6 +1079,41 @@ namespace VEPROMS.CSLA.Library throw new DbCslaException("Error on RoFstInfoList.GetBySize", ex); } } + public static bool ROFstDiffBySize(string rofstPath, int roDbID, int len) + { + try + { + bool isDifferent = false; + using (ROFstInfoList tmp = GetBySize(roDbID, len)) + { + if (tmp.Count > 0) + { + // B2017-078 WCN users with Read only access to the RO FST file where not able to open the file for reading when + // another user was accessing the file. Changed FileShare from Read to ReadWrite + FileStream fsIn = new FileStream(rofstPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); + // Create an instance of StreamReader that can read characters from the FileStream. + BinaryReader r = new BinaryReader(fsIn); + byte[] ab = r.ReadBytes((int)fsIn.Length); + r.Close(); + fsIn.Close(); + foreach (ROFstInfo irofst in tmp) + { + // compare contents by comparing each byte. + for (int i = 20; i < len; i++) // this skips past RO.FST header which has the FST creation date/time + if (ab[i] != irofst.ROLookup[i]) isDifferent = true; + irofst.Dispose(); + if (isDifferent) break; + } + } + } + GC.Collect(); + return isDifferent; + } + catch (Exception ex) + { + throw new DbCslaException("Error on RoFstInfoList.ROFstDiffBySize", ex); + } + } private void DataPortal_Fetch(RoFstSizeCriteria criteria) { this.RaiseListChangedEvents = false;