public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
            {
                throw new ArgumentNullException("conditionScript");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            var inputs = new Dictionary <string, object> {
                { "input", runtime.Input }
            };

            foreach (var providerRuntimeResult in runtime.ProviderResults)
            {
                if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                {
                    inputs.Add(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
                }
            }
            var engine = IronPython.Hosting.Python.CreateEngine();
            var scope  = engine.CreateScope(inputs);

            return(engine.Execute <bool>(conditionScript, scope));
        }
        public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
            {
                throw new ArgumentNullException("conditionScript");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            using (var scriptContext = new JavascriptContext())
            {
                scriptContext.SetParameter("input", runtime.Input);
                foreach (var providerRuntimeResult in runtime.ProviderResults)
                {
                    if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                    {
                        scriptContext.SetParameter(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
                    }
                }
                conditionScript = "var result = (function() {" + conditionScript + "})()";
                scriptContext.Run(conditionScript);
                return(Convert.ToBoolean(scriptContext.GetParameter("result"), CultureInfo.InvariantCulture));
            }
        }
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var body = Helper.Instance.RenderTemplate(RenderTemplate);
            
            IList<string> files = new List<string>();

            foreach(var nodeId in ((UmbracoWorkflowInstance) workflowInstance).CmsNodes)
            {
                var node = new CMSNode(nodeId);
                if(node.IsMedia())
                {
                    files.Add(IOHelper.MapPath((string) new Media(nodeId).getProperty("umbracoFile").Value));
                }
            }

            var f = new User(From).Email;
            foreach(var r in GetRecipients())
            {
                var mail = new MailMessage(f, r) {Subject = Subject, IsBodyHtml = true, Body = body};

                foreach(var file in files)
                {
                    var attach = new Attachment(file);
                    mail.Attachments.Add(attach);
                }

                var smtpClient = new SmtpClient();
                smtpClient.Send(mail);
            }

            runtime.Transition(workflowInstance, this, "done");
        }
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // Cast to Umbraco worklow instance.
            var umbracoWorkflowInstance = (UmbracoWorkflowInstance) workflowInstance;

            var count = 0;
            var newCmsNodes = new List<int>();

            foreach(var nodeId in umbracoWorkflowInstance.CmsNodes)
            {
                var n = new CMSNode(nodeId);
                if(!n.IsDocument()) continue;

                var d = new Document(nodeId);
                if (!DocumentTypes.Contains(d.ContentType.Id)) continue;
                
                newCmsNodes.Add(nodeId);
                count++;
            }

            umbracoWorkflowInstance.CmsNodes = newCmsNodes;

            var transition = (count > 0) ? "contains_docs" : "does_not_contain_docs";
            runtime.Transition(workflowInstance, this, transition);
        }
        // Implement the Run method of IRunnableWorkflowTask
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // In Umbraco the workflowInstance should always be castable to an UmbracoWorkflowInstance
            var wf = (UmbracoWorkflowInstance) workflowInstance;

            // UmbracoWorkflowInstance has a list of node Ids that are associated with the workflow in the CmsNodes property
            foreach(var nodeId in wf.CmsNodes)
            {
                // We'll assume that only documents are attached to this workflow
                var doc = new Document(nodeId);

                var property = doc.getProperty(DocumentTypeProperty);
                
                if (!String.IsNullOrEmpty((string) property.Value)) continue;

                var host = HttpContext.Current.Request.Url.Host;
                var pageUrl = "http://" + host + umbraco.library.NiceUrl(nodeId);

                var shortUrl = API.Bit(BitLyLogin, BitLyApiKey, pageUrl, "Shorten");

                property.Value = shortUrl;
            }
            
            // The run method of a workflow task is responsible for informing the runtime of the outcome.
            // The outcome should be one of the items in the AvailableTransitions list.
            runtime.Transition(workflowInstance, this, "done");
        }
