using Microsoft.SharePoint; using System; using System.Collections; using System.IO; namespace SPSolutions.SharePoint.Alerts.Tokenization { public class ListItemTokenizer : TokenizerDecorator { private SPListItem m_item; private string m_eventXml = string.Empty; public ListItemTokenizer() { } public ListItemTokenizer(SPListItem item) { this.m_item = item; } public ListItemTokenizer(string eventXml) { this.m_eventXml = eventXml; } public override void PopulateTokenValues() { base.PopulateTokenValues(); this.AddedBehavior(); } private void AddedBehavior() { writeToFile("Inside added behaviour"); string text = string.Empty; string text2 = string.Empty; string text3 = string.Empty; string arg = string.Empty; if (this.m_item != null) { Hashtable tokensForListItem = SPAlertTemplateUtil.GetTokensForListItem(this.m_item); writeToFile("got the list of the tokens"); foreach (DictionaryEntry dictionaryEntry in tokensForListItem) { base.Tokens[(string)dictionaryEntry.Key] = tokensForListItem[(string)dictionaryEntry.Key]; } text = this.m_item.ID.ToString(); text3 = this.m_item.Title; if (this.m_item.ContentType != null && !string.IsNullOrEmpty(this.m_item.ContentType.DisplayFormUrl)) { writeToFile("find the content type"); arg = this.m_item.ContentType.DisplayFormUrl; } else { writeToFile("do not find content types"); writeToFile("List of forms :" + this.m_item.ParentList.Forms.Count); writeToFile("List of forms :" + this.m_item.ParentList.Forms[0].Url); arg = this.m_item.ParentList.Forms[0].Url; } text2 = string.Format("{0}/{1}?ID={2}", this.m_item.Web.Url, arg, text.ToString()); } else { if (!string.IsNullOrEmpty(this.m_eventXml)) { base.Tokens["Body"] = ""; base.Tokens["Modified"] = DateTime.Now.ToString(); text = " "; text3 = " "; text2 = " "; base.Tokens["Expires"] = " "; base.Tokens["Created"] = " "; base.Tokens["Attachments"] = " "; Hashtable tokensForeventXml = SPAlertTemplateUtil.GetTokensForeventXml(this.m_eventXml); if (tokensForeventXml.Count > 0) { foreach (DictionaryEntry dictionaryEntry2 in tokensForeventXml) { base.Tokens[dictionaryEntry2.Key] = dictionaryEntry2.Value; } if (tokensForeventXml.ContainsKey("ID")) { text = (string.IsNullOrEmpty(tokensForeventXml["ID"].ToString()) ? " " : tokensForeventXml["ID"].ToString()); } if (tokensForeventXml.ContainsKey("Title")) { text3 = (string.IsNullOrEmpty(tokensForeventXml["Title"].ToString()) ? " " : tokensForeventXml["Title"].ToString()); } } } } base.Tokens["ItemId"] = text; base.Tokens["ItemTitle"] = text3; base.Tokens["ItemDisplayFormAbsoluteUrl"] = text2; base.Tokens["ItemLink"] = string.Format("{0}", text3, text2); } public void writeToFile(string msg) { try { //string filePath = getFilePath(); //if (string.IsNullOrEmpty(filePath)) //{ // return; //} //msg = string.Format("{0}: {1}{2}", DateTime.Now, msg, Environment.NewLine); //File.AppendAllText(filePath, msg); FileStream fs = null; StreamWriter sw = null; try { string _strPath = "C://temp/LogsAlerts.txt"; // string ColumnNames = "SiteName,PageName,Event/Method,QueryDetails,QueryLog,Date"; fs = File.Open(_strPath, FileMode.Append, FileAccess.Write); sw = new StreamWriter(fs); sw.WriteLine(msg + "\n"); //sw.Close(); } catch (Exception) { // } finally { if (sw != null) { sw.Close(); } if (fs != null) { fs.Close(); } } } catch { } } } }