This commit is contained in:
Kathy Ruffing 2012-09-12 13:05:10 +00:00
parent 445b71ac38
commit 7bb9f393e8

View File

@ -232,7 +232,7 @@ namespace VEPROMS.CSLA.Library
using (ROImageInfoList myROImages = ROImageInfoList.GetByRODbID(rdi.RODbID)) using (ROImageInfoList myROImages = ROImageInfoList.GetByRODbID(rdi.RODbID))
{ {
Dictionary<string, int> myExistingROImages = BuildROImagesList(myROImages); Dictionary<string, int> myExistingROImages = BuildROImagesList(myROImages);
List<int> myChangedROImages = new List<int>(); List<int> myUnChangedROImages = new List<int>();
List<string> myAddedROImages = new List<string>(); List<string> myAddedROImages = new List<string>();
rofst = ROFst.MakeROFst(rodb, ab, null, di.LastWriteTimeUtc, rdi.UserID); rofst = ROFst.MakeROFst(rodb, ab, null, di.LastWriteTimeUtc, rdi.UserID);
// Hook this into the current docversion by replacing the rofstid field in the doc version // Hook this into the current docversion by replacing the rofstid field in the doc version
@ -248,12 +248,12 @@ namespace VEPROMS.CSLA.Library
{ {
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID)) using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{ {
rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myChangedROImages,myAddedROImages);// TODO: Need to add MyImages rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);// TODO: Need to add MyImages
} }
} }
} }
if(myChangedROImages.Count > 0) if (myUnChangedROImages.Count > 0)
using(FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID,buildImageIDString(myChangedROImages))); using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
return rofst; return rofst;
} }
} }
@ -300,7 +300,7 @@ namespace VEPROMS.CSLA.Library
using (ROImageInfoList myROImages = ROImageInfoList.GetByRODbIDNoData(rdi.RODbID)) using (ROImageInfoList myROImages = ROImageInfoList.GetByRODbIDNoData(rdi.RODbID))
{ {
Dictionary<string, int> myExistingROImages = BuildROImagesList(myROImages); Dictionary<string, int> myExistingROImages = BuildROImagesList(myROImages);
List<int> myChangedROImages = new List<int>(); List<int> myUnChangedROImages = new List<int>();
List<string> myAddedROImages = new List<string>(); List<string> myAddedROImages = new List<string>();
using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID)) using (ROFstInfo rfi = ROFstInfo.Get(rofst.ROFstID))
{ {
@ -309,12 +309,13 @@ namespace VEPROMS.CSLA.Library
// walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8: // walk through the rofst 'database' searching for all nodes that are integrated graphics, type 8:
if (rofst.ROFSTLookup.myHdr.myDbs[i].children != null) if (rofst.ROFSTLookup.myHdr.myDbs[i].children != null)
{ {
rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myChangedROImages,myAddedROImages); rfi.MigrateRoFstGraphics(rdi, rofst.ROFSTLookup.myHdr.myDbs[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
} }
} }
} }
if (myChangedROImages.Count > 0) // Add references for existing RO Images to the Figure table (Figure table relates ro.fst with its images)
using(FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID,buildImageIDString(myChangedROImages))); if (myUnChangedROImages.Count > 0)
using (FigureInfoList fil = FigureInfoList.AddByROFstIDImageIDs(rofst.ROFstID, buildImageIDString(myUnChangedROImages))) ;
} }
// Now update the usages: compare old to new rofsts and update usages accordingly, i.e. modified // Now update the usages: compare old to new rofsts and update usages accordingly, i.e. modified
// values, deleted ros, etc. // values, deleted ros, etc.
@ -498,15 +499,15 @@ namespace VEPROMS.CSLA.Library
retval = string.Format("{0}_{1}", roName, iSuffix + 1); retval = string.Format("{0}_{1}", roName, iSuffix + 1);
return retval; return retval;
} }
private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myChangedROImages, List<string> myAddedROImages) private void MigrateRoFstGraphics(RODbInfo rdi, ROFSTLookup.rochild[] rochild, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages)
{ {
for (int i = 0; i < rochild.Length; i++) for (int i = 0; i < rochild.Length; i++)
{ {
if (rochild[i].type == 8) this.AddGraphic(rdi, rochild[i].value, rodb, rofst, myExistingROImages, myChangedROImages, myAddedROImages); if (rochild[i].type == 8) this.AddGraphic(rdi, rochild[i].value, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myChangedROImages, myAddedROImages); if (rochild[i].children != null) this.MigrateRoFstGraphics(rdi, rochild[i].children, rodb, rofst, myExistingROImages, myUnChangedROImages, myAddedROImages);
} }
} }
private void AddGraphic(RODbInfo rdi, string p, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myChangedROImages, List<string> myAddedROImages) private void AddGraphic(RODbInfo rdi, string p, RODb rodb, ROFst rofst, Dictionary<string, int> myExistingROImages, List<int> myUnChangedROImages, List<string> myAddedROImages)
{ {
if (p == null) return; if (p == null) return;
string imgname = p.Substring(0, p.IndexOf('\n')); string imgname = p.Substring(0, p.IndexOf('\n'));
@ -529,8 +530,8 @@ namespace VEPROMS.CSLA.Library
if (myExistingROImages.ContainsKey(key)) if (myExistingROImages.ContainsKey(key))
{ {
int imageID = myExistingROImages[key]; int imageID = myExistingROImages[key];
if(!myChangedROImages.Contains(imageID)) if (!myUnChangedROImages.Contains(imageID))
myChangedROImages.Add(imageID); myUnChangedROImages.Add(imageID);
} }
else else
{ {
@ -541,7 +542,17 @@ namespace VEPROMS.CSLA.Library
byte[] ab = r.ReadBytes((int)fsIn.Length); byte[] ab = r.ReadBytes((int)fsIn.Length);
r.Close(); r.Close();
fsIn.Close(); fsIn.Close();
using (roImg = ROImage.MakeROImage(rodb, imgname, ab, null, fi.LastWriteTimeUtc, "Migration")) byte[] cmp = ROImageInfo.Compress(ab);
int existingImageID = FindExisting(myExistingROImages, imgname, imgfile, cmp, ab);
if (existingImageID != 0)
{
if (!myUnChangedROImages.Contains(existingImageID))
myUnChangedROImages.Add(existingImageID);
return;
}
ROImageConfig rc = new ROImageConfig();
rc.Image_Size = ab.Length.ToString();
using (roImg = ROImage.MakeROImage(rodb, imgname, ROImageInfo.Compress(ab), rc.ToString(), fi.LastWriteTimeUtc, "Migration"))
{ {
using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID)) using (Figure figure = Figure.GetByROFstID_ImageID(this.ROFstID, roImg.ImageID))
{ {
@ -555,6 +566,57 @@ namespace VEPROMS.CSLA.Library
} }
} }
private int FindExisting(Dictionary<string, int> myExistingROImages, string imgname, string imgfile, byte[] cmpFileContents, byte[] fileContents)
{
// the reason the following check is necessary is that the DTS can be off by hours
// because of the way windows handles Daylight savings time for file DTS.
FileInfo fi = new FileInfo(imgfile);
DateTime dts = fi.LastWriteTimeUtc;
// loop through myExistingROImages looking for matching name.
foreach (string key in myExistingROImages.Keys)
{
// if found, compare the date/time stamp
string part1 = Regex.Replace(key, ":.*$", "");
string part2 = Regex.Replace(key, "^.*?:", "");
if (part1.ToUpper() == imgname.ToUpper())
{
// if date/time stamps matches date, minutes & seconds, compare contents
string cmp1 = Regex.Replace(dts.ToString(), " [0-9]*:", " x:");
cmp1 = Regex.Replace(cmp1, " [AP]", " x");
string cmp2 = Regex.Replace(part2, " [0-9]*:", " x:");
cmp2 = Regex.Replace(cmp2, " [AP]", " x");
if (cmp1==cmp2)
{
// compare contents
int imgId = myExistingROImages[key];
using (ROImageInfo roii = ROImageInfo.Get(imgId))
{
ROImageConfig roicfg = new ROImageConfig(roii);
int size = Convert.ToInt32(roicfg.Image_Size);
byte[] tmpb = ROImageInfo.Decompress(roii.Content, size);
if (ByteArrayCompare(roii.Content, cmpFileContents))
return imgId;
if (ByteArrayCompare(tmpb, fileContents))
return imgId;
}
}
}
}
return 0;
}
private bool ByteArrayCompare(byte[] ba1, byte[] ba2)
{
// we wrote our own byte array comparinson because the system's 'equals' did not work!
if (ba1.Length != ba2.Length) return false;
for (int i = 0; i < ba1.Length; i++)
if (ba1[i] != ba2[i]) return false;
return true;
}
private ROImageInfo GetMyImage(Dictionary<string, ROImageInfo> myImages, string imgname, DateTime dts) private ROImageInfo GetMyImage(Dictionary<string, ROImageInfo> myImages, string imgname, DateTime dts)
{ {
string key = string.Format("{0}:{1}", imgname, dts); string key = string.Format("{0}:{1}", imgname, dts);