/// <summary> /// 保存引擎实例 /// </summary> /// <param name="model">引擎实例模型</param> /// <returns>是否保存成功</returns> public JsonResult SaveEngine(EngineViewModel model) { return(ExecuteFunctionRun(() => { ActionResult result = new ActionResult(false); OThinker.Clusterware.LogicUnitConfig config = new EngineConfig(); if (Code != string.Empty && false) { // ERROR, 更新状态 config = this.Connection.GetLogicUnitConfigByCode(Code); OThinker.Data.Database.DatabaseType dbType = (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType); string connString = OThinker.Data.Database.Database.GetConnectionString(dbType, config.DBServer, config.DBName, model.DBUser.Trim(), model.DBPassword.Trim()); string logConnString = OThinker.Data.Database.Database.GetConnectionString(dbType, config.LogDBServer, config.LogDBName, model.LogDBName.Trim(), model.LogDBPassword.Trim()); CommandFactory factory = new CommandFactory(dbType, connString); CommandFactory Logfactory = new CommandFactory(dbType, logConnString); if (!factory.CheckConnection() || !Logfactory.CheckConnection()) { result.Success = false; result.Message = "数据库无法正常连接"; } else { config.DBUser = model.DBUser.Trim(); config.DBPassword = model.DBPassword.Trim(); config.LogDBUser = model.LogDBUser.Trim(); config.LogDBPassword = model.LogDBPassword.Trim(); config.UnitState = Clusterware.LogicUnitState.Running; this.Connection.UpdateLogicUnit(config); result.Success = true; } return Json(result, JsonRequestBehavior.AllowGet); } else { Regex reg = new Regex("[\\u4e00-\\u9fa5]"); if (reg.IsMatch(model.Code.Trim())) { result.Success = false; result.Message = "引擎编码不可包含中文!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (model.Code.Contains(" ")) { result.Success = false; result.Message = "引擎编码不可包含空格!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (string.IsNullOrEmpty(model.DBName) && DatabaseType.SqlServer == (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType)) { result.Success = false; result.Message = "数据库名称不可为空!"; return Json(result, JsonRequestBehavior.AllowGet); } ; if (string.IsNullOrEmpty(model.LogDBName) && DatabaseType.SqlServer == (OThinker.Data.Database.DatabaseType) int.Parse(model.LogDBType)) { result.Success = false; result.Message = "日志数据库名称不可为空!"; return Json(result, JsonRequestBehavior.AllowGet); } ; config = new EngineConfig() { Code = model.Code.Trim(), DBType = (OThinker.Data.Database.DatabaseType) int.Parse(model.DBType), DBServer = model.DBServer.Trim(), DBName = string.IsNullOrEmpty(model.DBName) ? "" : model.DBName.Trim(), DBUser = model.DBUser.Trim(), DBPassword = model.DBPassword.Trim(), LogDBType = (OThinker.Data.Database.DatabaseType) int.Parse(model.LogDBType), LogDBServer = model.LogDBServer.Trim(), LogDBName = string.IsNullOrEmpty(model.LogDBName) ? "" : model.LogDBName.Trim(), LogDBUser = model.LogDBUser.Trim(), LogDBPassword = model.LogDBPassword.Trim(), UnitState = Clusterware.LogicUnitState.Running, InitialUserLoginName = "Administrator@" + Code }; if (!this.Connection.AddLogicUnit(config)) { this.Connection.RemoveLogicUnit(config.Code); result.Success = false; result.Message = "无法成功创建,信息不正确,或者没有足够可用的数据库"; } else { result.Success = true; } if (config.DBType == OThinker.Data.Database.DatabaseType.Oracle) { CommandFactory factory = new CommandFactory(DatabaseType.Oracle, config.DBConnString); if (!factory.CheckConnection()) { result.Success = false; result.Message = "数据库无法正常连接"; } } } return Json(result, JsonRequestBehavior.AllowGet); })); }