Skip to content

Instantly share code, notes, and snippets.

@azzlack
Created March 25, 2015 09:08
Show Gist options
  • Save azzlack/e47da479a502a8d29c28 to your computer and use it in GitHub Desktop.
Save azzlack/e47da479a502a8d29c28 to your computer and use it in GitHub Desktop.
Basic Umbraco Contour Workflow
/// <summary>
/// Basic Umbraco Contour Form Workflow.
/// </summary>
public class Workflow : WorkflowType
{
/// <summary>
/// Initializes a new instance of the <see cref="Workflow"/> class.
/// </summary>
public Workflow()
{
this.Name = "Basic workflow";
this.Id = new Guid("3909DB0B-14C7-4BE9-9DED-670AB64B7F31"); // NOTE: Create your own guid
this.Description = "Just an example of how to create settings and perform work";
}
/// <summary>
/// Gets or sets the site URL.
/// </summary>
/// <value>The site URL.</value>
[Setting("SharePoint Site URL", description = "Enter the url to the SharePoint site.", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
public string SiteUrl { get; set; }
/// <summary>
/// Gets or sets the name of the list.
/// </summary>
/// <value>The name of the list.</value>
[Setting("SharePoint List Name", description = "Enter the name of the list where you want to insert the records.", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
public string ListName { get; set; }
/// <summary>
/// Gets or sets the client identifier.
/// </summary>
/// <value>The client identifier.</value>
[Setting("SharePoint Site Username", description = "Enter the username of the user that will insert the records.", control = "Umbraco.Forms.Core.FieldSetting.TextField")]
public string ClientId { get; set; }
/// <summary>
/// Gets or sets the client secret.
/// </summary>
/// <value>The client secret.</value>
[Setting("SharePoint Site User Password", description = "Enter the password of the user that will insert the records.", control = "Umbraco.Forms.Core.FieldSetting.Password")]
public string ClientSecret { get; set; }
/// <summary>
/// Executes the workflow.
/// </summary>
/// <param name="record">The record.</param>
/// <param name="e">The <see cref="RecordEventArgs"/> instance containing the event data.</param>
/// <returns>The workflow execution status.</returns>
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
// Do your work here
// Return <c>WorkflowExecutionStatus.Failed</c> on errors,
// and <c>WorkflowExecutionStatus.Completed</c> if everything went well.
}
/// <summary>
/// Validates the settings. Returns an empty list if everything went well.
/// </summary>
/// <returns>A list of exceptions.</returns>
public override List<Exception> ValidateSettings()
{
var exceptions = new List<Exception>();
Uri uri;
if (!Uri.TryCreate(this.SiteUrl, UriKind.Absolute, out uri))
{
exceptions.Add(new ArgumentNullException("SiteUrl", "Site URL must be a valid absolute url"));
}
if (string.IsNullOrEmpty(this.ClientId))
{
exceptions.Add(new ArgumentNullException("ClientId", "Username must be specified"));
}
if (string.IsNullOrEmpty(this.ClientSecret))
{
exceptions.Add(new ArgumentNullException("ClientSecret", "Password must be specified"));
}
return exceptions;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment