/*
OpenCollective - http://www.netbrick.net/
Copyright (c) 2004
by Tyler Jensen ( tylerj@netbrick.net ) of NetBrick Inc. ( http://www.netbrick.net )
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
*/
using System;
using System.Collections;
using System.Data;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Mail;
using OpenCollective.Data;
namespace OpenCollective.Engine
{
/// <summary>
/// Summary description for WikiWatch.
/// </summary>
public class WikiWatch
{
public WikiWatch()
{
}
public void SendUpdates(int WikiTopicID, string hostName, string appUrlPath, string wikiName, string topicName, string userName,
bool IsMinor, string Summary, string BodyText, bool isTalk)
{
DataSet ds = DataAccess.GetWikiWatchList(WikiTopicID);
if(ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
//w.Author, a.WatchAddress
WikiWatchSender sndr = new WikiWatchSender(ds, hostName, appUrlPath, wikiName, topicName, userName, IsMinor, Summary, BodyText, isTalk);
Thread t = new Thread(new ThreadStart(sndr.SendMessages));
t.Start();
//sndr.SendMessages();
}
}
}
public class WikiWatchSender
{
private DataSet ds = null;
private string hostName = "";
private string appUrlPath = "";
private string wikiName = "";
private string topicName = "";
private string userName = "";
private bool IsMinor = false;
private string Summary = "";
private string Body = "";
private bool isTalk = false;
public WikiWatchSender(DataSet ds, string hostName, string appUrlPath, string wikiName, string topicName, string userName,
bool IsMinor, string Summary, string BodyText, bool isTalk)
{
this.ds = ds;
this.hostName = hostName;
this.appUrlPath = appUrlPath;
this.wikiName = wikiName;
this.topicName = topicName;
this.userName = userName;
this.IsMinor = IsMinor;
this.Summary = Summary;
this.Body = BodyText;
this.isTalk = isTalk;
}
//w.Author, a.WatchAddress
public void SendMessages()
{
string returnAddress = Config.WatchReturnAddress;
string appName = Config.ApplicationName;
string smtpServer = Config.SmtpServer;
string docLink = "http://" + hostName + appUrlPath + "/wiki/" + this.wikiName + "/" + this.topicName + ".wiki";
docLink = "<a href=\"" + docLink + "\">" + docLink + "</a>";
string talkLink = "http://" + hostName + appUrlPath + "/wiki/" + this.wikiName + "/" + this.topicName + ".wiki?talk";
talkLink = "<a href=\"" + talkLink + "\">" + talkLink + "</a>";
string watchLink = "http://" + hostName + appUrlPath + "/wiki/" + this.wikiName + "/" + this.topicName + ".wiki?watch";
watchLink = "<a href=\"" + watchLink + "\">" + watchLink + "</a>";
string msgBody = "<html><head></head><body><div style=\" font-weight: normal; font-size: 10pt; color: navy; font-family: Tahoma, Verdana, Arial;\">"
+ "@@NAME@@";
if(isTalk)
{
msgBody += "The discussion page for <b>" + this.topicName + "</b> in the <b>" + this.wikiName + "</b> project has been updated by "
+ this.userName.ToUpper() + ".<br><br>To see this discussion go to<br>" + talkLink
+ "<br><br>To visit the document go to<br>" + docLink
+ "<br><br>To remove yourself from this notification list, click the link below and then click the \"Unwatch\" button."
+ "<br>" + watchLink
+ "<br><br>Thank you for your participation.<br><br>Sincerely,<br>" + appName + " Administrator";
}
else
{
msgBody += "The document <b>" + this.topicName + "</b> in the <b>" + this.wikiName + "</b> project has been updated by "
+ this.userName.ToUpper() + ".<br><br>To see document go to<br>" + docLink
+ "<br><br>To discuss this document go to<br>" + talkLink
+ "<br><br>To remove yourself from this notification list, click the link below and then click the \"Unwatch\" button."
+ "<br>" + watchLink
+ "<br><br>Thank you for your participation.<br><br>Sincerely,<br>" + appName + " Administrator";
}
msgBody += "</div></body></html>";
string subject = (this.isTalk) ? "Discussion updated for " + this.wikiName + ": " + this.topicName : "Document updated for " + this.wikiName + ": " + this.topicName;
foreach(DataRow row in ds.Tables[0].Rows)
{
string emailTo = row["WatchAddress"].ToString();
string author = row["Author"].ToString();
msgBody = msgBody.Replace("@@NAME@@", "Dear " + author.ToUpper() + ":<br><br>");
MailMessage msg = new MailMessage();
SmtpMail.SmtpServer = smtpServer;
msg.From = "\"" + appName + " Daemon\" <" + returnAddress + ">"; //e.g.: "App Daemon" <admin@domain.net>
msg.To = "\"" + author + "\" <" + emailTo + ">";
msg.Subject = subject;
msg.BodyFormat = MailFormat.Html;
msg.Body = msgBody;
SmtpMail.Send(msg);
/*
try
{
SmtpMail.Send(msg);
}
catch
{
//TODO - log send errors
}
*/
}
}
}
}