89 lines
2.0 KiB
C#
89 lines
2.0 KiB
C#
using Microsoft.SharePoint;
|
|
using SPSolutions.SharePoint.Logging;
|
|
using System;
|
|
using System.Collections;
|
|
namespace SPSolutions.SharePoint.Alerts.Tokenization
|
|
{
|
|
public class ListTokenizer : TokenizerDecorator
|
|
{
|
|
private SPListItem m_item;
|
|
private SPList m_list;
|
|
private string m_eventXml;
|
|
public ListTokenizer()
|
|
{
|
|
}
|
|
public ListTokenizer(SPList list, SPListItem item)
|
|
{
|
|
this.m_list = list;
|
|
this.m_item = item;
|
|
}
|
|
public ListTokenizer(string eventXml)
|
|
{
|
|
this.m_eventXml = eventXml;
|
|
}
|
|
public override void PopulateTokenValues()
|
|
{
|
|
base.PopulateTokenValues();
|
|
this.AddedBehavior();
|
|
}
|
|
private void AddedBehavior()
|
|
{
|
|
string text = "'Item Name empty or not found'";
|
|
if (this.m_item != null)
|
|
{
|
|
try
|
|
{
|
|
text = this.m_item.Title;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
if (string.IsNullOrEmpty(text))
|
|
{
|
|
try
|
|
{
|
|
text = this.m_item.Name;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(text) && this.m_item.ContentType.Name == "Message")
|
|
{
|
|
try
|
|
{
|
|
text = this.m_item["Discussion Subject"].ToString();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
TraceProvider.WriteTrace(0u, TraceProvider.TraceSeverity.Medium, Guid.Empty, "w3wp.exe", "Alert Manager", "Custom Alert Handler", "Unable to get Discussion Subject. AlertName token set to " + text);
|
|
}
|
|
}
|
|
base.Tokens["AlertName"] = text;
|
|
base.Tokens["Title"] = text;
|
|
return;
|
|
}
|
|
if (!string.IsNullOrEmpty(this.m_eventXml))
|
|
{
|
|
Hashtable tokensForeventXml = SPAlertTemplateUtil.GetTokensForeventXml(this.m_eventXml);
|
|
if (tokensForeventXml.Count > 0)
|
|
{
|
|
if (tokensForeventXml.ContainsKey("Title"))
|
|
{
|
|
text = tokensForeventXml["Title"].ToString();
|
|
}
|
|
if (string.IsNullOrEmpty(text) && tokensForeventXml.ContainsKey("Name"))
|
|
{
|
|
text = tokensForeventXml["Name"].ToString();
|
|
}
|
|
}
|
|
base.Tokens["AlertName"] = text;
|
|
base.Tokens["Title"] = text;
|
|
return;
|
|
}
|
|
base.Tokens["AlertName"] = text;
|
|
base.Tokens["Title"] = text;
|
|
}
|
|
}
|
|
}
|