protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BaseConfigInfo bci = BaseConfigs.GetBaseConfig(); if (bci != null) { DatabaseInfo dbi = new DatabaseInfo(); dbi = Installer.GetDatabaseInfo(bci); ServerTextBox.Text = dbi.Server; DatabaseTextBox.Text = dbi.Database; UserTextBox.Text = dbi.User; PasswordTextBox.Text = dbi.Password; DBFileNameTextBox.Text = dbi.DBFile; if (DBFileNameTextBox.Text.IndexOf("\\") >= 0) { DBFileNameTextBox.Text = DBFileNameTextBox.Text.Substring(DBFileNameTextBox.Text.LastIndexOf("\\") + 1); } SelectDB = bci.DBType; CreateNewDBCheckBox.Checked = false; if (!CheckWebConfig()) { msg.Visible = true; } SiteConfigInfo sci = SiteConfigs.GetConfig(); if (sci != null) { WebsiteNameTextBox.Text = sci.SiteName; AdminNameTextBox.Text = sci.AdministratorName; } } } }
/// <summary> /// 取得数据类型 /// </summary> /// <param name="dc"></param> /// <returns></returns> string GetDbType(We7DataColumn dc) { switch (dc.DataType) { case TypeCode.Char: return(String.Format("nchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); case TypeCode.DateTime: return("datetime"); case TypeCode.Decimal: case TypeCode.Double: return("decimal"); case TypeCode.Int16: case TypeCode.Int32: case TypeCode.SByte: case TypeCode.UInt32: case TypeCode.UInt16: case TypeCode.Single: case TypeCode.Byte: case TypeCode.Boolean: return("int"); case TypeCode.UInt64: case TypeCode.Int64: return("bigint"); case TypeCode.String: string dbtype = BaseConfigs.GetBaseConfig().DBType; if (String.Compare(dbtype, "Access", true) == 0) { return(dc.MaxLength >= 255 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } else if (String.Compare(dbtype, "SqlServer", true) == 0) { return(dc.MaxLength >= 4000 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } else if (String.Compare(dbtype, "MySql", true) == 0) { return(dc.MaxLength >= 65535 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } else if (String.Compare(dbtype, "Oracle", true) == 0) { return(dc.MaxLength >= 4000 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } else if (String.Compare(dbtype, "SQLLite", true) == 0) { return(dc.MaxLength >= 4000 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } else { return(dc.MaxLength >= 4000 ? "text" : String.Format("nvarchar ({0})", dc.MaxLength > 0 ? dc.MaxLength : 50)); } default: return(String.Format("nvarchar ({0})", 50)); } return("nvarchar (50)"); }
public virtual IHttpHandler GetHandler(HttpContext context, string requestType, string newUrl, string path) { string pagepath = path; BaseConfigInfo baseconfig = BaseConfigs.GetBaseConfig(); GeneralConfigInfo config = GeneralConfigs.GetConfig(); if (baseconfig != null && config != null) { string requestPath = context.Request.Path.ToLower(); foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls) { if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.IgnoreCase)) { if (url.Page != "") { string queryString = Regex.Replace(requestPath, url.Pattern, url.QueryString, RegexOptions.IgnoreCase); context.RewritePath(url.Page, string.Empty, queryString); pagepath = context.Server.MapPath(url.Page); break; } } } if (!newUrl.EndsWith(config.UrlExtName, true, null)) { newUrl += "default." + config.UrlExtName; } } return(PageParser.GetCompiledPageInstance(newUrl, pagepath, context)); }
/// <summary> /// 自动检查当前程序的目录状态并保存 /// </summary> /// <param name="forumPath"></param> public static void SaveDntConfigForumPath() { HttpRequest request = HttpContext.Current.Request; string forumPath = request.Url.ToString().Replace("http://" + request.Url.Authority, ""); if (forumPath.IndexOf("install") < 0) { return; } forumPath = forumPath.Substring(0, forumPath.IndexOf("install")); BaseConfigInfo baseConfig = BaseConfigs.GetBaseConfig(); if (baseConfig.Forumpath.Trim() != forumPath) { baseConfig.Forumpath = forumPath; string dntPath = Utils.GetMapPath("~/DNT.config"); if (!Utils.FileExists(dntPath)) { dntPath = Utils.GetMapPath("/DNT.config"); } SerializationHelper.Save(baseConfig, dntPath); BaseConfigs.ResetRealConfig(); Utils.RestartIISProcess(); } }
public bool AllowEditUserInfo(int uid, bool redirect) { #region 是否允许编辑用户信息 if ((BaseConfigs.GetBaseConfig().Founderuid == uid) && (uid == this.userid)) { return(true); } else { if (BaseConfigs.GetBaseConfig().Founderuid != uid) //当要编辑的用户信息不是创建人的信息时 { return(true); } else { if (redirect) { base.RegisterStartupScript("", "<script>alert('您要编辑信息是论坛创始人信息,请您以创始人身份登陆后台才能修改!');</script>"); } return(false); } } #endregion }
/// <summary> /// 获得勋章列表 /// </summary> /// <returns>获得勋章列表</returns> public static DataTable GetMedalsList() { Discuz.Cache.DNTCache cache = Discuz.Cache.DNTCache.GetCacheService(); DataTable dt = cache.RetrieveObject("/UI/MedalsList") as DataTable; if (dt != null) { return(dt); } dt = DatabaseProvider.GetInstance().GetMedalsList(); string forumpath = BaseConfigs.GetBaseConfig().Forumpath; foreach (DataRow dr in dt.Rows) { if (dr["available"].ToString() == "1") { if (dr["image"].ToString().Trim() != "") { dr["image"] = "<img border=\"0\" src=\"" + forumpath + "images/medals/" + dr["image"] + "\" alt=\"" + dr["name"] + "\" title=\"" + dr["name"] + "\" class=\"medals\" />"; } else { dr["image"] = ""; } } else { dr["image"] = ""; } } cache.AddObject("/UI/MedalsList", dt); return(dt); }
private bool AllowEditUser(int managerUId, int targetUId) { #region 是否可以编辑用户 int managerGroupId = Users.GetUserInfo(managerUId).Groupid; if (Users.GetUserInfo(managerUId).Adminid == 0) { return(false); } int targetGroupId = Users.GetUserInfo(targetUId).Groupid; int founderUId = BaseConfigs.GetBaseConfig().Founderuid; if (managerUId == targetUId) //可自身修改 { return(true); } else if (managerUId == founderUId) //创始人可修改 { return(true); } else if (managerGroupId == targetGroupId) //管理组相同的不能修改 { return(false); } else { return(true); } #endregion }
public UpFileEntity() { BaseConfigInfo config = BaseConfigs.GetConfig(); this.ftpEnable = config.FTPEnable; this.distributeFileSystem = config.DistributeFileSystem; IsClose = true; }
/// <summary> /// 检测用户的数据库配置文件是否已经创建 /// </summary> protected virtual void CheckInstallation() { if (!BaseConfigs.ConfigFileExist()) { Response.Write("您的数据库配置文件尚未生成,看起来数据库尚未建立,您需要建立数据库配置文件或生成数据库。现在开始吗?<a href='/install/index.aspx'><u>现在配置数据库</u></a>"); Response.End(); } }
private bool CheckSponser(int uid) { #region 检查创建人 return(!((BaseConfigs.GetBaseConfig().Founderuid == uid) && (BaseConfigs.GetBaseConfig().Founderuid != this.userid))); #endregion }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); if (BaseConfigs.ConfigFileExist() && !SetupPage.LockFileExist()) { Response.Redirect("upgrade.aspx", true); } Init(); }
protected void Page_Load(object sender, EventArgs e) { if (!BaseConfigs.ConfigFileExist()) { Response.Write("您的数据库配置文件尚未生成,看起来数据库尚未建立,您需要建立数据库配置文件或生成数据库。现在开始吗?<a href='/install/index.aspx'><u>现在配置数据库</u></a>"); Response.End(); } AddStatistic(string.Empty, string.Empty); }
protected void ResetDBInfo_Click(object sender, EventArgs e) { BaseConfigInfo bci = BaseConfigs.GetBaseConfig(); if (bci.DBConnectionString != "" && bci.DBType != "") { Installer.ExecuteSQLGroup(bci); Response.Redirect("succeed.aspx?from=install"); } }
protected void Button1_Click(object sender, EventArgs e) { BaseConfigInfo info = new BaseConfigInfo(); info.Dbconnectstring = @"Data Source=F:\Doctments\Works\Mine\iTCAWeb\trunk\LiteCMS.Web\config\db.config"; info.Dbtype = "Sqlite"; info.Tableprefix = "wy_"; info.ApplictionPath = "/"; BaseConfigs.Save(info); }
/// <summary> /// 返回最新未使用的凭证号 /// </summary> /// <returns></returns> public static string GetNewNum() { GeneralConfigInfo ManageConfig = GeneralConfigs.GetConfig(); ManageConfig.CertificateCode = (Convert.ToInt32(Config.GeneralConfigs.GetConfig().CertificateCode.Trim()) + 1).ToString(); GeneralConfigs.Serialiaze(ManageConfig, Utils.GetMapPath(BaseConfigs.GetSysPath + "config/general.config")); BaseConfigs.ResetConfig(); return(ManageConfig.CertificateCode); }
private void ResetDBInfo_Click(object sender, EventArgs e) { //读取默认db.config文件内容 BaseConfigInfo bci = BaseConfigs.GetBaseConfig(); if (bci.DBType != "" && bci.DBConnectionString != "") { Installer.ExcuteSQLGroup(bci); this.Response.Redirect("succeed.aspx?from=install"); } }
/// <summary> /// 返回最新未使用单据号 /// </summary> /// <returns></returns> public static string GetNewOrderNum() { GeneralConfigInfo ManageConfig = GeneralConfigs.GetConfig(); ManageConfig.OrderID = (Convert.ToInt64(Config.GeneralConfigs.GetConfig().OrderID.Trim()) + 1).ToString(); GeneralConfigs.Serialiaze(ManageConfig, Utils.GetMapPath(BaseConfigs.GetSysPath + "config/general.config")); BaseConfigs.ResetConfig(); return(ManageConfig.OrderID); }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); if (SetupPage.LockFileExist() && BaseConfigs.ConfigFileExist()) //这个判断条件怎么理解,与index.aspx.cs中为何不同? { Init(); } else { Response.Redirect("upgrade.aspx", true); } }
protected virtual void Page_Load(object sender, EventArgs e) { if (this.userid > 0) { if (CheckUserPopedoms("X")) { Act = HTTPRequest.GetString("Act"); if (!ispost) { ManageConfig = GeneralConfigs.GetConfig(); if (ManageConfig == null) { AddErrLine("获取配置信息发生错误.<br>"); } else { dList = M_Utils.GetM_ConfigInfoList(" 1=1 order by m_ConfigInfoID desc").Tables[0]; } } else { try { ManageConfig = GeneralConfigs.GetConfig(); ManageConfig.Taobao_Open = HTTPRequest.GetInt("Taobao_Open", 0); ManageConfig.Taobao_SandBox = HTTPRequest.GetInt("Taobao_SandBox", 1); GeneralConfigs.Serialiaze(ManageConfig, Utils.GetMapPath(BaseConfigs.GetSysPath + "config/general.config")); BaseConfigs.ResetConfig(); Caches.ReSet(); AddMsgLine("提交成功!"); SetBackLink("mconfig.aspx?r=" + Utils.GetRanDomCode()); SetMetaRefresh(1, "mconfig.aspx?r=" + Utils.GetRanDomCode()); } catch (Exception ex) { AddErrLine("提交时发生错误:<br>" + ex.Message.ToString()); } } } else { AddErrLine("权限不足!"); AddScript("window.parent.HidBox();"); } } else { AddErrLine("请先登录!"); SetBackLink("login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer())); SetMetaRefresh(1, "login.aspx?referer=" + Utils.UrlEncode(Utils.GetUrlReferrer())); } }
protected override void OnPreInit(EventArgs e) { base.OnPreInit(e); if (Request["from"] == null || Request["from"].ToString() != "upgrade.aspx") { if (BaseConfigs.ConfigFileExist()) { Response.Redirect("upgrade.aspx", true); } } Init(); }
/// <summary> /// 执行指定的数据文件 /// </summary> /// <param name="info"></param> /// <param name="dataDirectory"></param> /// <param name="filePath"></param> /// <param name="log"></param> /// <returns></returns> private void ExecuteDBFile(string dataDir, List <string> DBFileList) { foreach (string file in DBFileList) { string filePath = Path.Combine(dataDir, file); if (!File.Exists(filePath)) { throw new Exception(String.Format("数据文件{0}不存在!", file)); } ExcuteSQL(BaseConfigs.GetBaseConfig(), filePath); } }
public BaseConfigInfo GetBaseConfig() { try { return(BaseConfigs.GetBaseConfig()); } catch (Exception ex) { string source = "We7.CMS.Install-InstallWebService—GetBaseconfig"; EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); throw ex; } }
private bool CheckSponser(int uid) { #region 检查创建人 if ((BaseConfigs.GetBaseConfig().Founderuid == uid) && (BaseConfigs.GetBaseConfig().Founderuid != this.userid)) { return(false); } else { return(true); } #endregion }
/// <summary> /// 备份数据库配置文件 /// </summary> /// <param name="bci"></param> /// <returns></returns> public static bool BackupBaseConfig(BaseConfigInfo bci) { try { if (!Directory.Exists(HttpContext.Current.Server.MapPath("/_Temp"))) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("/_Temp")); } BaseConfigs.SaveConfigTo(bci, HttpContext.Current.Server.MapPath("/_Temp/db.config")); return(true); } catch { return(false); } }
/// <summary> /// 当前用户是否是创始人 /// </summary> /// <param name="uid"></param> /// <returns></returns> public bool IsFounderUid(int uid) { if (BaseConfigs.GetBaseConfig().Founderuid == 0) return true; else { //如果当前登陆后台的用户就是论坛的创始人 if (BaseConfigs.GetBaseConfig().Founderuid == uid) { return true; } else { return false; } } }
private bool SaveDBConfig(BaseConfigInfo bci) { try { string file = Server.MapPath("~/config/db.config"); BaseConfigs.SaveConfigTo(bci, file); BaseConfigs.ResetConfig(); SetupPage.CreateLockFile(); return(true); } catch { ErrProcess(bci); } return(false); }
public static void ResetApplication() { lock (lockHelper) { HttpContext context = HttpContext.Current; context.Application.Clear(); if (context.Session != null) { context.Session.Clear(); } BaseConfigs.ResetConfig(); SiteConfigs.ResetConfig(); GeneralConfigs.ResetConfig(); context.Application["We7.Application.OnlinePeople.Key"] = 0; if (BaseConfigs.ConfigFileExist()) { BaseConfigInfo baseconfig = BaseConfigs.GetBaseConfig(); string root = context.Server.MapPath("~/"); string dataPath = context.Server.MapPath("~/App_Data/XML"); ObjectAssistant assistant = new ObjectAssistant(); try { if (baseconfig != null && baseconfig.DBConnectionString != "") { baseconfig.DBConnectionString = baseconfig.DBConnectionString.Replace("{$App}", AppDomain.CurrentDomain.BaseDirectory).Replace("\\\\", "\\"); assistant.LoadDBConnectionString(baseconfig.DBConnectionString, baseconfig.DBDriver); } assistant.LoadDataSource(dataPath); } catch (DataException ex) { Debug.WriteLine(ex.ToString()); string s = string.Format("注意检查:/app_data/xml目录下的配置文件:\r\n错误代码:{0}\r\n错误消息:{1}", ex.Errorcode, ex.Message); LogHelper.WriteLog(typeof(ApplicationHelper), s); throw ex; } HelperFactory factory = new HelperFactory(); factory.Assistant = assistant; factory.Root = root; factory.Initialize(); context.Application["We7.HelperFactory"] = factory; } } }
/// <summary> /// 重写Url /// </summary> /// <param name="sender">事件的源</param> /// <param name="e">包含事件数据的 EventArgs</param> private void ReUrl_BeginRequest(object sender, EventArgs e) { BaseConfigInfo baseconfig = BaseConfigs.GetBaseConfig(); if (baseconfig == null) { return; } GeneralConfigInfo config = GeneralConfigs.GetConfig(); HttpContext context = ((HttpApplication)sender).Context; string requestPath = context.Request.Path.ToLower(); if (requestPath == "" || requestPath == "/" || requestPath == "/default.aspx") { return; } foreach (SiteUrls.URLRewrite url in SiteUrls.GetSiteUrls().Urls) { if (Regex.IsMatch(requestPath, url.Pattern, RegexOptions.IgnoreCase)) { if (url.Page != "") { string newQueryString = Regex.Replace(requestPath, url.Pattern, url.QueryString, RegexOptions.IgnoreCase); string oldQuerystring = ""; if (context.Request.RawUrl.IndexOf("?") >= 0) { oldQuerystring = context.Request.RawUrl.Substring(context.Request.RawUrl.IndexOf("?") + 1); } if (oldQuerystring.Length > 0) { if (newQueryString.Length > 0) { newQueryString += "&" + oldQuerystring; } else { newQueryString = oldQuerystring; } } context.RewritePath(url.Page, string.Empty, newQueryString); } return; } } }
protected override void OnLoad(EventArgs e) { Response.Expires = -1; //设置浏览器缓存页面过期时间的优势,为什么要设置?(参考二十八条改善 ASP 性能和外观的技巧!) base.OnLoad(e); if (!BaseConfigs.ConfigFileExist()) { Response.Write("您的数据库配置文件尚未生成,看起来数据库尚未建立,您需要建立数据库配置文件或生成数据库。现在开始吗?<a href='/install/index.aspx'><u>现在配置数据库</u></a>"); Response.End(); } if (UnLoginCheck() && Request.RawUrl.ToLower().Contains("login.aspx")) { We7.Framework.Util.Utils.Redirect("/login.aspx?returnURL=" + Server.UrlEncode(HttpContext.Current.Request.RawUrl)); } Initialize(); }
[SoapHeader("header")] //用户身份验证的soap header public BaseConfigInfo GetBaseConfig() { //验证是否有权访问(当然,也可以通过查询数据库实现,具体视项目要求) if (!CheckAdmin(header.UserName, header.PassWord)) { throw new Exception("无权使用此服务"); } try { return(BaseConfigs.GetBaseConfig()); } catch (Exception ex) { string source = "We7.CMS.Install-InstallWebService—GetBaseconfig"; EventLogHelper.WriteToLog(source, ex, EventLogEntryType.Error); throw ex; } }