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

📄 applicationurls.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.IO;
using System.Web;
using CommunityServer.Configuration;

namespace CommunityServer.Components
{
	/// <summary>
	/// Provides a common hook into SiteUrls for each application
	/// </summary>
	public abstract class ApplicationUrls
	{
		public ApplicationUrls()
		{
			
		}

		/// <summary>
		/// Creates an instance of the provider using Activator. This instance should be
		/// cached since it is an expesivie operation
		/// </summary>
		public static object CreateInstance(Provider dataProvider)
		{
			return CreateInstance(dataProvider, null);
		}

		/// <summary>
		/// Creates an instance of the provider using Activator. This instance should be
		/// cached since it is an expesivie operation
		/// </summary>
		public static object CreateInstance(Provider dataProvider, params object[] args )
		{
			//Get the type
			Type type  = Type.GetType(dataProvider.Type);

			object newObject = null;
			if(type != null)
			{
				if(args != null)
					newObject = Activator.CreateInstance(type, args);
				else
					newObject = Activator.CreateInstance(type);
			}
            
			if(newObject == null) //If we can not create an instance, throw an exception
				ProviderException(dataProvider.Name);

			return newObject;
		}

        protected string FormatUrl(string name)
        {
            return Globals.GetSiteUrls().UrlData.FormatUrl(name);
        }

        protected string FormatUrl(string name, params object[] parameters)
        {
            return Globals.GetSiteUrls().UrlData.FormatUrl(name, parameters);
        }

		#region Exception
		private static void ProviderException(string providerName)
		{
			CSConfiguration config = CSConfiguration.GetConfig();
			HttpContext context = HttpContext.Current;
			if (context != null) 
			{
                    
				// We can't load the dataprovider
				//
				StreamReader reader = new StreamReader( context.Server.MapPath("~/Languages/" + config.DefaultLanguage + "/errors/DataProvider.htm") );
				string html = reader.ReadToEnd();
				reader.Close();

				html = html.Replace("[DATAPROVIDERCLASS]", providerName);
				html = html.Replace("[DATAPROVIDERASSEMBLY]", providerName);
				context.Response.Write(html);
				context.Response.End();
			} 
			else 
			{
				throw new CSException(CSExceptionType.DataProvider, "Unable to load " + providerName);
			}
		}
		#endregion
	}
}

⌨️ 快捷键说明

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