private void btnSave_Click(object sender, EventArgs e)
    {
        if (userIsAuthorized && (activityId > 0))
        {
            ActivityInfo ai = ActivityInfoProvider.GetActivityInfo(activityId);
            EditedObject = ai;
            ai.ActivityComment = txtComment.Value;
            ai.ActivityTitle = TextHelper.LimitLength(txtTitle.Text, 250, String.Empty);
            ai.ActivityURLReferrer = txtURLRef.Text;
            ai.ActivityURL = txtURL.Text;

            // Get changed columns
            List<string> changes = ai.ChangedColumns();

            // Save activity info
            ActivityInfoProvider.SetActivityInfo(ai);
            
            if ((changes != null) && (changes.Count > 0))
            {
                // Get IDs of scores where activity's contact exceeded score limit
                DataSet limitScores = ScoreInfoProvider.GetScoresWhereContactExceededLimit(ai.ActivityActiveContactID);

                // Recalculate scoring groups
                ScoreInfoProvider.RecalculateScores(ai.ActivityType, RuleTypeEnum.Activity, ai.ActivityActiveContactID, ai.ActivitySiteID);

                // Check if contact gained enough points and alternatively send notification e-mail
                ScoreInfoProvider.CheckScoringLimits(ContactInfoProvider.GetContactInfo(ai.ActivityActiveContactID), limitScores);
            }


            // Reload form (due to "view URL" button)
            LoadData();
        }
    }
Example #2
0
 private void RecalculatePersonas()
 {
     foreach (var score in ScoreInfoProvider.GetScores()
              .WhereEquals("ScoreStatus", ScoreStatusEnum.RecalculationRequired).WhereTrue("ScoreBelongsToPersona"))
     {
         new ScoreAsyncRecalculator(score).RunAsync();
     }
 }
