コード例 #1
0
        /// <summary>
        /// Resolves the specified expression into an object stored in WorkflowContext.
        /// </summary>
        /// <param name="expression">The expression resolving to the state stored in WorkflowContext. E.g. "MyData.MyProperty.MySubProperty"</param>
        private object ParseState(string expression, WorkflowContext workflowContext) {
            var path = expression.Split(new[] {'.'}, StringSplitOptions.RemoveEmptyEntries);
            var first = path.First();
            var obj = (dynamic)workflowContext.GetState(first);

            if (path.Length > 1) {
                foreach (var property in path.Skip(1)) {
                    obj = obj[property];
                }
            }

            return obj;
        }
コード例 #2
0
        /// <summary>
        /// Resolves the specified expression into an object stored in WorkflowContext.
        /// </summary>
        /// <param name="expression">The expression resolving to the state stored in WorkflowContext. E.g. "MyData.MyProperty.MySubProperty"</param>
        private object ParseState(string expression, WorkflowContext workflowContext)
        {
            var path  = expression.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            var first = path.First();
            var obj   = (dynamic)workflowContext.GetState(first);

            if (path.Length > 1)
            {
                foreach (var property in path.Skip(1))
                {
                    obj = obj[property];
                }
            }

            return(obj);
        }
コード例 #3
0
        public override IEnumerable <LocalizedString> Execute(
            WorkflowContext workflowContext, ActivityContext activityContext)
        {
            // Get the ContentItems form the context
            var contentItems = GetItems(workflowContext, activityContext);

            if (!contentItems.Any())
            {
                yield return(T("NoItem"));
            }

            var errorMessages = workflowContext.GetState <string>("ErrorMessage");

            errorMessages = string.IsNullOrWhiteSpace(errorMessages) ? "" : errorMessages + Environment.NewLine;

            var error = false;

            foreach (var item in contentItems)
            {
                try {
                    // for each ContentItem, invoke the process
                    GDPRProcess(item);
                } catch (Exception ex) {
                    error = true;
                    var msg = T("Error during the execution of {0} for ContentItem with Id {1}",
                                Name, item.Id).Text;
                    // log the exception
                    Logger.Error(ex, msg);
                    // add information on the error to the WorkflowContext
                    errorMessages += msg + Environment.NewLine;
                }
            }

            if (error)
            {
                workflowContext.SetState("ErrorMessage", errorMessages);
                yield return(T("Error"));
            }

            yield return(T("OK"));
        }
コード例 #4
0
        public override IEnumerable <LocalizedString> Execute(WorkflowContext workflowContext, ActivityContext activityContext)
        {
            FollowerPart followerPart = workflowContext.Content.As <FollowerPart>();

            if (followerPart == null)
            {
                this.Logger.Debug("ContentItem has no FollowerPart");
                return(new[] { T("Failed") });
            }

            // setup tokenizer
            Dictionary <string, object> temp = new Dictionary <string, object>();

            temp.Add("Content", workflowContext.Content);

            CRMCommentPart commentPart = workflowContext.Content.As <CRMCommentPart>();

            if (commentPart != null)
            {
                temp.Add(ActivityTokenProvider.CRMCommentKey, commentPart);
            }

            string emailTemplateIdString = activityContext.GetState <string>(EmailTemplateActivityForm.EmailTemplateIdFieldName);
            int    emailTemplateId;

            if (!int.TryParse(emailTemplateIdString, out emailTemplateId))
            {
                this.Logger.Debug("There is no email Template");
                return(new[] { T("Failed") });
            }

            var ticketEmailTemplate = this.emailTemplateRepository.Table.First(c => c.Id == emailTemplateId);

            if (ticketEmailTemplate == null)
            {
                this.Logger.Debug("There is no email Template");
                return(new[] { T("Failed") });
            }

            var queued   = activityContext.GetState <bool>("Queued");
            var priority = activityContext.GetState <int>("Priority");

            List <int> userIds = string.IsNullOrEmpty(followerPart.Followers) ? null : followerPart.Followers.Split(',').Select(c => int.Parse(c)).ToList();

            if (userIds == null)
            {
                return(new[] { T("Done") });
            }

            // Add activity stream record
            int?activityStreamRecordId = workflowContext.GetState <int?>("ActivityStreamId");

            ActivityStreamRecord activityStreamRecord = null;

            if (activityStreamRecordId != null)
            {
                activityStreamRecord = this.activityStreamRepository.Table.First(c => c.Id == activityStreamRecordId.Value);

                temp.Add(ActivityStreamTokenProvider.ActivityStreamRecordKey, activityStreamRecord);

                // do not send notification to himself/herself
                if (activityStreamRecord.User != null)
                {
                    userIds.Remove(activityStreamRecord.User.Id);
                }
            }
            else
            {
                return(new[] { T("Failed") });
            }

            var recipients = this.services.ContentManager.GetMany <IUser>(userIds, VersionOptions.Published, QueryHints.Empty);

            foreach (var recipient in recipients.Where(c => !string.IsNullOrEmpty(c.Email)))
            {
                var userPart = recipient.As <UserPart>();

                if (userPart != null)
                {
                    temp.Add(ActivityTokenProvider.UserKey, userPart.Record);
                }

                string body    = this.tokenizer.Replace(ticketEmailTemplate.Body, temp);
                string subject = this.tokenizer.Replace(ticketEmailTemplate.Subject, temp);
                this.SendEmail(subject, body, recipient.Email, queued, priority);
            }

            return(new[] { T("Done") });
        }