Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Charles Zipp 20 posts 81 karma points
    May 28, 2013 @ 19:15
    Charles Zipp
    0

    Custom Workflow Types in Medium Trust

    Hi,

    I wanted to ask if there are any known issues around custom workflow type availablity in medium trust environments. I had created a custom email notification workflow type that worked fine when running the site locally from visual studio. However, once published to stage (medium trust env), the workflow type is not showing in the list of workflow types.

    I have verified that the assembly that contains the workflow type is in the bin directory of the website

    Please note that this staging environment doesnt currently have a license for Contour (I only had a license available for the prod env). Is this a side effect of running in trial mode?

    Below is the code for my workflow type.

    public class EmailNotificationWT : WorkflowType
    {
        protected readonly SmtpClient _client;
        protected readonly UmbracoHelper _umbracoHelper;
    
        public EmailNotificationWT()
            : this(new UmbracoHelper(UmbracoContext.Current), new SmtpClient())
        {
        }
    
        public EmailNotificationWT(UmbracoHelper umbracoHelper, SmtpClient client)
        {
            _umbracoHelper = umbracoHelper;
            _client = client;
            Id = new Guid("A15245EB-EED5-425A-BAB6-90BEB5F4FAD9");
            Description = "Sends an email notification containing the form data.";
            Name = "Email Notification";
        }
    
        #region To Reciever Settings
    
        [Setting(
            "To Reciever - List",
            description = "Enter a list of email addresses seperated by a semi-colon that should receive the notification.",
            control = "Umbraco.Forms.Core.FieldSetting.TextArea")
            ]
        public string ToReceiverList { get; set; }
    
        #endregion To Reciever Settings
    
        #region From Sender Settings
    
        [Setting(
            "From Sender - User Defined",
            description = "User defined email address from which the notification will be sent. Only one can be specified.",
            control = "Umbraco.Forms.Core.FieldSetting.TextArea")
            ]
        public string FromSenderUserDefined { get; set; }
    
        #endregion From Sender Settings
    
        #region Email Content Settings
    
        [Setting(
            "Email Content - Macro",
            description = "The name of the macro to be used for the email content.",
            control = "Umbraco.Forms.Core.FieldSetting.TextField")
            ]
        public string EmailContentMacro { get; set; }
    
        [Setting(
            "Email Content - Subject",
            description = "The value that will be shown as the subject line of the notification.",
            control = "Umbraco.Forms.Core.FieldSetting.TextField")
            ]
        public string EmailContentSubject { get; set; }
    
        #endregion Email Content Settings
    
        public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
        {
            try
            {
                MailMessage msg = GetMessage(e);
                _client.Send(msg);
    
                return WorkflowExecutionStatus.Completed;
            }
            catch (Exception ex)
            {
                return WorkflowExecutionStatus.Failed;
            }
        }
    
        public override List<Exception> ValidateSettings()
        {
            List<Exception> rvalues = new List<Exception>();
    
            //Verify a recipient was provided.
            if (string.IsNullOrEmpty(ToReceiverList))
            {
                Exception exceptionToReceiverListEmpty = new Exception("A recipient must be provided.");
                rvalues.Add(exceptionToReceiverListEmpty);
            }
    
            //TODO: Verify Macro was provided. If possible, make sure the name matches to a macro we have.
    
            return rvalues;
        }
    
        private MailMessage GetMessage(RecordEventArgs e)
        {
            MailMessage rvalue = new MailMessage();
    
            rvalue.Subject = EmailContentSubject;
            rvalue.IsBodyHtml = true;
            rvalue.Body = GetMessageBody(e);
            rvalue.From = GetSender(e.Record);
    
            List<MailAddress> addressesTo = GetRecieversTo(e.Record);
    
            rvalue.To.AddRange(addressesTo);
    
            return rvalue;
        }
    
        private string GetMessageBody(RecordEventArgs e)
        {
            IHtmlString rvalue = null;
    
            IDictionary<string, object> model = e.Form.AllFields.ToModel(e);
    
            rvalue = _umbracoHelper.RenderMacro(EmailContentMacro, model);
    
            return rvalue.ToHtmlString();
        }
    
        private List<MailAddress> GetRecieversTo(Record record)
        {
            List<MailAddress> rvalues = new List<MailAddress>();
    
            if (!string.IsNullOrEmpty(ToReceiverList))
            {
                string[] addresses = ToReceiverList.Split(';');
                foreach (string address in addresses)
                {
                    MailAddress rvalue = new MailAddress(address);
                    rvalues.Add(rvalue);
                }
            }
    
            return rvalues;
        }
    
        private MailAddress GetSender(Record record)
        {
            System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("/web.config");
            MailSettingsSectionGroup mailSettings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
            string rvalue = mailSettings.Smtp.From;
    
            if (!string.IsNullOrEmpty(FromSenderUserDefined))
            {
                rvalue = FromSenderUserDefined;
            }
    
            return new MailAddress(rvalue);
        }
    }
  • Comment author was deleted

    Jun 03, 2013 @ 12:48

    Nope  trial mode shouldn't have an effect on that it should just work

  • Charles Zipp 20 posts 81 karma points
    Jun 08, 2013 @ 18:56
    Charles Zipp
    0

    I dont think this is working in Medium Trust environments then. I have tested this on Azure and the custom type shows in the drop down. It does when running locally as well. However, when running at NetworkSolutions.com (medium trust shared hosting), my custom types are not available in the drop down. Bug?

  • Michael Lawrence 128 posts 200 karma points
    Jun 12, 2013 @ 03:36
    Michael Lawrence
    0

    I'm having a similar issue myself, except our web server is running in Full Trust. It's an Umbraco 4.7.2 install with Contour 3.0.12. The custom workflow works on our local and internal dev environments, but doesn't show up on our production environment. We're not running in trial mode either so I have no clue why this isn't working. Maybe it is a bug afterall?

  • Comment author was deleted

    Jun 12, 2013 @ 13:30

    @Michael, @Charles any chance you can send me your custom types then I can try to reproduce

    You can mail them to tg at umbraco dot com

    Regards,
    Tim 

  • Michael Lawrence 128 posts 200 karma points
    Jun 12, 2013 @ 16:45
    Michael Lawrence
    0

    @Tim Sure thing, I just sent you an email. Thanks!

  • Charles Zipp 20 posts 81 karma points
    Jun 12, 2013 @ 16:53
    Charles Zipp
    0

    Sent you mine this morning as well. Let me know if you didnt get it.

  • Michael Lawrence 128 posts 200 karma points
    Jun 14, 2013 @ 02:26
    Michael Lawrence
    0

    @Tim, any word yet on what the issue might be?

  • Comment author was deleted

    Jun 17, 2013 @ 11:21

    Looking into this today so more info coming a bit later :)

  • Comment author was deleted

    Jun 18, 2013 @ 16:27

    Unable to reproduce the issue :( tried setting trust level to medium locally but the custom workflow types still show..

    Any other details you can share that might help?

  • Comment author was deleted

    Jun 18, 2013 @ 16:30

    What is the target framework set to in your project? maybe it's set to 4.5 and the host doesn't support that... try setting it to 4...

  • Charles Zipp 20 posts 81 karma points
    Jun 18, 2013 @ 16:34
    Charles Zipp
    0

    @Tim: Ah very good point! I will give that a shot and let you know. Currently the target framework is set to .NET 4.5. Thanks again for looking into this.

  • Comment author was deleted

    Jun 18, 2013 @ 16:41

    @Charles great let me know if that does the trick

  • Charles Zipp 20 posts 81 karma points
    Jun 23, 2013 @ 18:46
    Charles Zipp
    0

    @Tim I have refactored my custom types to their own class library that is set to build for .NET 4.0. I deployed this today and I my custom workflow type is still not showing in the drop down list. I did verify that the assembly for this new library was included in the bin directory.

    I also called my client's hosting provider (networksolutions.com) and verified that they do not yet support .net 4.5.

    Not sure where to go from here. I can share the source for the class library that holds my custom types if that would help.

  • Comment author was deleted

    Jun 24, 2013 @ 10:32

    @Charles yeah if you could mail me that component that would be great tg at umbraco dot com , thanks

Please Sign in or register to post replies

Write your reply to:

Draft