Example #3
0
        /// <summary>Performs scoring objects and rules generation.</summary>
        public void Generate()
        {
            if (ScoreInfoProvider.GetScores().WhereEquals("ScoreName", "EngagementAndBusinessFit")
                .WhereFalse("ScoreBelongsToPersona").TopN(1).FirstOrDefault() != null)
            {
                return;
            }

            var scoreObj = new ScoreInfo
            {
                ScoreDisplayName = "Engagement and business fit",
                ScoreName        = "EngagementAndBusinessFit",
                ScoreDescription =
                    "Measures the fit and interest of B2B prospects on the site. Fit is measured by demographics and geographics. Interest is measured by behavior on the site that can be tied to B2B activities, such as visiting the 'Partnership' section of the site or providing a phone number.",
                ScoreEnabled           = true,
                ScoreStatus            = ScoreStatusEnum.RecalculationRequired,
                ScoreEmailAtScore      = 20,
                ScoreNotificationEmail = "*****@*****.**"
            };

            ScoreInfoProvider.SetScoreInfo(scoreObj);
            var treeNode = DocumentHelper.GetDocuments().All().Culture("en-US").Path("/Partnership").Columns("NodeID")
                           .OnCurrentSite().TopN(1).FirstOrDefault();

            if (treeNode != null)
            {
                var rule = GenerateRule("Visited the Partnership section", 5, scoreObj.ScoreID,
                                        "<condition>\r\n  <activity name=\"pagevisit\">\r\n    <field name=\"ActivityCreated\">\r\n      <settings>\r\n        <seconddatetime>1/1/0001 12:00:00 AM</seconddatetime>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityNodeID\">\r\n      <value>" +
                                        treeNode.NodeID +
                                        "</value>\r\n    </field>\r\n    <field name=\"ActivityURL\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityTitle\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityComment\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityCampaign\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityURLReferrer\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityABVariantName\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n    <field name=\"ActivityMVTCombinationName\">\r\n      <settings>\r\n        <operator>0</operator>\r\n      </settings>\r\n    </field>\r\n  </activity>\r\n  <wherecondition>(ActivityType='pagevisit') AND ([ActivityNodeID] = " +
                                        treeNode.NodeID + ")</wherecondition>\r\n</condition>", RuleTypeEnum.Activity, "pagevisit", false);
                rule.RuleIsRecurring = true;
                rule.RuleMaxPoints   = 15;
                RuleInfoProvider.SetRuleInfo(rule);
            }

            var bizFormInfo = BizFormInfoProvider.GetBizFormInfo("BusinessCustomerRegistration", _mSite.SiteID);

            if (bizFormInfo != null)
            {
                GenerateRule("Submitted the business registration form", 15, scoreObj.ScoreID,
                             BuildMacroRuleCondition("{%Rule(\"(Contact.SubmittedForm(\\\"" + bizFormInfo.FormName +
                                                     "\\\", ToInt(0)))\", \"&lt;rules&gt;&lt;r pos=\\\"0\\\" par=\\\"\\\" op=\\\"and\\\" n=\\\"CMSContactHasSubmittedSpecifiedFormInLastXDays\\\" &gt;&lt;p n=\\\"_perfectum\\\"&gt;&lt;t&gt;has&lt;/t&gt;&lt;v&gt;&lt;/v&gt;&lt;r&gt;0&lt;/r&gt;&lt;d&gt;select operation&lt;/d&gt;&lt;vt&gt;text&lt;/vt&gt;&lt;tv&gt;0&lt;/tv&gt;&lt;/p&gt;&lt;p n=\\\"days\\\"&gt;&lt;t&gt;#enter days&lt;/t&gt;&lt;v&gt;0&lt;/v&gt;&lt;r&gt;0&lt;/r&gt;&lt;d&gt;enter days&lt;/d&gt;&lt;vt&gt;text&lt;/vt&gt;&lt;tv&gt;0&lt;/tv&gt;&lt;/p&gt;&lt;p n=\\\"item\\\"&gt;&lt;t&gt;" +
                                                     bizFormInfo.FormName + "&lt;/t&gt;&lt;v&gt;" + bizFormInfo.FormName +
                                                     "&lt;/v&gt;&lt;r&gt;1&lt;/r&gt;&lt;d&gt;select form&lt;/d&gt;&lt;vt&gt;text&lt;/vt&gt;&lt;tv&gt;0&lt;/tv&gt;&lt;/p&gt;&lt;/r&gt;&lt;/rules&gt;\")%}"),
                             RuleTypeEnum.Macro, null, false);
            }

            GenerateRule("Provided phone number", 10, scoreObj.ScoreID,
                         "<condition>\r\n  <attribute name=\"ContactBusinessPhone\">\r\n    <params>\r\n      <ContactBusinessPhoneOperator>9</ContactBusinessPhoneOperator>\r\n    </params>\r\n  </attribute>\r\n  <wherecondition>([ContactBusinessPhone] &lt;&gt; N'' AND [ContactBusinessPhone] IS NOT NULL)</wherecondition>\r\n</condition>",
                         RuleTypeEnum.Attribute, "ContactBusinessPhone");
            RecalculateScores();
        }
