/// <summary> /// Get active notification profile ids /// </summary> /// <returns></returns> private NotificationProfile GetActiveNotificationProfile(int storeID) { NotificationProfile notificationProfile = null; try { notificationProfile = new NotificationProfile(); notificationProfile.NotifyProfileID = _notifyProfileID; notificationProfile.StoreID = storeID; notificationProfile = notificationProfile.Execute(); } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching notification profile Ids ", ex, "CooperAtkins.NotificationClient.NotificationComposer.NotificationEligibility"); } finally { notificationProfile.Dispose(); } return(notificationProfile); }
/// <summary> /// Get E-mail Notification ID /// </summary> /// <param name="notifyProfileID"></param> /// <returns></returns> private int GetEmailNotificationID(int notifyProfileID) { NotificationProfile notificationProfile = null; int emailNotificationID = 0; try { /*Create NotificationProfile instance*/ notificationProfile = new NotificationProfile(); /*Send criteria notifyProfileID to get the Notification ID*/ notificationProfile.NotifyProfileID = notifyProfileID; /*Execute*/ notificationProfile = notificationProfile.Execute(); /*Assign the EmailNotifyID to local variable emailNotificationID*/ emailNotificationID = notificationProfile.EmailNotifyID; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write("Error has occurred while fetching EmailNotifyID ", ex, "CooperAtkins.NotificationClient.NotificationComposer.EmailNotificationComposer"); } finally { /*Dispose the notificationProfile object*/ notificationProfile.Dispose(); } return(emailNotificationID); }
/// <summary> /// Get Pager Notification ID /// </summary> /// <param name="notifyProfileID"></param> /// <returns></returns> private int GetPagerNotificationID(int notifyProfileID) { NotificationProfile notificationProfile = null; int pagerNotificationID = 0; try { notificationProfile = new NotificationProfile(); notificationProfile.NotifyProfileID = notifyProfileID; notificationProfile = notificationProfile.Execute(); pagerNotificationID = notificationProfile.PagerNotifyID; } catch (Exception ex) { /*Debug Object values for reference*/ LogBook.Debug(notificationProfile, this); /*Write exception log*/ LogBook.Write(_logContent + " Error has occurred while fetching PagerNotifyID ", ex, "CooperAtkins.NotificationClient.NotificationComposer.PagerNotificationComposer"); } finally { notificationProfile.Dispose(); } return(pagerNotificationID); }
public virtual async Task CreateNotificationProfile(NotificationProfileModelDto dto) { #region Profile var entity = new NotificationProfile() { Id = dto.Id, Name = dto.Name }; await _notificationsContext.NotificationProfiles.AddAsync(entity); #endregion #region Users var users = dto.Users.Select(id => new NotificationUser() { UserId = id, NotificationProfileId = entity.Id }).ToList(); await _notificationsContext.NotificationUsers.AddRangeAsync(users); #endregion #region profileEvents var profileEvents = dto.Events.Select(id => new NotificationEvent() { EventId = id, NotificationProfileId = entity.Id }).ToList(); await _notificationsContext.NotificationEvents.AddRangeAsync(profileEvents); #endregion await _notificationsContext.SaveChangesAsync(); }
private static void CreateNotificationItem(IEnumerable entityList, string primaryKey, string entityName, NotificationProfile config, Guid operatorUserId, string relationEntityName , Dictionary <string, object> oldValue, int languageId) { DbContext context = DynamicModelBuilder.CreateDataSource(); foreach (var entityDataItem in entityList) { ProcessOneEntityData(entityDataItem, primaryKey, entityName, context, config, operatorUserId, relationEntityName, oldValue, languageId); } context.SaveChanges(); }
private static List <Guid> GetUserList(NotificationProfile config, Dictionary <string, object> variablesValues, Guid operatorUserId) { DbContext commonContext = DynamicModelBuilder.CreateDataSource(); List <Guid> userList = new List <Guid>(); List <NotificationRecipientAttribute> recipientConfigs = config.NotificationRecipientAttributes.ToList() as List <NotificationRecipientAttribute>; MetadataService client = new MetadataService(); foreach (NotificationRecipientAttribute reipientConfig in recipientConfigs) { FilterCriteriaHelper helper = new FilterCriteriaHelper(reipientConfig.RecipientEntityId ?? Guid.Empty, variablesValues); CriteriaOperator theOperator = helper.GeneratrCriteria(reipientConfig.Criterion); var filterEntiy = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == reipientConfig.RecipientEntityId).First(); Type filterEntityType = DynamicTypeBuilder.Instance.GetDynamicType(filterEntiy.Name); IQueryable query = commonContext.Set(filterEntityType).AsQueryable(); System.Linq.Expressions.Expression exception = GetExpression(query, theOperator); query = query.Provider.CreateQuery(exception); IEnumerator iter = query.GetEnumerator(); EntityAttribute att = filterEntiy.Attributes.Where(c => c.AttributeId == reipientConfig.AttributeId).First(); while (iter.MoveNext()) { object userIdValue = GetPropertyValue(iter.Current, att.PhysicalName); if (userIdValue is Guid) { Guid userId = (Guid)GetPropertyValue(iter.Current, att.PhysicalName); if (!userList.Contains(userId) && userId != operatorUserId) { userList.Add(userId); } } } } if (config.Subscriptions != null) { foreach (var subscription in config.Subscriptions) { if (subscription.UserId != null && subscription.UserId != operatorUserId) { if (!userList.Contains((Guid)subscription.UserId)) { userList.Add((Guid)subscription.UserId); } } } } return(userList); }
/// <summary> /// Method to get the switch id based on Notify Profile ID /// </summary> /// <param name="notifyProfileID"></param> /// <param name="notificationID"></param> /// <returns></returns> private int GetSwitchNotifyID(int notifyProfileID, int notificationID) { NotificationProfile notificationProfile = new NotificationProfile(); NotificationStyle notificationStyle = new NotificationStyle(); try { notificationProfile.NotifyProfileID = notifyProfileID; notificationProfile.Execute(); //if (notificationProfile.SwitchNotifyID == 0) // notificationStyle.RecordNotification("Relay switch not configured for this notification", notificationID, NotifyStatus.FAIL, NotifyTypes.SWITCH); } catch (Exception ex) { LogBook.Write(" *** Error in GetSwitchNotifyID method:" + ex.Message); } return(notificationProfile.SwitchNotifyID); }
private int GetMessageBoardID(int notifyProfileID, int notificationID) { //get the message board id, to which the message has to be sent NotificationProfile notificationProfile = new NotificationProfile(); NotificationStyle notificationStyle = new NotificationStyle(); try { notificationProfile.NotifyProfileID = notifyProfileID; notificationProfile = notificationProfile.Execute(); if (notificationProfile.MsgBoardNotifyID == 0) { notificationStyle.RecordNotification("Message board not found", notificationID, 0, NotifyStatus.FAIL, NotifyTypes.MSGBOARD); } } catch (Exception ex) { LogBook.Write(" *** Error in GetMessageBoardID :" + ex.Message); } return(notificationProfile.MsgBoardNotifyID); }
public string[] GetNotifyTypes() { List <string> notifyTypes = new List <string>(); GenStoreInfo genStoreInfo = null; /*Get GenStore Information*/ genStoreInfo = GenStoreInfo.GetInstance(); /* 10/22/15 JH * below 3 lines of code are junk - this will never return NULL */ NotificationProfile notificationProfile = GetActiveNotificationProfile(genStoreInfo.StoreID); /*Check for IsAlertEnabled flag.If the flag is not set return null to stop all notifications*/ if (notificationProfile.IsAlertEnabled) { return(null); } /*get all notification type from configuration file.*/ List <NotificationTypes> notificationTypelist = new NotificationTypes().GetNotificationTypes(); IVRUserID = notificationProfile.IVR_UserID; HasDynamicTypes = false; /* Check for the alarm cleared or Check for the sensor comes to the normal range or the notification type is resumed type * then load only dynamic notification types */ if ((_isProcessCompleted && NotificationSentCount > 0) || _isResumedNotification) { /*Stop notifications for email,popup,script,pager.... and check whether MessageBoard and Relay Switch are active or not */ foreach (NotificationTypes notificationType in notificationTypelist) { if ((notificationProfile.NotifyType & notificationType.Value).ToBoolean() && notificationType.IsDynamicType) { HasDynamicTypes = true; notifyTypes.Add(notificationType.Name); if (notificationType.Name == "MessageBoard") { HasPreviousMessageBoard = true; } if (notificationType.Name == "Switch") { HasPreviousSwitch = true; } } } } else { /* Otherwise load all configured notification types*/ foreach (NotificationTypes notificationType in notificationTypelist) { if ((notificationProfile.NotifyType & notificationType.Value).ToBoolean()) { /*if this is to clear dynamic notification then do not add other types to the notify types*/ if (_isDynamicNotificationCleared == true && _isDynamicNotificationRemoved == false) { if (notificationType.IsDynamicType) { notifyTypes.Add(notificationType.Name); if (notificationType.Name == "MessageBoard") { HasPreviousMessageBoard = true; } if (notificationType.Name == "Switch") { HasPreviousSwitch = true; } } continue; } /* checking whether the notification type is dynamic*/ if (notificationType.IsDynamicType) { HasDynamicTypes = true; if (notificationType.Name == "MessageBoard") { HasPreviousMessageBoard = true; } if (notificationType.Name == "Switch") { HasPreviousSwitch = true; } } /* don't add dynamic types if the user already cleared dynamic in previous escalation*/ if (_isDynamicNotificationRemoved && notificationType.IsDynamicType) { continue; } notifyTypes.Add(notificationType.Name); } } } return(notifyTypes.ToArray()); }
public Tuple <bool, string> SaveProfile(dynamic item) { bool success = false; string msg = ""; int ProcessId, StepId; int? ProfileId; string UserId, CC, BCC; bool WeekDay1, WeekDay2, WeekDay3, WeekDay4, WeekDay5, WeekDay6, WeekDay7; bool TimeSlot1 = false, TimeSlot2 = false, TimeSlot3 = false, TimeSlot4 = false, TimeSlot5 = false, TimeSlot6 = false, TimeSlot7 = false, TimeSlot8 = false, TimeSlot9 = false, TimeSlot10 = false, TimeSlot11 = false, TimeSlot12 = false, TimeSlot13 = false, TimeSlot14 = false, TimeSlot15 = false, TimeSlot16 = false, TimeSlot17 = false, TimeSlot18 = false, TimeSlot19 = false, TimeSlot20 = false, TimeSlot21 = false, TimeSlot22 = false, TimeSlot23 = false, TimeSlot24 = false; try { ProfileId = item.ProfileId; ProcessId = item.ProcessId; StepId = item.StepId; UserId = item.UserId; CC = item.CC; BCC = item.BCC; WeekDay1 = item.WeekDay1; WeekDay2 = item.WeekDay2; WeekDay3 = item.WeekDay3; WeekDay4 = item.WeekDay4; WeekDay5 = item.WeekDay5; WeekDay6 = item.WeekDay6; WeekDay7 = item.WeekDay7; int timeSlot = item.TimeSlot; switch (timeSlot) { case 1: TimeSlot1 = true; break; case 2: TimeSlot2 = true; break; case 3: TimeSlot3 = true; break; case 4: TimeSlot4 = true; break; case 5: TimeSlot5 = true; break; case 6: TimeSlot6 = true; break; case 7: TimeSlot7 = true; break; case 8: TimeSlot8 = true; break; case 9: TimeSlot9 = true; break; case 10: TimeSlot10 = true; break; case 11: TimeSlot11 = true; break; case 12: TimeSlot12 = true; break; case 13: TimeSlot13 = true; break; case 14: TimeSlot14 = true; break; case 15: TimeSlot15 = true; break; case 16: TimeSlot16 = true; break; case 17: TimeSlot17 = true; break; case 18: TimeSlot18 = true; break; case 19: TimeSlot19 = true; break; case 20: TimeSlot20 = true; break; case 21: TimeSlot21 = true; break; case 22: TimeSlot22 = true; break; case 23: TimeSlot23 = true; break; case 24: TimeSlot24 = true; break; default: break; } if (ProfileId.GetValueOrDefault(0) != 0) { var profile = Db.NotificationProfile.Where(p => p.EmailNotificationProfileID == ProfileId).FirstOrDefault(); if (profile != null) { string employeeID = ""; if (UserId == "DEFAULT") { employeeID = UserId; } else { var UserRecord = Db.vUser.Where(p => p.UserID == UserId).FirstOrDefault(); employeeID = UserRecord.EmployeeID; } profile.ProcessID = ProcessId; profile.ActivityGroupID = StepId; profile.UserID = UserId; profile.EmployeeID = employeeID; profile.cc = CC; profile.bcc = BCC; profile.WeekDay1 = WeekDay1; profile.WeekDay2 = WeekDay2; profile.WeekDay3 = WeekDay3; profile.WeekDay4 = WeekDay4; profile.WeekDay5 = WeekDay5; profile.WeekDay6 = WeekDay6; profile.WeekDay7 = WeekDay7; profile.TimeSlot1 = TimeSlot1; profile.TimeSlot2 = TimeSlot2; profile.TimeSlot3 = TimeSlot3; profile.TimeSlot4 = TimeSlot4; profile.TimeSlot5 = TimeSlot5; profile.TimeSlot6 = TimeSlot6; profile.TimeSlot7 = TimeSlot7; profile.TimeSlot8 = TimeSlot8; profile.TimeSlot9 = TimeSlot9; profile.TimeSlot10 = TimeSlot10; profile.TimeSlot11 = TimeSlot11; profile.TimeSlot12 = TimeSlot12; profile.TimeSlot13 = TimeSlot13; profile.TimeSlot14 = TimeSlot14; profile.TimeSlot15 = TimeSlot15; profile.TimeSlot16 = TimeSlot16; profile.TimeSlot17 = TimeSlot17; profile.TimeSlot18 = TimeSlot18; profile.TimeSlot19 = TimeSlot19; profile.TimeSlot20 = TimeSlot20; profile.TimeSlot21 = TimeSlot21; profile.TimeSlot22 = TimeSlot22; profile.TimeSlot23 = TimeSlot23; profile.TimeSlot24 = TimeSlot24; Db.SaveChanges(); success = true; } } else { //var haveRecord = Db.NotificationProfile.Where(p => p.UserID == UserId && p.ActivityGroupID == StepId && p.ProcessID == ProcessId && (bool)p.GetType().GetProperty("TimeSlot" + timeSlot).GetValue(p) == true).FirstOrDefault(); string employeeID = ""; if (UserId == "DEFAULT") { employeeID = UserId; } else { var UserRecord = Db.vUser.Where(p => p.UserID == UserId).FirstOrDefault(); employeeID = UserRecord.EmployeeID; } NotificationProfile profile = new NotificationProfile(); profile.ProcessID = ProcessId; profile.ActivityGroupID = StepId; profile.UserID = UserId; profile.EmployeeID = employeeID; profile.cc = CC; profile.bcc = BCC; profile.WeekDay1 = WeekDay1; profile.WeekDay2 = WeekDay2; profile.WeekDay3 = WeekDay3; profile.WeekDay4 = WeekDay4; profile.WeekDay5 = WeekDay5; profile.WeekDay6 = WeekDay6; profile.WeekDay7 = WeekDay7; profile.TimeSlot1 = TimeSlot1; profile.TimeSlot2 = TimeSlot2; profile.TimeSlot3 = TimeSlot3; profile.TimeSlot4 = TimeSlot4; profile.TimeSlot5 = TimeSlot5; profile.TimeSlot6 = TimeSlot6; profile.TimeSlot7 = TimeSlot7; profile.TimeSlot8 = TimeSlot8; profile.TimeSlot9 = TimeSlot9; profile.TimeSlot10 = TimeSlot10; profile.TimeSlot11 = TimeSlot11; profile.TimeSlot12 = TimeSlot12; profile.TimeSlot13 = TimeSlot13; profile.TimeSlot14 = TimeSlot14; profile.TimeSlot15 = TimeSlot15; profile.TimeSlot16 = TimeSlot16; profile.TimeSlot17 = TimeSlot17; profile.TimeSlot18 = TimeSlot18; profile.TimeSlot19 = TimeSlot19; profile.TimeSlot20 = TimeSlot20; profile.TimeSlot21 = TimeSlot21; profile.TimeSlot22 = TimeSlot22; profile.TimeSlot23 = TimeSlot23; profile.TimeSlot24 = TimeSlot24; profile.CreatedOn = DateTime.Now; Db.NotificationProfile.Add(profile); Db.SaveChanges(); success = true; } } catch (Exception ex) { throw ex; } return(Tuple.Create(success, msg)); }
private static void ProcessOneEntity(NotificationProfile config, DbContext commonContext, Guid entityId, Guid operatorUserId, string relationEntityName , Dictionary <string, object> oldValue, int languageId, bool isSys) { if (commonContext == null) { commonContext = DynamicModelBuilder.CreateDataSource(); } var entityInfo = MetadataProvider.Instance.EntiyMetadata.Where(c => c.EntityId == config.ProfileVariables.First().NotificationVariable.EntityId).First(); var entityTypeId = entityInfo.EntityId; FilterCriteriaHelper helper = new FilterCriteriaHelper(oldValue, entityTypeId); CriteriaOperator theOperator = helper.GeneratrCriteria(config.Criterion); string primaryKey = string.Empty; primaryKey = entityInfo.Attributes.Where(c => c.IsPKAttribute == true).First().TableColumnName; Type entityInfoType = DynamicTypeBuilder.Instance.GetDynamicType(entityInfo.Name); //fetch data if (entityId != Guid.Empty) { theOperator = new GroupOperator(GroupOperatorType.And, theOperator, GetKeyOperator(entityId, primaryKey)); } IQueryable query = commonContext.Set(entityInfoType).AsQueryable(); try { System.Linq.Expressions.Expression expression = GetExpression(query, theOperator); query = query.Provider.CreateQuery(expression); IEnumerator iter = query.GetEnumerator(); var tempEntityList = new ArrayList(); while (iter.MoveNext()) { tempEntityList.Add(iter.Current); } Type attentionType = DynamicTypeBuilder.Instance.GetDynamicType("Notification"); var entityList = new ArrayList(); foreach (var item in tempEntityList) { bool isExist = false; if (entityId == Guid.Empty && isSys) { IQueryable notificationQuery = commonContext.Set(attentionType).AsQueryable(); BinaryOperator binaryOperator = new BinaryOperator(); binaryOperator.OperatorType = BinaryOperatorType.Equal; binaryOperator.LeftOperand = ConstantValue.Parse("ObjectId"); binaryOperator.RightOperand = (Guid)item.GetType().GetProperty(primaryKey).GetValue(item, null); System.Linq.Expressions.Expression attentionException = GetExpression(notificationQuery, binaryOperator); notificationQuery = notificationQuery.Provider.CreateQuery(attentionException); IEnumerator notificationIter = notificationQuery.GetEnumerator(); while (notificationIter.MoveNext()) { if (notificationIter.Current != null) { isExist = true; continue; } } } if (!isExist) { entityList.Add(item); } } if (entityList.Count <= 0) { return; } CreateNotificationItem(entityList, primaryKey, entityInfo.Name, config, operatorUserId, relationEntityName, oldValue, languageId); } catch { } }
private static void ProcessOneEntityData(object entityDataItem, string primaryKey, string entityName, DbContext context, NotificationProfile config, Guid operatorUserId, string relationEntityName , Dictionary <string, object> oldValue, int languageId) { string templet = config.NotificationTemplate.SubjectTemplate; List <NotificationVariable> notificationVariables = MetadataProvider.Instance.MetadataServiceClient.GetNotificationVariablesById(config.ProfileVariables.First().NotificationVariable.NotificationVariableId); Type recipientType = DynamicTypeBuilder.Instance.GetDynamicType("NotificationRecipient"); Type notificationType = DynamicTypeBuilder.Instance.GetDynamicType("Notification"); object notificationInfo = Activator.CreateInstance(notificationType); Guid notificationId = Guid.NewGuid(); SetPropertyValue(notificationInfo, "NotificationId", notificationId); Guid objectId = (Guid)GetPropertyValue(entityDataItem, primaryKey); SetPropertyValue(notificationInfo, "ObjectId", objectId); Guid relationId = Guid.Empty; Dictionary <string, object> variablesValues = GetVariablesValues(notificationVariables, objectId, relationEntityName, ref relationId, oldValue, languageId); if (config.SubjectTemplateId != null && config.SubjectNotificationTemplate != null) { string subjectTemplet = config.SubjectNotificationTemplate.SubjectTemplate; SetPropertyValue(notificationInfo, "Subject", BuildTemplate(subjectTemplet, variablesValues)); } else { SetPropertyValue(notificationInfo, "Subject", entityName); } SetPropertyValue(notificationInfo, "Body", BuildTemplate(templet, variablesValues)); string notificationUrl = entityName + "#" + objectId; string objectType = entityName; if (!string.IsNullOrEmpty(relationEntityName) && relationEntityName != entityName && relationId != Guid.Empty) { notificationUrl = relationEntityName + "#" + relationId; objectType = entityName + "-" + relationEntityName; } SetPropertyValue(notificationInfo, "NotificationUrl", notificationUrl); SetPropertyValue(notificationInfo, "ObjectType", objectType); if (operatorUserId != Guid.Empty) { SetPropertyValue(notificationInfo, "CreatedById", operatorUserId); SetPropertyValue(notificationInfo, "ModifiedById", operatorUserId); } SetPropertyValue(notificationInfo, "CreatedOn", DateTime.Now); SetPropertyValue(notificationInfo, "ModifiedOn", DateTime.Now); IList recipientList = GetPropertyValue(notificationInfo, "NotificationRecipients") as IList; List <Guid> userList = GetUserList(config, variablesValues, operatorUserId); if (userList.Count > 0) { context.Set(notificationType).Add(notificationInfo); } foreach (var user in userList) { var recipientInfo = Activator.CreateInstance(recipientType); SetPropertyValue(recipientInfo, "NotificationRecipientId", Guid.NewGuid()); SetPropertyValue(recipientInfo, "NotificationId", notificationId); SetPropertyValue(recipientInfo, "RecipientId", user); SetPropertyValue(recipientInfo, "NotificationStatus", "NotSend"); context.Set(recipientType).Add(recipientInfo); recipientList.Add(recipientInfo); } }