public void ExecuteImport(long id) { using (var ctx = new DbMonitorEntities()) { var me = ctx.MirrorExport.Find(id); var dic = ctx.Dictionary.Where(d => d.DTypeCode == "DmExport" && d.DEnable == 1).ToList(); //导入到本地 var home = dic.Where(d => d.DCode == "dm_home").First().DName; var backup_dir = dic.Where(d => d.DCode == "backup_dir").FirstOrDefault().DName; var local_user = dic.Where(d => d.DCode == "user").FirstOrDefault().DName; var local_pwd = dic.Where(d => d.DCode == "pwd").FirstOrDefault().DName; var imp_log = me.MELogFile.Replace(".log", "_imp.log"); using (var dal = new DmDAL(connStr)) { var sql = string.Format("SELECT COUNT(1) FROM DBA_USERS WHERE USERNAME='******'", me.MESchemas); var cnt = Convert.ToInt32(dal.ExecuteScalar(sql)); if (cnt == 1) { sql = string.Format("DROP USER {0} CASCADE", me.MESchemas); dal.ExecuteNonQuery(sql); } sql = string.Format("create user {0} identified by {0} default tablespace BACKUP", me.MESchemas); dal.ExecuteNonQuery(sql); } StringBuilder sbExp = new StringBuilder(); sbExp.AppendFormat("%DM_HOME%\\bin\\dimp USERID={0}/{1} FILE={2} LOG={3} DIRECTORY={4}", local_user, local_pwd, me.MEFileName, imp_log, backup_dir); me.MEImportStatus = "开始导入"; me.MEImportTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ctx.SaveChanges(); bool bImportOK = false; bImportOK = ImportTask(home, backup_dir, imp_log, sbExp.ToString()); if (bImportOK) { me.MEImportStatus = "导入成功"; me.EditingTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ctx.SaveChanges(); } else { me.MEImportStatus = "导入失败"; me.EditingTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); ctx.SaveChanges(); } } }
public ActionResult DeleteStatement(long scId, string type, string username, string whenever) { JsonResult ret = new JsonResult(); try { using (var dal = new DmDAL(GetSessionConnStr(scId))) { StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat("SP_NOAUDIT_STMT('{0}', '{1}', '{2}')", type, string.IsNullOrWhiteSpace(username) ? "NULL" : username, whenever); dal.ExecuteNonQuery(sbSql.ToString()); } ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "" }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = "发生异常:" + ex.Message }); RecordException(ex); } return(ret); }
public ActionResult CreateStatement(long scId, string type, string username, string whenever) { JsonResult ret = new JsonResult(); try { using (var dal = new DmDAL(GetSessionConnStr(scId))) { StringBuilder sbSql = new StringBuilder(); //sbSql.Append("SP_AUDIT_STMT"); //dal.ExecuteProcedureNonQuery(sbSql.ToString(), // new DmParameter("TYPE", type), // new DmParameter("USERNAME", username), // new DmParameter("WHENEVER", whenever)); sbSql.AppendFormat("SP_AUDIT_STMT('{0}', '{1}', '{2}')", type, username, whenever); dal.ExecuteNonQuery(sbSql.ToString()); } ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "" }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = "发生异常:" + ex.Message }); RecordException(ex); } return(ret); }
public ActionResult Create(Domain.AuditPolicy policy, FormCollection collection) { JsonResult ret = new JsonResult(); try { using (var dal = new DmDAL(GetSessionConnStr(policy.SCID.Value))) { StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat("SP_AUDIT_OBJECT('{0}', '{1}', '{2}', '{3}','{4}','{5}')", policy.APStatement, policy.APUser, policy.APSchema, policy.APObjectName, policy.APColumnName, policy.APWhen); dal.ExecuteNonQuery(sbSql.ToString()); } db.AuditPolicy.Add(policy); db.SaveChanges(); ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "" }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = ex.Message }); RecordException(ex); } return(ret); }
public ActionResult CreateObject(long scId, string type, string username, string schemaname, string tvname, string colname, string whenever) { JsonResult ret = new JsonResult(); try { using (var dal = new DmDAL(GetSessionConnStr(scId))) { StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat("SP_AUDIT_OBJECT('{0}', '{1}', '{2}', '{3}'", type, username, schemaname, tvname); if (!string.IsNullOrWhiteSpace(colname)) { sbSql.AppendFormat(",'{0}'", colname); } sbSql.AppendFormat(",'{0}')", whenever); dal.ExecuteNonQuery(sbSql.ToString()); } ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "" }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = "发生异常:" + ex.Message }); RecordException(ex); } return(ret); }
public ActionResult Delete(List <int> idList) { JsonResult ret = new JsonResult(); try { var pt = db.AuditPolicy.Find(idList[0]); using (var dal = new DmDAL(GetSessionConnStr(pt.SCID.Value))) { foreach (var id in idList) { var policy = db.AuditPolicy.Find(id); StringBuilder sbSql = new StringBuilder(); sbSql.AppendFormat("SP_NOAUDIT_OBJECT('{0}', '{1}', '{2}', '{3}','{4}','{5}')", policy.APStatement, policy.APUser, policy.APSchema, policy.APObjectName, policy.APColumnName, policy.APWhen); dal.ExecuteNonQuery(sbSql.ToString()); db.AuditPolicy.Remove(policy); } } db.SaveChanges(); ret.Data = JsonConvert.SerializeObject(new { status = 0, message = "" }); } catch (Exception ex) { ret.Data = JsonConvert.SerializeObject(new { status = 1, message = ex.Message }); RecordException(ex); } return(ret); }