62,040
社区成员
发帖
与我相关
我的任务
分享
internal Context(string mappingFile, string connectString, CustomProvider customProvider, int sessionMinutes, int cleanupMinutes)
{
this.instances = Hashtable.Synchronized(new Hashtable());
this.license = LicenseManager.Validate(base.GetType(), this);
Mappings.LoadAssemblies();
XmlDocument xmlMappings = new XmlDocument();
if (((mappingFile.IndexOf("/") > -1) || (mappingFile.IndexOf(@"\") > -1)) || (mappingFile.Split(new char[] { '.' }).Length <= 2))
{
string fullPath = Mappings.GetFullPath(mappingFile);
xmlMappings.Load(fullPath);
}
else
{
using (Stream stream = Mappings.GetResourceStream(mappingFile))
{
xmlMappings.Load(stream);
}
}
this.Init(xmlMappings, connectString, customProvider, sessionMinutes, cleanupMinutes);
}
private void Init(XmlDocument xmlMappings, string connectString, CustomProvider customProvider, int sessionMinutes, int cleanupMinutes)
{
if ((connectString == null) || (connectString.Length == 0))
{
throw new ORMapperException("ObjectSpace: ConnectionString was Empty");
}
this.mappings = new Mappings(xmlMappings, customProvider);
this.connection = new Connection(connectString, customProvider);
this.provider = customProvider;
this.session = new TimeSpan(0, (sessionMinutes < 0) ? 0 : sessionMinutes, 0);
this.timer = new Timer((double) (((cleanupMinutes < 1) ? 1 : cleanupMinutes) * 0xea60));
this.timer.Elapsed += new ElapsedEventHandler(this.CleanupInstances);
this.timer.Start();
}
internal static Stream GetResourceStream(string resourceName)
{
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
if (!(assembly is AssemblyBuilder))
{
Stream manifestResourceStream = assembly.GetManifestResourceStream(resourceName);
if (manifestResourceStream != null)
{
return manifestResourceStream;
}
}
}
throw new MappingException("ObjectSpace: MappingStream was not Found - " + resourceName);
}
public sealed class Manager
{
// Fields
private static string _connectionString;
private static ObjectSpace _engine;
private static string _mappingFile = (AppDomain.CurrentDomain.BaseDirectory + "Mappings.config");
// Methods
public static void getEngine()
{
_mappingFile = (AppDomain.CurrentDomain.BaseDirectory + "Mappings.config");
_connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connstring"].ConnectionString;
_engine = new ObjectSpace(_mappingFile, _connectionString, Provider.MsSql);
}
public static ObjectSpace Engine
{
get
{
return _engine;
}
}
}
internal static void LoadAssemblies()
{
Assembly entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly == null)
{
entryAssembly = Assembly.GetCallingAssembly();
}
if (entryAssembly != null)
{
foreach (AssemblyName name in entryAssembly.GetReferencedAssemblies())
{
AppDomain.CurrentDomain.Load(name.FullName);
}
}
}