Example #6
0
        // Implement the Run method of IRunnableWorkflowTask
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // In Umbraco the workflowInstance should always be castable to an UmbracoWorkflowInstance
            var wf = (UmbracoWorkflowInstance)workflowInstance;

            // UmbracoWorkflowInstance has a list of node Ids that are associated with the workflow in the CmsNodes property
            foreach (var nodeId in wf.CmsNodes)
            {
                // We'll assume that only documents are attached to this workflow
                var doc = new Document(nodeId);

                var property = doc.getProperty(DocumentTypeProperty);

                if (!String.IsNullOrEmpty((string)property.Value))
                {
                    continue;
                }

                var host    = HttpContext.Current.Request.Url.Host;
                var pageUrl = "http://" + host + umbraco.library.NiceUrl(nodeId);

                var shortUrl = API.Bit(BitLyLogin, BitLyApiKey, pageUrl, "Shorten");

                property.Value = shortUrl;
            }

            // The run method of a workflow task is responsible for informing the runtime of the outcome.
            // The outcome should be one of the items in the AvailableTransitions list.
            runtime.Transition(workflowInstance, this, "done");
        }
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // Cast to Umbraco worklow instance.
            var umbracoWorkflowInstance = (UmbracoWorkflowInstance)workflowInstance;

            var count       = 0;
            var newCmsNodes = new List <int>();

            foreach (var nodeId in umbracoWorkflowInstance.CmsNodes)
            {
                var n = new CMSNode(nodeId);
                if (!n.IsMedia())
                {
                    continue;
                }

                var d = new Media(nodeId);
                if (!MediaTypes.Contains(d.ContentType.Id))
                {
                    continue;
                }

                newCmsNodes.Add(nodeId);
                count++;
            }

            umbracoWorkflowInstance.CmsNodes = newCmsNodes;

            var transition = (count > 0) ? "contains_media" : "does_not_contain_media";

            runtime.Transition(workflowInstance, this, transition);
        }
Example #8
0
        public virtual void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            Instantiator = ((UmbracoWorkflowInstance)workflowInstance).Instantiator;
            CmsNodes     = ((UmbracoWorkflowInstance)workflowInstance).CmsNodes;

            Comment           = workflowInstance.Comment;
            TransitionHistory = workflowInstance.TransitionHistory;
        }
Example #9
0
        private static void PassingDataSample(IWorkflowRegistry registry, IWorkflowRuntime runtime)
        {
            MyDataClass initialData = new MyDataClass();

            initialData.Value1 = 2;
            initialData.Value2 = 3;
            runtime.StartWorkflow("PassingDataWorkflow", 1, initialData);
            Console.ReadLine();
        }
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var nodes = ((UmbracoWorkflowInstance)workflowInstance).CmsNodes;

            SendMail(Body + Environment.NewLine + GetAttachmentLinks(nodes));
            runtime.Transition(workflowInstance, this, "done");
        }
        public virtual void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            Instantiator = ((UmbracoWorkflowInstance)workflowInstance).Instantiator;
            CmsNodes = ((UmbracoWorkflowInstance)workflowInstance).CmsNodes;

            Comment = workflowInstance.Comment;
            Flags = workflowInstance.Flags;
            TransitionHistory = workflowInstance.TransitionHistory;
        }
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var nodes = ((UmbracoWorkflowInstance) workflowInstance).CmsNodes;

            SendMail(Body + Environment.NewLine + GetAttachmentLinks(nodes));
            runtime.Transition(workflowInstance, this, "done");
        }
Example #13
0
        private static void EventSample(IWorkflowRegistry registry, IWorkflowRuntime runtime)
        {
            runtime.StartWorkflow("EventSampleWorkflow", 1, new MyDataClass());

            Console.WriteLine("Enter value");
            string value = Console.ReadLine();

            runtime.PublishEvent("MyEvent", "0", value);
            Console.ReadLine();
        }
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var nodes = ((UmbracoWorkflowInstance) workflowInstance).CmsNodes;

            var body = Helper.Instance.RenderTemplate(RenderTemplate) + GetAttachmentLinks(nodes);

            SendMail(body);
            runtime.Transition(workflowInstance, this, "done");
        }
