Пример #1
0
    /// <summary>
    /// Creates automation state. Called when the "Start process" button is pressed.
    /// Expects the CreateProcess, CreateProcessStep and CreateTemporaryObjects method to be run first.
    /// </summary>
    private bool CreateAutomationState()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        int topN     = 1;
        var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(topN);

        // Get the process
        WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation);

        if (!DataHelper.DataSourceIsEmpty(contacts) && (process != null))
        {
            // Get the contact from dataset
            ContactInfo contact = contacts.First <ContactInfo>();

            // Get the instance of automation manager
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            // Start the process
            manager.StartProcess(contact, process.WorkflowID);

            return(true);
        }

        return(false);
    }
    void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        try
        {
            int processId             = ValidationHelper.GetInteger(ucSelector.Value, 0);
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
            var infoObj = ProviderHelper.GetInfoById(listElem.ObjectType, listElem.ObjectID);
            using (CMSActionContext context = new CMSActionContext())
            {
                context.AllowAsyncActions = false;

                manager.StartProcess(infoObj, processId);
            }
        }
        catch (ProcessRecurrenceException ex)
        {
            ShowError(ex.Message);
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }

        listElem.UniGrid.ReloadData();
        pnlUpdate.Update();
    }
Пример #3
0
    /// <summary>
    /// Gets the automation state and move contact to specific step. Called when the "Move to specific step" button is pressed.
    /// Expects the CreateAutomationState method to be run first.
    /// </summary>
    private bool MoveContactToSpecificStep()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        int topN     = 1;
        var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(topN);

        // Get the process
        WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation);

        if (!DataHelper.DataSourceIsEmpty(contacts) && (process != null))
        {
            // Get the contact from dataset
            ContactInfo contact = contacts.First <ContactInfo>();

            // Get the instance of automation manager
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            // Get the automation state
            AutomationStateInfo state = contact.Processes.FirstItem as AutomationStateInfo;

            if (state != null)
            {
                // Get the finished step
                WorkflowStepInfo finishedStep = manager.GetFinishedStep(contact, state);

                // Move contact to specific step
                manager.MoveToSpecificStep(contact, state, finishedStep, "Move to specific step");

                return(true);
            }
        }

        return(false);
    }
Пример #4
0
    private string ExecuteProcess(int processId, ObjectQuery <ContactInfo> query)
    {
        AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
        string            error   = string.Empty;

        using (new CMSActionContext()
        {
            AllowAsyncActions = false
        })
        {
            query.ForEachPage(contacts =>
            {
                foreach (var contact in contacts)
                {
                    try
                    {
                        manager.StartProcess(contact, processId);
                    }
                    catch (ProcessRecurrenceException ex)
                    {
                        error += "<div>" + ex.Message + "</div>";
                    }
                }
            }, 10000);
        }

        return(error);
    }
Пример #5
0
    void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        try
        {
            int contactId             = ValidationHelper.GetInteger(ucSelector.Value, 0);
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
            var infoObj = ContactInfoProvider.GetContactInfo(contactId);
            if (WorkflowStepInfoProvider.CanUserStartAutomationProcess(CurrentUser, SiteInfoProvider.GetSiteName(infoObj.ContactSiteID)))
            {
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;

                    manager.StartProcess(infoObj, ProcessID);
                }
            }
        }
        catch (ProcessRecurrenceException ex)
        {
            ShowError(ex.Message);
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }

        listContacts.ReloadData();
        pnlUpdate.Update();
    }
Пример #6
0
    /// <summary>
    /// Gets the automation state and move contact to previous step. Called when the "Move to previous step" button is pressed.
    /// Expects the CreateAutomationState method to be run first.
    /// </summary>
    private bool MoveContactToPreviousStep()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        int topN = 1;
        InfoDataSet <ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, topN, null);

        // Get the process
        WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation);

        if (!DataHelper.DataSourceIsEmpty(contacts) && (process != null))
        {
            // Get the contact from dataset
            ContactInfo contact = contacts.First <ContactInfo>();

            // Get the instance of automation manager
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            // Get the process state
            AutomationStateInfo state = contact.Processes.FirstItem as AutomationStateInfo;

            if (state != null)
            {
                // Move contact to next step
                manager.MoveToPreviousStep(contact, state, "Move to previous step");

                return(true);
            }
        }

        return(false);
    }