Example #4
0
    /// <summary>
    /// OnAfterSave event handler.
    /// </summary>
    protected void EditForm_OnAfterSave(object sender, EventArgs e)
    {
        // Get edited contact group
        ScoreInfo score = (ScoreInfo)EditForm.EditedObject;

        // Set info for scheduled task
        task = GetScheduledTask(score);

        // Update scheduled task
        if (chkSchedule.Checked)
        {
            if (!schedulerInterval.CheckOneDayMinimum())
            {
                // If problem occurred while setting schedule interval
                EditForm.ErrorLabel.Text    = GetString("Newsletter_Edit.NoDaySelected");
                EditForm.ErrorLabel.Visible = true;
                EditForm.StopProcessing     = true;
                return;
            }

            if (!IsValidDate(SchedulingHelper.DecodeInterval(schedulerInterval.ScheduleInterval).StartTime))
            {
                // Start date is not in valid format
                EditForm.ErrorLabel.Text    = GetString("Newsletter.IncorrectDate");
                EditForm.ErrorLabel.Visible = true;
                EditForm.StopProcessing     = true;
                return;
            }

            task.TaskInterval    = schedulerInterval.ScheduleInterval;
            task.TaskNextRunTime = SchedulingHelper.GetNextTime(task.TaskInterval, new DateTime(), new DateTime());
            task.TaskEnabled     = true;
        }
        else
        {
            task.TaskInterval    = schedulerInterval.ScheduleInterval;
            task.TaskNextRunTime = TaskInfoProvider.NO_TIME;
            task.TaskEnabled     = false;
        }
        TaskInfoProvider.SetTaskInfo(task);

        score.ScoreScheduledTaskID = task.TaskID;
        pnlInfo.Visible            = true;
        InitInfoPanel(score);

        // Update score
        ScoreInfoProvider.SetScoreInfo(score);

        InitHeaderActions();
        ((CMSPage)Page).CurrentMaster.HeaderActions.ReloadData();
    }
    /// <summary>
    /// Recalculates score at time that user specified.
    /// </summary>
    /// <param name="score">Score to recalculate</param>
    private void StartRecalculationLater(ScoreInfo score)
    {
        // Set info for scheduled task
        var task = ScoreInfoProvider.EnsureScheduledTask(score, String.Empty, TaskInfoProvider.NO_TIME, false, false);

        task.TaskNextRunTime        = calendarControl.SelectedDateTime;
        task.TaskDeleteAfterLastRun = true;
        task.TaskEnabled            = true;
        TaskInfoProvider.SetTaskInfo(task);

        // Update score
        score.ScoreScheduledTaskID = task.TaskID;
        ScoreInfoProvider.SetScoreInfo(score);
    }
Example #6
0
    /// <summary>
    /// Unigrid button clicked.
    /// </summary>
    protected void gridElem_OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            // Check modify permission
            if (!CheckPermissions("cms.scoring", "Modify"))
            {
                return;
            }

            int scoreId = ValidationHelper.GetInteger(actionArgument, 0);
            // Delete score
            ScoreInfoProvider.DeleteScoreInfo(scoreId);
        }
    }
