⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remotingserviceobjectfactory.cs

📁 用于c#.net数据库操作的类库。能把结婚集以数组的形成操作。
💻 CS
字号:
using System;
using System.Text;

namespace EnterpriseObjects
{
	/// <summary>
	/// Summary description for RemoteServiceObjectFactory.
	/// </summary>
	public class RemotingServiceObjectFactory : ServiceObjectFactory
	{
		// members...
		public RemotingChannelType ChannelType = RemotingChannelType.Tcp;
		public string RemoteAppName;
		public string RemoteServerName;
		public int RemotePort;

		// enum...
		public enum RemotingChannelType { Tcp = 0, Http };


		public RemotingServiceObjectFactory()
		{
			// go through the parts...
			foreach(string part in EnterpriseApplication.Application.ConnectionStringParts.Keys)
			{
				// check...
				switch(part.ToLower())
				{
					case "appname":
						RemoteAppName = (string)EnterpriseApplication.Application.ConnectionStringParts[part];
						break;
					case "servername":
						RemoteServerName = (string)EnterpriseApplication.Application.ConnectionStringParts[part];
						break;
					case "port":
						RemotePort = Int32.Parse((string)EnterpriseApplication.Application.ConnectionStringParts[part]);
						break;
					case "protocol":
						string protocol = (string)EnterpriseApplication.Application.ConnectionStringParts[part];
						switch(protocol.ToLower())
						{
							case "tcp":
								ChannelType = RemotingChannelType.Tcp;
								break;
							case "http":
								ChannelType = RemotingChannelType.Http;
								break;
							default:
								throw new NotSupportedException("Channel type '" + protocol + "' not supported.");
						}
						break;
				}
			}

	        // did we get everything?
			if(RemoteAppName == "")
				throw new RemotingConnectionException("You must provide a remote application name");
	        if(RemoteServerName == "")
				throw new RemotingConnectionException("You must provide a remote server name");
			if(RemotePort == 0)
				throw new RemotingConnectionException("You must provide a remote port");
		}
	
		public override Service Create(Type serviceObjectType)
		{
			// get the url...
			string url = GetRemotingUrl(serviceObjectType);
			Service serviceObject = (Service)System.Activator.GetObject(serviceObjectType, url);

			// return it...
			return serviceObject;
		}

		public override string ToString()
		{
			return "Remoting";
		}

		public string GetRemotingUrl(Type serviceObjectType)
		{
			// create it...
			StringBuilder url = new StringBuilder();
			switch(ChannelType)
			{
				case RemotingChannelType.Tcp:
					url.Append("tcp");
					break;
				case RemotingChannelType.Http:
					url.Append("http");
					break;
				default:
					throw new NotSupportedException("Remoting channel type '" + ChannelType + "' not supported.");
			}

			// append...
			url.Append("://");
			url.Append(RemoteServerName);
			url.Append(":");
			url.Append(RemotePort.ToString());
			url.Append("/");
			url.Append(RemoteAppName);
			url.Append("/");
			url.Append(serviceObjectType.ToString());
			url.Append(".remote");

			// return...
			return url.ToString();
		}

		//law 2003-7-26 add
		public override Service Create(string TypeString)
		{
			// get the url...
			string url = GetRemotingUrl(TypeString);
			Service serviceObject = (Service)System.Activator.GetObject(Type.GetType(TypeString), url);

			// return it...
			return serviceObject;			
			
		}
		//law 2003-7-26 add
		public string GetRemotingUrl(string serviceObjectType)
		{
			// create it...
			StringBuilder url = new StringBuilder();
			switch(ChannelType)
			{
				case RemotingChannelType.Tcp:
					url.Append("tcp");
					break;
				case RemotingChannelType.Http:
					url.Append("http");
					break;
				default:
					throw new NotSupportedException("Remoting channel type '" + ChannelType + "' not supported.");
			}

			// append...
			url.Append("://");
			url.Append(RemoteServerName);
			url.Append(":");
			url.Append(RemotePort.ToString());
			url.Append("/");
			url.Append(RemoteAppName);
			url.Append("/");
			url.Append(serviceObjectType);
			url.Append(".remote");

			// return...
			return url.ToString();
		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -