Finishing the implementation of the action, by adding the code which represents the behaviour.
- (page 5 of 6)
This action is going to send a mail so we need to add a reference to
System.Web
Then add the following implementation:
using System;
using System.Web.Mail;
using Ant.ContentEntry;
using Ant.ContentEntry.ClassInformation;
using Ant.ContentEntry.FieldDisplayers;
using Ant.ContentEntry.Converters;
using Ant.Database;
using Ant.Security;
using Ant.Workflow;
namespace HowTos
{
/// <summary>
/// This is an example action
/// </summary>
[ClassOverview]
public class HowToAction : Action
{
private string message;
AuthenticatedUser user;
/// <summary>
/// Constructor, taking a user which is supplied whenever
/// this action is constructed by the workflow engine
/// </summary>
/// Logged on user
public HowToAction(AuthenticatedUser user)
{
this.user = user;
}
/// <summary>
/// Message of the email
/// </summary>
[PropertyInformation(typeof(StringConverter), typeof(InputEntry), true, 0)]
[PropertyLanguage(PropertyLanguage.English, "Message",
"This is the message of the email", "You must enter a message")]
public string Message
{
get {return message;}
set {message = value;}
}
#region Action Members
/// <summary>
/// Terminates the action, in this case takes no action
/// </summary>
public void Terminate(ActivityInstance instance, Ant.Database.AntConnection connection,
Ant.Database.AntTransaction transaction, ref string state)
{
}
/// <summary>
/// Starts the action, returns true to say that a response is to be waited for
/// </summary>
public bool StartAction(ActivityInstance instance, Ant.Database.AntConnection connection,
Ant.Database.AntTransaction transaction, User performer, ref string state)
{
// Sends the mail
SmtpMail.SmtpServer = "****";
MailMessage mail = new MailMessage();
mail.To = "***";
mail.From = "****";
mail.Subject = "Test";
mail.Body = message;
SmtpMail.Send(mail);
// add a response which is picked up in ProcessActionResults,
// this is how a synchronous action is implemented
instance.AddResponse(this.user, performer, "Response received in ProcessActionResults",
"", connection, transaction);
return true;
}
/// <summary>
/// Gets the URL for context sensitive help, returns null as there is no help for this action
/// </summary>
///
public string GetHelpUrl()
{
return null;
}
/// <summary>
/// Gets the name of the action
/// </summary>
public string GetActionName()
{
return "How to action";
}
/// <summary>
/// Gets the short description of the action
/// </summary>
public string ShortDescription
{
get
{
return "Sends a message";
}
}
/// <summary>
/// Gets the long description of the action
/// </summary>
public string LongDescription
{
get
{
return message;
}
}
/// <summary>
/// Process the results of the action
/// </summary>
public string ProcessActionResults(ActivityInstance instance, Ant.Database.AntConnection connection,
Ant.Database.AntTransaction transaction, User performedBy, string results, ref string state)
{
// nothing to do here, just return the name of the transition to fire
return "Next";
}
/// <summary>
/// Gets the names of transitions that this action supports
/// </summary>
public System.Collections.ICollection GetRequiredTransitionNames()
{
return new string[] {"Next"};
// only one transition, matches string that is returned from ProcessActionResults
}
#endregion
}
}
The key points of the implementation have been picked out in comments. As this is a synchronous action, ProcessActionResult has nothing to do and StartAction posts a response for the workflow engine to pick up on.