// ========================================================================
// Copyright 2007 - Volian Enterprises, Inc. All rights reserved.
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $ $Revision: $
// $Author: $ $Date: $
//
// $History: $
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
namespace VEPROMS.CSLA.Library
{
public delegate void FolderInfoEvent(object sender);
///
/// FolderInfo Generated by MyGeneration using the CSLA Object Mapping template
///
[Serializable()]
[TypeConverter(typeof(FolderInfoConverter))]
public partial class FolderInfo : ReadOnlyBase, IDisposable
{
public event FolderInfoEvent Changed;
private void OnChange()
{
if (Changed != null) Changed(this);
}
#region Log4Net
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
#region Collection
private static List _CacheList = new List();
protected static void AddToCache(FolderInfo folderInfo)
{
if (!_CacheList.Contains(folderInfo)) _CacheList.Add(folderInfo); // In AddToCache
}
protected static void RemoveFromCache(FolderInfo folderInfo)
{
while (_CacheList.Contains(folderInfo)) _CacheList.Remove(folderInfo); // In RemoveFromCache
}
private static Dictionary> _CacheByPrimaryKey = new Dictionary>();
private static void ConvertListToDictionary()
{
while (_CacheList.Count > 0) // Move FolderInfo(s) from temporary _CacheList to _CacheByPrimaryKey
{
FolderInfo tmp = _CacheList[0]; // Get the first FolderInfo
string pKey = tmp.FolderID.ToString();
if (!_CacheByPrimaryKey.ContainsKey(pKey))
{
_CacheByPrimaryKey[pKey] = new List(); // Add new list for PrimaryKey
}
_CacheByPrimaryKey[pKey].Add(tmp); // Add to Primary Key list
_CacheList.RemoveAt(0); // Remove the first FolderInfo
}
}
internal static void AddList(FolderInfoList lst)
{
foreach (FolderInfo item in lst) AddToCache(item);
}
protected static FolderInfo GetCachedByPrimaryKey(int folderID)
{
ConvertListToDictionary();
string key = folderID.ToString();
if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
return null;
}
#endregion
#region Business Methods
private string _ErrorMessage = string.Empty;
public string ErrorMessage
{
get { return _ErrorMessage; }
}
protected Folder _Editable;
private IVEHasBrokenRules HasBrokenRules
{
get
{
IVEHasBrokenRules hasBrokenRules = null;
if (_Editable != null)
hasBrokenRules = _Editable.HasBrokenRules;
return hasBrokenRules;
}
}
private int _FolderID;
[System.ComponentModel.DataObjectField(true, true)]
public int FolderID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _FolderID;
}
}
private int _ParentID;
public int ParentID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyParent != null) _ParentID = _MyParent.FolderID;
return _ParentID;
}
}
private FolderInfo _MyParent;
public FolderInfo MyParent
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyParent == null && _ParentID != _FolderID) _MyParent = FolderInfo.Get(_ParentID);
return _MyParent;
}
}
private int _DBID;
public int DBID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyConnection != null) _DBID = _MyConnection.DBID;
return _DBID;
}
}
private ConnectionInfo _MyConnection;
public ConnectionInfo MyConnection
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyConnection == null && _DBID != 0) _MyConnection = ConnectionInfo.Get(_DBID);
return _MyConnection;
}
}
private string _Name = string.Empty;
public string Name
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _Name;
}
}
private string _Title = string.Empty;
public string Title
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _Title;
}
}
private string _ShortName = string.Empty;
public string ShortName
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _ShortName;
}
}
private int? _FormatID;
public int? FormatID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyFormat != null) _FormatID = _MyFormat.FormatID;
return _FormatID;
}
}
private FormatInfo _MyFormat;
public FormatInfo MyFormat
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_MyFormat == null && _FormatID != null) _MyFormat = FormatInfo.Get((int)_FormatID);
return _MyFormat;
}
}
private double? _ManualOrder;
public double? ManualOrder
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _ManualOrder;
}
}
private string _Config = string.Empty;
public string Config
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _Config;
}
}
private DateTime _DTS = new DateTime();
public DateTime DTS
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _DTS;
}
}
private string _UsrID = string.Empty;
public string UsrID
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
return _UsrID;
}
}
private int _FolderAssignmentCount = 0;
///
/// Count of FolderAssignments for this Folder
///
public int FolderAssignmentCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_FolderAssignmentCount < 0)
_FolderAssignmentCount = FolderAssignments.Count;
return _FolderAssignmentCount;
}
}
private AssignmentInfoList _FolderAssignments = null;
[TypeConverter(typeof(AssignmentInfoListConverter))]
public AssignmentInfoList FolderAssignments
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_FolderAssignmentCount < 0 || (_FolderAssignmentCount > 0 && _FolderAssignments == null))
_FolderAssignments = AssignmentInfoList.GetByFolderID(_FolderID);
if (_FolderAssignmentCount < 0)
_FolderAssignmentCount = _FolderAssignments.Count;
return _FolderAssignments;
}
}
public void RefreshFolderAssignments()
{
_FolderAssignmentCount = -1;
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._FolderAssignmentCount = -1; // This will cause the data to be requeried
}
private int _FolderDocVersionCount = 0;
///
/// Count of FolderDocVersions for this Folder
///
public int FolderDocVersionCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_FolderDocVersionCount < 0)
_FolderDocVersionCount = FolderDocVersions.Count;
return _FolderDocVersionCount;
}
}
private DocVersionInfoList _FolderDocVersions = null;
[TypeConverter(typeof(DocVersionInfoListConverter))]
public DocVersionInfoList FolderDocVersions
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_FolderDocVersionCount < 0 || (_FolderDocVersionCount > 0 && _FolderDocVersions == null))
_FolderDocVersions = DocVersionInfoList.GetByFolderID(_FolderID);
if (_FolderDocVersionCount < 0)
_FolderDocVersionCount = _FolderDocVersions.Count;
return _FolderDocVersions;
}
}
public void RefreshFolderDocVersions()
{
_FolderDocVersionCount = -1;
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._FolderDocVersionCount = -1; // This will cause the data to be requeried
}
private int _ChildFolderCount = 0;
///
/// Count of ChildFolders for this Folder
///
public int ChildFolderCount
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_ChildFolderCount < 0)
_ChildFolderCount = ChildFolders.Count;
return _ChildFolderCount;
}
}
private FolderInfoList _ChildFolders = null;
[TypeConverter(typeof(FolderInfoListConverter))]
public FolderInfoList ChildFolders
{
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
get
{
if (_ChildFolderCount < 0 || (_ChildFolderCount > 0 && _ChildFolders == null))
_ChildFolders = FolderInfoList.GetChildren(_FolderID);
if (_ChildFolderCount < 0)
_ChildFolderCount = _ChildFolders.Count;
return _ChildFolders;
}
}
public void RefreshChildFolders()
{
_ChildFolderCount = -1;
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(_FolderID.ToString()))
foreach (FolderInfo tmp in _CacheByPrimaryKey[_FolderID.ToString()])
tmp._ChildFolderCount = -1; // This will cause the data to be requeried
}
// CSLATODO: Replace base FolderInfo.ToString function as necessary
///
/// Overrides Base ToString
///
/// A string representation of current FolderInfo
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check FolderInfo.GetIdValue to assure that the ID returned is unique
///
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
///
/// A Unique ID for the current FolderInfo
protected override object GetIdValue()
{
return MyFolderInfoUnique; // Absolutely Unique ID
}
#endregion
#region Factory Methods
private static int _FolderInfoUnique = 0;
private static int FolderInfoUnique
{ get { return ++_FolderInfoUnique; } }
private int _MyFolderInfoUnique = FolderInfoUnique;
public int MyFolderInfoUnique // Absolutely Unique ID - Info
{ get { return _MyFolderInfoUnique; } }
protected FolderInfo()
{/* require use of factory methods */
AddToCache(this);
}
private bool _Disposed = false;
private static int _CountCreated = 0;
private static int _CountDisposed = 0;
private static int _CountFinalized = 0;
private static int IncrementCountCreated
{ get { return ++_CountCreated; } }
private int _CountWhenCreated = IncrementCountCreated;
public static int CountCreated
{ get { return _CountCreated; } }
public static int CountNotDisposed
{ get { return _CountCreated - _CountDisposed; } }
public static int CountNotFinalized
{ get { return _CountCreated - _CountFinalized; } }
~FolderInfo()
{
_CountFinalized++;
}
public void Dispose()
{
if (_Disposed) return;
_CountDisposed++;
_Disposed = true;
RemoveFromCache(this);
if (!_CacheByPrimaryKey.ContainsKey(FolderID.ToString())) return;
List listFolderInfo = _CacheByPrimaryKey[FolderID.ToString()]; // Get the list of items
while (listFolderInfo.Contains(this)) listFolderInfo.Remove(this); // Remove the item from the list
if (listFolderInfo.Count == 0) // If there are no items left in the list
_CacheByPrimaryKey.Remove(FolderID.ToString()); // remove the list
}
public virtual Folder Get()
{
return _Editable = Folder.Get(_FolderID);
}
public static void Refresh(Folder tmp)
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
protected virtual void RefreshFields(Folder tmp)
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
_FolderInfoExtension.Refresh(this);
OnChange();// raise an event
}
public static void Refresh(ConnectionFolder tmp)
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
protected virtual void RefreshFields(ConnectionFolder tmp)
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
if (_FormatID != tmp.FormatID)
{
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for old value
_FormatID = tmp.FormatID; // Update the value
}
_MyFormat = null; // Reset list so that the next line gets a new list
if (MyFormat != null) MyFormat.RefreshFormatFolders(); // Update List for new value
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
_FolderInfoExtension.Refresh(this);
OnChange();// raise an event
}
public static void Refresh(FormatFolder tmp)
{
string key = tmp.FolderID.ToString();
ConvertListToDictionary();
if (_CacheByPrimaryKey.ContainsKey(key))
foreach (FolderInfo tmpInfo in _CacheByPrimaryKey[key])
tmpInfo.RefreshFields(tmp);
}
protected virtual void RefreshFields(FormatFolder tmp)
{
if (_ParentID != tmp.ParentID)
{
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for old value
_ParentID = tmp.ParentID; // Update the value
}
_MyParent = null; // Reset list so that the next line gets a new list
if (MyParent != null) MyParent.RefreshChildFolders(); // Update List for new value
if (_DBID != tmp.DBID)
{
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for old value
_DBID = tmp.DBID; // Update the value
}
_MyConnection = null; // Reset list so that the next line gets a new list
if (MyConnection != null) MyConnection.RefreshConnectionFolders(); // Update List for new value
_Name = tmp.Name;
_Title = tmp.Title;
_ShortName = tmp.ShortName;
_ManualOrder = tmp.ManualOrder;
_Config = tmp.Config;
_DTS = tmp.DTS;
_UsrID = tmp.UsrID;
_FolderInfoExtension.Refresh(this);
OnChange();// raise an event
}
public static FolderInfo Get(int folderID)
{
//if (!CanGetObject())
// throw new System.Security.SecurityException("User not authorized to view a Folder");
try
{
FolderInfo tmp = GetCachedByPrimaryKey(folderID);
if (tmp == null)
{
tmp = DataPortal.Fetch(new PKCriteria(folderID));
AddToCache(tmp);
}
if (tmp.ErrorMessage == "No Record Found")
{
tmp.Dispose(); // Clean-up FolderInfo
tmp = null;
}
return tmp;
}
catch (Exception ex)
{
throw new DbCslaException("Error on FolderInfo.Get", ex);
}
}
#endregion
#region Data Access Portal
internal FolderInfo(SafeDataReader dr)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.Constructor", GetHashCode());
try
{
ReadData(dr);
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.Constructor", ex);
throw new DbCslaException("FolderInfo.Constructor", ex);
}
}
[Serializable()]
protected class PKCriteria
{
private int _FolderID;
public int FolderID
{ get { return _FolderID; } }
public PKCriteria(int folderID)
{
_FolderID = folderID;
}
}
private void ReadData(SafeDataReader dr)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.ReadData", GetHashCode());
try
{
_FolderID = dr.GetInt32("FolderID");
_ParentID = dr.GetInt32("ParentID");
_DBID = dr.GetInt32("DBID");
_Name = dr.GetString("Name");
_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");
_FolderAssignmentCount = dr.GetInt32("AssignmentCount");
_FolderDocVersionCount = dr.GetInt32("DocVersionCount");
_ChildFolderCount = dr.GetInt32("ChildCount");
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.ReadData", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("FolderInfo.ReadData", ex);
}
}
private void DataPortal_Fetch(PKCriteria criteria)
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] FolderInfo.DataPortal_Fetch", GetHashCode());
try
{
using (SqlConnection cn = Database.VEPROMS_SqlConnection)
{
ApplicationContext.LocalContext["cn"] = cn;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "getFolder";
cm.Parameters.AddWithValue("@FolderID", criteria.FolderID);
cm.CommandTimeout = Database.DefaultTimeout;
using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
{
if (!dr.Read())
{
_ErrorMessage = "No Record Found";
return;
}
ReadData(dr);
}
}
// removing of item only needed for local data portal
if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
ApplicationContext.LocalContext.Remove("cn");
}
}
catch (Exception ex)
{
if (_MyLog.IsErrorEnabled) _MyLog.Error("FolderInfo.DataPortal_Fetch", ex);
_ErrorMessage = ex.Message;
throw new DbCslaException("FolderInfo.DataPortal_Fetch", ex);
}
}
#endregion
// Standard Refresh
#region extension
FolderInfoExtension _FolderInfoExtension = new FolderInfoExtension();
[Serializable()]
partial class FolderInfoExtension : extensionBase { }
[Serializable()]
class extensionBase
{
// Default Refresh
public virtual void Refresh(FolderInfo tmp) { }
}
#endregion
} // Class
#region Converter
internal class FolderInfoConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is FolderInfo)
{
// Return the ToString value
return ((FolderInfo)value).ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
} // Namespace