Exemple #1
0
 public ApproveRecord(XElement xe, Workflow wf) : base(xe, wf)
 {
     RecordId   = GetSetting("record");
     AssignedTo = GetSetting("assignedTo");
     OnApproved = GetSetting("onApproved");
     OnRejected = GetSetting("onRejected");
     OnDeleted  = GetSetting("onDeleted");
     OnStopped  = GetSetting("onStopped");
 }
Exemple #2
0
 public ApproveRecord(XElement xe, Workflow wf) : base(xe, wf)
 {
     RecordId              = GetSetting("record");
     AssignedTo            = GetSetting("assignedTo");
     ReminderDelay         = TimeSpan.Parse(GetSetting("reminderDelay", "3.00:00:00"));
     OnApproved            = GetSetting("onApproved");
     OnRejected            = GetSetting("onRejected");
     OnDueDateReached      = GetSetting("onDueDateReached");
     OnReminderDateReached = GetSetting("onReminderDateReached");
     OnDeleted             = GetSetting("onDeleted");
     OnStopped             = GetSetting("onStopped");
 }
Exemple #3
0
        private void ScheduleWorkflow(Workflow wf)
        {
            try
            {
                if (wf.IsEnabled)
                {
                    if (wf.LaunchType == LaunchType.Startup)
                    {
                        wf.Start();
                    }
                    else if (wf.LaunchType == LaunchType.Periodic)
                    {
                        IDictionary <string, object> map = new Dictionary <string, object>();
                        map.Add("workflow", wf);

                        string     jobIdentity = "Workflow Job " + wf.Id;
                        IJobDetail jobDetail   = JobBuilder.Create <WorkflowJob>()
                                                 .WithIdentity(jobIdentity)
                                                 .SetJobData(new JobDataMap(map))
                                                 .Build();

                        ITrigger trigger = TriggerBuilder.Create()
                                           .ForJob(jobDetail)
                                           .WithSimpleSchedule(x => x.WithInterval(wf.Period).RepeatForever())
                                           .WithIdentity("Workflow Trigger " + wf.Id)
                                           .StartNow()
                                           .Build();

                        var jobKey = new JobKey(jobIdentity);
                        if (QuartzScheduler.CheckExists(jobKey).Result)
                        {
                            QuartzScheduler.DeleteJob(jobKey);
                        }

                        QuartzScheduler.ScheduleJob(jobDetail, trigger).Wait();
                    }
                    else if (wf.LaunchType == LaunchType.Cron)
                    {
                        IDictionary <string, object> map = new Dictionary <string, object>();
                        map.Add("workflow", wf);

                        string     jobIdentity = "Workflow Job " + wf.Id;
                        IJobDetail jobDetail   = JobBuilder.Create <WorkflowJob>()
                                                 .WithIdentity(jobIdentity)
                                                 .SetJobData(new JobDataMap(map))
                                                 .Build();

                        ITrigger trigger = TriggerBuilder.Create()
                                           .ForJob(jobDetail)
                                           .WithCronSchedule(wf.CronExpression)
                                           .WithIdentity("Workflow Trigger " + wf.Id)
                                           .StartNow()
                                           .Build();

                        var jobKey = new JobKey(jobIdentity);
                        if (QuartzScheduler.CheckExists(jobKey).Result)
                        {
                            QuartzScheduler.DeleteJob(jobKey);
                        }

                        QuartzScheduler.ScheduleJob(jobDetail, trigger).Wait();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.ErrorFormat("An error occured while scheduling the workflow {0}: ", e, wf);
            }
        }
Exemple #4
0
        /// <summary>
        /// Creates a new task.
        /// </summary>
        /// <param name="xe">XElement.</param>
        /// <param name="wf">Workflow.</param>
        protected Task(XElement xe, Workflow wf)
        {
            Logs      = new List <string>();
            IsStopped = false;
            _xElement = xe;
            var xId = xe.Attribute("id");

            if (xId == null)
            {
                throw new Exception("Task id attribute not found.");
            }
            Id = int.Parse(xId.Value);
            var xName = xe.Attribute("name");

            if (xName == null)
            {
                throw new Exception("Task name attribute not found.");
            }
            Name = xName.Value;
            var xType = xe.Attribute("type");

            if (xType == null)
            {
                throw new Exception("Task type attribute not found.");
            }
            TaskType = xType.Value;
            var xDesc = xe.Attribute("description");

            if (xDesc == null)
            {
                throw new Exception("Task description attribute not found.");
            }
            Description = xDesc.Value;
            var xEnabled = xe.Attribute("enabled");

            if (xEnabled == null)
            {
                throw new Exception("Task enabled attribute not found.");
            }
            IsEnabled            = bool.Parse(xEnabled.Value);
            IsWaitingForApproval = false;
            Workflow             = wf;
            Workflow.FilesPerTask.Add(Id, new List <FileInf>());
            Workflow.EntitiesPerTask.Add(Id, new List <Entity>());

            // settings
            IList <Setting> settings = new List <Setting>();

            foreach (var xSetting in xe.XPathSelectElements("wf:Setting", Workflow.XmlNamespaceManager))
            {
                // setting name
                var xSettingName = xSetting.Attribute("name");
                if (xSettingName == null)
                {
                    throw new Exception("Setting name not found");
                }
                string settingName = xSettingName.Value;

                // setting value
                var    xSettingValue = xSetting.Attribute("value");
                string settingValue  = string.Empty;
                if (xSettingValue != null)
                {
                    settingValue = xSettingValue.Value;
                }

                // setting attributes
                IList <Attribute> attributes = new List <Attribute>();

                foreach (var xAttribute in xSetting.Attributes().Where(attr => attr.Name.LocalName != "name" && attr.Name.LocalName != "value"))
                {
                    Attribute attr = new Attribute(xAttribute.Name.LocalName, xAttribute.Value);
                    attributes.Add(attr);
                }

                Setting setting = new Setting(settingName, settingValue, attributes.ToArray());
                settings.Add(setting);
            }

            Settings = settings.ToArray();

            Prerequisites = xe.XPathSelectElements("wf:Prerequisite", Workflow.XmlNamespaceManager)
                            .Select(TaskPrerequisite.FromElement)
                            .ToArray();
        }