public void Remove(PM_ALT_BASE entity, out string returnMessage) { returnMessage = string.Empty; // try { DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8); // if (entity == null) { returnMessage = "Input parameter [ALERT entity] can not be null."; return; } if (!entity.AlertID.HasValue) { returnMessage = "[ALERT ID] can not be null."; return; } // entity.RowDeleted = true; entity.ModifiedOn = datetime; this.UpdateSome(entity); } catch (Exception ex) { returnMessage = ex.Message; return; } }
/// <summary> /// Get with transaction /// </summary> public PM_ALT_BASE Get(object entityId, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entityId, "entityId"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PM_ALT_BASE PM_ALT_BASEEntity = null; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_BASEDAO.SqlGet); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, entityId); using (IDataReader dataReader = db.ExecuteReader(dbCommand, transaction)) { if (dataReader.Read()) { PM_ALT_BASEEntity = ReadEntity(dataReader); } } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } return(PM_ALT_BASEEntity); }
public virtual bool DoService() { //后续可能被删除 _alert = _PM_ALT_BASEBO.GetEntity(_alert.AlertID.Value); if (_alert == null || _alert.RowDeleted == true || _alert.IsActive == false) { return(true); } object readyData = this.GetReadyData(); if (readyData != null) { try { this.Execute(readyData); } finally { GC.Collect(); } } // return(true); }
public void Update(PM_ALT_BASE entity, bool updateAll) { if (!updateAll) { UpdateSome(entity); } else { UpdateAll(entity); } }
public void Update(PM_ALT_BASE entity, bool updateAll, DbTransaction transaction) { if (!updateAll) { UpdateSome(entity, transaction); } else { UpdateAll(entity, transaction); } }
public void UpdateSome(PM_ALT_BASE entity) { try { ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_BASE Entity"); _PM_ALT_BASEDAO.Update(entity, false); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } }
public string DateMainRemove(PM_ALT_BASE entity) { string message = ""; try { pm_ALT_BASEBO.Remove(entity, out message); return(message); } catch (Exception e) { throw e; } }
public void receiveAlert(PM_ALT_BASE entity) { if (entity == null) { entity = new PM_ALT_BASE(); alertID = new Guid(); entity.AlertID = alertID; alertEntity = entity; } else if (entity.AlertID != null) { alertID = (Guid)entity.AlertID; alertEntity = entity; } }
public PM_ALT_BASE Insert(PM_ALT_BASE entity) { PM_ALT_BASE newEntity = null; try { ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_BASE Entity"); newEntity = _PM_ALT_BASEDAO.Insert(entity); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } return(newEntity); }
public PM_ALT_BASE GetEntity(Guid entityGuid) { PM_ALT_BASE entity = null; try { ArgumentValidator.CheckForNullArgument(entityGuid, "PM_ALT_BASE Guid"); entity = _PM_ALT_BASEDAO.Get(entityGuid); } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy); } return(entity); }
private void UpdateAll(PM_ALT_BASE entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_BASE PM_ALT_BASEEntity = entity as PersistentPM_ALT_BASE; try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_BASEDAO.SqlUpdate); db.AddInParameter(dbCommand, "@AlertID", DbType.Guid, PM_ALT_BASEEntity.AlertID); db.AddInParameter(dbCommand, "@AlertName", DbType.String, PM_ALT_BASEEntity.AlertName); db.AddInParameter(dbCommand, "@AlertAlias", DbType.String, PM_ALT_BASEEntity.AlertAlias); db.AddInParameter(dbCommand, "@SqlScript", DbType.String, PM_ALT_BASEEntity.SqlScript); db.AddInParameter(dbCommand, "@URL", DbType.String, PM_ALT_BASEEntity.URL); db.AddInParameter(dbCommand, "@AlertDesc", DbType.String, PM_ALT_BASEEntity.AlertDesc); db.AddInParameter(dbCommand, "@AlertContent", DbType.String, PM_ALT_BASEEntity.AlertContent); db.AddInParameter(dbCommand, "@Category", DbType.String, PM_ALT_BASEEntity.Category); db.AddInParameter(dbCommand, "@AlertType", DbType.Int32, PM_ALT_BASEEntity.AlertType); db.AddInParameter(dbCommand, "@Format", DbType.String, PM_ALT_BASEEntity.Format); db.AddInParameter(dbCommand, "@AlertObject", DbType.String, PM_ALT_BASEEntity.AlertObject); db.AddInParameter(dbCommand, "@PreProcedure", DbType.String, PM_ALT_BASEEntity.PreProcedure); db.AddInParameter(dbCommand, "@PostProcedure", DbType.String, PM_ALT_BASEEntity.PostProcedure); db.AddInParameter(dbCommand, "@AlertInterval", DbType.Int32, PM_ALT_BASEEntity.AlertInterval); db.AddInParameter(dbCommand, "@AlertTimePoints", DbType.String, PM_ALT_BASEEntity.AlertTimePoints); db.AddInParameter(dbCommand, "@LastAlertedTime", DbType.DateTime, PM_ALT_BASEEntity.LastAlertedTime); db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, PM_ALT_BASEEntity.IsActive); db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_BASEEntity.RowDeleted); db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, PM_ALT_BASEEntity.CreatedBy); db.AddInParameter(dbCommand, "@CreatedOn", DbType.DateTime, PM_ALT_BASEEntity.CreatedOn); db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, PM_ALT_BASEEntity.ModifiedBy); db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_BASEEntity.ModifiedOn); int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
/// <summary> /// 频率设置 /// </summary> /// <param name="name"></param> public MainService(string name) { Name = name; _PM_ALT_BASEBO = ObjectContainer.BuildUp <IPM_ALT_BASEBO>(); _ICV_PM_EMAIL_NOTIBO = ObjectContainer.BuildUp <ICV_PM_EMAIL_NOTIBO>(); _ICV_PM_WECHAT_NOTIBO = ObjectContainer.BuildUp <ICV_PM_WECHAT_NOTIBO>(); // //1.load alert _alert = _PM_ALT_BASEBO.GetEntity(name); if (_alert == null) { _loopPeriod = new TimeSpan(0, 0, 300); } else { if (_alert.AlertInterval.HasValue) { _loopPeriod = new TimeSpan(0, 0, _alert.AlertInterval.Value); } else if (!string.IsNullOrEmpty(_alert.AlertTimePoints)) { _fixedTimers = new List <DateTime>(); foreach (string fixedTimer in _alert.AlertTimePoints.Split(',')) { if (string.IsNullOrEmpty(fixedTimer.Trim())) { continue; } // _fixedTimers.Add(Convert.ToDateTime(string.Format("2000-01-01 {0}:00", fixedTimer.Trim()))); } // _loopPeriod = new TimeSpan(0, 0, 60); } else //没有设置频率,默认5分钟 { _loopPeriod = new TimeSpan(0, 0, 300); } } }
public string updateBase(PM_ALT_BASE entity) { try { if (entity.AlertInterval.HasValue) { if (entity.AlertInterval < 10) { return("执行间隔不能低于10秒"); } } if (!string.IsNullOrEmpty(entity.AlertTimePoints)) { foreach (string fixedTimer in entity.AlertTimePoints.Split(',')) { if (string.IsNullOrEmpty(fixedTimer.Trim())) { continue; } string strTime = string.Format("2000-01-01 {0}:00", fixedTimer.Trim()); DateTime dateTime = new DateTime(); bool result = DateTime.TryParse(strTime, out dateTime); if (!result) { return("执行时间点格式错误"); } } } entity.ModifiedOn = SSGlobalConfig.Now; pm_ALT_BASEBO.Update(entity); return("OK"); } catch (Exception ex) { return("更新异常:" + ex.Message); } }
public void Restore(PM_ALT_BASE entity, out string returnMessage) { returnMessage = string.Empty; // try { DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8); // if (entity == null) { returnMessage = "Input parameter [ALERT entity] can not be null."; return; } if (!entity.AlertID.HasValue) { returnMessage = "[ALERT ID] can not be null."; return; } #region check security SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity; if (identity == null) { returnMessage = "[Authentication.Identity] is required."; return; } #endregion // entity.ModifiedBy = identity.Name; entity.ModifiedOn = datetime; entity.RowDeleted = false; this.UpdateSome(entity); } catch (Exception ex) { returnMessage = ex.Message; return; } }
/// <summary> /// 触发--查询预警数据 /// </summary> /// <param name="alert"></param> /// <returns></returns> public DataTable Run2(string alertID) { //前置存储过程 //if (!string.IsNullOrEmpty(alert.PreProcedure)) //{ // this.CallProcedure(alert.PreProcedure); //} PM_ALT_BASE alert = GetEntityByID(alertID); DataTable dtResult = new DataTable(); if (string.IsNullOrEmpty(alert.SqlScript)) { return(null); } else { dtResult = _PM_ALT_BASEDAO.Run(alert.SqlScript); return(dtResult); } }
public string SaveBase(PM_ALT_BASE entity, IList <PM_ALT_NOTI> notis, AlertSaveOptions saveOptions) { string message = "添加成功"; try { PM_ALT_BASE exist = pm_ALT_BASEBO.GetEntity(entity.AlertName); if (exist == null || exist.AlertID == null) { pm_ALT_BASEBO.Save(entity, notis, saveOptions, out message); } else { message = "预警名称已存在"; } return(message); } catch (Exception e) { return("添加失败"); throw e; } }
public string InsertBase(PM_ALT_BASE entity) { if (entity == null) { return("预警内容为空"); } if (entity.AlertInterval.HasValue) { if (entity.AlertInterval < 10) { return("执行间隔不能低于10秒"); } } if (!string.IsNullOrEmpty(entity.AlertTimePoints)) { foreach (string fixedTimer in entity.AlertTimePoints.Split(',')) { if (string.IsNullOrEmpty(fixedTimer.Trim())) { continue; } string strTime = string.Format("2000-01-01 {0}:00", fixedTimer.Trim()); DateTime dateTime = new DateTime(); bool result = DateTime.TryParse(strTime, out dateTime); if (!result) { return("执行时间点格式错误"); } } } PM_ALT_BASE exist = pm_ALT_BASEBO.GetEntity(entity.AlertName); if (exist == null || exist.AlertID == null) { //nothing } else { return("预警名称已存在"); } IList <CV_PM_ALT_BASE_QuaryParam> list = new List <CV_PM_ALT_BASE_QuaryParam>(); CV_PM_ALT_BASE_QuaryParam cvAltBace = new CV_PM_ALT_BASE_QuaryParam(); entity.AlertID = Guid.NewGuid(); entity.CreatedOn = SSGlobalConfig.Now; entity.ModifiedOn = entity.CreatedOn; entity.RowDeleted = false; try { PM_ALT_BASE altBase = new PM_ALT_BASE(); altBase = pm_ALT_BASEBO.Insert(entity); cvAltBace.AlertAlias = altBase.AlertAlias; cvAltBace.AlertContent = altBase.AlertContent; cvAltBace.AlertDesc = altBase.AlertDesc; cvAltBace.AlertID = altBase.AlertID; cvAltBace.AlertInterval = altBase.AlertInterval; cvAltBace.AlertName = altBase.AlertName; cvAltBace.AlertObject = altBase.AlertObject; cvAltBace.AlertTimePoints = altBase.AlertTimePoints; cvAltBace.AlertType = altBase.AlertType; cvAltBace.Category = altBase.Category; cvAltBace.CreatedBy = altBase.CreatedBy; cvAltBace.CreatedOn = altBase.CreatedOn; cvAltBace.Format = altBase.Format; cvAltBace.IsActive = altBase.IsActive; cvAltBace.LastAlertedTime = altBase.LastAlertedTime; cvAltBace.ModifiedBy = altBase.ModifiedBy; cvAltBace.ModifiedOn = altBase.ModifiedOn; cvAltBace.PostProcedure = altBase.PostProcedure; cvAltBace.PreProcedure = altBase.PreProcedure; cvAltBace.RowDeleted = altBase.RowDeleted; cvAltBace.URL = altBase.URL; if (altBase.AlertType.ToString() == "1") { cvAltBace.alertTypeName = "邮件"; } else if (altBase.AlertType.ToString() == "2") { cvAltBace.alertTypeName = "微信"; } list.Add(cvAltBace); return("OK"); } catch (Exception ex) { return("新增异常:" + ex.Message); } }
/// <summary> /// Update with transaction /// </summary> public void Update(PM_ALT_BASE entity, DbTransaction transaction) { Update(entity, true, transaction); }
/// <summary> /// Update /// </summary> public void Update(PM_ALT_BASE entity) { Update(entity, true); }
protected override bool Execute(object readyData) { try { if (readyData == null) { return(false); } // DataTable dtAll = readyData as DataTable; IList <PM_ALT_LOG> logs = new List <PM_ALT_LOG>(); IList <PM_ALT_MESSAGE> messages = new List <PM_ALT_MESSAGE>(); if (_alert.Format == "TABLE" || _alert.Format == "IMAGE") { //fill Log Subject & Content string logSubject = _alert.AlertContent; if (!string.IsNullOrEmpty(logSubject)) { logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd")); } string logContent = _alert.AlertDesc; if (!string.IsNullOrEmpty(logContent)) { logContent = _PM_ALT_BASEBO.BuildTable(_alert.AlertDesc, dtAll); } PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE(); msg.MsgSubject = logSubject; msg.MsgContent = logContent; msg.MsgFrom = "MESAdmin"; msg.MsgTo = _MessageToMembers; msg.Category = _alert.AlertName; msg.MsgType = _alert.AlertType; msg.Format = _alert.Format; msg.ObjectID = _alert.AlertID; msg.SentCnt = 0; msg.RowDeleted = false; messages.Add(msg); PM_ALT_LOG log = new PM_ALT_LOG(); log.AlertID = _alert.AlertID; log.LogTitle = logSubject; //_alert.AlertAlias; log.LogContent = logContent; log.NotifiedCnt = 1; log.IsClosed = false; log.RowDeleted = false; logs.Add(log); } else { for (int z = 0; z < dtAll.Rows.Count; z++) { //fill Log Subject & Content string logSubject = _alert.AlertContent; if (!string.IsNullOrEmpty(logSubject)) { logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd")); } if (!string.IsNullOrEmpty(logSubject)) { for (int i = 0; i < dtAll.Columns.Count; i++) { logSubject = logSubject.Replace("@" + dtAll.Columns[i].ColumnName + "$", dtAll.Rows[z][i].ToString()); } } string logURL = _alert.URL; if (!string.IsNullOrEmpty(logURL)) { for (int i = 0; i < dtAll.Columns.Count; i++) { logURL = logURL.Replace("@" + dtAll.Columns[i].ColumnName + "$", dtAll.Rows[z][i].ToString()); } } string logContent = _alert.AlertDesc; if (!string.IsNullOrEmpty(logContent)) { logContent = _PM_ALT_BASEBO.BuildContent(_alert.AlertDesc, dtAll, z); } PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE(); msg.MsgSubject = logSubject; //_alert.AlertAlias; msg.MsgContent = logContent; msg.MsgFrom = "MESAdmin"; msg.MsgTo = _MessageToMembers; msg.Category = _alert.AlertName; msg.MsgType = _alert.AlertType; msg.Format = _alert.Format; msg.ObjectID = _alert.AlertID; msg.SentCnt = 0; msg.RowDeleted = false; msg.URL = logURL; messages.Add(msg); // //create log PM_ALT_LOG log = new PM_ALT_LOG(); log.AlertID = _alert.AlertID; log.LogTitle = logSubject; //_alert.AlertAlias; log.LogContent = logContent; log.NotifiedCnt = 1; log.IsClosed = false; log.RowDeleted = false; logs.Add(log); } } // string returnMessage = string.Empty; if (!string.IsNullOrEmpty(returnMessage)) { log.Error("Exception: " + returnMessage + this.Name + ".SaveLogs()"); return(false); } // _PM_ALT_MESSAGEBO.SaveBatch(messages, out returnMessage); if (!string.IsNullOrEmpty(returnMessage)) { log.Error("Exception: " + returnMessage + this.Name + ".SaveMessages()"); return(false); } // if (!string.IsNullOrEmpty(_alert.PostProcedure)) { try { _PM_ALT_BASEBO.CallProcedure(_alert.PostProcedure); } catch (Exception ex) { log.Error(this.Name + ".CallPostProcedure()", ex); return(false); } } // if (_alert != null) { PM_ALT_BASE alert = new PM_ALT_BASE(); alert.AlertID = _alert.AlertID; alert.LastAlertedTime = Siemens.Simatic.Util.Utilities.DAO.UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8); _PM_ALT_BASEBO.UpdateSome(alert); } } catch (Exception ex) { log.Error(this.Name + ".Execute()", ex); return(false); } // return(true); }
public void Save(PM_ALT_BASE entity, IList <PM_ALT_NOTI> notis, AlertSaveOptions saveOptions, out string returnMessage) { returnMessage = string.Empty; // try { DateTime?datetime = UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8); // #region check #region check basic if (saveOptions == null) { returnMessage = "Parameter [SaveOptions saveOptions] can not be null."; return; } if (entity == null) { returnMessage = "Input parameter [ALERT entity] can not be null."; return; } if (!entity.AlertID.HasValue) { returnMessage = "Input parameter [ALERT.AlertID] can not be null."; return; } if (saveOptions.IsChangeNoti) { if (notis == null) { returnMessage = "Input parameter [IList<ALERT_NOTI> notis] can not be null."; return; } } // SSIdentity identity = SSAuthentication.CurrentIdentity as SSIdentity; if (identity == null) { returnMessage = "[Authentication.Identity] is required."; return; } #endregion // #region check alert if (saveOptions.IsChangeAlert) { if (string.IsNullOrEmpty(entity.AlertName)) { returnMessage = "[ALERT Name] is required."; return; } if (string.IsNullOrEmpty(entity.AlertAlias)) { returnMessage = "[ALERT Alias] is required."; return; } if (string.IsNullOrEmpty(entity.AlertObject)) { returnMessage = "[ALERT Object] is required."; return; } if (!_PM_ALT_BASEDAO.CheckDatabaseObject(entity.AlertObject)) { returnMessage = "[ALERT Object] is invalid."; return; } // if (!entity.AlertID.HasValue) { entity.AlertID = Guid.NewGuid(); entity.CreatedBy = identity.Name; entity.CreatedOn = datetime; } else { entity.ModifiedBy = identity.Name; entity.ModifiedOn = datetime; } // if (!entity.RowDeleted.HasValue) { entity.RowDeleted = false; } if (string.IsNullOrEmpty(entity.CreatedBy)) { entity.CreatedBy = identity.Name; } if (!entity.CreatedOn.HasValue) { entity.CreatedOn = datetime; } } #endregion // #region check noti if (saveOptions.IsChangeNoti) { } #endregion #endregion // #region save // #region save alert if (saveOptions.IsChangeAlert) { PM_ALT_BASE entityExisted = this.GetEntity(entity.AlertID.Value); if (entityExisted == null) { if (null != this.GetEntity(entity.AlertName)) { returnMessage = "The item with the same code has existed."; return; } // entity.ModifiedBy = null; entity.ModifiedOn = null; // this.Insert(entity); } else { this.UpdateSome(entity); } } #endregion // #region save noti if (saveOptions.IsChangeNoti) { _PM_ALT_NOTIBO.SaveBatch(entity.AlertID.Value, notis, out returnMessage); // if (!string.IsNullOrEmpty(returnMessage)) { return; } } #endregion #endregion } catch (Exception ex) { returnMessage = ex.Message; return; } }
private void UpdateSome(PM_ALT_BASE entity, DbTransaction transaction) { ArgumentValidator.CheckForNullArgument(entity, "entity"); ArgumentValidator.CheckForNullArgument(transaction, "transaction"); PersistentPM_ALT_BASE PM_ALT_BASEEntity = entity as PersistentPM_ALT_BASE; StringBuilder sqlUpdateSome = new StringBuilder(); sqlUpdateSome.Append("UPDATE dbo.PM_ALT_BASE SET "); PropertyInfo[] propertyInfos = PM_ALT_BASEEntity.GetType().GetProperties(); Hashtable propertyValues = new System.Collections.Hashtable(); int columnCountForUpdate = 0; foreach (PropertyInfo propertyInfo in propertyInfos) { if (EntityMapping.ContainsProperty(propertyInfo.Name)) { object propertyValue = propertyInfo.GetValue(PM_ALT_BASEEntity, null); ORProperty property = EntityMapping[propertyInfo.Name]; if (!property.IsPrimaryKey) { if (!PM_ALT_BASEEntity.IsDefaultValue(propertyInfo.Name)) { propertyValues[propertyInfo.Name] = propertyValue; sqlUpdateSome.Append(" " + property.ColumnName + " = @" + property.ColumnName + ","); columnCountForUpdate++; } } else { propertyValues[propertyInfo.Name] = propertyValue; } } } if (columnCountForUpdate == 0) { return; } sqlUpdateSome.Remove(sqlUpdateSome.Length - 1, 1); sqlUpdateSome.Append(" WHERE 1 = 1 "); sqlUpdateSome.Append(" AND AlertID = @AlertID "); try { Database db = GetDatabaseInstance(); DbCommand dbCommand = db.GetSqlStringCommand(sqlUpdateSome.ToString()); foreach (DictionaryEntry de in propertyValues) { ORProperty property = EntityMapping[de.Key.ToString()]; db.AddInParameter(dbCommand, "@" + property.ColumnName, property.DatabaseType, de.Value); } int result = db.ExecuteNonQuery(dbCommand, transaction); if (result == 0) { throw new EntityNotFoundException(); } } catch (Exception ex) { ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy); } }
private static PM_ALT_BASE ReadEntity(IDataReader dataReader) { PM_ALT_BASE PM_ALT_BASEEntity = new PM_ALT_BASE(); object value; value = dataReader["AlertID"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertID = (Guid?)value; } value = dataReader["AlertName"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertName = (String)value; } value = dataReader["AlertAlias"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertAlias = (String)value; } value = dataReader["SqlScript"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.SqlScript = (String)value; } value = dataReader["URL"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.URL = (String)value; } value = dataReader["AlertDesc"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertDesc = (String)value; } value = dataReader["AlertContent"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertContent = (String)value; } value = dataReader["Category"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.Category = (String)value; } value = dataReader["AlertType"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertType = (Int32?)value; } value = dataReader["Format"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.Format = (String)value; } value = dataReader["AlertObject"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertObject = (String)value; } value = dataReader["PreProcedure"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.PreProcedure = (String)value; } value = dataReader["PostProcedure"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.PostProcedure = (String)value; } value = dataReader["AlertInterval"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertInterval = (Int32?)value; } value = dataReader["AlertTimePoints"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.AlertTimePoints = (String)value; } value = dataReader["LastAlertedTime"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.LastAlertedTime = (DateTime?)value; } value = dataReader["IsActive"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.IsActive = (Boolean?)value; } value = dataReader["RowDeleted"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.RowDeleted = (Boolean?)value; } value = dataReader["CreatedBy"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.CreatedBy = (String)value; } value = dataReader["CreatedOn"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.CreatedOn = (DateTime?)value; } value = dataReader["ModifiedBy"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.ModifiedBy = (String)value; } value = dataReader["ModifiedOn"]; if (value != DBNull.Value) { PM_ALT_BASEEntity.ModifiedOn = (DateTime?)value; } return(PM_ALT_BASEEntity); }
/// <summary> /// 插入消息表 /// </summary> /// <returns></returns> public string Trigger(DataTable dtTrigger, PM_ALT_BASE alertEntity) { try { if (dtTrigger == null || dtTrigger.Rows.Count == 0) { return("没有执行内容"); } IList <PM_ALT_LOG> logs = new List <PM_ALT_LOG>(); IList <PM_ALT_MESSAGE> messages = new List <PM_ALT_MESSAGE>(); if (alertEntity.Format == "TABLE" || alertEntity.Format == "IMAGE") { //fill Log Subject & Content string logSubject = alertEntity.AlertContent; if (!string.IsNullOrEmpty(logSubject)) { logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd")); } string logContent = alertEntity.AlertDesc; if (!string.IsNullOrEmpty(logContent)) { logContent = this.BuildTable(alertEntity.AlertDesc, dtTrigger); } PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE(); msg.MsgSubject = logSubject; msg.MsgContent = logContent; msg.MsgFrom = "MESAdmin"; msg.MsgTo = this.GetEmailToList(alertEntity.AlertID.ToString()); msg.Category = alertEntity.AlertName; msg.MsgType = alertEntity.AlertType; msg.Format = alertEntity.Format; msg.ObjectID = alertEntity.AlertID; msg.SentCnt = 0; msg.RowDeleted = false; messages.Add(msg); PM_ALT_LOG log = new PM_ALT_LOG(); log.AlertID = alertEntity.AlertID; log.LogTitle = logSubject; //_alert.AlertAlias; log.LogContent = logContent; log.NotifiedCnt = 1; log.IsClosed = false; log.RowDeleted = false; logs.Add(log); } else { for (int z = 0; z < dtTrigger.Rows.Count; z++) { //fill Log Subject & Content string logSubject = alertEntity.AlertContent; if (!string.IsNullOrEmpty(logSubject)) { logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd")); } if (!string.IsNullOrEmpty(logSubject)) { for (int i = 0; i < dtTrigger.Columns.Count; i++) { logSubject = logSubject.Replace("@" + dtTrigger.Columns[i].ColumnName + "$", dtTrigger.Rows[z][i].ToString()); } } string logContent = alertEntity.AlertDesc; if (!string.IsNullOrEmpty(logContent)) { logContent = this.BuildContent(alertEntity.AlertDesc, dtTrigger, z); } string logURL = alertEntity.URL; if (!string.IsNullOrEmpty(logURL)) { for (int i = 0; i < dtTrigger.Columns.Count; i++) { logURL = logURL.Replace("@" + dtTrigger.Columns[i].ColumnName + "$", dtTrigger.Rows[z][i].ToString()); } } PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE(); msg.MsgSubject = logSubject; //_alert.AlertAlias; msg.MsgContent = logContent; msg.MsgFrom = "MESAdmin"; msg.MsgTo = this.GetEmailToList(alertEntity.AlertID.ToString()); msg.Category = alertEntity.AlertName; msg.MsgType = alertEntity.AlertType; msg.Format = alertEntity.Format; msg.ObjectID = alertEntity.AlertID; msg.URL = logURL; msg.SentCnt = 0; msg.RowDeleted = false; messages.Add(msg); // //create log PM_ALT_LOG log = new PM_ALT_LOG(); log.AlertID = alertEntity.AlertID; log.LogTitle = logSubject; //_alert.AlertAlias; log.LogContent = logContent; log.NotifiedCnt = 1; log.IsClosed = false; log.RowDeleted = false; logs.Add(log); } } // string returnMessage = string.Empty; if (!string.IsNullOrEmpty(returnMessage)) { return("Exception: " + returnMessage + ".SaveLogs()"); } // pm_ALT_MESSAGEBO.SaveBatch(messages, out returnMessage); if (!string.IsNullOrEmpty(returnMessage)) { return("Exception: " + returnMessage + ".SaveEmails()"); } // if (alertEntity != null) { PM_ALT_BASE alert = new PM_ALT_BASE(); alert.AlertID = alertEntity.AlertID; alert.LastAlertedTime = Siemens.Simatic.Util.Utilities.DAO.UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8); this.UpdateSome(alert); } return("生成预警成功"); } catch (Exception ex) { return("生成预警失败"); } }
/// <summary> /// 插入消息表-并发送 /// </summary> /// <param name="dtTrigger"></param> /// <param name="alertEntity"></param> /// <returns></returns> public string TriggerAndSend(DataTable dtTrigger, PM_ALT_BASE alertEntity) { if (dtTrigger == null || dtTrigger.Rows.Count == 0) { return("没有执行内容"); } //IList<PM_ALT_SCALE> scales = new List<PM_ALT_SCALE>(); //IList<PM_ALT_LOG> logs = new List<PM_ALT_LOG>(); IList <PM_ALT_MESSAGE> messageList = new List <PM_ALT_MESSAGE>(); if (alertEntity.Format == "TABLE" || alertEntity.Format == "IMAGE") { string logSubject = alertEntity.AlertName; //预警标题 logSubject = logSubject.Replace("@日期", SSGlobalConfig.Now.ToString("yyyy-MM-dd")); string logContent = ""; logContent = this.BuildTable2(logSubject + "\r\n", dtTrigger); PM_ALT_MESSAGE email = new PM_ALT_MESSAGE(); email.MsgSubject = logSubject; //_alert.AlertAlias; email.MsgContent = logContent; email.MsgFrom = "MESAdmin"; email.MsgTo = this.GetEmailToList(alertEntity.AlertID.Value.ToString()); email.Category = alertEntity.Category; email.MsgType = alertEntity.AlertType; email.Format = alertEntity.Format; email.ObjectID = alertEntity.AlertID; email.SentCnt = 0; email.RowDeleted = false; messageList.Add(email); //PM_ALT_LOG log = new PM_ALT_LOG(); //log.AlertID = alertEntity.AlertID; //log.LogTitle = logSubject; //_alert.AlertAlias; //log.LogContent = logContent; //log.NotifiedCnt = 1; //log.IsClosed = false; //log.RowDeleted = false; //logs.Add(log); } else if (alertEntity.Format == "TEXT") //文本--作废 { for (int z = 0; z < dtTrigger.Rows.Count; z++) //每行数据发一次 { string logSubject = alertEntity.AlertName; string logContent = ""; //alertEntity.AlertDesc; logContent = this.BuildContent2(logSubject + "\r\n", dtTrigger, z); //logContent.Replace("@" + dtEvents.Columns[i].ColumnName, dtEvents.Rows[z][i].ToString()); PM_ALT_MESSAGE email = new PM_ALT_MESSAGE(); email.MsgSubject = logSubject; //_alert.AlertAlias; email.MsgContent = logContent; email.MsgFrom = "MESAdmin"; email.MsgTo = this.GetEmailToList(alertEntity.AlertID.ToString()); email.Category = alertEntity.Category; email.MsgType = alertEntity.AlertType; email.Format = alertEntity.Format; email.ObjectID = alertEntity.AlertID; email.SentCnt = 0; email.RowDeleted = false; messageList.Add(email); } //end for } string returnMessage = string.Empty; //if (scales != null) //{ // PM_ALT_SCALEBO.SaveBatch(scales, out returnMessage); // if (!string.IsNullOrEmpty(returnMessage)) // { // SSMessageBox.ShowError(returnMessage); // return returnMessage; // } //} //保存预警消息 //pm_ALT_MESSAGEBO.SaveBatch(messageList, out returnMessage); //if (!string.IsNullOrEmpty(returnMessage)) //{ // return returnMessage; //} foreach (PM_ALT_MESSAGE msg in messageList) { string insertSql = @"INSERT INTO PM_ALT_MESSAGE(MsgSubject,MsgContent,MsgType,Format,ObjectID,MsgFrom,MsgTo,Category,SentCnt,ModifiedOn,RowDeleted) SELECT '{0}','{1}',alt.AlertType,alt.Format,alt.AlertID,'MESAdmin', STUFF((SELECT ','+u.Email FROM PM_ALT_NOTI t JOIN PM_WECHAT_USER u ON t.UserGuid=u.UserGuid WHERE t.AlertID=alt.AlertID AND u.Email<>'' for xml path('') ),1,1,'' ) AS MsgTo,alt.Category,0,GETDATE(),0 FROM PM_ALT_BASE as alt WHERE alertID='{2}';select @@identity "; insertSql = string.Format(insertSql, msg.MsgSubject, msg.MsgContent, msg.ObjectID); DataTable dt = alt_BSC_BO.GetDataTableBySql(insertSql); if (dt == null || dt.Rows.Count == 0) { return("插入数据失败"); } else { msg.MsgPK = int.Parse(dt.Rows[0][0].ToString()); alt_BSC_BO.ExecuteNotify(msg); //发送消息 } } return("生成预警成功"); }
public IList <CV_PM_ALT_BASE_QuaryParam> getAltBase(CV_PM_ALT_BASE pmAltBase) { IList <CV_PM_ALT_BASE_QuaryParam> listQuary = new List <CV_PM_ALT_BASE_QuaryParam>(); IList <CV_PM_ALT_BASE> list = new List <CV_PM_ALT_BASE>(); if (pmAltBase != null) { try { list = cv_PM_ALT_BASEBO.GetEntities(pmAltBase); if (list.Count > 0) { for (int i = 0; i < list.Count; i++) { CV_PM_ALT_BASE_QuaryParam Entity = new CV_PM_ALT_BASE_QuaryParam(); Entity.AlertID = list[i].AlertID; Entity.AlertName = list[i].AlertName; Entity.AlertAlias = list[i].AlertAlias; Entity.AlertDesc = list[i].AlertDesc; Entity.AlertContent = list[i].AlertContent; Entity.Category = list[i].Category; Entity.AlertType = list[i].AlertType; Entity.Format = list[i].Format; Entity.AlertObject = list[i].AlertObject; Entity.PreProcedure = list[i].PreProcedure; Entity.PostProcedure = list[i].PostProcedure; Entity.AlertInterval = list[i].AlertInterval; Entity.AlertTimePoints = list[i].AlertTimePoints; Entity.LastAlertedTime = list[i].LastAlertedTime; Entity.IsActive = list[i].IsActive; Entity.CIsActive = list[i].CIsActive; Entity.RowDeleted = list[i].RowDeleted; Entity.CreatedBy = list[i].CreatedBy; Entity.CreatedOn = list[i].CreatedOn; Entity.ModifiedBy = list[i].ModifiedBy; Entity.ModifiedOn = list[i].ModifiedOn; Entity.SqlScript = list[i].SqlScript; Entity.URL = list[i].URL; if (list[i].AlertType.ToString() == "1") { Entity.alertTypeName = "邮件"; } else if (list[i].AlertType.ToString() == "2") { Entity.alertTypeName = "微信"; } listQuary.Add(Entity); } } if (list.Count == 0) { alertEntity = null; } else { listQuary = listQuary.OrderByDescending(c => c.ModifiedOn).ToList(); } return(listQuary); } catch (Exception e) { throw e; } } else { return(null); } }