//安装、更新数据库 private void Setup_Database() { Settings setting = Settings.Current; setting.Error = -1; int stepIndex = 0; try { stepIndex = 1; setting.ProgressAccess = new Progress("写入配置信息", 0, stepIndex); //SetupManager.ConfigConnectionString(); setting.ProgressAccess = new Progress("写入配置信息", 100, stepIndex); //============================================== stepIndex = 2; setting.ProgressAccess = new Progress("建立数据库", 0, stepIndex); SetupManager.InstallDatabase(delegate(int percent, string message) { setting.ProgressAccess = new Progress("建立数据库", percent, stepIndex); }); #if SQLSERVER if (Settings.Current.SetupMode == Max.Installs.SetupMode.New) SetupManager.CreateAdministrator(); #endif setting.ProgressAccess = new Progress("建立数据库", 100, stepIndex); //============================================== if (Settings.Current.SetupMode != Max.Installs.SetupMode.New) { stepIndex = 3; setting.ProgressAccess = new Progress("处理用户组和勋章数据", 0, stepIndex); SetupManager.ConvertRoles(); SetupManager.ConvertMedals(); //处理用户扩展信息 一定要放在 ConvertRoles 和 ConvertMedals 后面执行 SetupManager.ProcessUserExtendData(); SetupManager.ConvertLinks(); SetupManager.ConvertPoints(); SetupManager.ConvertForumLogos(); SetupManager.ConvertJudgements(); SetupManager.ConvertEmailSettingsAndKeywords(); SetupManager.ProcessSetting(); //SetupManager.ProcessUsernames(); setting.ProgressAccess = new Progress("处理用户组和勋章数据", 100, stepIndex); //============================================== stepIndex = 4; setting.ProgressAccess = new Progress("处理头像数据", 0, stepIndex); SetupManager.ConvertAvatars(delegate(int percent, string message) { setting.ProgressAccess = new Progress("处理头像数据", percent, stepIndex); }); SetupManager.ProcessAvatars(); setting.ProgressAccess = new Progress("处理头像数据", 100, stepIndex); //============================================== stepIndex = 5; setting.ProgressAccess = new Progress("正在准备数据库校对", 0, stepIndex); string[] prefixs = new string[] { "bx_", "bbsMax_", "Max_", "System_bbsMax_", "System_Max_" }; SetupManager.AutoDeployDatabase(delegate(int percent, string message) { setting.ProgressAccess = new Progress(message, percent, stepIndex); }, prefixs); setting.ProgressAccess = new Progress("升级积分公式", 95, stepIndex); SetupManager.ProcessPointsExpression(); setting.ProgressAccess = new Progress("升级用户信息", 97, stepIndex); SetupManager.UpdateUserInfos(); setting.ProgressAccess = new Progress("数据库校对完成", 100, stepIndex); //============================================== } //============================================== stepIndex = 6; setting.ProgressAccess = new Progress("完成安装", 0, stepIndex); setting.IsCompleted = true; setting.ProgressAccess = new Progress("完成安装", 100, stepIndex); setting.ProgressAccess = new Progress("Completed", 100, 10000); } catch (Exception e) { setting.Error = 1; SetupManager.CreateLog(e); setting.ProgressAccess = new Progress("安装出错", 0, stepIndex, string.Format("安装出错:{0}", e.Message)); setting.Error = stepIndex + 1; setting.IsThreadAlive = false; } finally { Thread.CurrentThread.Abort(); } stepIndex += 1; }