This commit is contained in:
2008-08-12 11:25:17 +00:00
parent 25458190e6
commit 50e163dae0
8 changed files with 493 additions and 279 deletions

View File

@@ -54,28 +54,36 @@ namespace VEPROMS.CSLA.Library
}
#endregion
#region Collection
protected static List<DocVersion> _AllList = new List<DocVersion>();
private static Dictionary<string, List<DocVersion>> _AllByPrimaryKey = new Dictionary<string, List<DocVersion>>();
private static List<DocVersion> _CacheList = new List<DocVersion>();
protected static void AddToCache(DocVersion docVersion)
{
if (!_CacheList.Contains(docVersion)) _CacheList.Add(docVersion); // In AddToCache
}
protected static void RemoveFromCache(DocVersion docVersion)
{
while (_CacheList.Contains(docVersion)) _CacheList.Remove(docVersion); // In RemoveFromCache
}
private static Dictionary<string, List<DocVersion>> _CacheByPrimaryKey = new Dictionary<string, List<DocVersion>>();
private static void ConvertListToDictionary()
{
List<DocVersion> remove = new List<DocVersion>();
foreach (DocVersion tmp in _AllList)
foreach (DocVersion tmp in _CacheList)
{
if (!_AllByPrimaryKey.ContainsKey(tmp.VersionID.ToString()))
if (!_CacheByPrimaryKey.ContainsKey(tmp.VersionID.ToString()))
{
_AllByPrimaryKey[tmp.VersionID.ToString()] = new List<DocVersion>(); // Add new list for PrimaryKey
_CacheByPrimaryKey[tmp.VersionID.ToString()] = new List<DocVersion>(); // Add new list for PrimaryKey
}
_AllByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list
_CacheByPrimaryKey[tmp.VersionID.ToString()].Add(tmp); // Add to Primary Key list
remove.Add(tmp);
}
foreach (DocVersion tmp in remove)
_AllList.Remove(tmp);
RemoveFromCache(tmp);
}
public static DocVersion GetExistingByPrimaryKey(int versionID)
protected static DocVersion GetCachedByPrimaryKey(int versionID)
{
ConvertListToDictionary();
string key = versionID.ToString();
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
@@ -223,7 +231,7 @@ namespace VEPROMS.CSLA.Library
set
{
CanWriteProperty("MyItem", true);
if (_MyItem != value)
if ((_MyItem == null ? _ItemID : (int?)_MyItem.ItemID) != (value == null ? null : (int?)value.ItemID))
{
_MyItem = value;
_ItemID = (value == null ? null : (int?)value.ItemID);
@@ -256,7 +264,7 @@ namespace VEPROMS.CSLA.Library
set
{
CanWriteProperty("MyFormat", true);
if (_MyFormat != value)
if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID))
{
_MyFormat = value;
_FormatID = (value == null ? null : (int?)value.FormatID);
@@ -497,24 +505,29 @@ namespace VEPROMS.CSLA.Library
public int CurrentEditLevel
{ get { return EditLevel; } }
private static int _DocVersionUnique = 0;
private int _MyDocVersionUnique;
protected static int DocVersionUnique
{ get { return ++_DocVersionUnique; } }
private int _MyDocVersionUnique = DocVersionUnique;
public int MyDocVersionUnique
{
get { return _MyDocVersionUnique; }
}
{ get { return _MyDocVersionUnique; } }
protected DocVersion()
{/* require use of factory methods */
_MyDocVersionUnique = ++_DocVersionUnique;
_AllList.Add(this);
AddToCache(this);
}
public void Dispose()
{
_AllList.Remove(this);
if (!_AllByPrimaryKey.ContainsKey(VersionID.ToString())) return;
List<DocVersion> listDocVersion = _AllByPrimaryKey[VersionID.ToString()]; // Get the list of items
listDocVersion.Remove(this); // Remove the item from the list
if (listDocVersion.Count == 0) //If there are no items left in the list
_AllByPrimaryKey.Remove(VersionID.ToString()); // remove the list
RemoveFromDictionaries();
}
private void RemoveFromDictionaries()
{
RemoveFromCache(this);
if (_CacheByPrimaryKey.ContainsKey(VersionID.ToString()))
{
List<DocVersion> listDocVersion = _CacheByPrimaryKey[VersionID.ToString()]; // Get the list of items
while (listDocVersion.Contains(this)) listDocVersion.Remove(this); // Remove the item from the list
if (listDocVersion.Count == 0) //If there are no items left in the list
_CacheByPrimaryKey.Remove(VersionID.ToString()); // remove the list
}
}
public static DocVersion New()
{
@@ -554,7 +567,11 @@ namespace VEPROMS.CSLA.Library
{
DocVersion tmp = DocVersion.New(myFolder, versionType, name, title, myItem, myFormat, config, dts, userID);
if (tmp.IsSavable)
tmp = tmp.Save();
{
DocVersion tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@@ -581,7 +598,11 @@ namespace VEPROMS.CSLA.Library
{
DocVersion tmp = DocVersion.New(myFolder, name, title, myItem, myFormat, config);
if (tmp.IsSavable)
tmp = tmp.Save();
{
DocVersion tmp2 = tmp;
tmp = tmp2.Save();
tmp2.Dispose();
}
else
{
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
@@ -599,13 +620,17 @@ namespace VEPROMS.CSLA.Library
throw new System.Security.SecurityException("User not authorized to view a DocVersion");
try
{
DocVersion tmp = GetExistingByPrimaryKey(versionID);
DocVersion tmp = GetCachedByPrimaryKey(versionID);
if (tmp == null)
{
tmp = DataPortal.Fetch<DocVersion>(new PKCriteria(versionID));
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up DocVersion
tmp = null;
}
if (tmp.ErrorMessage == "No Record Found") tmp = null;
return tmp;
}
catch (Exception ex)
@@ -647,7 +672,8 @@ namespace VEPROMS.CSLA.Library
{
BuildRefreshList();
DocVersion docVersion = base.Save();
_AllList.Add(docVersion);//Refresh the item in AllList
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
AddToCache(docVersion);//Refresh the item in AllList
ProcessRefreshList();
return docVersion;
}