Пример #7
0
    private void UniSelector_OnItemsSelected(object sender, EventArgs e)
    {
        var contacts = ValidationHelper.GetString(ucSelector.Value, null);

        if (String.IsNullOrEmpty(contacts) || !WorkflowStepInfoProvider.CanUserStartAutomationProcess(CurrentUser, CurrentSiteName))
        {
            return;
        }

        var contactIds     = contacts.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Select(i => ValidationHelper.GetInteger(i, 0));
        var manager        = AutomationManager.GetInstance(CurrentUser);
        var processId      = UIContext.ObjectID;
        var warningBuilder = new StringBuilder();

        using (CMSActionContext context = new CMSActionContext {
            AllowAsyncActions = false
        })
        {
            try
            {
                foreach (var contactId in contactIds)
                {
                    var contact = ContactInfo.Provider.Get(contactId);
                    try
                    {
                        manager.StartProcess(contact, processId);
                    }
                    catch (ProcessRecurrenceException ex)
                    {
                        warningBuilder.AppendFormat("<div>{0}</div>", ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                LogAndShowError("Automation", "STARTPROCESS", ex);
                return;
            }
        }

        var warning = warningBuilder.ToString();

        if (!String.IsNullOrEmpty(warning))
        {
            ShowWarning(String.Format(GetString("sf.automation.error"), ""), warning);
        }
        else
        {
            ShowConfirmation(GetString("ma.process.startedselected"));
        }

        // Reload grid
        listContacts.ReloadData();
        pnlUpdate.Update();

        // Reset selector
        ucSelector.Value = null;
    }
Пример #8
0
 private void gridState_OnAction(string actionName, object actionArgument)
 {
     switch (actionName.ToLowerCSafe())
     {
     case "delete":
         int stateId = ValidationHelper.GetInteger(actionArgument, 0);
         AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
         var obj   = CMSObjectHelper.GetObjectById(ObjectType, ObjectID);
         var state = AutomationStateInfoProvider.GetAutomationStateInfo(stateId);
         manager.RemoveProcess(obj, state);
         break;
     }
 }
Пример #9
0
    void Process_OnItemsSelected(object sender, EventArgs e)
    {
        try
        {
            int processId             = ValidationHelper.GetInteger(processSelector.Value, 0);
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            ContactGroupContactListInfo listInfo = new ContactGroupContactListInfo();
            var contacts = listInfo.Generalized.GetData(null, GetWhereCondition(), null, 0, "ContactID", false);
            if (!DataHelper.DataSourceIsEmpty(contacts))
            {
                string error = null;
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;
                    foreach (DataRow row in contacts.Tables[0].Rows)
                    {
                        // Get contact
                        int contactId = ValidationHelper.GetInteger(row[0], 0);
                        var contact   = ContactInfoProvider.GetContactInfo(contactId);

                        try
                        {
                            // Start process
                            manager.StartProcess(contact, processId);
                        }
                        catch (ProcessRecurrenceException ex)
                        {
                            error += ex.Message + "<br />";
                        }
                    }
                }

                if (string.IsNullOrEmpty(error))
                {
                    ShowConfirmation(GetString("ma.process.started"));
                }
                else
                {
                    ShowError(GetString("ma.process.error"), error, null);
                }
            }
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }

        gridElem.ReloadData();
        pnlUpdate.Update();
    }
Пример #10
0
    /// <summary>
    /// Remove contact from process. Called when the "Remove contact from process" button is pressed.
    /// Expects the CreateAutomationState method to be run first.
    /// </summary>
    private bool RemoveContactFromProcess()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        int topN     = 1;
        var contacts = ContactInfoProvider.GetContacts().Where(where).TopN(topN);

        // Get the process
        WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation);

        if (DataHelper.DataSourceIsEmpty(contacts) || (process == null))
        {
            return(false);
        }

        // Get the contact from dataset
        ContactInfo contact = contacts.First <ContactInfo>();

        // Get the instance of automation manager
        AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

        // Get the states
        var states = AutomationStateInfoProvider.GetAutomationStates()
                     .WhereEquals("StateWorkflowID", process.WorkflowID)
                     .WhereEquals("StateObjectID", contact.ContactID)
                     .WhereEquals("StateObjectType", PredefinedObjectType.CONTACT);

        if (states.Any())
        {
            // Loop through the individual items
            foreach (AutomationStateInfo state in states)
            {
                // Remove contact from process
                manager.RemoveProcess(contact, state);
            }

            return(true);
        }

        return(false);
    }
