This commit is contained in:
@@ -86,38 +86,46 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<Folder> _AllList = new List<Folder>();
|
||||
private static Dictionary<string, List<Folder>> _AllByPrimaryKey = new Dictionary<string, List<Folder>>();
|
||||
private static Dictionary<string, List<Folder>> _AllByParentID_Name = new Dictionary<string, List<Folder>>();
|
||||
private static List<Folder> _CacheList = new List<Folder>();
|
||||
protected static void AddToCache(Folder folder)
|
||||
{
|
||||
if (!_CacheList.Contains(folder)) _CacheList.Add(folder); // In AddToCache
|
||||
}
|
||||
protected static void RemoveFromCache(Folder folder)
|
||||
{
|
||||
while (_CacheList.Contains(folder)) _CacheList.Remove(folder); // In RemoveFromCache
|
||||
}
|
||||
private static Dictionary<string, List<Folder>> _CacheByPrimaryKey = new Dictionary<string, List<Folder>>();
|
||||
private static Dictionary<string, List<Folder>> _CacheByParentID_Name = new Dictionary<string, List<Folder>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<Folder> remove = new List<Folder>();
|
||||
foreach (Folder tmp in _AllList)
|
||||
foreach (Folder tmp in _CacheList)
|
||||
{
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.FolderID.ToString()))
|
||||
if (!_CacheByPrimaryKey.ContainsKey(tmp.FolderID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.FolderID.ToString()] = new List<Folder>(); // Add new list for PrimaryKey
|
||||
_AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List<Folder>(); // Add new list for ParentID_Name
|
||||
_CacheByPrimaryKey[tmp.FolderID.ToString()] = new List<Folder>(); // Add new list for PrimaryKey
|
||||
_CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()] = new List<Folder>(); // Add new list for ParentID_Name
|
||||
}
|
||||
_AllByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_AllByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
_CacheByPrimaryKey[tmp.FolderID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
_CacheByParentID_Name[tmp.ParentID.ToString() + "_" + tmp.Name.ToString()].Add(tmp); // Unique Index
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (Folder tmp in remove)
|
||||
_AllList.Remove(tmp);
|
||||
RemoveFromCache(tmp);
|
||||
}
|
||||
public static Folder GetExistingByPrimaryKey(int folderID)
|
||||
protected static Folder GetCachedByPrimaryKey(int folderID)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = folderID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
public static Folder GetExistingByParentID_Name(int parentID, string name)
|
||||
protected static Folder GetCachedByParentID_Name(int parentID, string name)
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = parentID.ToString() + "_" + name.ToString();
|
||||
if (_AllByParentID_Name.ContainsKey(key)) return _AllByParentID_Name[key][0];
|
||||
if (_CacheByParentID_Name.ContainsKey(key)) return _CacheByParentID_Name[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -295,7 +303,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);
|
||||
@@ -303,6 +311,26 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
private double? _ManualOrder;
|
||||
public double? ManualOrder
|
||||
{
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("ManualOrder", true);
|
||||
return _ManualOrder;
|
||||
}
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
set
|
||||
{
|
||||
CanWriteProperty("ManualOrder", true);
|
||||
if (_ManualOrder != value)
|
||||
{
|
||||
_ManualOrder = value;
|
||||
PropertyHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
private string _Config = string.Empty;
|
||||
public string Config
|
||||
{
|
||||
@@ -586,6 +614,7 @@ namespace VEPROMS.CSLA.Library
|
||||
//AuthorizationRules.AllowRead(Title, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ShortName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ManualOrder, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
|
||||
@@ -595,6 +624,7 @@ namespace VEPROMS.CSLA.Library
|
||||
//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ShortName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ManualOrder, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
|
||||
@@ -651,28 +681,41 @@ namespace VEPROMS.CSLA.Library
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _FolderUnique = 0;
|
||||
private int _MyFolderUnique;
|
||||
protected static int FolderUnique
|
||||
{ get { return ++_FolderUnique; } }
|
||||
private int _MyFolderUnique = FolderUnique;
|
||||
public int MyFolderUnique
|
||||
{
|
||||
get { return _MyFolderUnique; }
|
||||
}
|
||||
{ get { return _MyFolderUnique; } }
|
||||
protected Folder()
|
||||
{/* require use of factory methods */
|
||||
_MyFolderUnique = ++_FolderUnique;
|
||||
_AllList.Add(this);
|
||||
AddToCache(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
if (!_AllByPrimaryKey.ContainsKey(FolderID.ToString())) return;
|
||||
List<Folder> listFolder = _AllByPrimaryKey[FolderID.ToString()]; // Get the list of items
|
||||
listFolder.Remove(this); // Remove the item from the list
|
||||
if (listFolder.Count == 0) //If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(FolderID.ToString()); // remove the list
|
||||
listFolder = _AllByParentID_Name[FolderID.ToString()]; // Get the list of items
|
||||
listFolder.Remove(this); // Remove the item from the list
|
||||
if (listFolder.Count == 0) //If there are no items left in the list
|
||||
_AllByParentID_Name.Remove(FolderID.ToString()); // remove the list
|
||||
RemoveFromDictionaries();
|
||||
}
|
||||
private void RemoveFromDictionaries()
|
||||
{
|
||||
RemoveFromCache(this);
|
||||
if (_CacheByPrimaryKey.ContainsKey(FolderID.ToString()))
|
||||
{
|
||||
List<Folder> listFolder = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items
|
||||
while (listFolder.Contains(this)) listFolder.Remove(this); // Remove the item from the list
|
||||
if (listFolder.Count == 0) //If there are no items left in the list
|
||||
_CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list
|
||||
}
|
||||
string myKey;
|
||||
myKey = null;
|
||||
foreach (string key in _CacheByParentID_Name.Keys)
|
||||
if (_CacheByParentID_Name[key].Contains(this))
|
||||
myKey = key;
|
||||
if (myKey != null)
|
||||
{
|
||||
List<Folder> listFolder = _CacheByParentID_Name[myKey]; // Get the list of items
|
||||
listFolder.Remove(this); // Remove the item from the list
|
||||
if (listFolder.Count == 0) //If there are no items left in the list
|
||||
_CacheByParentID_Name.Remove(myKey); // remove the list
|
||||
}
|
||||
}
|
||||
public static Folder New()
|
||||
{
|
||||
@@ -695,7 +738,7 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.ShortName = shortName;
|
||||
return tmp;
|
||||
}
|
||||
public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID)
|
||||
public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID)
|
||||
{
|
||||
Folder tmp = Folder.New();
|
||||
tmp.MyParent = myParent;
|
||||
@@ -704,16 +747,21 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.Title = title;
|
||||
tmp.ShortName = shortName;
|
||||
tmp.MyFormat = myFormat;
|
||||
tmp.ManualOrder = manualOrder;
|
||||
tmp.Config = config;
|
||||
tmp.DTS = dts;
|
||||
tmp.UsrID = usrID;
|
||||
return tmp;
|
||||
}
|
||||
public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID)
|
||||
public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID)
|
||||
{
|
||||
Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, config, dts, usrID);
|
||||
Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config, dts, usrID);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Folder tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -725,7 +773,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config)
|
||||
public static Folder New(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config)
|
||||
{
|
||||
Folder tmp = Folder.New();
|
||||
tmp.MyParent = myParent;
|
||||
@@ -734,14 +782,19 @@ namespace VEPROMS.CSLA.Library
|
||||
tmp.Title = title;
|
||||
tmp.ShortName = shortName;
|
||||
tmp.MyFormat = myFormat;
|
||||
tmp.ManualOrder = manualOrder;
|
||||
tmp.Config = config;
|
||||
return tmp;
|
||||
}
|
||||
public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config)
|
||||
public static Folder MakeFolder(Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config)
|
||||
{
|
||||
Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, config);
|
||||
Folder tmp = Folder.New(myParent, myConnection, name, title, shortName, myFormat, manualOrder, config);
|
||||
if (tmp.IsSavable)
|
||||
tmp = tmp.Save();
|
||||
{
|
||||
Folder tmp2 = tmp;
|
||||
tmp = tmp2.Save();
|
||||
tmp2.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
|
||||
@@ -759,13 +812,17 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new System.Security.SecurityException("User not authorized to view a Folder");
|
||||
try
|
||||
{
|
||||
Folder tmp = GetExistingByPrimaryKey(folderID);
|
||||
Folder tmp = GetCachedByPrimaryKey(folderID);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Folder>(new PKCriteria(folderID));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Folder
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -773,19 +830,23 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on Folder.Get", ex);
|
||||
}
|
||||
}
|
||||
private static Folder GetByParentID_Name(int parentID, string name)
|
||||
public static Folder GetByParentID_Name(int parentID, string name)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Folder");
|
||||
try
|
||||
{
|
||||
Folder tmp = GetExistingByParentID_Name(parentID, name);
|
||||
Folder tmp = GetCachedByParentID_Name(parentID, name);
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<Folder>(new ParentID_NameCriteria(parentID, name));
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
AddToCache(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found")
|
||||
{
|
||||
tmp.Dispose(); // Clean-up Folder
|
||||
tmp = null;
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -837,7 +898,8 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
BuildRefreshList();
|
||||
Folder folder = base.Save();
|
||||
_AllList.Add(folder);//Refresh the item in AllList
|
||||
RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
|
||||
AddToCache(folder);//Refresh the item in AllList
|
||||
ProcessRefreshList();
|
||||
return folder;
|
||||
}
|
||||
@@ -899,6 +961,7 @@ namespace VEPROMS.CSLA.Library
|
||||
_Title = dr.GetString("Title");
|
||||
_ShortName = dr.GetString("ShortName");
|
||||
_FormatID = (int?)dr.GetValue("FormatID");
|
||||
_ManualOrder = (double?)dr.GetValue("ManualOrder");
|
||||
_Config = dr.GetString("Config");
|
||||
_DTS = dr.GetDateTime("DTS");
|
||||
_UsrID = dr.GetString("UsrID");
|
||||
@@ -1037,6 +1100,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@Title", _Title);
|
||||
cm.Parameters.AddWithValue("@ShortName", _ShortName);
|
||||
cm.Parameters.AddWithValue("@FormatID", FormatID);
|
||||
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
@@ -1068,7 +1132,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Add(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID)
|
||||
public static byte[] Add(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Add", 0);
|
||||
try
|
||||
@@ -1084,6 +1148,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@Title", title);
|
||||
cm.Parameters.AddWithValue("@ShortName", shortName);
|
||||
if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID);
|
||||
cm.Parameters.AddWithValue("@ManualOrder", manualOrder);
|
||||
cm.Parameters.AddWithValue("@Config", config);
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UsrID", usrID);
|
||||
@@ -1154,6 +1219,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@Title", _Title);
|
||||
cm.Parameters.AddWithValue("@ShortName", _ShortName);
|
||||
cm.Parameters.AddWithValue("@FormatID", FormatID);
|
||||
cm.Parameters.AddWithValue("@ManualOrder", _ManualOrder);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
@@ -1188,9 +1254,9 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (IsNew)
|
||||
_LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID);
|
||||
_LastChanged = Folder.Add(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID);
|
||||
else
|
||||
_LastChanged = Folder.Update(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _Config, _DTS, _UsrID, ref _LastChanged);
|
||||
_LastChanged = Folder.Update(cn, ref _FolderID, _MyParent, _MyConnection, _Name, _Title, _ShortName, _MyFormat, _ManualOrder, _Config, _DTS, _UsrID, ref _LastChanged);
|
||||
MarkOld();
|
||||
}
|
||||
if (_FolderAssignments != null) _FolderAssignments.Update(this);
|
||||
@@ -1208,7 +1274,7 @@ namespace VEPROMS.CSLA.Library
|
||||
MarkNew();
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Update(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, string config, DateTime dts, string usrID, ref byte[] lastChanged)
|
||||
public static byte[] Update(SqlConnection cn, ref int folderID, Folder myParent, Connection myConnection, string name, string title, string shortName, Format myFormat, double? manualOrder, string config, DateTime dts, string usrID, ref byte[] lastChanged)
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Folder.Update", 0);
|
||||
try
|
||||
@@ -1225,6 +1291,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@Title", title);
|
||||
cm.Parameters.AddWithValue("@ShortName", shortName);
|
||||
if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID);
|
||||
cm.Parameters.AddWithValue("@ManualOrder", manualOrder);
|
||||
cm.Parameters.AddWithValue("@Config", config);
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UsrID", usrID);
|
||||
|
Reference in New Issue
Block a user