Example #7
0
    /// <summary>
    /// Initiates header actions.
    /// </summary>
    private void InitHeaderActions()
    {
        var recalculationQuery = QueryHelper.BuildQueryWithHash("scoreID", ScoreId.ToString(CultureInfo.InvariantCulture));
        var recalculationURL   = ResolveUrl("~/CMSModules/Scoring/Pages/ScheduleRecalculationDialog.aspx") + recalculationQuery;
        var score = ScoreInfoProvider.GetScoreInfo(ScoreId);

        mButtonRecalculate = mButtonRecalculate ?? new HeaderAction
        {
            Text          = GetString("om.score.recalculate"),
            OnClientClick = "modalDialog('" + recalculationURL + @"', '', 660, 320);",
            Enabled       = false,
            ResourceName  = score.TypeInfo.ModuleName,
            Permission    = "modify"
        };
        HeaderActions.AddAction(mButtonRecalculate);
    }
    private object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter)
    {
        switch (sourceName)
        {
        case "view":
            CMSGridActionButton viewBtn = (CMSGridActionButton)sender;
            viewBtn.OnClientClick = "ViewDetails(" + viewBtn.CommandArgument + "); return false;";
            break;

        case "scorestatus":
            DataRowView rowView = parameter as DataRowView;
            int         ScoreID = ValidationHelper.GetInteger(rowView["ScoreID"], 0);
            ScoreInfo   info    = ScoreInfoProvider.GetScoreInfo(ScoreID);
            return(GetFormattedStatus(info));
        }
        return(null);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var score = ScoreInfoProvider.GetScoreInfo(ScoreId);

        if (score == null)
        {
            RedirectToInformation("Internal error. Unknown score.");
        }

        // Check permissions
        if (!score.CheckPermissions(PermissionsEnum.Modify, CurrentSite.SiteName, CurrentUser))
        {
            UIForm.Enabled = false;
            ShowError(GetString("ui.notauthorizemodified"));
            UIForm.StopProcessing = true;
        }

        InitControls();
        InitHeaderActions();

        // Note: controls has to be initialized here with previously selected values to avoid "Must match the control tree" error when loading ViewState
        switch (SelectedRuleType)
        {
        case RuleTypeEnum.Activity:
            InitActivitySettings(PreviousSelectedActivity);
            break;

        case RuleTypeEnum.Attribute:
            InitAttributeSettings(PreviousSelectedAttribute);
            break;

        case RuleTypeEnum.Macro:
            InitMacroSettings();
            break;
        }

        if (QueryHelper.GetBoolean("saved", false))
        {
            InitWarnings();
        }

        // Use mode always to update header actions to show warning info all the time.
        HeaderActions.UpdatePanel.UpdateMode = UpdatePanelUpdateMode.Always;
    }
    /// <summary>
    /// Shows warning message if score needs to be rebuilt.
    /// </summary>
    private void InitWarnings()
    {
        ScoreInfo info = ScoreInfoProvider.GetScoreInfo(ScoreId);

        // Do nothing if recalculation is already scheduled
        if (info.ScoreScheduledTaskID > 0)
        {
            TaskInfo taskInfo = TaskInfoProvider.GetTaskInfo(info.ScoreScheduledTaskID);
            if (taskInfo != null && taskInfo.TaskEnabled)
            {
                return;
            }
        }

        if (info.ScoreStatus == ScoreStatusEnum.RecalculationRequired)
        {
            ShowInformation(GetString(mRecalculationNeededResourceString));
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        QueryHelper.ValidateHash("hash");
        ScoreInfo scoreInfo = ScoreInfoProvider.GetScoreInfo(QueryHelper.GetInteger("scoreID", 0));

        if (scoreInfo == null)
        {
            ShowError(GetString("general.objectnotfound"));
            return;
        }

        if (!RequestHelper.IsPostBack())
        {
            LoadValuesFromExistingScore(scoreInfo);
        }

        string tooltipTextKey = scoreInfo.ScoreBelongsToPersona ? "persona.recalculationwarninglong" : "om.score.recalculationwarninglong";

        ShowWarning(GetString("om.score.recalculationwarning"), null, GetString(tooltipTextKey));

        Save += (s, ea) => ScheduleRecalculation(scoreInfo);
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        int scoreId = QueryHelper.GetInteger("scoreid", 0);
        var rule    = EditedObject as RuleInfo;

        // Check if rule is child of score
        // If creating new rule, it is allowed for the rule to be null
        if ((rule != null) && (rule.RuleScoreID != scoreId))
        {
            AccessDenied();
        }

        // Check if score is visible in scoring module
        var score = ScoreInfoProvider.GetScoreInfo(scoreId);

        if (score != null && score.ScoreBelongsToPersona)
        {
            AccessDenied();
        }

        editElem.ScoreId = scoreId;
        editElem.RedirectUrlAfterCreate = string.Format("Tab_Rules_Edit.aspx?ruleid={{%EditedObject.ID%}}&scoreid={0}&saved=1", scoreId);
    }
    /// <summary>
    /// Immediately recalculates score.
    /// </summary>
    /// <param name="score">Score to recalculate</param>
    private void StartRecalculationNow(ScoreInfo score)
    {
        if (score.ScoreStatus == ScoreStatusEnum.Recalculating)
        {
            // Score is already being recalculated
            return;
        }

        // Delete already scheduled task, it is not needed
        if (score.ScoreScheduledTaskID > 0)
        {
            TaskInfoProvider.DeleteTaskInfo(score.ScoreScheduledTaskID);
            score.ScoreScheduledTaskID = 0;
        }

        // Set score as recalculating before running the async recalculator, so the change is displayed at the UI immediatelly
        ScoreInfoProvider.MarkScoreAsRecalculating(score);

        // Recalculate the score
        ScoreAsyncRecalculator recalculator = new ScoreAsyncRecalculator(score);
        Task result = recalculator.RunAsync();

        LogTaskException(result);
    }
Example #14
0
    /// <summary>
    /// Performs custom validation and displays error in top of the page.
    /// </summary>
    /// <returns>Returns true if validation is successful.</returns>
    private bool ValidateForm()
    {
        ScoreInfo info = ScoreInfoProvider.GetScoreInfo(ScoreId);

        if (info.ScoreStatus == ScoreStatusEnum.Recalculating)
        {
            ShowError(GetString("om.score.editrulefailedrecalculating"));
            return(false);
        }

        switch (SelectedRuleType)
        {
        case RuleTypeEnum.Activity:
            return(ValidateActivityData());

        case RuleTypeEnum.Attribute:
            return(ValidateAttributeData());

        case RuleTypeEnum.Macro:
            return(ValidateMacroData());
        }

        return(true);
    }
Example #15
0
    public static string GetScoreStatus(int scoreID)
    {
        var score = ScoreInfoProvider.GetScoreInfo(scoreID);

        return(score != null?score.ScoreStatus.ToString() : null);
    }
Example #16
0
    /// <summary>
    /// Gets formatted score status. Score can be disabled, it can be scheduled to rebuild in the future or its status is one of <see cref="ScoreStatusEnum"/>.
    /// </summary>
    private void InitWarnings(int scoreID)
    {
        var info = ScoreInfoProvider.GetScoreInfo(scoreID);

        if (info == null)
        {
            return;
        }

        // "Recalculation scheduled" status
        if (info.ScoreScheduledTaskID > 0)
        {
            TaskInfo taskInfo = TaskInfoProvider.GetTaskInfo(info.ScoreScheduledTaskID);
            if (taskInfo != null && taskInfo.TaskEnabled)
            {
                ShowInformation(String.Format(GetString("om.score.recalculatescheduledat"), taskInfo.TaskNextRunTime.ToString()));
                mButtonRecalculate.Enabled = true;
                return;
            }
        }

        // Other statuses
        switch (info.ScoreStatus)
        {
        case ScoreStatusEnum.Ready:
            // Score should be up to date, no need to inform user about anything
            if (info.ScoreEnabled)
            {
                mButtonRecalculate.Tooltip = GetString(mRecalculationNotNeededTooltipResourceString);
            }
            else
            {
                mButtonRecalculate.Enabled = true;
            }
            break;

        case ScoreStatusEnum.RecalculationRequired:
            ShowInformation(GetString(mRecalculationNeededResourceString));
            mButtonRecalculate.Enabled = true;
            break;

        case ScoreStatusEnum.Recalculating:
            ShowInformation(GetString("om.score.recalculationstarted2"));
            gridElem.GridView.Enabled = false;
            break;

        case ScoreStatusEnum.RecalculationFailed:
            ShowInformation(GetString("om.score.recalcfailed"));
            mButtonRecalculate.Enabled = true;
            break;

        default:
        case ScoreStatusEnum.Unspecified:
            throw new Exception("[RuleList.InitInformation]: Score status not specified.");
        }

        if ((ModifyPermissions != null) && !ModifyPermissions.Value)
        {
            mButtonRecalculate.Enabled = false;
            mButtonRecalculate.Tooltip = GetString("general.modifynotallowed");
        }
    }
Example #17
0
    /// <summary>
    /// UIForm OnBeforeSave event handler.
    /// </summary>
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        // Store parent score ID
        EditForm.Data["RuleScoreID"] = scoreId;

        // Store site ID
        if (EditForm.EditedObject.Generalized.ObjectID == 0)
        {
            EditForm.Data["RuleSiteID"] = CMSContext.CurrentSiteID;
        }

        // Store attribute or activity rule
        EditForm.Data["RuleType"] = ValidationHelper.GetInteger(radType.SelectedValue, 0);

        // For activity rule store validity
        if (!AttributeRuleSelected)
        {
            EditForm.Data["RuleValidity"] = validity.Validity;
            if (validity.Validity == ValidityEnum.Until)
            {
                if (validity.ValidUntil != DateTimeHelper.ZERO_TIME)
                {
                    EditForm.Data["RuleValidUntil"] = validity.ValidUntil;
                }
                else
                {
                    EditForm.Data["RuleValidUntil"] = null;
                }
            }
            else
            {
                EditForm.Data["RuleValidFor"]   = validity.ValidFor;
                EditForm.Data["RuleValidUntil"] = null;
            }

            // Store contact column for attribute rule
            EditForm.Data["RuleParameter"] = ucActivityType.SelectedValue;

            // Store xml with where condition
            activityFormCondition.SaveData(null);
            string whereCond = "ActivityType='" + SqlHelperClass.GetSafeQueryString(ucActivityType.SelectedValue, false) + "'";
            whereCond = SqlHelperClass.AddWhereCondition(whereCond, activityFormCondition.GetWhereCondition());
            EditForm.Data["RuleCondition"] = RuleHelper.GetConditionFromData(activityFormCondition.Data, whereCond, RuleTypeEnum.Activity, ucActivityType.SelectedValue);
        }
        // For attribute rule don't store validity
        else
        {
            EditForm.Data["RuleValidity"]   = null;
            EditForm.Data["RuleValidUntil"] = null;
            EditForm.Data["RuleValidFor"]   = null;

            // Store contact column for attribute rule
            EditForm.Data["RuleParameter"] = selectedField.Name;

            // Store xml with where condition
            formCondition.SaveData(null);
            EditForm.Data["RuleCondition"] = RuleHelper.GetConditionFromData(formCondition.Data, formCondition.GetWhereCondition(), RuleTypeEnum.Attribute, null);
        }

        // Get rule's parent object (score)
        ScoreInfo score = ScoreInfoProvider.GetScoreInfo(scoreId);

        if (score != null)
        {
            // Change status to 'Recalculation required'
            score.ScoreStatus = ScoreStatusEnum.New;
            ScoreInfoProvider.SetScoreInfo(score);
        }
    }
