コード例 #1
0
        public bool BeforeSave(ReceivedEmailMessage message, out Action postSaveAction)
        {
            postSaveAction = null;

            string sequenceString;
            long   tenantId;
            long   sequenceId;

            try
            {
                UserTaskHelper.SequenceIdGenerator.SplitSequenceId(message.EmSubject, out sequenceString, out tenantId, out sequenceId);
            }
            catch (SequenceIdGenerator.InvalidSequenceId)
            {
                return(false); // no sequence, so ignore the message
            }

            var task = UserTaskHelper.GetTaskFromEmbededSequenceId(sequenceString);

            if (task == null)
            {
                SendNoTaskReply(message);
            }
            else if (task.UserTaskCompletedOn != null)
            {
                SendTaskCompletedReply(message);
            }
            else
            {
                // try to complete the message
                var completionOptions = task.WorkflowRunForTask.PendingActivity.ForwardTransitions;

                var completionState = ExtractCompletionOption(completionOptions, message.EmBody);

                if (completionState == null)
                {
                    SendInvalidStateReply(message);
                }
                else
                {
                    // update the task after the save
                    var taskId = task.Id;

                    postSaveAction = () =>
                    {
                        UserTaskHelper.ProcessApproval(task, completionState, (writableTask) =>
                        {
                            writableTask.RelatedMessages.Add(message.Cast <EmailMessage>());
                        });
                    };
                }
            }

            return(false);
        }
コード例 #2
0
        public HttpResponseMessage Get(
            [FromUri] string tenant,
            [FromUri] string token,
            [FromUri] string select = null
            )
        {
            if (!Factory.FeatureSwitch.Get("enableWfUserActionNotify"))
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.NotFound));
            }

            using (Profiler.Measure("ApproveController.Approve"))
            {
                using (WebApiHelpers.GetTenantContext(tenant))
                {
                    string responseHtml = null;

                    var task = UserTaskHelper.GetTaskFromLinkToken(token);

                    if (task == null)
                    {
                        responseHtml = _htmlGenerator.GenerateRejectionPage();
                    }
                    else
                    {
                        if (select == null)
                        {
                            responseHtml = _htmlGenerator.GenerateSelectionPage(task);
                        }
                        else
                        {
                            // TODO: make the selection]
                            UserTaskHelper.ProcessApproval(task.Id, select);
                            responseHtml = _htmlGenerator.GenerateCompletedPage(task);
                        }
                    }

                    var response = new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
                    response.Content = new StringContent(responseHtml, Encoding.UTF8, "text/html");

                    return(response);
                }
            }
        }