Example #15
0
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var nodes = ((UmbracoWorkflowInstance)workflowInstance).CmsNodes;

            var body = Helper.Instance.RenderTemplate(RenderTemplate) + GetAttachmentLinks(nodes);

            SendMail(body);
            runtime.Transition(workflowInstance, this, "done");
        }
        public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
                throw new ArgumentNullException("conditionScript");
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            var inputs = new Dictionary<string, object> { {"input", runtime.Input }};
            foreach (var providerRuntimeResult in runtime.ProviderResults)
            {
                if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                    inputs.Add(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
            }
            var engine = IronPython.Hosting.Python.CreateEngine();
            var scope = engine.CreateScope(inputs);
            return engine.Execute<bool>(conditionScript, scope);
        }
        public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
                throw new ArgumentNullException("conditionScript");
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            var context = new IronJS.Hosting.CSharp.Context();
            context.SetGlobal("input", runtime.Input);
            foreach (var providerRuntimeResult in runtime.ProviderResults)
            {
                if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                    context.SetGlobal(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
            }
            conditionScript = "(function(){ " + conditionScript + "})()";
            return context.Execute<bool>(conditionScript);
        }
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // Cast to Umbraco worklow instance.
            var umbracoWorkflowInstance = (UmbracoWorkflowInstance) workflowInstance;

            foreach(var nodeId in umbracoWorkflowInstance.CmsNodes)
            {
                var n = new CMSNode(nodeId);
                if(!n.IsDocument()) continue;

                var d = new Document(nodeId);
                d.Publish(User.GetUser(0));

                umbraco.library.UpdateDocumentCache(d.Id);
            }

            runtime.Transition(workflowInstance, this, "done");
        }
        public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
                throw new ArgumentNullException("conditionScript");
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            using (var scriptContext = new JavascriptContext())
            {
                scriptContext.SetParameter("input", runtime.Input);
                foreach (var providerRuntimeResult in runtime.ProviderResults)
                {
                    if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                        scriptContext.SetParameter(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
                }
                conditionScript = "var result = (function() {" + conditionScript + "})()";
                scriptContext.Run(conditionScript);
                return Convert.ToBoolean(scriptContext.GetParameter("result"), CultureInfo.InvariantCulture);
            }
        }
        // Implement the Run method of IRunnableWorkflowTask
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // In Umbraco the workflowInstance should always be castable to an UmbracoWorkflowInstance
            var wf = (UmbracoWorkflowInstance)workflowInstance;

            var accessToken = new OAuthTokens
            {
                AccessToken       = AccessToken,
                AccessTokenSecret = AccessTokenSecret,
                ConsumerKey       = ConsumerKey,
                ConsumerSecret    = ConsumerSecret
            };

            foreach (var nodeId in wf.CmsNodes)
            {
                // We'll assume that only documents are attached to this workflow
                var doc = new Document(nodeId);

                string pageUrl;

                if (string.IsNullOrEmpty(ShortUrlProperty))
                {
                    // The user hasn't specified a property for a Short URL.
                    var host = HttpContext.Current.Request.Url.Host;
                    pageUrl = "http://" + host + umbraco.library.NiceUrl(nodeId);
                }
                else
                {
                    pageUrl = (string)doc.getProperty(ShortUrlProperty).Value;
                }

                var tweet = string.Format(TweetText, doc.Text, pageUrl);

                // We could do some error checking with the result here....
                var result = TwitterStatus.Update(accessToken, tweet);
            }

            // The run method of a workflow task is responsible for informing the runtime of the outcome.
            // The outcome should be one of the items in the AvailableTransitions list.
            runtime.Transition(workflowInstance, this, "done");
        }
Example #21
0
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // Cast to Umbraco worklow instance.
            var umbracoWorkflowInstance = (UmbracoWorkflowInstance)workflowInstance;

            foreach (var nodeId in umbracoWorkflowInstance.CmsNodes)
            {
                var n = new CMSNode(nodeId);
                if (!n.IsDocument())
                {
                    continue;
                }

                var d = new Document(nodeId);
                d.Publish(User.GetUser(0));

                umbraco.library.UpdateDocumentCache(d.Id);
            }

            runtime.Transition(workflowInstance, this, "done");
        }
        // Implement the Run method of IRunnableWorkflowTask
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            // In Umbraco the workflowInstance should always be castable to an UmbracoWorkflowInstance
            var wf = (UmbracoWorkflowInstance)workflowInstance;
            
            var accessToken = new OAuthTokens
            {
                AccessToken = AccessToken,
                AccessTokenSecret = AccessTokenSecret,
                ConsumerKey = ConsumerKey,
                ConsumerSecret = ConsumerSecret
            };

            foreach (var nodeId in wf.CmsNodes)
            {
                // We'll assume that only documents are attached to this workflow
                var doc = new Document(nodeId);

                string pageUrl;

                if(string.IsNullOrEmpty(ShortUrlProperty))
                {
                    // The user hasn't specified a property for a Short URL.
                    var host = HttpContext.Current.Request.Url.Host;
                    pageUrl = "http://" + host + umbraco.library.NiceUrl(nodeId);
                } else
                {
                    pageUrl = (string)doc.getProperty(ShortUrlProperty).Value;
                }

                var tweet = string.Format(TweetText, doc.Text, pageUrl);

                // We could do some error checking with the result here....
                var result = TwitterStatus.Update(accessToken, tweet);
            }

            // The run method of a workflow task is responsible for informing the runtime of the outcome.
            // The outcome should be one of the items in the AvailableTransitions list.
            runtime.Transition(workflowInstance, this, "done");
        }