Example #18
0
    /// <summary>
    /// Actions handler.
    /// </summary>
    protected void HeaderActions_ActionPerformed(object sender, CommandEventArgs e)
    {
        // Check modify permission
        CheckPermissions("cms.scoring", "modify");

        switch (e.CommandName.ToLower())
        {
        case "save":
            // Save changes in the contact group
            EditForm.SaveData(null);
            break;

        case "recalculate":
            if (EditForm.EditedObject != null)
            {
                ScoreInfo score = (ScoreInfo)EditForm.EditedObject;
                if (score != null)
                {
                    // Set 'Recalculating' status
                    score.ScoreStatus = ScoreStatusEnum.Recalculating;
                    // Ensure scheduled task
                    if (score.ScoreScheduledTaskID == 0)
                    {
                        // Create and initialize new scheduled task
                        task = GetScheduledTask(score);
                        task.TaskInterval    = schedulerInterval.ScheduleInterval;
                        task.TaskNextRunTime = TaskInfoProvider.NO_TIME;
                        task.TaskEnabled     = false;
                        TaskInfoProvider.SetTaskInfo(task);

                        // Update score info
                        score.ScoreScheduledTaskID = task.TaskID;
                    }
                    ScoreInfoProvider.SetScoreInfo(score);

                    // Recalculate the score
                    ScoreEvaluator evaluator = new ScoreEvaluator();
                    evaluator.ScoreID = score.ScoreID;
                    evaluator.Execute(null);

                    EditForm.InfoLabel.Text    = GetString("om.score.recalculationstarted");
                    EditForm.InfoLabel.Visible = true;

                    // Get scheduled task and update last run time
                    if (task == null)
                    {
                        task = TaskInfoProvider.GetTaskInfo(score.ScoreScheduledTaskID);
                    }
                    if (task != null)
                    {
                        task.TaskLastRunTime = DateTime.Now;
                        TaskInfoProvider.SetTaskInfo(task);
                    }

                    // Display basic info about score
                    InitInfoPanel(score);
                }
            }
            break;
        }
    }