Пример #11
0
    private void gridState_OnAction(string actionName, object actionArgument)
    {
        switch (actionName.ToLowerCSafe())
        {
        case "delete":
            int stateId = ValidationHelper.GetInteger(actionArgument, 0);

            var obj   = BaseAbstractInfoProvider.GetInfoById(ObjectType, ObjectID);
            var state = AutomationStateInfoProvider.GetAutomationStateInfo(stateId);

            if (!CurrentUser.IsAuthorizedPerResource(ModuleName.ONLINEMARKETING, "RemoveProcess", SiteInfoProvider.GetSiteName(state.StateSiteID)))
            {
                RedirectToAccessDenied(ModuleName.ONLINEMARKETING, "RemoveProcess");
            }

            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);
            manager.RemoveProcess(obj, state);

            break;
        }
    }
Пример #12
0
    /// <summary>
    /// Remove contact from process. Called when the "Remove contact from process" button is pressed.
    /// Expects the CreateAutomationState method to be run first.
    /// </summary>
    private bool RemoveContactFromProcess()
    {
        // Get dataset of contacts
        string where = "ContactLastName LIKE N'My New Contact%'";
        int topN = 1;
        InfoDataSet <ContactInfo> contacts = ContactInfoProvider.GetContacts(where, null, topN, null);

        // Get the process
        WorkflowInfo process = WorkflowInfoProvider.GetWorkflowInfo("MyNewProcess", WorkflowTypeEnum.Automation);

        if (!DataHelper.DataSourceIsEmpty(contacts) && (process != null))
        {
            // Get the contact from dataset
            ContactInfo contact = contacts.First <ContactInfo>();

            // Get the instance of automation manager
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            // Prepare the parameters
            where = "StateWorkflowID = " + process.WorkflowID + " AND StateObjectID = " + contact.ContactID + " AND StateObjectType = '" + PredefinedObjectType.CONTACT + "'";

            // Get the states
            InfoDataSet <AutomationStateInfo> states = AutomationStateInfoProvider.GetStates(where, null);

            if (!DataHelper.DataSourceIsEmpty(states))
            {
                // Loop through the individual items
                foreach (AutomationStateInfo state in states)
                {
                    // Remove contact from process
                    manager.RemoveProcess(contact, state);
                }

                return(true);
            }
        }

        return(false);
    }
    private void StartNewProcess(What what, string where)
    {
        try
        {
            AutomationManager manager = AutomationManager.GetInstance(CurrentUser);

            List <string> contactIds = null;

            switch (what)
            {
            case What.All:
                // Get selected IDs based on where condition
                DataSet contacts = ContactGroupMemberInfoProvider.GetRelationships().Where(where).Column("ContactGroupMemberRelatedID");
                if (!DataHelper.DataSourceIsEmpty(contacts))
                {
                    contactIds = DataHelper.GetUniqueValues(contacts.Tables[0], "ContactGroupMemberRelatedID", true);
                }
                break;

            case What.Selected:
                contactIds = gridElem.SelectedItems;
                break;
            }

            if (contactIds != null)
            {
                string error = String.Empty;
                using (CMSActionContext context = new CMSActionContext())
                {
                    context.AllowAsyncActions = false;
                    int processId = ValidationHelper.GetInteger(hdnIdentifier.Value, 0);

                    foreach (string contactId in contactIds)
                    {
                        var contact = ContactInfoProvider.GetContactInfo(ValidationHelper.GetInteger(contactId, 0));

                        try
                        {
                            manager.StartProcess(contact, processId);
                        }
                        catch (ProcessRecurrenceException ex)
                        {
                            error += "<div>" + ex.Message + "</div>";
                        }
                    }
                }

                if (String.IsNullOrEmpty(error))
                {
                    string confirmation = GetString(what == What.All ? "ma.process.started" : "ma.process.startedselected");
                    ShowConfirmation(confirmation);
                }
                else
                {
                    ShowError(GetString("ma.process.error"), error, null);
                }
            }
        }
        catch (Exception ex)
        {
            LogAndShowError("Automation", "STARTPROCESS", ex);
        }
    }