This project is read-only.

Workflow error with custom Activity

Topics: General, Troubleshooting, Writing modules
Nov 20, 2014 at 11:40 AM
Edited Nov 20, 2014 at 12:18 PM
I've created a Workflow that uses a custom Activity. Everything works except that if I try to edit the Workflow later, it's all mangled up.





I'm wondering if this error is caused by my Activity. If I change the Name of the Activity, the Workflow becomes dissociated with it and it will open like so:


Here's the code of the Activity:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Workflows.Models;
using Orchard.Workflows.Services;
using Orchard.Taxonomies;
using Orchard.Autoroute;
using System.Collections;
using Orchard.Taxonomies.Services;
using Orchard.Taxonomies.Models;
using Orchard.Core.Common.Models;
using Orchard.Autoroute.Services;
using System.Text.RegularExpressions;
using System.Security.Policy;

namespace Traplet.OrchardTheme.Modelling.Workflows.Activities
    public class WhatsHotActivity : Task
        private readonly IContentManager _contentManager;
        private readonly ITaxonomyService _taxonomyService;
        private readonly IAutorouteService _autorouteService;

        public WhatsHotActivity(IContentManager contentManager, ITaxonomyService taxonomyService, IAutorouteService autorouteService)
            _contentManager = contentManager;
            _taxonomyService = taxonomyService;
            _autorouteService = autorouteService;
            T = NullLocalizer.Instance;

        public Localizer T { get; set; }

        public override bool CanExecute(WorkflowContext workflowContext, ActivityContext activityContext) {
            var url = activityContext.GetState<string>("Url");
            return !string.IsNullOrWhiteSpace(url);

        public override IEnumerable<LocalizedString> GetPossibleOutcomes(WorkflowContext workflowContext, ActivityContext activityContext) {
            yield return T("Error");
            yield return T("Success");

        public override IEnumerable<LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext) {

            HttpContext context = HttpContext.Current;
            ContentItem content = workflowContext.Content.ContentItem;
            bool success = false;
            string[] taxonomyNames = { "Air", "Earth", "Water" };
            Orchard.Autoroute.Models.AutoroutePart route = content.As<Orchard.Autoroute.Models.AutoroutePart>();
            string path = context.Request.AppRelativeCurrentExecutionFilePath.Substring(
                context.Request.AppRelativeCurrentExecutionFilePath.IndexOf('/') + 1,
                context.Request.AppRelativeCurrentExecutionFilePath.Length - (context.Request.AppRelativeCurrentExecutionFilePath.IndexOf('/') + 1)
            path = path.Substring(0, path.LastIndexOf('/'));
            foreach (string taxonomyName in taxonomyNames)
                var taxonomy = _taxonomyService.GetTaxonomyByName(taxonomyName);
                var terms = _taxonomyService.GetTerms(taxonomy.Id);
                TermPart tp = terms.FirstOrDefault(t => t.Slug == path);
                if (tp != null)
                    List<TermPart> termsToAdd = new List<TermPart>();
                    _taxonomyService.UpdateTerms(content, termsToAdd, taxonomyName);
                    string contentName = Regex.Replace(route.DisplayAlias, @"[^a-zA-Z0-9 -]", "", RegexOptions.IgnoreCase);
                    path += "/" + contentName;
                    route.DisplayAlias = path;
                    success = true;
            if (success)
                yield return T("Success");
                yield return T("Error");

        public override string Name {
            get { return "Url Autoroute"; }

        public override LocalizedString Category {
            get { return T("Routing"); }

        public override LocalizedString Description {
            get { return T("Configures a route alias & assigns a Taxonomy"); }

        public override string Form {
            get { return "Tell Us Whats Hot"; }
Any ideas?
Nov 20, 2014 at 8:44 PM
Interesting! I have the same problem with one of my custom workflows. I checked the records in the database and they seem finde to me, but the visual representation is wrong. I will take a closer look when I can find time.

Which version of Orchard do you use? (By the way I have the problem with 1.x)
Nov 20, 2014 at 9:05 PM
It's because of the Name of the activity - you can't use spaces.
Marked as answer by TroyTempest on 11/21/2014 at 1:14 AM
Nov 21, 2014 at 12:54 AM
That's it. Thanks spike. Work like charm now ;).
Nov 21, 2014 at 9:14 AM
Back of the net!!!