Example #23
0
        public override void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            base.Run(workflowInstance, runtime);

            var body = Helper.Instance.RenderTemplate(RenderTemplate);

            IList <string> files = new List <string>();

            foreach (var nodeId in ((UmbracoWorkflowInstance)workflowInstance).CmsNodes)
            {
                var node = new CMSNode(nodeId);
                if (node.IsMedia())
                {
                    files.Add(IOHelper.MapPath((string)new Media(nodeId).getProperty("umbracoFile").Value));
                }
            }

            var f = new User(From).Email;

            foreach (var r in GetRecipients())
            {
                var mail = new MailMessage(f, r)
                {
                    Subject = Subject, IsBodyHtml = true, Body = body
                };

                foreach (var file in files)
                {
                    var attach = new Attachment(file);
                    mail.Attachments.Add(attach);
                }

                var smtpClient = new SmtpClient();
                smtpClient.Send(mail);
            }

            runtime.Transition(workflowInstance, this, "done");
        }
        public bool Evaluate(string conditionScript, IWorkflowRuntime runtime)
        {
            if (conditionScript == null)
            {
                throw new ArgumentNullException("conditionScript");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }

            var context = new IronJS.Hosting.CSharp.Context();

            context.SetGlobal("input", runtime.Input);
            foreach (var providerRuntimeResult in runtime.ProviderResults)
            {
                if (providerRuntimeResult.ProviderStatus == EWorkflowProviderRuntimeStatus.Success)
                {
                    context.SetGlobal(providerRuntimeResult.ProviderName, providerRuntimeResult.Result);
                }
            }
            conditionScript = "(function(){ " + conditionScript + "})()";
            return(context.Execute <bool>(conditionScript));
        }
 /// <summary>
 /// Initializes a new <see cref="V1CreateWorkflowCommandHandler"/>
 /// </summary>
 /// <param name="loggerFactory">The service used to create <see cref="ILogger"/>s</param>
 /// <param name="mediator">The service used to mediate calls</param>
 /// <param name="mapper">The service used to map objects</param>
 /// <param name="workflowValidator">The service used to validate <see cref="WorkflowDefinition"/>s</param>
 /// <param name="workflows">The <see cref="IRepository"/> used to manage <see cref="V1Workflow"/>s</param>
 /// <param name="runtimeHost">The current <see cref="IWorkflowRuntime"/></param>
 public V1CreateWorkflowCommandHandler(ILoggerFactory loggerFactory, IMediator mediator, IMapper mapper, IWorkflowValidator workflowValidator, IRepository <V1Workflow> workflows, IWorkflowRuntime runtimeHost)
     : base(loggerFactory, mediator, mapper)
 {
     this.WorkflowValidator = workflowValidator;
     this.Workflows         = workflows;
     this.RuntimeHost       = runtimeHost;
 }
Example #26
0
 /// <summary>
 /// Initializes a new <see cref="WorkflowProcessManager"/>
 /// </summary>
 /// <param name="serviceProvider">The current <see cref="IServiceProvider"/></param>
 /// <param name="runtime">The <see cref="IWorkflowRuntime"/> used to create <see cref="IWorkflowProcess"/>es</param>
 public WorkflowProcessManager(IServiceProvider serviceProvider, IWorkflowRuntime runtime)
 {
     this.ServiceProvider = serviceProvider;
     this.Runtime         = runtime;
 }
Example #27
0
 void LoadWorkflowRuntime()
 {
     this.m_WorkflowRuntime = EAS.Objects.ClassProvider.GetObjectInstance("EAS.BPM.SilverlightUI", "EAS.BPM.SilverlightUI.WorkflowRuntime") as IWorkflowRuntime;
 }
Example #28
0
        public void Run(IWorkflowInstance workflowInstance, IWorkflowRuntime runtime)
        {
            Log.Debug("This is where my task logic would happen");

            runtime.Transition(workflowInstance, this, "done");
        }
Example #29
0
 private static void SimpleDecisionWorkflow(IWorkflowRegistry registry, IWorkflowRuntime runtime)
 {
     runtime.StartWorkflow("Simple Decision Workflow", 1, null);
     Console.ReadLine();
 }