private void UpdateCampaign(SurveyCampaign campaign)
        {
            IEntityFieldValues fields;
            IDictionary <long, IChangeTracker <IMutableIdKey> > forwardRelationships;
            IDictionary <long, IChangeTracker <IMutableIdKey> > reverseRelationships;

            campaign.GetChanges(out fields, out forwardRelationships, out reverseRelationships);

            // handle a campaign having the due date updated.
            if (fields != null)
            {
                if (fields.ContainsField(SurveyCampaign.SurveyClosesOn_Field.Id))
                {
                    var tasks = new List <IEntity>();
                    foreach (var result in campaign.SurveyResponses)
                    {
                        foreach (var task in result.UserSurveyTaskForResults)
                        {
                            if (!(task.UserSurveyTaskForReview ?? false))
                            {
                                var writableTask = task.AsWritable <UserSurveyTask>();
                                writableTask.UserTaskDueOn = campaign.SurveyClosesOn;
                                tasks.Add(writableTask);
                            }
                        }
                    }

                    if (tasks.Any())
                    {
                        Entity.Save(tasks);
                    }
                }
            }
        }
        private void DeleteCampaign(SurveyCampaign campaign)
        {
            // delete any tasks that are out there for this campaign
            var tasks = campaign.SurveyResponses.SelectMany(r => r.UserSurveyTaskForResults)
                        .Where(t => !t.IsTemporaryId)
                        .Select(t => new EntityRef(t)).ToList();

            if (tasks.Any())
            {
                Entity.Delete(tasks);
            }
        }
        public void CampaignWithSurveyCompleteTrigger()
        {
            var            workflow = Entity.Create <Workflow>();
            SurveyCampaign campaign = CreateSurveyPersonCampaign().AsWritable <SurveyCampaign>();

            var survey = campaign.SurveyForCampaign.AsWritable <UserSurvey>();

            survey.SurveyTriggerOnSurveyComplete = workflow;

            survey.Save();


            var dummyRunner = new DummyWorkflowRunner();


            using (var scope = Factory.Current.BeginLifetimeScope(builder =>
            {
                builder.Register(ctx => dummyRunner).As <IWorkflowRunner>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    int runCount = 0;
                    dummyRunner.StartWorkflowAsyncFn = (dummyWf, args) =>
                    {
                        Assert.That(dummyWf.Id, Is.EqualTo(workflow.Id));
                        Assert.That(args.Keys, Contains.Item("Input"));

                        var inputEntity = args["Input"] as IEntity;
                        Assert.That(inputEntity.Id, Is.EqualTo(campaign.SurveyResponses.First().Id));

                        runCount++;
                        return("111");
                    };

                    var task = campaign.SurveyResponses.First().UserSurveyTaskForResults.First().AsWritable <UserSurveyTask>();

                    task.UserTaskIsComplete = true;
                    task.TaskStatus_Enum    = TaskStatusEnum_Enumeration.TaskStatusCompleted;
                    var taskId = task.Id;
                    task.Save();

                    //Thread.Sleep(1000);

                    Assert.That(runCount, Is.EqualTo(1));
                }
        }
Exemplo n.º 4
0
        private static SurveyResponse CreateSurveyResponse(SurveyCampaign campaign, Person recipient, UserResource targetObject = null)
        {
            var survey = campaign.SurveyForCampaign;

            if (survey == null)
            {
                throw new InvalidCampaignException("Survey campaign must be part of an existing survey.");
            }

            var result = Entity.Create <SurveyResponse>();

            result.CampaignForResults = campaign;
            result.SurveyTaker        = recipient;
            result.SurveyAnswers.AddRange(survey.SurveySections.SelectMany(section => section.SurveyQuestions.Select(q => CreateQuestionResults(section, q))));
            result.SurveyTarget      = targetObject;
            result.SurveyStatus_Enum = SurveyStatusEnum_Enumeration.SseNotStarted;

            return(result);
        }
        /// <summary>
        /// Update the campaigns completness based upon the results it has received.
        /// </summary>
        /// <param name="campaign"></param>
        void UpdateCampaignIsComplete(SurveyCampaign campaign)
        {
            if (!(campaign.CampaignIsComplete ?? false))
            {
                if (campaign.SurveyResponses.All(results => results.SurveyCompletedOn != null))
                {
                    var writableCampaign = campaign.AsWritable <SurveyCampaign>();
                    writableCampaign.CampaignIsComplete = true;
                    writableCampaign.Save();

                    var survey     = campaign.SurveyForCampaign;
                    var completeWf = survey.SurveyTriggerOnCampaignComplete;
                    if (completeWf != null)
                    {
                        TriggerCampaignCompleteWf(survey.SecurityOwner, completeWf, campaign);
                    }
                }
            }
        }
Exemplo n.º 6
0
        private static IEnumerable <UserSurveyTask> LaunchCampaign(SurveyCampaign campaign, DateTime?taskDueOn, UserResource targetObject, string taskName)
        {
            // If the campaign is directed at people then process accordingly
            var personCampaign = campaign.As <SurveyPersonCampaign>();

            if (personCampaign != null)
            {
                return(personCampaign.Launch(taskDueOn, targetObject, taskName));
            }

            // otherwise the campaign is targeting objects
            var targetCampaign = campaign.As <SurveyTargetCampaign>();

            if (targetCampaign != null)
            {
                return(targetCampaign.Launch(taskDueOn, taskName));
            }

            return(Enumerable.Empty <UserSurveyTask>());
        }
Exemplo n.º 7
0
        private static UserSurveyTask CreateTaskForResponse(SurveyCampaign campaign, SurveyResponse result)
        {
            var task = Entity.Create <UserSurveyTask>();

            task.AssignedToUser = result.SurveyTaker;
            task.UserSurveyTaskSurveyResponse = result;
            task.TaskPriority_Enum            = EventEmailPriorityEnum_Enumeration.NormalPriority;
            task.TaskStatus_Enum = TaskStatusEnum_Enumeration.TaskStatusNotStarted;

            var target = campaign.CampaignTarget;

            task.UserTaskDueOn = campaign.SurveyClosesOn;
            task.Name          = campaign.SurveyForCampaign.Name;
            task.UserSurveyTaskTargetDefinition = target;
            task.UserSurveyTaskAllowTargetEdit  = target != null;

            // set help text for the survey based on the description
            if (campaign.SurveyForCampaign.ShowSurveyHelpText == true)
            {
                task.UserSurveyTaskHelp = campaign.SurveyForCampaign.Description;
            }

            return(task);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Create the results and task for a survey.
 /// </summary>
 /// <param name="campaign">The campaign.</param>
 /// <param name="taskDueOn">Task due on date, null indicates no due date.</param>
 /// <param name="targetObject">The target object.</param>
 /// <param name="taskName">If not null or empty, use as task name.</param>
 /// <returns>The tasks for each recipient of the survey.</returns>
 public static IEnumerable <UserSurveyTask> Launch(this SurveyCampaign campaign, DateTime?taskDueOn = null, UserResource targetObject = null, string taskName = null)
 {
     return(LaunchCampaign(campaign, taskDueOn, targetObject, taskName));
 }
 void TriggerCampaignCompleteWf(UserAccount surveyOwner, Workflow wf, SurveyCampaign campaign)
 {
     TriggerWf(surveyOwner, wf, campaign);
 }