📄 enterpriseapplication.cs
字号:
using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.Remoting.Messaging;
namespace EnterpriseObjects
{
/// <summary>
/// Summary description for EnterpriseApplication.
/// </summary>
public class EnterpriseApplication
{
// members...
private static EnterpriseApplication _application = new EnterpriseApplication();
private string _connectionString;
private Hashtable _connectionStringParts;
public ConnectionType ConnectionMode = ConnectionType.Direct;
private ServiceObjectFactory _serviceObjectFactory;
private string _securityToken;
private EnterpriseCounters _counters = new EnterpriseCounters();
//law 2003-7-26 add
private static Service _Service=null;
// const...
public const string SecurityTokenSlotName = "WeoSecurityToken";
// enum...
public enum ConnectionType { Direct=0, Remoting };
public static EnterpriseApplication Application
{
get
{
return _application;
}
}
// ConnectionString property...
public string ConnectionString
{
get
{
return _connectionString;
}
set
{
// set it...
_connectionString = value;
// bool iscon=false;
// System.Data.SqlClient.SqlConnection sqlcon;
// do
// {
// try
// {
// sqlcon=new System.Data.SqlClient.SqlConnection(_connectionString);
// sqlcon.Open();
// iscon=true;
// sqlcon.Close();
//
// }
// catch
// {
// ConDB.ConnectServer fm=new ConDB.ConnectServer();
// if(fm.ShowDialog()==System.Windows.Forms.DialogResult.OK)
// {
// _connectionString=fm.GetSqlStr();
// }
// else
// {
// iscon=true;
// System.Windows.Forms.Application.ExitThread();
// }
// }
//
// }
// while(!iscon);
// reset...
_serviceObjectFactory = null;
_connectionStringParts = null;
//law 2003-7-26 add
_Service=null;
}
}
public Service Service
{
get
{
if(_Service==null)
{
_Service=ServiceObjectFactory.Create("EnterpriseObjects.LAWService");
}
return _Service;
}
}
// ConnectionStringParts property - split up the connection string...
public Hashtable ConnectionStringParts
{
get
{
// do we have it?
if(_connectionStringParts == null)
{
// create it...
_connectionStringParts = new Hashtable();
// split it...
string[] parts = ConnectionString.Split(';');
foreach(string part in parts)
{
// split into value...
string[] valueParts = part.Split('=');
_connectionStringParts.Add(valueParts[0], valueParts[1]);
}
}
// return...
return _connectionStringParts;
}
}
// ServiceObjectFactory - create a factory...
public ServiceObjectFactory ServiceObjectFactory
{
get
{
// do we have one?
if(_serviceObjectFactory == null)
{
// look at the string...
if(ConnectionStringParts.Contains("Enterprise Connection Type") == true)
{
string connectionType = ConnectionStringParts["Enterprise Connection Type"].ToString().ToLower();
switch(connectionType)
{
// direct...
case "direct":
_serviceObjectFactory = new DirectServiceObjectFactory();
break;
// remoting...
case "remoting":
_serviceObjectFactory = new RemotingServiceObjectFactory();
break;
// else...
default:
throw new NotSupportedException("Connection type '" + connectionType + "' not supported.");
}
}
// did we get one? create a default one...
if(_serviceObjectFactory == null)
_serviceObjectFactory = new DirectServiceObjectFactory();
}
// return it...
return _serviceObjectFactory;
}
}
public string SecurityToken
{
get
{
return _securityToken;
}
set
{
// set the value...
_securityToken = value;
// configure the thread...
ConfigureThread();
}
}
public EnterpriseCounters Counters
{
get
{
return _counters;
}
}
public void ConfigureThread()
{
// add it...
CallContext.SetData(SecurityTokenSlotName, new ContextToken(SecurityToken));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -