init lserp cs 5.0
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using System.Web.Configuration;
|
||||
using Zhaizj.Framework.Utils;
|
||||
|
||||
namespace Zhaizj.Framework.Config.DotNetConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置组(依赖 .NET的配置架构)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <code>
|
||||
/// <configSections>
|
||||
/// <sectionGroup name="KEB.devfx" type="KEB.DevFx.Config.DotNetConfig.GroupHandler, KEB.DevFx.BaseFx">
|
||||
/// <section name="mail" type="KEB.DevFx.Utils.Mail.Config.SectionHandler, KEB.DevFx.BaseFx" />
|
||||
/// ......
|
||||
/// </sectionGroup>
|
||||
/// </configSections>
|
||||
///
|
||||
/// ......
|
||||
///
|
||||
/// <KEB.devfx>
|
||||
/// <mail>
|
||||
/// <smtpSetting server="" port="" userName="" password="" />
|
||||
/// </mail>
|
||||
/// </KEB.devfx>
|
||||
/// ......
|
||||
/// </code>
|
||||
/// </remarks>
|
||||
public class GroupHandler : ConfigurationSectionGroup
|
||||
{
|
||||
private static GroupHandler instance;
|
||||
private static bool isInit;
|
||||
private static bool isWebApp;
|
||||
private static Dictionary<Type, ConfigurationSection> sectionCache;
|
||||
private static readonly object lockObject = new object();
|
||||
|
||||
private static void Init(bool throwOnError) {
|
||||
if (isInit) {
|
||||
return;
|
||||
}
|
||||
Configuration config;
|
||||
if (HttpContext.Current != null) {
|
||||
isWebApp = true;
|
||||
config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
|
||||
} else {
|
||||
isWebApp = false;
|
||||
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
||||
}
|
||||
foreach (string key in config.SectionGroups.Keys) {
|
||||
ConfigurationSectionGroup csg = config.SectionGroups[key];
|
||||
if(csg == null || string.IsNullOrEmpty(csg.Type)) {
|
||||
continue;
|
||||
}
|
||||
Type csgType = TypeHelper.CreateType(csg.Type, false);
|
||||
if (csgType == typeof(GroupHandler)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sectionCache = new Dictionary<Type, ConfigurationSection>();
|
||||
|
||||
if (instance == null) {
|
||||
isInit = true;
|
||||
if (throwOnError) {
|
||||
throw new Exception("配置组未正确配置");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ConfigurationSection section in instance.Sections) {
|
||||
string sectionTypeName = section.SectionInformation.Type;
|
||||
string sectionName = section.SectionInformation.SectionName;
|
||||
Type sectionType = TypeHelper.CreateType(sectionTypeName, false);
|
||||
object objectSection;
|
||||
if (isWebApp) {
|
||||
objectSection = WebConfigurationManager.GetSection(sectionName);
|
||||
} else {
|
||||
objectSection = ConfigurationManager.GetSection(sectionName);
|
||||
}
|
||||
if (objectSection != null) {
|
||||
sectionCache.Add(sectionType, (ConfigurationSection)objectSection);
|
||||
}
|
||||
}
|
||||
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前配置组的实例(单件)
|
||||
/// </summary>
|
||||
public static GroupHandler Instance {
|
||||
get { return instance; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置节(泛型)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">配置节类型</typeparam>
|
||||
/// <returns>配置节</returns>
|
||||
public static T GetSection<T>() where T : ConfigurationSection {
|
||||
return GetSection<T>(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取配置节(泛型)
|
||||
/// </summary>
|
||||
/// <typeparam name="T">配置节类型</typeparam>
|
||||
/// <param name="throwOnError">如果配置组未配置是否抛出异常</param>
|
||||
/// <returns>配置节</returns>
|
||||
public static T GetSection<T>(bool throwOnError) where T : ConfigurationSection {
|
||||
if (!isInit) {
|
||||
lock (lockObject) {
|
||||
if (!isInit) {
|
||||
Init(throwOnError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Type type = typeof(T);
|
||||
ConfigurationSection sectionObject;
|
||||
sectionCache.TryGetValue(type, out sectionObject);
|
||||
return sectionObject as T;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造方法
|
||||
/// </summary>
|
||||
protected GroupHandler() {
|
||||
instance = this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// Ⱥ×éÅäÖÃ
|
||||
/// </summary>
|
||||
public class GroupSetting {
|
||||
|
||||
public int LogoHeight {
|
||||
get { return 120; }
|
||||
}
|
||||
|
||||
public int LogoWidth {
|
||||
get { return 120; }
|
||||
}
|
||||
|
||||
public int TemplateId {
|
||||
get { return 1; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
using System.Configuration;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using Zhaizj.Framework.Data;
|
||||
|
||||
namespace Zhaizj.Framework.Config.DotNetConfig
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 配置节基础处理类,继承自 <see cref="ConfigurationSection"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T">派生类</typeparam>
|
||||
/// <remarks>
|
||||
/// 注意与 <see cref="BaseConfigurationElement"/> 的区别
|
||||
/// </remarks>
|
||||
public abstract class SectionBaseHandler<T> : ConfigurationSection where T : SectionBaseHandler<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// 字段绑定预置值
|
||||
/// </summary>
|
||||
public const BindingFlags FieldBindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
/// <summary>
|
||||
/// 获取当前配置节实例
|
||||
/// </summary>
|
||||
public static T Current {
|
||||
get { return GroupHandler.GetSection<T>(false); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示反序列化过程中是否遇到未知属性
|
||||
/// </summary>
|
||||
/// <param name="name">无法识别的属性的名称</param>
|
||||
/// <param name="value">无法识别的属性的值</param>
|
||||
/// <returns>如果反序列化过程中遇到未知属性,则为<c>true</c></returns>
|
||||
protected override bool OnDeserializeUnrecognizedAttribute(string name, string value) {
|
||||
return this.OnDeserializeUnrecognizedFlag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个值,该值指示反序列化过程中是否遇到未知元素
|
||||
/// </summary>
|
||||
/// <param name="elementName">未知的子元素的名称</param>
|
||||
/// <param name="reader">用于反序列化的 <seealso cref="XmlReader"/> 对象</param>
|
||||
/// <returns>如果反序列化过程中遇到未知元素,则为 true</returns>
|
||||
protected override bool OnDeserializeUnrecognizedElement(string elementName, XmlReader reader) {
|
||||
return this.OnDeserializeUnrecognizedFlag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否遇到未知的属性或元素
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>派生类如果要允许未定义的属性,则必须重写本属性</para>
|
||||
/// </remarks>
|
||||
protected virtual bool OnDeserializeUnrecognizedFlag {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 本配置节对应的Xml
|
||||
/// </summary>
|
||||
public virtual string OuterXml {
|
||||
get { return this.outerXml; }
|
||||
}
|
||||
|
||||
private string outerXml;
|
||||
|
||||
/// <summary>
|
||||
/// 读取配置文件中的 XML
|
||||
/// </summary>
|
||||
/// <param name="reader">在配置文件中进行读取操作的 <seealso cref="XmlReader"/></param>
|
||||
/// <param name="serializeCollectionKey">为 <c>true</c>,则只序列化集合的键属性;否则为 <c>false</c></param>
|
||||
protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey) {
|
||||
FieldInfo field = reader.GetType().GetField("_rawXml", FieldBindingFlags);
|
||||
this.outerXml = (string)field.GetValue(reader);
|
||||
base.DeserializeElement(reader, serializeCollectionKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
public interface ISetting {
|
||||
|
||||
int Id { get; set; }
|
||||
|
||||
String DataType { get; set; }
|
||||
|
||||
String Name { get; set; }
|
||||
String Description { get; set; }
|
||||
|
||||
// 格式json
|
||||
String Options { get; set; }
|
||||
|
||||
String SettingValue { get; set; }
|
||||
|
||||
|
||||
String ValueString { get; }
|
||||
int ValueInt { get; }
|
||||
Boolean ValueBool { get; }
|
||||
DateTime ValueTime { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// 配置值的接口
|
||||
/// </summary>
|
||||
public interface ISettingValue {
|
||||
|
||||
int Id { get; set; }
|
||||
String DataType { get; set; }
|
||||
|
||||
String SettingValue { get; set; }
|
||||
void Update( String propertyName );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Zhaizj.Framework.Common.Resource;
|
||||
using Zhaizj.Framework.Serialization;
|
||||
|
||||
using Zhaizj.Framework.Web;
|
||||
using Zhaizj.Framework.Web.Context;
|
||||
using Zhaizj.Framework.Web.Mvc;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// ÅäÖÃ±íµ¥¹¤¾ß
|
||||
/// </summary>
|
||||
public class SettingFormTool {
|
||||
|
||||
public static void BindTemplate( Template template, IList list, String categoryName, String actionUrl ) {
|
||||
template.Set( "settingCategory.Name", categoryName );
|
||||
template.Set( "ActionUrl", actionUrl );
|
||||
IBlock block = template.GetBlock( "list" );
|
||||
foreach (ISetting setting in list) {
|
||||
block.Set( "setting.Id", setting.Id );
|
||||
block.Set( "setting.Title", setting.Name );
|
||||
SetInput( block, setting );
|
||||
SetNote( block, setting );
|
||||
block.Next();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void SetInput( IBlock block, ISetting setting ) {
|
||||
|
||||
String lbl = "setting.inputControl";
|
||||
String inputName = GetInputName( setting.Id );
|
||||
String settingValue = setting.SettingValue;
|
||||
int width = 500;
|
||||
if (setting.DataType == SettingType.Int.ToString()) {
|
||||
block.Set( lbl, Html.TextInput( inputName, settingValue, "width:40px;" ) );
|
||||
}
|
||||
else if (setting.DataType == SettingType.Bool.ToString()) {
|
||||
block.Set( lbl, Html.CheckBox( inputName, "", "1", Convert.ToBoolean( setting.SettingValue ) ) );
|
||||
}
|
||||
else if (setting.DataType == SettingType.Droplist.ToString()) {
|
||||
block.Set( lbl, Html.DropList( getDropOptions(setting.Options), inputName, "Name", "Value", setting.ValueInt ) );
|
||||
}
|
||||
else if (setting.DataType == SettingType.ShortText.ToString()) {
|
||||
block.Set( lbl, Html.TextInput( inputName, settingValue, "width:" + width + "px;" ) );
|
||||
}
|
||||
else if (setting.DataType == SettingType.BigText.ToString()) {
|
||||
block.Set( lbl, Html.TextArea( inputName, settingValue, "width:" + width + "px;height:300px;" ) );
|
||||
}
|
||||
else {
|
||||
block.Set( lbl, Html.TextArea( inputName, settingValue, "width:" + width + "px;height:50px;" ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static PropertyCollection getDropOptions( String Options ) {
|
||||
|
||||
PropertyCollection result = new PropertyCollection();
|
||||
if (strUtil.IsNullOrEmpty( Options )) return result;
|
||||
|
||||
Dictionary<String, object> dic = JsonParser.Parse( Options ) as Dictionary<String, object>;
|
||||
foreach (KeyValuePair<String, object> pair in dic) {
|
||||
result.Add( new PropertyItem( pair.Key, cvt.ToInt( pair.Value ) ) );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SetNote( IBlock block, ISetting setting ) {
|
||||
if (strUtil.HasText( setting.Description )) {
|
||||
if ((setting.DataType == SettingType.Int.ToString()) || (setting.DataType == SettingType.Bool.ToString())) {
|
||||
block.Set( "setting.Note", "<span class=\"note\">(" + setting.Description + ")</span>" );
|
||||
}
|
||||
else {
|
||||
block.Set( "setting.Note", "<div class=\"note\">(" + setting.Description + ")</div>" );
|
||||
}
|
||||
}
|
||||
else {
|
||||
block.Set( "setting.Note", "" );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
public static void UpdateSettings( IList list, MvcContext ctx ) {
|
||||
for (int i = 0; i < list.Count; i++) {
|
||||
ISettingValue s = list[i] as ISettingValue;
|
||||
String target = ctx.Post( GetInputName( s.Id ) );
|
||||
if (strUtil.HasText( target )) {
|
||||
if (s.DataType == SettingType.Bool.ToString()) {
|
||||
updateSetting( s, cvt.ToBool( target ).ToString() );
|
||||
}
|
||||
else if (!(s.DataType == SettingType.Int.ToString()) || cvt.IsInt( target )) {
|
||||
updateSetting( s, target );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateSetting( ISettingValue s, String val ) {
|
||||
if ((val != null) && (s.SettingValue.ToLower() != val.ToLower())) {
|
||||
s.SettingValue = val;
|
||||
s.Update( "SettingValue" );
|
||||
}
|
||||
}
|
||||
|
||||
private static String GetInputName( int settingId ) {
|
||||
return ("SettingValue" + settingId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// 配置项的数据类型
|
||||
/// </summary>
|
||||
public enum SettingType {
|
||||
|
||||
Int,
|
||||
Bool,
|
||||
ShortText,
|
||||
LongText,
|
||||
BigText,
|
||||
Droplist
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,712 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Zhaizj.Framework.Web.Handler;
|
||||
using Zhaizj.Framework.Web.Mvc;
|
||||
|
||||
namespace Zhaizj.Framework.Config {
|
||||
|
||||
/// <summary>
|
||||
/// 注册类型
|
||||
/// </summary>
|
||||
public class RegisterType {
|
||||
|
||||
/// <summary>
|
||||
/// 开放注册
|
||||
/// </summary>
|
||||
public static readonly int Open = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 关闭注册
|
||||
/// </summary>
|
||||
public static readonly int Close = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 关闭注册,但受邀请的除外
|
||||
/// </summary>
|
||||
public static readonly int CloseUnlessInvite = 2;
|
||||
}
|
||||
|
||||
public class LoginType {
|
||||
|
||||
/// <summary>
|
||||
/// 注册之后自动登录
|
||||
/// </summary>
|
||||
public static readonly int Open = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 注册之后并不自动登录;必须激活才能登录
|
||||
/// </summary>
|
||||
public static readonly int ActivationEmail = 1;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// (网站页面顶部的)用户导航栏的显示状态
|
||||
/// </summary>
|
||||
public class TopNavDisplay {
|
||||
|
||||
/// <summary>
|
||||
/// 显示
|
||||
/// </summary>
|
||||
public static readonly int Show = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 隐藏
|
||||
/// </summary>
|
||||
public static readonly int Hide = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 在关闭注册之后隐藏
|
||||
/// </summary>
|
||||
public static readonly int NoRegHide = 2;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称:Name 用户名,RealName 真实姓名,默认为RealName
|
||||
/// </summary>
|
||||
public class UserDisplayNameType
|
||||
{
|
||||
public static readonly int RealName = 1;
|
||||
public static readonly int Name = 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网站配置
|
||||
/// </summary>
|
||||
public class SiteSetting {
|
||||
|
||||
//-------------------------------base---------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// 网站名称
|
||||
/// </summary>
|
||||
public String SiteName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站的网址
|
||||
/// </summary>
|
||||
public String SiteUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// logo的图片网址
|
||||
/// </summary>
|
||||
public String SiteLogo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 站长名字
|
||||
/// </summary>
|
||||
public String Webmaster { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站的email
|
||||
/// </summary>
|
||||
public String Email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网页默认关键词
|
||||
/// </summary>
|
||||
public String Keywords { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网页默认的描述
|
||||
/// </summary>
|
||||
public String Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网页默认的标题
|
||||
/// </summary>
|
||||
public String PageDefaultTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网站是否需要登录才能访问,默认不需要登录
|
||||
/// </summary>
|
||||
public Boolean NeedLogin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户注册之后必须经过人工审核
|
||||
/// </summary>
|
||||
public Boolean UserNeedApprove { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对尚未激活的用户,是否提醒他激活
|
||||
/// </summary>
|
||||
public Boolean AlertActivation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户自己重发激活邮件的间隔
|
||||
/// </summary>
|
||||
public int UserSendConfirmEmailInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对尚未上传头像的用户,是否提醒他上传头像
|
||||
/// </summary>
|
||||
public Boolean AlertUserPic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注册的三种类型 (1)开放注册 (2)关闭注册 (3)只有受邀请用户才可以注册
|
||||
/// </summary>
|
||||
public int RegisterType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录限制(1)注册之后自动登录 (2)必须激活才能登录)
|
||||
/// </summary>
|
||||
public int LoginType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 顶部用户栏状态(1)显示 (2)隐藏 (3)在关闭注册之后隐藏
|
||||
/// </summary>
|
||||
public int TopNavDisplay { get; set; }
|
||||
|
||||
private String _initApp;
|
||||
|
||||
/// <summary>
|
||||
/// 用户注册之后默认安装的app。
|
||||
/// </summary>
|
||||
public String UserInitApp {
|
||||
get {
|
||||
//if (strUtil.IsNullOrEmpty( _initApp )) return "home, blog, photo";
|
||||
if (strUtil.IsNullOrEmpty( _initApp )) return "";
|
||||
return _initApp;
|
||||
}
|
||||
set { _initApp = value; }
|
||||
}
|
||||
|
||||
private int _ValidationType;
|
||||
|
||||
/// <summary>
|
||||
/// 验证码类型
|
||||
/// </summary>
|
||||
public int ValidationType {
|
||||
get {
|
||||
if (_ValidationType == 0) return ValidationDefault.Type;
|
||||
return _ValidationType;
|
||||
}
|
||||
set {
|
||||
_ValidationType = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int _ValidationLength;
|
||||
|
||||
/// <summary>
|
||||
/// 英文或数字的验证没长度
|
||||
/// </summary>
|
||||
public int ValidationLength {
|
||||
get {
|
||||
if (_ValidationLength == 0) return ValidationDefault.Length;
|
||||
return _ValidationLength;
|
||||
}
|
||||
set {
|
||||
_ValidationLength = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int _ValidationChineseLength;
|
||||
|
||||
/// <summary>
|
||||
/// 中文验证码长度
|
||||
/// </summary>
|
||||
public int ValidationChineseLength {
|
||||
get {
|
||||
if (_ValidationChineseLength == 0) return ValidationDefault.ChineseLength;
|
||||
return _ValidationChineseLength;
|
||||
}
|
||||
set {
|
||||
_ValidationChineseLength = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Boolean IsInstall { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 网站是否关闭
|
||||
/// </summary>
|
||||
public Boolean IsClose { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 如果关闭,关闭的原因
|
||||
/// </summary>
|
||||
public String CloseReason { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否开启统计,需要结合StatsJs
|
||||
/// </summary>
|
||||
public Boolean StatsEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 统计js
|
||||
/// </summary>
|
||||
public String StatsJs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 版权信息
|
||||
/// </summary>
|
||||
public String Copyright { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// logo宽度
|
||||
/// </summary>
|
||||
public int LogoWidth { get { return 250; } }
|
||||
|
||||
/// <summary>
|
||||
/// logo高度
|
||||
/// </summary>
|
||||
public int LogoHeight { get { return 80; } }
|
||||
|
||||
/// <summary>
|
||||
/// 网站当前皮肤的ID
|
||||
/// </summary>
|
||||
public int SkinId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 用户密码是否采用16位的md5加密方式(默认为否,用于兼容旧的系统)
|
||||
/// </summary>
|
||||
public Boolean Md5Is16 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 评论内容的长度
|
||||
/// </summary>
|
||||
public int CommentLength { get { return 500; } }
|
||||
|
||||
private int _TagLength;
|
||||
|
||||
/// <summary>
|
||||
/// tag的长度
|
||||
/// </summary>
|
||||
public int TagLength {
|
||||
get {
|
||||
if (_TagLength == 0) return 20;
|
||||
return _TagLength;
|
||||
}
|
||||
set {
|
||||
_TagLength = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网站logo图片的完整网址
|
||||
/// </summary>
|
||||
public String SiteLogoFull {
|
||||
get { return strUtil.Join( sys.Path.Photo, this.SiteLogo ); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取统计的js内容
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public String GetStatsJs() {
|
||||
if (this.StatsEnabled == false) return "";
|
||||
return this.StatsJs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 如果设置了logo图片,返回img;否则返回siteName
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public String GetLogoHtml() {
|
||||
|
||||
String logo;
|
||||
if (strUtil.HasText( this.SiteLogo )) {
|
||||
logo = "<img src=\"" + SiteLogoFull + "?v=" + MvcConfig.Instance.CssVersion + "\"/>";
|
||||
}
|
||||
else {
|
||||
logo = "<div class=\"nologo\">" + this.SiteName + "</div>";
|
||||
}
|
||||
|
||||
return logo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取邮件发送服务器的域名,比如根据 abc@gmail.com,得到 gmail.com
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public String GetSmtpUserDomain() {
|
||||
return GetSmtpUserDomain( this.SmtpUser );
|
||||
}
|
||||
|
||||
public String GetSmtpUserDomain( string smtpUser ) {
|
||||
if (strUtil.IsNullOrEmpty( smtpUser )) return string.Concat( 'w', 'o', 'j', 'i', 'l', 'u', '.', 'c', 'o', 'm' );
|
||||
if (smtpUser.IndexOf( '@' ) <= 0) return string.Concat( 'w', 'o', 'j', 'i', 'l', 'u', '.', 'c', 'o', 'm' );
|
||||
String[] arr = smtpUser.Split( '@' );
|
||||
return arr[1].Trim();
|
||||
}
|
||||
|
||||
//----------------------------- user -----------------------------------
|
||||
|
||||
public Boolean ShowSexyInfoInProfile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注册用户名允许的长度
|
||||
/// </summary>
|
||||
public int UserNameLengthMax { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注册用户名至少要达到的长度
|
||||
/// </summary>
|
||||
public int UserNameLengthMin { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 登录是否启用验证码
|
||||
/// </summary>
|
||||
public Boolean LoginNeedImgValidation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 注册是否启用验证码
|
||||
/// </summary>
|
||||
public Boolean RegisterNeedImgValidateion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 给新注册用户发送的欢迎信息的标题
|
||||
/// </summary>
|
||||
public String SystemMsgTitle { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 给新注册用户发送的欢迎信息的内容(支持html)
|
||||
/// </summary>
|
||||
public String SystemMsgContent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留用户名(不可以注册的用户名)
|
||||
/// </summary>
|
||||
public String[] ReservedUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留的用户个性网址
|
||||
/// </summary>
|
||||
public String[] ReservedUserUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保留的关键词(不可以在用户名和个性网址中使用)
|
||||
/// </summary>
|
||||
public String[] ReservedKey { get; set; }
|
||||
|
||||
public Boolean IsReservedKeyContains( String inputName ) {
|
||||
|
||||
string[] arr = this.ReservedKey;
|
||||
foreach (String key in arr) {
|
||||
if (strUtil.EqualsIgnoreCase( inputName, key ) || strUtil.EqualsIgnoreCase( inputName, key + "s" )) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用MS的Membership数据库验证登录,需要配合AuthenticationModule的自动注册功能一起使用,默认为否
|
||||
/// </summary>
|
||||
public Boolean ValidateUserByMembership { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称:Name 用户名,RealName 真实姓名,默认为RealName
|
||||
/// </summary>
|
||||
public int UserDisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止修改真实性名与空间名称,默认不禁止
|
||||
/// </summary>
|
||||
public Boolean DenyEditUserRealName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否禁止修改空间名称,默认不禁止
|
||||
/// </summary>
|
||||
public Boolean DenyEditUserTitle { get; set; }
|
||||
|
||||
//------------------------------filter----------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// 禁用的关键词
|
||||
/// </summary>
|
||||
public String[] BadWords { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 禁用词汇的替换词
|
||||
/// </summary>
|
||||
public String BadWordsReplacement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所有被禁的ip地址
|
||||
/// </summary>
|
||||
public String[] BannedIp { get; set; }
|
||||
|
||||
private String _bannedIpInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 给被屏蔽访客的警告信息
|
||||
/// </summary>
|
||||
public String BannedIpInfo {
|
||||
get {
|
||||
if (_bannedIpInfo == null) return "对不起,你的 ip 地址已被屏蔽";
|
||||
return _bannedIpInfo;
|
||||
}
|
||||
set { _bannedIpInfo = value; }
|
||||
}
|
||||
|
||||
|
||||
//public Boolean IsWatermark { get; set; }
|
||||
|
||||
|
||||
private int _microblogContentMax;
|
||||
/// <summary>
|
||||
/// 微博内容字数最高限制
|
||||
/// </summary>
|
||||
public int MicroblogContentMax {
|
||||
get {
|
||||
if (_microblogContentMax <= 0) return 140;
|
||||
return _microblogContentMax;
|
||||
}
|
||||
set {
|
||||
_microblogContentMax = value;
|
||||
}
|
||||
}
|
||||
|
||||
private int _microblogPageSize;
|
||||
/// <summary>
|
||||
/// 微博内容字数最高限制
|
||||
/// </summary>
|
||||
public int MicroblogPageSize {
|
||||
get {
|
||||
if (_microblogPageSize <= 0) return 20;
|
||||
return _microblogPageSize;
|
||||
}
|
||||
set {
|
||||
_microblogPageSize = value;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
public Boolean EnableEmail { get; set; } // 是否开启邮件服务,比如:邮件激活等
|
||||
public String SmtpUrl { get; set; }
|
||||
public String SmtpUser { get; set; }
|
||||
public String SmtpPwd { get; set; }
|
||||
public Boolean SmtpEnableSsl { get; set; }
|
||||
|
||||
public Boolean CloseComment { get; set; }
|
||||
|
||||
//-------------------------------other---------------------------------
|
||||
|
||||
public int MaxOnline { get; set; }
|
||||
public DateTime MaxOnlineTime { get; set; }
|
||||
public int UserTemplateId { get; set; }
|
||||
|
||||
public int NoRefreshSecond { get; set; }
|
||||
|
||||
public int FeedKeepDay { get; set; }
|
||||
public DateTime LastFeedClearTime { get; set; }
|
||||
|
||||
public String[] Spider { get; set; }
|
||||
|
||||
private static string getArrayString( String[] arr ) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < arr.Length; i++) {
|
||||
sb.Append( arr[i] );
|
||||
if (i < arr.Length - 1) sb.Append( "/" );
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
public int PhotoThumbHeight { get; set; }
|
||||
public int PhotoThumbWidth { get; set; }
|
||||
|
||||
public int PhotoThumbHeightMedium { get; set; }
|
||||
public int PhotoThumbWidthMedium { get; set; }
|
||||
|
||||
public int PhotoThumbHeightBig { get; set; }
|
||||
public int PhotoThumbWidthBig { get; set; }
|
||||
|
||||
|
||||
public int AvatarThumbHeight { get; set; }
|
||||
public int AvatarThumbWidth { get; set; }
|
||||
|
||||
public int AvatarThumbHeightMedium { get; set; }
|
||||
public int AvatarThumbWidthMedium { get; set; }
|
||||
|
||||
public int AvatarThumbHeightBig { get; set; }
|
||||
public int AvatarThumbWidthBig { get; set; }
|
||||
|
||||
public Boolean IsSaveAvatarMedium { get; set; }
|
||||
public Boolean IsSaveAvatarBig { get; set; }
|
||||
|
||||
public String[] UploadFileTypes { get; set; }
|
||||
public String[] UploadPicTypes { get; set; }
|
||||
|
||||
private int _uploadPicMaxMB;
|
||||
private int _uploadFileMaxMB;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 图片最大上传的大小,单位MB
|
||||
/// </summary>
|
||||
public int UploadPicMaxMB {
|
||||
get {
|
||||
if (_uploadPicMaxMB == 0) return 5;
|
||||
return _uploadPicMaxMB;
|
||||
}
|
||||
set { _uploadPicMaxMB = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片最大上传的大小,单位MB
|
||||
/// </summary>
|
||||
public int UploadFileMaxMB {
|
||||
get {
|
||||
if (_uploadFileMaxMB == 0) return 20;
|
||||
return _uploadFileMaxMB;
|
||||
}
|
||||
set { _uploadFileMaxMB = value; }
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 扩展的值
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
public int GetValueInt( String key ) {
|
||||
return cvt.ToInt( GetValue( key ) );
|
||||
}
|
||||
|
||||
public Boolean GetValueBool( String key ) {
|
||||
return cvt.ToBool( GetValue( key ) );
|
||||
}
|
||||
|
||||
public decimal GetValueDecimal( String key ) {
|
||||
return cvt.ToDecimal( GetValue( key ) );
|
||||
}
|
||||
|
||||
public DateTime GetValueTime( String key ) {
|
||||
return cvt.ToTime( GetValue( key ) );
|
||||
}
|
||||
|
||||
public String GetValue( String key ) {
|
||||
if (strUtil.IsNullOrEmpty( key )) return null;
|
||||
if (_valueAll == null) return null;
|
||||
if (_valueAll.ContainsKey( key ) == false) return null;
|
||||
return _valueAll[key];
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
|
||||
public String[] GetArrayValue( String key ) {
|
||||
return getArrayValue( _valueAll, key );
|
||||
}
|
||||
|
||||
internal String[] getArrayValue( Dictionary<String, String> dic, String key ) {
|
||||
|
||||
if (dic == null) return new String[] { };
|
||||
|
||||
if (dic.ContainsKey( key ) && strUtil.HasText( dic[key] )) {
|
||||
return GetArrayValueByString( dic[key] );
|
||||
}
|
||||
|
||||
return new String[] { };
|
||||
}
|
||||
|
||||
public static String[] GetArrayValueByString( String valOne ) {
|
||||
|
||||
if (strUtil.IsNullOrEmpty( valOne )) return new String[] { };
|
||||
|
||||
String[] arrValue = valOne.Split( new char[] { ',', '/', '|', ',', '、' } );
|
||||
|
||||
// 剔除掉无效的字符串
|
||||
ArrayList results = new ArrayList();
|
||||
foreach (String val in arrValue) {
|
||||
if (strUtil.HasText( val )) results.Add( val.Trim() );
|
||||
}
|
||||
|
||||
return (String[])results.ToArray( typeof( String ) );
|
||||
}
|
||||
|
||||
private Dictionary<String, String> _valueAll;
|
||||
|
||||
internal void setValueAll( Dictionary<String, String> valueAll ) {
|
||||
_valueAll = valueAll;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// 将更新保存到磁盘
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <param name="val"></param>
|
||||
public void Update( String item, Object val ) {
|
||||
|
||||
String itemValue = "";
|
||||
if (val != null) itemValue = val.ToString();
|
||||
|
||||
itemValue = strUtil.Text2Html( itemValue );
|
||||
|
||||
saveConfig( item, itemValue );
|
||||
}
|
||||
|
||||
public void UpdateHtml( String item, Object val ) {
|
||||
|
||||
String itemValue = "";
|
||||
if (val != null) itemValue = val.ToString();
|
||||
itemValue = itemValue.Replace( "\n", "" ).Replace( "\r", "" );
|
||||
|
||||
saveConfig( item, itemValue );
|
||||
}
|
||||
|
||||
private void saveConfig( String item, String itemValue ) {
|
||||
String[] configString = file.ReadAllLines( config.siteconfigAbsPath );
|
||||
List<String> results = new List<string>();
|
||||
|
||||
checkSingleLine( item, itemValue, configString, results );
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (String line in results) {
|
||||
sb.Append( line );
|
||||
sb.Append( Environment.NewLine );
|
||||
}
|
||||
lock (objLock) {
|
||||
file.Write( config.siteconfigAbsPath, sb.ToString() );
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSingleLine( String item, String itemValue, String[] configString, List<String> results ) {
|
||||
Boolean hasItem = false;
|
||||
foreach (String line in configString) {
|
||||
|
||||
if (startsWith( line, item )) {
|
||||
hasItem = true;
|
||||
results.Add( item + " : " + itemValue );
|
||||
_valueAll[item] = itemValue;
|
||||
}
|
||||
else {
|
||||
results.Add( line );
|
||||
}
|
||||
}
|
||||
if (hasItem == false) {
|
||||
results.Add( item + " : " + itemValue );
|
||||
_valueAll[item] = itemValue;
|
||||
}
|
||||
}
|
||||
|
||||
private static Boolean startsWith( String line, String item ) {
|
||||
|
||||
if (line.StartsWith( item )) {
|
||||
String noPrefixLine = strUtil.TrimStart( line, item ).Trim();
|
||||
if (noPrefixLine.StartsWith( ":" )) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Object objLock = new object();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,276 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Zhaizj.Framework.Data;
|
||||
|
||||
namespace Zhaizj.Framework.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 关于类型、实例的一些实用方法
|
||||
/// </summary>
|
||||
public static class TypeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 字段绑定预置值
|
||||
/// </summary>
|
||||
public const BindingFlags FieldBindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
|
||||
/// <summary>
|
||||
/// 从类型名称中创建类型
|
||||
/// </summary>
|
||||
/// <param name="typeName">类型名</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <returns>Type</returns>
|
||||
public static Type CreateType(string typeName, bool throwOnError) {
|
||||
try
|
||||
{
|
||||
return Type.GetType(typeName, throwOnError, false);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在当前应用程序域中查找指定的类型
|
||||
/// </summary>
|
||||
/// <param name="assemblyFile">动态库文件的绝对路径</param>
|
||||
/// <param name="typeName">类型全名(包括命名空间)</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <returns>找到则返回指定的类型,否则返回空</returns>
|
||||
public static Type GetType(string assemblyFile, string typeName, bool throwOnError)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assemblyFile))
|
||||
{
|
||||
throw new ArgumentNullException("assemblyFile");
|
||||
}
|
||||
Assembly assembly = GetAssembly(assemblyFile);
|
||||
Type type = assembly.GetType(typeName);
|
||||
|
||||
return type;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据文件名装入程序集合
|
||||
/// </summary>
|
||||
/// <param name="path">绝对路径</param>
|
||||
/// <returns></returns>
|
||||
public static Assembly GetAssembly(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new InvalidOperationException(path + "文件不存在或拒绝访问!");
|
||||
}
|
||||
Assembly assembly = Assembly.LoadFrom(path);
|
||||
if (assembly == null)
|
||||
throw new InvalidOperationException("无法正确载入程序集合!请确认文件格式正确。");
|
||||
return assembly;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从类型中创建此类型的实例
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="expectedType">期望的类型</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <param name="parameterTypes">创建实例所需参数的类型列表</param>
|
||||
/// <param name="parameterValues">创建实例所需的参数值列表</param>
|
||||
/// <returns>类型实例</returns>
|
||||
public static object CreateObject(Type type, Type expectedType, bool throwOnError, Type[] parameterTypes, object[] parameterValues) {
|
||||
if (expectedType != null && !expectedType.IsAssignableFrom(type)) {
|
||||
if (throwOnError) {
|
||||
throw new Exception(string.Format("将要创建的类型:{0},不是期望的类型:{1}", type.FullName, expectedType.FullName));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (parameterTypes != null && parameterValues != null && parameterTypes.Length != parameterValues.Length) {
|
||||
if (throwOnError) {
|
||||
throw new Exception("构造函数参数类型数量和参数数量不一致");
|
||||
}
|
||||
}
|
||||
object createdObject = null;
|
||||
ConstructorInfo constructor = type.GetConstructor(parameterTypes);
|
||||
if (constructor == null) {
|
||||
try {
|
||||
createdObject = Activator.CreateInstance(type, BindingFlags.CreateInstance | (BindingFlags.NonPublic | (BindingFlags.Public | BindingFlags.Instance)), null, parameterValues, null);
|
||||
} catch (Exception e) {
|
||||
if (throwOnError) {
|
||||
throw new Exception("即将创建的类型不支持指定的构造函数:" + e.Message, e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
createdObject = constructor.Invoke(parameterValues);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("对象创建失败:" + e.Message, e);
|
||||
}
|
||||
}
|
||||
return createdObject;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从类型中创建此类型的实例(本方法不支持参数可为Null的构造函数)
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="expectedType">期望的类型</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <param name="parameters">创建实例所需的参数值列表</param>
|
||||
/// <returns>类型实例</returns>
|
||||
public static object CreateObject(Type type, Type expectedType, bool throwOnError, params object[] parameters) {
|
||||
int paramNum = 0;
|
||||
if (parameters != null) {
|
||||
paramNum = parameters.Length;
|
||||
}
|
||||
Type[] paramTypes = new Type[paramNum];
|
||||
object[] paramValues = new object[paramNum];
|
||||
for (int i = 0; i < paramNum; i++) {
|
||||
if (parameters[i] == null) {
|
||||
if (throwOnError) {
|
||||
throw new Exception("不支持参数可为Null的构造函数,请使用本方法的另外重载版本");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
paramTypes[i] = parameters[i].GetType();
|
||||
paramValues[i] = parameters[i];
|
||||
}
|
||||
return CreateObject(type, expectedType, throwOnError, paramTypes, paramValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从类型名中创建此类型的实例
|
||||
/// </summary>
|
||||
/// <param name="typeName">类型名</param>
|
||||
/// <param name="expectedType">期望的类型</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <param name="parameters">创建实例所需的参数值列表</param>
|
||||
/// <returns>类型实例</returns>
|
||||
public static object CreateObject(string typeName, Type expectedType, bool throwOnError, params object[] parameters) {
|
||||
Type type = CreateType(typeName, throwOnError);
|
||||
return CreateObject(type, expectedType, throwOnError, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从类型名中创建此类型的实例
|
||||
/// </summary>
|
||||
/// <param name="typeName">类型名</param>
|
||||
/// <param name="expectedType">期望的类型</param>
|
||||
/// <param name="throwOnError">失败时是否抛出异常</param>
|
||||
/// <param name="parameterTypes">创建实例所需参数的类型列表</param>
|
||||
/// <param name="parameterValues">创建实例所需的参数值列表</param>
|
||||
/// <returns>类型实例</returns>
|
||||
public static object CreateObject(string typeName, Type expectedType, bool throwOnError, Type[] parameterTypes, object[] parameterValues) {
|
||||
Type type = CreateType(typeName, throwOnError);
|
||||
return CreateObject(type, expectedType, throwOnError, parameterTypes, parameterValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用反射调用方法
|
||||
/// </summary>
|
||||
/// <param name="obj">类型实例</param>
|
||||
/// <param name="methodName">方法名</param>
|
||||
/// <param name="parameters">参数列表</param>
|
||||
/// <returns>方法返回值</returns>
|
||||
public static object Invoke(object obj, string methodName, params object[] parameters) {
|
||||
if (obj == null) {
|
||||
return obj;
|
||||
}
|
||||
return obj.GetType().GetMethod(methodName, FieldBindingFlags).Invoke(obj, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在当前应用程序域中查找指定的类型
|
||||
/// </summary>
|
||||
/// <param name="typeName">类型全名(包括命名空间)</param>
|
||||
/// <returns>找到则返回指定的类型,否则返回空</returns>
|
||||
public static Type FindType(string typeName) {
|
||||
if (string.IsNullOrEmpty(typeName))
|
||||
return null;
|
||||
Type type = null;
|
||||
List<string> files = new List<string>();
|
||||
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) {
|
||||
type = assembly.GetType(typeName, false);
|
||||
if (type != null) {
|
||||
break;
|
||||
} else if(!assembly.GlobalAssemblyCache) {
|
||||
files.Add(assembly.ManifestModule.ScopeName.ToLower());
|
||||
}
|
||||
}
|
||||
if(type == null) {
|
||||
string[] fileNames = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in fileNames) {
|
||||
try
|
||||
{
|
||||
string fileName = Path.GetFileName(file);
|
||||
if (!files.Contains(fileName.ToLower()))
|
||||
{
|
||||
//只载入在系统公用缓存中的集合
|
||||
string assemblyName = Path.GetFileNameWithoutExtension(fileName);
|
||||
string typeFullName = typeName + ", " + assemblyName;
|
||||
type = CreateType(typeFullName, false);
|
||||
if (type != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//从文件中载入程序集并返回类型
|
||||
type = GetType(file, typeName, false);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从程序集中获得元属性
|
||||
/// </summary>
|
||||
/// <param name="assemblies">程序集,如果为null,则从当前应用程序域中获取所载入的所有程序集</param>
|
||||
/// <returns>找到的元属性的数组</returns>
|
||||
public static T[] GetAttributeFromAssembly<T>(Assembly[] assemblies) where T : Attribute {
|
||||
List<T> list = new List<T>();
|
||||
T[] attributes = null;
|
||||
if (assemblies == null) {
|
||||
assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
}
|
||||
foreach (Assembly assembly in assemblies) {
|
||||
attributes = (T[])assembly.GetCustomAttributes(typeof(T), false);
|
||||
if (attributes != null && attributes.Length > 0) {
|
||||
list.AddRange(attributes);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从运行时的堆栈中获取元属性
|
||||
/// </summary>
|
||||
/// <param name="includeAll">是否包含堆栈上所有的元属性</param>
|
||||
/// <typeparam name="T">元属性类型</typeparam>
|
||||
/// <returns>找到的元属性的数组</returns>
|
||||
public static T[] GetAttributeFromRuntimeStack<T>(bool includeAll) where T : Attribute {
|
||||
var list = new List<T>();
|
||||
var t = new StackTrace();
|
||||
for (var i = 0; i < t.FrameCount; i++) {
|
||||
var f = t.GetFrame(i);
|
||||
var m = (MethodInfo)f.GetMethod();
|
||||
var a = Attribute.GetCustomAttributes(m, typeof(T)) as T[];
|
||||
if (a != null && a.Length > 0) {
|
||||
list.AddRange(a);
|
||||
if (!includeAll) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
using System.Collections.Generic;
|
||||
using Zhaizj.Framework.Config;
|
||||
using System;
|
||||
|
||||
namespace Zhaizj.Framework {
|
||||
|
||||
/// <summary>
|
||||
/// 网站的配置信息
|
||||
/// </summary>
|
||||
public class config {
|
||||
|
||||
|
||||
private SiteSetting _siteSetting;
|
||||
private GroupSetting _groupSetting;
|
||||
|
||||
/// <summary>
|
||||
/// 网站的配置信息
|
||||
/// </summary>
|
||||
public SiteSetting Site {
|
||||
get { return _siteSetting; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 群组的配置信息
|
||||
/// </summary>
|
||||
public GroupSetting Group {
|
||||
get { return _groupSetting; }
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
private config() { loadAll(); }
|
||||
|
||||
private static volatile config _instance;
|
||||
private static Object _syncRoot = new object();
|
||||
public static config Instance {
|
||||
get {
|
||||
if (_instance == null) {
|
||||
lock (_syncRoot) {
|
||||
if (_instance == null) _instance = new config();
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private void Reload() {
|
||||
loadAll();
|
||||
}
|
||||
|
||||
|
||||
private void loadAll() {
|
||||
initSiteSettings();
|
||||
initGroupSettings();
|
||||
}
|
||||
|
||||
|
||||
private void initGroupSettings() {
|
||||
_groupSetting = new GroupSetting();
|
||||
}
|
||||
|
||||
// ------------------------- site settings -------------------------
|
||||
|
||||
private void initSiteSettings() {
|
||||
|
||||
_siteSetting = new SiteSetting();
|
||||
|
||||
Dictionary<String, String> dic = cfgHelper.Read( siteconfigAbsPath );
|
||||
if (dic.Count <= 0) return;
|
||||
|
||||
|
||||
_siteSetting.SiteName = getVal( dic, "SiteName" );
|
||||
_siteSetting.SiteUrl = getVal( dic, "SiteUrl" );
|
||||
_siteSetting.SiteLogo = getVal( dic, "SiteLogo" );
|
||||
|
||||
_siteSetting.Webmaster = getVal( dic, "Webmaster" );
|
||||
_siteSetting.Email = getVal( dic, "Email" );
|
||||
_siteSetting.Copyright = getVal( dic, "Copyright" );
|
||||
_siteSetting.Keywords = getVal( dic, "Keywords" );
|
||||
_siteSetting.Description = getVal( dic, "Description" );
|
||||
_siteSetting.PageDefaultTitle = getVal( dic, "PageDefaultTitle" );
|
||||
_siteSetting.IsClose = cvt.ToBool( getVal( dic, "IsClose" ) );
|
||||
_siteSetting.CloseReason = getVal( dic, "CloseReason" );
|
||||
_siteSetting.IsInstall = cvt.ToBool( getVal( dic, "IsInstall" ) );
|
||||
|
||||
_siteSetting.RegisterType = cvt.ToInt( getVal( dic, "RegisterType" ) );
|
||||
_siteSetting.LoginType = cvt.ToInt( getVal( dic, "LoginType" ) );
|
||||
_siteSetting.TopNavDisplay = cvt.ToInt( getVal( dic, "TopNavDisplay" ) );
|
||||
|
||||
_siteSetting.NeedLogin = cvt.ToBool( getVal( dic, "NeedLogin" ) );
|
||||
_siteSetting.UserNeedApprove = cvt.ToBool( getVal( dic, "UserNeedApprove" ) );
|
||||
|
||||
_siteSetting.AlertActivation = cvt.ToBool( getVal( dic, "AlertActivation" ) );
|
||||
_siteSetting.AlertUserPic = cvt.ToBool( getVal( dic, "AlertUserPic" ) );
|
||||
|
||||
|
||||
_siteSetting.UserSendConfirmEmailInterval = cvt.ToInt( getVal( dic, "UserSendConfirmEmailInterval" ) );
|
||||
|
||||
_siteSetting.UserInitApp = getVal( dic, "UserInitApp" );
|
||||
|
||||
//
|
||||
_siteSetting.TagLength = cvt.ToInt( getVal( dic, "TagLength" ) );
|
||||
|
||||
_siteSetting.ValidationType = cvt.ToInt( getVal( dic, "ValidationType" ) );
|
||||
_siteSetting.ValidationLength = cvt.ToInt( getVal( dic, "ValidationLength" ) );
|
||||
_siteSetting.ValidationChineseLength = cvt.ToInt( getVal( dic, "ValidationChineseLength" ) );
|
||||
|
||||
|
||||
_siteSetting.StatsEnabled = cvt.ToBool( getVal( dic, "StatsEnabled" ) );
|
||||
_siteSetting.StatsJs = getVal( dic, "StatsJs" );
|
||||
|
||||
_siteSetting.MicroblogContentMax = cvt.ToInt( getVal( dic, "MicroblogContentMax" ) );
|
||||
_siteSetting.MicroblogPageSize = cvt.ToInt( getVal( dic, "MicroblogPageSize" ) );
|
||||
|
||||
|
||||
_siteSetting.SkinId = cvt.ToInt( getVal( dic, "SkinId" ) );
|
||||
_siteSetting.Md5Is16 = cvt.ToBool( getVal( dic, "Md5Is16" ) );
|
||||
|
||||
_siteSetting.SystemMsgTitle = getVal( dic, "SystemMsgTitle" );
|
||||
_siteSetting.SystemMsgContent = getVal( dic, "SystemMsgContent" );
|
||||
_siteSetting.UserNameLengthMax = cvt.ToInt( getVal( dic, "UserNameLengthMax" ) );
|
||||
_siteSetting.UserNameLengthMin = cvt.ToInt( getVal( dic, "UserNameLengthMin" ) );
|
||||
_siteSetting.LoginNeedImgValidation = cvt.ToBool( getVal( dic, "LoginNeedImgValidation" ) );
|
||||
_siteSetting.RegisterNeedImgValidateion = cvt.ToBool( getVal( dic, "RegisterNeedImgValidateion" ) );
|
||||
_siteSetting.ShowSexyInfoInProfile = cvt.ToBool( getVal( dic, "ShowSexyInfoInProfile" ) );
|
||||
|
||||
_siteSetting.ReservedUserName = _siteSetting.getArrayValue( dic, "ReservedUserName" );
|
||||
_siteSetting.ReservedUserUrl = _siteSetting.getArrayValue( dic, "ReservedUserUrl" );
|
||||
_siteSetting.ReservedKey = _siteSetting.getArrayValue( dic, "ReservedKey" );
|
||||
|
||||
_siteSetting.PhotoThumbHeight = cvt.ToInt( getVal( dic, "PhotoThumbHeight" ) );
|
||||
_siteSetting.PhotoThumbWidth = cvt.ToInt( getVal( dic, "PhotoThumbWidth" ) );
|
||||
_siteSetting.PhotoThumbHeightMedium = cvt.ToInt( getVal( dic, "PhotoThumbHeightMedium" ) );
|
||||
_siteSetting.PhotoThumbWidthMedium = cvt.ToInt( getVal( dic, "PhotoThumbWidthMedium" ) );
|
||||
_siteSetting.PhotoThumbHeightBig = cvt.ToInt( getVal( dic, "PhotoThumbHeightBig" ) );
|
||||
_siteSetting.PhotoThumbWidthBig = cvt.ToInt( getVal( dic, "PhotoThumbWidthBig" ) );
|
||||
|
||||
_siteSetting.AvatarThumbHeight = cvt.ToInt( getVal( dic, "AvatarThumbHeight" ) );
|
||||
_siteSetting.AvatarThumbWidth = cvt.ToInt( getVal( dic, "AvatarThumbWidth" ) );
|
||||
_siteSetting.AvatarThumbHeightMedium = cvt.ToInt( getVal( dic, "AvatarThumbHeightMedium" ) );
|
||||
_siteSetting.AvatarThumbWidthMedium = cvt.ToInt( getVal( dic, "AvatarThumbWidthMedium" ) );
|
||||
_siteSetting.AvatarThumbHeightBig = cvt.ToInt( getVal( dic, "AvatarThumbHeightBig" ) );
|
||||
_siteSetting.AvatarThumbWidthBig = cvt.ToInt( getVal( dic, "AvatarThumbWidthBig" ) );
|
||||
|
||||
_siteSetting.UploadFileTypes = _siteSetting.getArrayValue( dic, "UploadFileTypes" );
|
||||
_siteSetting.UploadPicTypes = _siteSetting.getArrayValue( dic, "UploadPicTypes" );
|
||||
|
||||
_siteSetting.UploadPicMaxMB = cvt.ToInt( getVal( dic, "UploadPicMaxMB" ) );
|
||||
_siteSetting.UploadFileMaxMB = cvt.ToInt( getVal( dic, "UploadFileMaxMB" ) );
|
||||
|
||||
|
||||
_siteSetting.IsSaveAvatarMedium = cvt.ToBool( getVal( dic, "IsSaveAvatarMedium" ) );
|
||||
_siteSetting.IsSaveAvatarBig = cvt.ToBool( getVal( dic, "IsSaveAvatarBig" ) );
|
||||
|
||||
_siteSetting.BadWords = _siteSetting.getArrayValue( dic, "BadWords" );
|
||||
_siteSetting.BadWordsReplacement = getVal( dic, "BadWordsReplacement" );
|
||||
|
||||
_siteSetting.BannedIp = _siteSetting.getArrayValue( dic, "BannedIp" );
|
||||
_siteSetting.BannedIpInfo = getVal( dic, "BannedIpInfo" );
|
||||
|
||||
|
||||
_siteSetting.Spider = _siteSetting.getArrayValue( dic, "Spider" );
|
||||
if (_siteSetting.Spider.Length == 0) _siteSetting.Spider = new String[] { "spider", "robot", "Slurp", "sogou", "youdao", "google" };
|
||||
|
||||
|
||||
_siteSetting.MaxOnline = cvt.ToInt( getVal( dic, "MaxOnline" ) );
|
||||
_siteSetting.MaxOnlineTime = cvt.ToTime( getVal( dic, "MaxOnlineTime" ) );
|
||||
_siteSetting.UserTemplateId = cvt.ToInt( getVal( dic, "UserTemplateId" ) );
|
||||
|
||||
_siteSetting.FeedKeepDay = cvt.ToInt( getVal( dic, "FeedKeepDay" ) );
|
||||
_siteSetting.LastFeedClearTime = cvt.ToTime( getVal( dic, "LastFeedClearTime" ) );
|
||||
|
||||
_siteSetting.NoRefreshSecond = cvt.ToInt( getVal( dic, "NoRefreshSecond" ) );
|
||||
|
||||
_siteSetting.SmtpUrl = getVal( dic, "SmtpUrl" );
|
||||
_siteSetting.SmtpUser = getVal( dic, "SmtpUser" );
|
||||
_siteSetting.SmtpPwd = getVal( dic, "SmtpPwd" );
|
||||
_siteSetting.SmtpEnableSsl = cvt.ToBool( getVal( dic, "SmtpEnableSsl" ) );
|
||||
_siteSetting.EnableEmail = cvt.ToBool( getVal( dic, "EnableEmail" ) );
|
||||
|
||||
_siteSetting.CloseComment = cvt.ToBool( getVal( dic, "CloseComment" ) );
|
||||
|
||||
_siteSetting.UserDisplayName = cvt.ToInt(getVal(dic, "UserDisplayName"));
|
||||
_siteSetting.ValidateUserByMembership = cvt.ToBool(getVal(dic, "ValidateUserByMembership"));
|
||||
_siteSetting.DenyEditUserRealName = cvt.ToBool(getVal(dic, "DenyEditUserRealName"));
|
||||
_siteSetting.DenyEditUserTitle = cvt.ToBool(getVal(dic, "DenyEditUserTitle"));
|
||||
|
||||
_siteSetting.setValueAll( dic );
|
||||
}
|
||||
|
||||
private String getVal( Dictionary<String, String> dic, String key ) {
|
||||
String val;
|
||||
dic.TryGetValue( key, out val );
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
internal static readonly String siteconfigAbsPath = getSiteConfigAbsPath();
|
||||
|
||||
private static String getSiteConfigAbsPath() {
|
||||
return PathHelper.Map( strUtil.Join( cfgHelper.ConfigRoot, "site.config" ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user