This commit is contained in:
@@ -37,13 +37,17 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Collection
|
||||
protected static List<FormatInfo> _AllList = new List<FormatInfo>();
|
||||
private static Dictionary<string, FormatInfo> _AllByPrimaryKey = new Dictionary<string, FormatInfo>();
|
||||
private static Dictionary<string, List<FormatInfo>> _AllByPrimaryKey = new Dictionary<string, List<FormatInfo>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
List<FormatInfo> remove = new List<FormatInfo>();
|
||||
foreach (FormatInfo tmp in _AllList)
|
||||
{
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()]=tmp; // Primary Key
|
||||
if (!_AllByPrimaryKey.ContainsKey(tmp.FormatID.ToString()))
|
||||
{
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()] = new List<FormatInfo>(); // Add new list for PrimaryKey
|
||||
}
|
||||
_AllByPrimaryKey[tmp.FormatID.ToString()].Add(tmp); // Add to Primary Key list
|
||||
remove.Add(tmp);
|
||||
}
|
||||
foreach (FormatInfo tmp in remove)
|
||||
@@ -57,7 +61,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
ConvertListToDictionary();
|
||||
string key = formatID.ToString();
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key];
|
||||
if (_AllByPrimaryKey.ContainsKey(key)) return _AllByPrimaryKey[key][0];
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
@@ -85,7 +89,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatID",true);
|
||||
CanReadProperty("FormatID", true);
|
||||
return _FormatID;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +99,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("ParentID",true);
|
||||
CanReadProperty("ParentID", true);
|
||||
if (_MyParent != null) _ParentID = _MyParent.FormatID;
|
||||
return _ParentID;
|
||||
}
|
||||
@@ -106,7 +110,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("MyParent",true);
|
||||
CanReadProperty("MyParent", true);
|
||||
if (_MyParent == null && _ParentID != _FormatID) _MyParent = FormatInfo.Get(_ParentID);
|
||||
return _MyParent;
|
||||
}
|
||||
@@ -117,7 +121,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Name",true);
|
||||
CanReadProperty("Name", true);
|
||||
return _Name;
|
||||
}
|
||||
}
|
||||
@@ -127,7 +131,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Description",true);
|
||||
CanReadProperty("Description", true);
|
||||
return _Description;
|
||||
}
|
||||
}
|
||||
@@ -137,7 +141,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("Data",true);
|
||||
CanReadProperty("Data", true);
|
||||
return _Data;
|
||||
}
|
||||
}
|
||||
@@ -147,7 +151,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("GenMac",true);
|
||||
CanReadProperty("GenMac", true);
|
||||
return _GenMac;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +161,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("DTS",true);
|
||||
CanReadProperty("DTS", true);
|
||||
return _DTS;
|
||||
}
|
||||
}
|
||||
@@ -167,7 +171,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("UserID",true);
|
||||
CanReadProperty("UserID", true);
|
||||
return _UserID;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +184,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatContentCount",true);
|
||||
CanReadProperty("FormatContentCount", true);
|
||||
return _FormatContentCount;
|
||||
}
|
||||
}
|
||||
@@ -191,7 +195,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatContents",true);
|
||||
CanReadProperty("FormatContents", true);
|
||||
if (_FormatContentCount < 0 || (_FormatContentCount > 0 && _FormatContents == null))
|
||||
_FormatContents = ContentInfoList.GetByFormatID(_FormatID);
|
||||
if (_FormatContentCount < 0)
|
||||
@@ -201,7 +205,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshFormatContents()
|
||||
{
|
||||
_FormatContentCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatContentCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _FormatDocVersionCount = 0;
|
||||
/// <summary>
|
||||
@@ -212,7 +219,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatDocVersionCount",true);
|
||||
CanReadProperty("FormatDocVersionCount", true);
|
||||
return _FormatDocVersionCount;
|
||||
}
|
||||
}
|
||||
@@ -223,7 +230,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatDocVersions",true);
|
||||
CanReadProperty("FormatDocVersions", true);
|
||||
if (_FormatDocVersionCount < 0 || (_FormatDocVersionCount > 0 && _FormatDocVersions == null))
|
||||
_FormatDocVersions = DocVersionInfoList.GetByFormatID(_FormatID);
|
||||
if (_FormatDocVersionCount < 0)
|
||||
@@ -233,7 +240,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshFormatDocVersions()
|
||||
{
|
||||
_FormatDocVersionCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatDocVersionCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _FormatFolderCount = 0;
|
||||
/// <summary>
|
||||
@@ -244,7 +254,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatFolderCount",true);
|
||||
CanReadProperty("FormatFolderCount", true);
|
||||
return _FormatFolderCount;
|
||||
}
|
||||
}
|
||||
@@ -255,7 +265,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("FormatFolders",true);
|
||||
CanReadProperty("FormatFolders", true);
|
||||
if (_FormatFolderCount < 0 || (_FormatFolderCount > 0 && _FormatFolders == null))
|
||||
_FormatFolders = FolderInfoList.GetByFormatID(_FormatID);
|
||||
if (_FormatFolderCount < 0)
|
||||
@@ -265,7 +275,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshFormatFolders()
|
||||
{
|
||||
_FormatFolderCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._FormatFolderCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
private int _ChildFormatCount = 0;
|
||||
/// <summary>
|
||||
@@ -276,7 +289,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("ChildFormatCount",true);
|
||||
CanReadProperty("ChildFormatCount", true);
|
||||
return _ChildFormatCount;
|
||||
}
|
||||
}
|
||||
@@ -287,7 +300,7 @@ namespace VEPROMS.CSLA.Library
|
||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
||||
get
|
||||
{
|
||||
CanReadProperty("ChildFormats",true);
|
||||
CanReadProperty("ChildFormats", true);
|
||||
if (_ChildFormatCount < 0 || (_ChildFormatCount > 0 && _ChildFormats == null))
|
||||
_ChildFormats = FormatInfoList.GetChildren(_FormatID);
|
||||
if (_ChildFormatCount < 0)
|
||||
@@ -297,7 +310,10 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void RefreshChildFormats()
|
||||
{
|
||||
_ChildFormatCount = -1; // This will cause the data to be requeried
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(_FormatID.ToString()))
|
||||
foreach (FormatInfo tmp in _AllByPrimaryKey[_FormatID.ToString()])
|
||||
tmp._ChildFormatCount = -1; // This will cause the data to be requeried
|
||||
}
|
||||
// TODO: Replace base FormatInfo.ToString function as necessary
|
||||
/// <summary>
|
||||
@@ -319,14 +335,25 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
private static int _FormatInfoUnique = 0;
|
||||
private int _MyFormatInfoUnique;
|
||||
public int MyFormatInfoUnique
|
||||
{
|
||||
get { return _MyFormatInfoUnique; }
|
||||
}
|
||||
private FormatInfo()
|
||||
{/* require use of factory methods */
|
||||
_MyFormatInfoUnique = ++_FormatInfoUnique;
|
||||
_AllList.Add(this);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
_AllList.Remove(this);
|
||||
_AllByPrimaryKey.Remove(FormatID.ToString());
|
||||
if (!_AllByPrimaryKey.ContainsKey(FormatID.ToString())) return;
|
||||
List<FormatInfo> listFormatInfo = _AllByPrimaryKey[FormatID.ToString()]; // Get the list of items
|
||||
listFormatInfo.Remove(this); // Remove the item from the list
|
||||
if (listFormatInfo.Count == 0) // If there are no items left in the list
|
||||
_AllByPrimaryKey.Remove(FormatID.ToString()); // remove the list
|
||||
}
|
||||
public virtual Format Get()
|
||||
{
|
||||
@@ -334,9 +361,11 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static void Refresh(Format tmp)
|
||||
{
|
||||
FormatInfo tmpInfo = GetExistingByPrimaryKey(tmp.FormatID);
|
||||
if (tmpInfo == null) return;
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
string key = tmp.FormatID.ToString();
|
||||
ConvertListToDictionary();
|
||||
if (_AllByPrimaryKey.ContainsKey(key))
|
||||
foreach (FormatInfo tmpInfo in _AllByPrimaryKey[key])
|
||||
tmpInfo.RefreshFields(tmp);
|
||||
}
|
||||
private void RefreshFields(Format tmp)
|
||||
{
|
||||
@@ -344,9 +373,9 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
MyParent.RefreshChildFormats(); // Update List for old value
|
||||
_ParentID = tmp.ParentID; // Update the value
|
||||
_MyParent = null; // Reset list so that the next line gets a new list
|
||||
MyParent.RefreshChildFormats(); // Update List for new value
|
||||
}
|
||||
_MyParent = null; // Reset list so that the next line gets a new list
|
||||
if (MyParent != null) MyParent.RefreshChildFormats(); // Update List for new value
|
||||
_Name = tmp.Name;
|
||||
_Description = tmp.Description;
|
||||
_Data = tmp.Data;
|
||||
@@ -367,7 +396,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (tmp == null)
|
||||
{
|
||||
tmp = DataPortal.Fetch<FormatInfo>(new PKCriteria(formatID));
|
||||
_AllList.Add(tmp);
|
||||
if (!_AllList.Contains(tmp)) _AllList.Add(tmp);
|
||||
}
|
||||
if (tmp.ErrorMessage == "No Record Found") tmp = null;
|
||||
return tmp;
|
||||
@@ -381,14 +410,15 @@ namespace VEPROMS.CSLA.Library
|
||||
#region Data Access Portal
|
||||
internal FormatInfo(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode());
|
||||
_MyFormatInfoUnique = ++_FormatInfoUnique;
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.Constructor", GetHashCode());
|
||||
try
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatInfo.Constructor", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.Constructor", ex);
|
||||
throw new DbCslaException("FormatInfo.Constructor", ex);
|
||||
}
|
||||
}
|
||||
@@ -405,7 +435,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
private void ReadData(SafeDataReader dr)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.ReadData", GetHashCode());
|
||||
try
|
||||
{
|
||||
_FormatID = dr.GetInt32("FormatID");
|
||||
@@ -423,14 +453,14 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatInfo.ReadData", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.ReadData", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("FormatInfo.ReadData", ex);
|
||||
}
|
||||
}
|
||||
private void DataPortal_Fetch(PKCriteria criteria)
|
||||
{
|
||||
if(_MyLog.IsDebugEnabled)_MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode());
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FormatInfo.DataPortal_Fetch", GetHashCode());
|
||||
try
|
||||
{
|
||||
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
|
||||
@@ -458,7 +488,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if(_MyLog.IsErrorEnabled)_MyLog.Error("FormatInfo.DataPortal_Fetch", ex);
|
||||
if (_MyLog.IsErrorEnabled) _MyLog.Error("FormatInfo.DataPortal_Fetch", ex);
|
||||
_ErrorMessage = ex.Message;
|
||||
throw new DbCslaException("FormatInfo.DataPortal_Fetch", ex);
|
||||
}
|
||||
@@ -468,7 +498,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#region extension
|
||||
FormatInfoExtension _FormatInfoExtension = new FormatInfoExtension();
|
||||
[Serializable()]
|
||||
partial class FormatInfoExtension : extensionBase {}
|
||||
partial class FormatInfoExtension : extensionBase { }
|
||||
[Serializable()]
|
||||
class extensionBase
|
||||
{
|
||||
|
Reference in New Issue
Block a user