internal bool IsValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { if (!this.CustomEvaluation) { if (this.conditions != null) { foreach (Condition condition in this.conditions) { if (condition != null) { if (!condition.isValid(item, eventType, properties)) { return(false); } } } } return(true); } else { ConditionGroup group = new ConditionGroup(this.CustomEvaluationData); return(group.isValid(item, eventType, properties)); } }
internal bool SendMail(Alert alert, AlertEventType eventType, SPListItem item) { //bool succes = true; //try //{ // MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); // string toAddress = GetRecipientEmailAddresses(alert.ToAddress, item); // string ccAddress = GetRecipientEmailAddresses(alert.CcAddress, item); // string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item); // string subject = ReplacePlaceHolders(mtObject.Template.Subject, item); // string body = ReplacePlaceHolders(mtObject.Template.Body, item); // string smtpSName = GetSMTPServer(item); // SendMail(smtpSName, // toAddress, // fromAddress, // ccAddress, // subject, // body, // null); //} //catch { succes = false; } //return succes; return(SendMail(alert, eventType, item, string.Empty)); }
private void CreateDelayedAlert(Alert alert, AlertEventType eventType, SPItemEventProperties properties, AlertManager alertManager) { //, SPWeb web try { if (!alert.SendAsSingleMessage) { Notifications notificationSender = new Notifications(); //Need to get the Alert instances MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); //string subject = mtObject.Template.Subject; //string body = mtObject.Template.Body + "<br>" + "<br>" + FinalBody; string subject = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem); string body = notificationSender.ReplacePlaceHolders(mtObject.Template.Body, properties.ListItem) + "<br>" + "<br>" + FinalBody; string parentItemId = Convert.ToString(properties.ListItem.ID); DelayedAlert dAlert = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType); alertManager.AddDelayedAlert(dAlert); } else { Notifications notificationSender = new Notifications(); MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); string subject = properties.ListTitle; string body = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem) + "<br>" + "<br>" + notificationSender.ReplacePlaceHolders(mtObject.Template.Body, properties.ListItem) + "<br>" + "<br>" + FinalBody; string parentItemId = Convert.ToString(properties.ListItem.ID); DelayedAlert dAlert = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType); alertManager.AddDelayedAlert(dAlert); } } catch { } }
public AlertEventType GetAlertEventTypeRecord(string recordID, string UserSNo) { AlertEventType alertEventType = new AlertEventType(); SqlDataReader dr = null; try { SqlParameter[] Parameters = { new SqlParameter("@SNo", (recordID)), new SqlParameter("@UserID", Convert.ToInt32(UserSNo)) }; dr = SqlHelper.ExecuteReader(ReadConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "GetRecordAlertEventType", Parameters); if (dr.Read()) { alertEventType.SNo = Convert.ToInt32(dr["SNo"]); alertEventType.AlertEventTypeName = Convert.ToString(dr["AlertEventTypeName"]); alertEventType.UpdatedBy = dr["UpdatedBy"].ToString(); alertEventType.CreatedBy = dr["CreatedBy"].ToString(); alertEventType.IsActive = Convert.ToBoolean(dr["IsActive"]); alertEventType.Active = dr["Active"].ToString(); } } catch (Exception ex)// (Exception ex) { dr.Close(); } return(alertEventType); }
public DelayedAlert(string subject, string body, string parentAlertId, string parentItemId, AlertEventType eventType) { this.subject = subject; this.body = body; this.parentAlertID = parentAlertId; this.alertType = eventType; this.parentItemID = parentItemId; }
public DelayedAlert(string subject,string body,string parentAlertId,string parentItemId, AlertEventType eventType) { this.subject = subject; this.body = body; this.parentAlertID = parentAlertId; this.alertType = eventType; this.parentItemID = parentItemId; }
/// <summary> /// Get the alerts based on event type /// </summary> /// <param name="listItem"></param> /// <param name="eventType"></param> /// <param name="mTManager"></param> /// <returns></returns> internal IList <Alert> GetAlertForList(SPListItem listItem, AlertEventType eventType, MailTemplateManager mTManager) { IList <Alert> alerts = new List <Alert>(); try { if (alertList != null) { //TODO: write a caml query to get the alerts based eventtype StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<Where>"); stringBuilder.AppendFormat( "<And>" + "<And>" + "<And>" + "<Eq>" + "<FieldRef Name=\"{0}\"/>" + "<Value Type=\"Text\">{1}</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name=\"{2}\"/>" + "<Value Type=\"Text\">{3}</Value>" + "</Eq>" + "</And>" + "<Contains>" + "<FieldRef Name=\"{4}\"/>" + "<Value Type=\"Choice\">{5}</Value>" + "</Contains>" + "</And>" + "<Or>" + "<Eq>" + "<FieldRef Name=\"{6}\"/>" + "<Value Type=\"Text\">0</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name=\"{6}\"/>" + "<Value Type=\"Text\">{7}</Value>" + "</Eq>" + "</Or>" + "</And>", new object[] { "WebID", listItem.ParentList.ParentWeb.ID, "ListID", listItem.ParentList.ID, "EventType", eventType, "ItemID", "0" }); stringBuilder.Append("</Where>"); SPQuery query = new SPQuery(); query.Query = stringBuilder.ToString(); SPListItemCollection lItemCollection = alertList.GetItems(query); foreach (SPListItem item in lItemCollection) { alerts.Add(new Alert(item, mTManager)); } } } catch { } return(alerts); }
/// <summary> /// Get the alerts based on event type /// </summary> /// <param name="listItem"></param> /// <param name="eventType"></param> /// <param name="mTManager"></param> /// <returns></returns> internal IList<Alert> GetAlertForList(SPListItem listItem, AlertEventType eventType, MailTemplateManager mTManager) { IList<Alert> alerts = new List<Alert>(); try { if (alertList != null) { //TODO: write a caml query to get the alerts based eventtype StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("<Where>"); stringBuilder.AppendFormat( "<And>" + "<And>" + "<And>" + "<Eq>" + "<FieldRef Name=\"{0}\"/>" + "<Value Type=\"Text\">{1}</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name=\"{2}\"/>" + "<Value Type=\"Text\">{3}</Value>" + "</Eq>" + "</And>" + "<Contains>" + "<FieldRef Name=\"{4}\"/>" + "<Value Type=\"Choice\">{5}</Value>" + "</Contains>" + "</And>" + "<Or>" + "<Eq>" + "<FieldRef Name=\"{6}\"/>" + "<Value Type=\"Text\">0</Value>" + "</Eq>" + "<Eq>" + "<FieldRef Name=\"{6}\"/>" + "<Value Type=\"Text\">{7}</Value>" + "</Eq>" + "</Or>" + "</And>", new object[] { "WebID", listItem.ParentList.ParentWeb.ID, "ListID", listItem.ParentList.ID, "EventType", eventType, "ItemID", "0" }); stringBuilder.Append("</Where>"); SPQuery query = new SPQuery(); query.Query = stringBuilder.ToString(); SPListItemCollection lItemCollection = alertList.GetItems(query); foreach (SPListItem item in lItemCollection) { alerts.Add(new Alert(item, mTManager)); } } } catch { } return alerts; }
private void ExecuteReceivedEvent(AlertEventType eventType, SPItemEventProperties properties) { LogManager.write("Entered in to ExecuteReceivedEvent with event type" + eventType); try { using (SPWeb web = properties.OpenWeb()) { //TODO we have to check is feature activated for this site or not AlertManager alertManager = new AlertManager(web.Site.Url); MailTemplateManager mailTemplateManager = new MailTemplateManager(web.Site.Url); IList <Alert> alerts = alertManager.GetAlertForList(properties.ListItem, eventType, mailTemplateManager); Notifications notifications = new Notifications(); foreach (Alert alert in alerts) { if (eventType != AlertEventType.DateColumn) { if (alert.IsValid(properties.ListItem, eventType, properties)) { try { if (alert.SendType == SendType.ImmediateAlways) { notifications.SendMail(alert, eventType, properties.ListItem, FinalBody); } else if (alert.SendType == SendType.ImmediateBusinessDays) { if (alert.ImmediateBusinessDays.Contains((WeekDays)DateTime.UtcNow.DayOfWeek)) { if (alert.BusinessStartHour <= Convert.ToInt32(DateTime.UtcNow.Hour) && alert.BusinessendtHour >= Convert.ToInt32(DateTime.UtcNow.Hour)) { notifications.SendMail(alert, eventType, properties.ListItem, FinalBody); } else { return; } } } else { CreateDelayedAlert(alert, eventType, properties, alertManager); } } catch { } } } } } } catch (System.Exception Ex) { LogManager.write("Error occured white excuting event receiver" + Ex.Message); } }
internal bool SendMail(Alert alert, AlertEventType eventType, SPListItem item, string strAfterProperties) { bool succes = true; string body = string.Empty; try { MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); List <Attachment> attachmentsToSend = null; if (mtObject.Template.InsertAttachments) { if (item.Attachments != null && item.Attachments.Count > 0) { if (attachmentsToSend == null) { attachmentsToSend = new List <Attachment>(); } foreach (string fileName in item.Attachments) { SPFile file = item.ParentList.ParentWeb.GetFile(item.Attachments.UrlPrefix + fileName); System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(file.OpenBinaryStream(), fileName, string.Empty); attachmentsToSend.Add(attachment); } } } string toAddress = GetRecipientEmailAddresses(alert.ToAddress, item); string ccAddress = GetRecipientEmailAddresses(alert.CcAddress, item); string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item); string subject = ReplacePlaceHolders(mtObject.Template.Subject, item); if (mtObject.Template.InsertUpdatedFields) { body = ReplacePlaceHolders(mtObject.Template.Body, item) + "<br>" + "<br>" + strAfterProperties; } else { body = ReplacePlaceHolders(mtObject.Template.Body, item); } string smtpSName = GetSMTPServer(item); SendMail(smtpSName, toAddress, fromAddress, ccAddress, subject, body, attachmentsToSend); } catch { succes = false; } return(succes); }
public DelayedAlert(SPListItem item) { try { this.subject = Convert.ToString(item[ListAndFieldNames.DelayedSubjectFieldName]); this.body = Convert.ToString(item[ListAndFieldNames.DelayedBodyFieldName]); SPFieldLookupValue lookupValue = new SPFieldLookupValue(item[ListAndFieldNames.DelayedAlertLookupFieldName].ToString()); this.parentAlertID = Convert.ToString(lookupValue.LookupId); this.alertType = (AlertEventType)Enum.Parse(typeof(AlertEventType), Convert.ToString(item[ListAndFieldNames.DelayedEventTypeFieldName])); this.item = item; this.id = Convert.ToString(item.ID); this.parentItemID = Convert.ToString(item[ListAndFieldNames.DelayedParentItemID]); } catch { } }
internal bool isValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { bool bReturn; if (evalType == GroupEvalType.And) { bReturn = true; } else { bReturn = false; } foreach (Condition cond in conditions) { bool cond_val = cond.isValid(item, eventType, properties); if (evalType == GroupEvalType.And && cond_val == false) { return(false); } if (evalType == GroupEvalType.Or && cond_val == true) { return(true); } } foreach (ConditionGroup grp in sub_groups) { bool grp_val = grp.isValid(item, eventType, properties); if (evalType == GroupEvalType.And && grp_val == false) { return(false); } if (evalType == GroupEvalType.Or && grp_val == true) { return(true); } } return(bReturn); }
public List <string> UpdateAlertEventType(AlertEventType alertEventType) { //validate Business Rule List <string> ErrorMessage = new List <string>(); BaseBusiness baseBusiness = new BaseBusiness(); SqlParameter[] Parameters = { new SqlParameter("@AlertSNo", alertEventType.SNo), new SqlParameter("@AlertEventTypeName", alertEventType.AlertEventTypeName), new SqlParameter("@UpdatedBy", alertEventType.UpdatedBy), new SqlParameter("@IsActive", alertEventType.IsActive), }; //DataSet ds = SqlHelper.ExecuteDataset(DMLConnectionString.WebConfigConnectionString, CommandType.StoredProcedure, "UpdateAlertEventType", Parameters); int ret = (int)SqlHelper.ExecuteScalar(DMLConnectionString.WebConfigConnectionString, "UpdateAlertEventType", Parameters); if (ret > 0) { if (ret > 1000) { //For Customised Validation Messages like 'Record Already Exists' etc string serverErrorMessage = baseBusiness.ReadServerErrorMessages(ret, "AlertEventType"); if (!string.IsNullOrEmpty(serverErrorMessage)) { ErrorMessage.Add(serverErrorMessage); } } else { //For DataBase Exceptions like 'Foreign Key refrence Errors' etc string dataBaseExceptionMessage = baseBusiness.ReadServerErrorMessages(ret, baseBusiness.DatabaseExceptionFileName); if (!string.IsNullOrEmpty(dataBaseExceptionMessage)) { ErrorMessage.Add(dataBaseExceptionMessage); } } } return(ErrorMessage); }
internal bool isValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { SPList list = item.ParentList; if (list == null) { return(false); } SPField field = list.Fields.TryGetFieldByStaticName(this.fieldName); ConditionValueType valType = GetConditionValueType(); if (field != null && valType != ConditionValueType.Invalid) { object fieldValue = item[this.fieldName]; if (eventType == AlertEventType.ItemUpdated && properties != null) { if (this.comparisionType != ConditionComparisionType.Always) { //if (!properties.AfterProperties.ChangedProperties.Contains(this.fieldName)) if (Convert.ToString(item[this.fieldName]) .Equals(Convert.ToString(properties.AfterProperties[this.fieldName]), StringComparison.CurrentCultureIgnoreCase)) { return(false); } else { fieldValue = properties.AfterProperties[this.fieldName]; } } } return(MatchItemValueBasedOnOperatorAndValueType(fieldValue, field.FieldValueType, eventType, item.ParentList.ParentWeb)); } return(false); }
internal bool isValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { bool bReturn; if (evalType == GroupEvalType.And) { bReturn = true; } else { bReturn = false; } foreach (Condition cond in conditions) { bool cond_val = cond.isValid(item, eventType, properties); if (evalType == GroupEvalType.And && cond_val == false) return false; if (evalType == GroupEvalType.Or && cond_val == true) return true; } foreach (ConditionGroup grp in sub_groups) { bool grp_val = grp.isValid(item, eventType, properties); if (evalType == GroupEvalType.And && grp_val == false) return false; if (evalType == GroupEvalType.Or && grp_val == true) return true; } return bReturn; }
internal bool IsValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { if (!this.CustomEvaluation) { if (this.conditions != null) { foreach (Condition condition in this.conditions) { if (condition != null) { if (!condition.isValid(item, eventType, properties)) { return false; } } } } return true; } else { ConditionGroup group = new ConditionGroup(this.CustomEvaluationData); return group.isValid(item, eventType, properties); } }
public MailTemplateUsageObject GetMailTemplateUsageObjectForEventType( AlertEventType eventType) { return this.templateManager.GetTemplateUsageObjectForAlert(this.Id, eventType); }
private void CreateDelayedAlert(Alert alert, AlertEventType eventType, SPItemEventProperties properties, AlertManager alertManager) { //, SPWeb web try { if (!alert.SendAsSingleMessage) { Notifications notificationSender = new Notifications(); //Need to get the Alert instances MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); //string subject = mtObject.Template.Subject; //string body = mtObject.Template.Body + "<br>" + "<br>" + FinalBody; string subject = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem); string body = notificationSender.ReplacePlaceHolders(mtObject.Template.Body, properties.ListItem) + "<br>" + "<br>" + FinalBody; string parentItemId = Convert.ToString(properties.ListItem.ID); DelayedAlert dAlert = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType); alertManager.AddDelayedAlert(dAlert); } else { Notifications notificationSender = new Notifications(); MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); string subject = properties.ListTitle; string body = notificationSender.ReplacePlaceHolders(mtObject.Template.Subject, properties.ListItem) + "<br>" + "<br>" +notificationSender.ReplacePlaceHolders(mtObject.Template.Body,properties.ListItem) + "<br>" + "<br>" + FinalBody; string parentItemId = Convert.ToString(properties.ListItem.ID); DelayedAlert dAlert = new DelayedAlert(subject, body, alert.Id, parentItemId, eventType); alertManager.AddDelayedAlert(dAlert); } } catch { } }
private void ExecuteReceivedEvent(AlertEventType eventType, SPItemEventProperties properties) { LogManager.write("Entered in to ExecuteReceivedEvent with event type" + eventType); try { using (SPWeb web = properties.OpenWeb()) { //TODO we have to check is feature activated for this site or not AlertManager alertManager = new AlertManager(web.Site.Url); MailTemplateManager mailTemplateManager = new MailTemplateManager(web.Site.Url); IList<Alert> alerts = alertManager.GetAlertForList(properties.ListItem ,eventType, mailTemplateManager); Notifications notifications = new Notifications(); foreach (Alert alert in alerts) { if (eventType != AlertEventType.DateColumn) { if (alert.IsValid(properties.ListItem, eventType, properties)) { try { if (alert.SendType == SendType.ImmediateAlways) { notifications.SendMail(alert, eventType, properties.ListItem, FinalBody); } else if (alert.SendType == SendType.ImmediateBusinessDays) { if (alert.ImmediateBusinessDays.Contains((WeekDays)DateTime.UtcNow.DayOfWeek)) { if (alert.BusinessStartHour <= Convert.ToInt32(DateTime.UtcNow.Hour) && alert.BusinessendtHour >= Convert.ToInt32(DateTime.UtcNow.Hour)) { notifications.SendMail(alert, eventType, properties.ListItem, FinalBody); } else { return; } } } else { CreateDelayedAlert(alert, eventType, properties, alertManager); } } catch { } } } } } } catch (System.Exception Ex) { LogManager.write("Error occured white excuting event receiver" + Ex.Message); } }
internal MailTemplateUsageObject GetTemplateUsageObjectForAlert(string alertId, AlertEventType eventType) { MailTemplateUsageObject mObject = null; try { SPQuery query = new SPQuery(); string strQuery = string.Format("<Where><And><Eq><FieldRef Name=\"{0}\"/><Value Type=\"Choice\">{1}</Value></Eq><Eq><FieldRef Name=\"Alert\" LookupId=\"TRUE\"/><Value Type=\"Lookup\">{2}</Value></Eq></And></Where>", "EventType", eventType.ToString(), alertId); query.Query = strQuery; SPListItemCollection listItemcollection = mailTemlateUsageList.GetItems(query); if (listItemcollection != null && listItemcollection.Count > 0) { mObject = GetMailTemplateUsageObjectFromListItem(listItemcollection[0]); } } catch{} return mObject; }
internal MailTemplateUsageObject GetTemplateUsageObjectForAlert(string alertId, AlertEventType eventType) { MailTemplateUsageObject mObject = null; try { SPQuery query = new SPQuery(); string strQuery = string.Format("<Where><And><Eq><FieldRef Name=\"{0}\"/><Value Type=\"Choice\">{1}</Value></Eq><Eq><FieldRef Name=\"Alert\" LookupId=\"TRUE\"/><Value Type=\"Lookup\">{2}</Value></Eq></And></Where>", "EventType", eventType.ToString(), alertId); query.Query = strQuery; SPListItemCollection listItemcollection = mailTemlateUsageList.GetItems(query); if (listItemcollection != null && listItemcollection.Count > 0) { mObject = GetMailTemplateUsageObjectFromListItem(listItemcollection[0]); } } catch {} return(mObject); }
internal bool isValid(SPListItem item, AlertEventType eventType, SPItemEventProperties properties) { SPList list = item.ParentList; if (list == null) return false; SPField field = list.Fields.TryGetFieldByStaticName(this.fieldName); ConditionValueType valType = GetConditionValueType(); if (field != null && valType != ConditionValueType.Invalid) { object fieldValue = item[this.fieldName]; if (eventType == AlertEventType.ItemUpdated && properties !=null) { if (this.comparisionType != ConditionComparisionType.Always) { //if (!properties.AfterProperties.ChangedProperties.Contains(this.fieldName)) if (Convert.ToString(item[this.fieldName]) .Equals(Convert.ToString(properties.AfterProperties[this.fieldName]), StringComparison.CurrentCultureIgnoreCase)) { return false; } else { fieldValue = properties.AfterProperties[this.fieldName]; } } } return MatchItemValueBasedOnOperatorAndValueType(fieldValue, field.FieldValueType, eventType,item.ParentList.ParentWeb); } return false; }
public bool MatchItemValueBasedOnOperatorAndValueType(object fieldValue, Type fieldValueType, AlertEventType eventType, SPWeb web) { //SPWeb web = item.ParentList.ParentWeb; //string strComputedValue = GetConditionComputedValue(item); if (fieldValue != null && !string.IsNullOrEmpty(fieldValue.ToString())) { if (fieldValueType == (typeof(SPFieldUrlValue))) { SPFieldUrlValue fieldUrlValue = new SPFieldUrlValue(fieldValue.ToString()); bool isDescMatched = CompareValuesBasedOnOperator(fieldUrlValue.Description, this.comparisionOperator, this.strValue); bool isUrlMatched = CompareValuesBasedOnOperator(fieldUrlValue.Url, this.comparisionOperator, strValue); return isDescMatched || isUrlMatched; } else if (fieldValueType == (typeof(SPFieldUserValue))) { //SPFieldUserValue fieldUserValue = new SPFieldUserValue(SPContext.Current.Web, fieldValue.ToString()); SPFieldUserValue fieldUserValue = new SPFieldUserValue(web, fieldValue.ToString()); string userLoginName = fieldUserValue.User.LoginName; string userDispalyName = fieldUserValue.User.Name; bool isLoginMatched = CompareValuesBasedOnOperator(userLoginName, this.comparisionOperator, strValue); bool isDisplayNameMatched = CompareValuesBasedOnOperator(userLoginName, this.comparisionOperator, strValue); return isLoginMatched || isDisplayNameMatched; } else if (fieldValueType == (typeof(SPFieldUserValueCollection))) { //SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(SPContext.Current.Web, fieldValue.ToString()); SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(web, fieldValue.ToString()); string userLoginNames = ""; string userDispalyNames = ""; foreach (SPFieldUserValue userValue in fieldUserValueCollection) { userLoginNames += userValue.LookupValue + ValueCollectionSeperator; if (userValue.User != null) userDispalyNames += userValue.User.Name + ValueCollectionSeperator; } userLoginNames = userLoginNames.TrimEnd(ValueCollectionSeperator.ToCharArray()); userDispalyNames = userDispalyNames.TrimEnd(ValueCollectionSeperator.ToCharArray()); bool isLoginMatched = CompareValuesBasedOnOperator(userLoginNames, this.comparisionOperator, strValue); bool isDisplayNameMatched = CompareValuesBasedOnOperator(userLoginNames, this.comparisionOperator, strValue); return isLoginMatched || isDisplayNameMatched; } else if (fieldValueType == (typeof(SPFieldLookupValue))) { SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(fieldValue.ToString()); string strFieldValue = fieldLookupValue.LookupValue; return CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue); } else if (fieldValueType == (typeof(SPFieldLookupValueCollection))) { SPFieldLookupValueCollection fieldLookupValueCollection = new SPFieldLookupValueCollection(fieldValue.ToString()); string strFieldValue = ""; foreach (SPFieldLookupValue lookup in fieldLookupValueCollection) { strFieldValue += lookup.LookupValue + ValueCollectionSeperator; } strFieldValue = strFieldValue.TrimEnd(ValueCollectionSeperator.ToCharArray()); return CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue); } else if (fieldValueType == (typeof(DateTime))) { DateTime sourceDT = DateTime.Parse(fieldValue.ToString()); DateTime targetDT = new DateTime(); if (DateTime.TryParse(strValue, out targetDT)) { switch (this.comparisionOperator) { case Operators.Eq: return sourceDT == targetDT; case Operators.Neq: return sourceDT != targetDT; case Operators.Gt: return sourceDT > targetDT; case Operators.Geq: return sourceDT >= targetDT; case Operators.Lt: return sourceDT < targetDT; case Operators.Leq: return sourceDT <= targetDT; default: return false; } } else { return false; } } else if (fieldValueType == (typeof(int))) { int sourceInt = int.Parse(fieldValue.ToString()); int targetInt; if (Int32.TryParse(strValue, out targetInt)) { switch (this.comparisionOperator) { case Operators.Eq: return sourceInt == targetInt; case Operators.Neq: return sourceInt != targetInt; case Operators.Gt: return sourceInt > targetInt; case Operators.Geq: return sourceInt >= targetInt; case Operators.Lt: return sourceInt < targetInt; case Operators.Leq: return sourceInt <= targetInt; default: return false; } } else { return false; } } else if (fieldValueType == (typeof(Boolean))) { bool sourceBool = Boolean.Parse(fieldValue.ToString()); bool targetBool = false; if (strValue.Equals("True", StringComparison.InvariantCultureIgnoreCase) || strValue.Equals("Yes", StringComparison.InvariantCultureIgnoreCase)) { targetBool = true; } else if (strValue.Equals("False", StringComparison.InvariantCultureIgnoreCase) || strValue.Equals("No", StringComparison.InvariantCultureIgnoreCase)) { targetBool = false; } else { return false; } switch (this.comparisionOperator) { case Operators.Eq: return sourceBool == targetBool; case Operators.Neq: return sourceBool != targetBool; case Operators.Contains: return sourceBool == targetBool; case Operators.NotContains: return sourceBool != targetBool; default: return false; } } else // default matching will be performed with string type { string strFieldValue = fieldValue.ToString(); return CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue); } } else { return false; } }
public MailTemplateUsageObject GetMailTemplateUsageObjectForEventType(AlertEventType eventType) { return(this.templateManager.GetTemplateUsageObjectForAlert(this.Id, eventType)); }
public bool MatchItemValueBasedOnOperatorAndValueType(object fieldValue, Type fieldValueType, AlertEventType eventType, SPWeb web) { //SPWeb web = item.ParentList.ParentWeb; //string strComputedValue = GetConditionComputedValue(item); if (fieldValue != null && !string.IsNullOrEmpty(fieldValue.ToString())) { if (fieldValueType == (typeof(SPFieldUrlValue))) { SPFieldUrlValue fieldUrlValue = new SPFieldUrlValue(fieldValue.ToString()); bool isDescMatched = CompareValuesBasedOnOperator(fieldUrlValue.Description, this.comparisionOperator, this.strValue); bool isUrlMatched = CompareValuesBasedOnOperator(fieldUrlValue.Url, this.comparisionOperator, strValue); return(isDescMatched || isUrlMatched); } else if (fieldValueType == (typeof(SPFieldUserValue))) { //SPFieldUserValue fieldUserValue = new SPFieldUserValue(SPContext.Current.Web, fieldValue.ToString()); SPFieldUserValue fieldUserValue = new SPFieldUserValue(web, fieldValue.ToString()); string userLoginName = fieldUserValue.User.LoginName; string userDispalyName = fieldUserValue.User.Name; bool isLoginMatched = CompareValuesBasedOnOperator(userLoginName, this.comparisionOperator, strValue); bool isDisplayNameMatched = CompareValuesBasedOnOperator(userLoginName, this.comparisionOperator, strValue); return(isLoginMatched || isDisplayNameMatched); } else if (fieldValueType == (typeof(SPFieldUserValueCollection))) { //SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(SPContext.Current.Web, fieldValue.ToString()); SPFieldUserValueCollection fieldUserValueCollection = new SPFieldUserValueCollection(web, fieldValue.ToString()); string userLoginNames = ""; string userDispalyNames = ""; foreach (SPFieldUserValue userValue in fieldUserValueCollection) { userLoginNames += userValue.LookupValue + ValueCollectionSeperator; if (userValue.User != null) { userDispalyNames += userValue.User.Name + ValueCollectionSeperator; } } userLoginNames = userLoginNames.TrimEnd(ValueCollectionSeperator.ToCharArray()); userDispalyNames = userDispalyNames.TrimEnd(ValueCollectionSeperator.ToCharArray()); bool isLoginMatched = CompareValuesBasedOnOperator(userLoginNames, this.comparisionOperator, strValue); bool isDisplayNameMatched = CompareValuesBasedOnOperator(userLoginNames, this.comparisionOperator, strValue); return(isLoginMatched || isDisplayNameMatched); } else if (fieldValueType == (typeof(SPFieldLookupValue))) { SPFieldLookupValue fieldLookupValue = new SPFieldLookupValue(fieldValue.ToString()); string strFieldValue = fieldLookupValue.LookupValue; return(CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue)); } else if (fieldValueType == (typeof(SPFieldLookupValueCollection))) { SPFieldLookupValueCollection fieldLookupValueCollection = new SPFieldLookupValueCollection(fieldValue.ToString()); string strFieldValue = ""; foreach (SPFieldLookupValue lookup in fieldLookupValueCollection) { strFieldValue += lookup.LookupValue + ValueCollectionSeperator; } strFieldValue = strFieldValue.TrimEnd(ValueCollectionSeperator.ToCharArray()); return(CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue)); } else if (fieldValueType == (typeof(DateTime))) { DateTime sourceDT = DateTime.Parse(fieldValue.ToString()); DateTime targetDT = new DateTime(); if (DateTime.TryParse(strValue, out targetDT)) { switch (this.comparisionOperator) { case Operators.Eq: return(sourceDT == targetDT); case Operators.Neq: return(sourceDT != targetDT); case Operators.Gt: return(sourceDT > targetDT); case Operators.Geq: return(sourceDT >= targetDT); case Operators.Lt: return(sourceDT < targetDT); case Operators.Leq: return(sourceDT <= targetDT); default: return(false); } } else { return(false); } } else if (fieldValueType == (typeof(int))) { int sourceInt = int.Parse(fieldValue.ToString()); int targetInt; if (Int32.TryParse(strValue, out targetInt)) { switch (this.comparisionOperator) { case Operators.Eq: return(sourceInt == targetInt); case Operators.Neq: return(sourceInt != targetInt); case Operators.Gt: return(sourceInt > targetInt); case Operators.Geq: return(sourceInt >= targetInt); case Operators.Lt: return(sourceInt < targetInt); case Operators.Leq: return(sourceInt <= targetInt); default: return(false); } } else { return(false); } } else if (fieldValueType == (typeof(Boolean))) { bool sourceBool = Boolean.Parse(fieldValue.ToString()); bool targetBool = false; if (strValue.Equals("True", StringComparison.InvariantCultureIgnoreCase) || strValue.Equals("Yes", StringComparison.InvariantCultureIgnoreCase)) { targetBool = true; } else if (strValue.Equals("False", StringComparison.InvariantCultureIgnoreCase) || strValue.Equals("No", StringComparison.InvariantCultureIgnoreCase)) { targetBool = false; } else { return(false); } switch (this.comparisionOperator) { case Operators.Eq: return(sourceBool == targetBool); case Operators.Neq: return(sourceBool != targetBool); case Operators.Contains: return(sourceBool == targetBool); case Operators.NotContains: return(sourceBool != targetBool); default: return(false); } } else // default matching will be performed with string type { string strFieldValue = fieldValue.ToString(); return(CompareValuesBasedOnOperator(strFieldValue, this.comparisionOperator, strValue)); } } else { return(false); } }
internal bool SendMail(Alert alert, AlertEventType eventType, SPListItem item) { //bool succes = true; //try //{ // MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); // string toAddress = GetRecipientEmailAddresses(alert.ToAddress, item); // string ccAddress = GetRecipientEmailAddresses(alert.CcAddress, item); // string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item); // string subject = ReplacePlaceHolders(mtObject.Template.Subject, item); // string body = ReplacePlaceHolders(mtObject.Template.Body, item); // string smtpSName = GetSMTPServer(item); // SendMail(smtpSName, // toAddress, // fromAddress, // ccAddress, // subject, // body, // null); //} //catch { succes = false; } //return succes; return SendMail(alert, eventType, item, string.Empty); }
internal bool SendMail(Alert alert, AlertEventType eventType, SPListItem item, string strAfterProperties) { bool succes = true; string body = string.Empty; try { MailTemplateUsageObject mtObject = alert.GetMailTemplateUsageObjectForEventType(eventType); List<Attachment> attachmentsToSend = null; if (mtObject.Template.InsertAttachments) { if (item.Attachments != null && item.Attachments.Count > 0) { if (attachmentsToSend == null) { attachmentsToSend = new List<Attachment>(); } foreach (string fileName in item.Attachments) { SPFile file = item.ParentList.ParentWeb.GetFile(item.Attachments.UrlPrefix + fileName); System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(file.OpenBinaryStream(), fileName, string.Empty); attachmentsToSend.Add(attachment); } } } string toAddress = GetRecipientEmailAddresses(alert.ToAddress, item); string ccAddress = GetRecipientEmailAddresses(alert.CcAddress, item); string fromAddress = GetRecipientEmailAddresses(alert.FromAdderss, item); string subject = ReplacePlaceHolders(mtObject.Template.Subject, item); if (mtObject.Template.InsertUpdatedFields) { body = ReplacePlaceHolders(mtObject.Template.Body, item) + "<br>" + "<br>" + strAfterProperties; } else { body = ReplacePlaceHolders(mtObject.Template.Body, item); } string smtpSName = GetSMTPServer(item); SendMail(smtpSName, toAddress, fromAddress, ccAddress, subject, body, attachmentsToSend); } catch { succes = false; } return succes; }