Exemple #1
0
 public void CancelExecuting(EmailTemplateUserTask userTask, Action <object[]> callBase,
                             params object[] parameters)
 {
     UserConnection.IProcessEngine.RemoveActivityProcessListener(userTask.ActivityId, userTask.UId,
                                                                 ActivityConsts.CanceledStatusUId);
     callBase(parameters);
 }
Exemple #2
0
        public bool CompleteExecuting(EmailTemplateUserTask userTask, Func <object[], bool> callBase,
                                      params object[] parameters)
        {
            var activity = parameters[0] as Activity;

            if (activity == null)
            {
                return(false);
            }
            userTask.OwnerId = activity.OwnerId;
            IEnumerable <string> activityConnections = GetActivityConnections();

            foreach (string activityConnection in activityConnections)
            {
                SetParameterByActivity(userTask, activity, activityConnection);
            }
            ProcessUserTaskUtilities.SetEntityColumnValues(userTask, activity);
            userTask.ActivityResult      = activity.ResultId;
            userTask.IsActivityCompleted = true;
            bool result = callBase(parameters);

            activity.SetColumnValue("ProcessElementId", null);
            activity.UseAdminRights = false;
            activity.Save();
            return(result);
        }
        protected Dictionary <string, string> GetMacrosValues(EmailTemplateUserTask userTask,
                                                              IEnumerable <MacrosInfo> macrosInfoCollection)
        {
            ProcessSchemaUserTask userTaskSchema = GetProcessSchemaUserTask(userTask);
            var macrosValues     = new Dictionary <string, string>();
            var lookupParameters = new List <ProcessSchemaParameter>();

            foreach (MacrosInfo macrosInfo in macrosInfoCollection)
            {
                ProcessSchemaParameter parameter = GetParameterByName(userTaskSchema, macrosInfo.Alias);
                if (parameter == null)
                {
                    _logger.Log("Parameter for macros {0} is not found", macrosInfo.Alias);
                    continue;
                }
                object propertyValue = GetParameterValue(userTask, parameter);
                if (propertyValue != null)
                {
                    _logger.Log("Property value is {0}", propertyValue);
                    macrosValues.Add(macrosInfo.Alias, propertyValue.ToString());
                    lookupParameters.Add(parameter);
                }
            }
            foreach (ProcessSchemaParameter parameter in lookupParameters)
            {
                string entityDisplayName = GetEntityPrimaryColumnDisplayName(userTask,
                                                                             macrosValues[parameter.Name], parameter);
                if (!string.IsNullOrEmpty(entityDisplayName))
                {
                    _logger.Log("Entity display value is {0}", entityDisplayName);
                    macrosValues[parameter.Name] = entityDisplayName;
                }
            }
            return(macrosValues);
        }
Exemple #4
0
        public bool Execute(IEmailUserTaskMessageProvider messageProvider, ProcessExecutingContext context)
        {
            EmailTemplateUserTask userTask = messageProvider.EmailUserTask;
            EmailMessage          message  = messageProvider.GetEmailMessage();

            if (message.To.IsNullOrEmpty())
            {
                return(true);
            }
            if (message.From.IsEmpty())
            {
                SendEmailWithDefaultSender(message, userTask.IgnoreErrors);
                return(true);
            }
            var constructorArguments = new ConstructorArgument("userConnection", UserConnection);
            var emailClientFactory   = ClassFactory.Get <EmailClientFactory>(constructorArguments);
            var emailSender          = new HtmlEmailMessageSender(emailClientFactory, UserConnection);

            try {
                bool ignoreRights = (SendEmailType)userTask.SendEmailType == SendEmailType.Auto;
                emailSender.Send(message, ignoreRights);
            } catch (Exception e) {
                _log.Error(e);
                if (!userTask.IgnoreErrors)
                {
                    throw;
                }
            }
            return(true);
        }
Exemple #5
0
        public string GetExecutionData(EmailTemplateUserTask userTask)
        {
            string informationOnStep = LocalizableString.IsNullOrEmpty(userTask.InformationOnStep)
                                ? userTask.GetParameterValue("InformationOnStep")?.ToString() ?? string.Empty
                                : userTask.InformationOnStep.Value;
            string allowedActivityResults = ProcessUserTaskUtilities.GetAllowedActivityResults(UserConnection,
                                                                                               userTask.ActivityId);
            Guid parentProcessId = ProcessUserTaskUtilities.GetParentProcessId(userTask.Owner);

            return
                (ServiceStackTextHelper.Serialize(
                     new {
                procElUId = userTask.UId,
                name = userTask.Name,
                processId = parentProcessId,
                isProcessExecutedBySignal = userTask.Owner.IsProcessExecutedBySignal,
                processName = userTask.Owner.Name,
                entitySchemaName = "Activity",
                recommendation = GetActivityTitle(userTask),
                informationOnStep,
                pageTypeId = ActivityConsts.EmailTypeUId,
                activityRecordId = userTask.ActivityId,
                executionContext = userTask.ExecutionContext,
                nextProcElUId = "nextProcElUIdValue",
                allowedResults = allowedActivityResults
            }));
        }
        public static IEmailUserTaskMacrosProvider GetMacrosHelper(
            EmailTemplateUserTask userTask, UserConnection userConnection)
        {
            bool useAdminRights = userTask.SendEmailType != (int)SendEmailType.Auto;

            switch ((BodyTemplateType)userTask.BodyTemplateType)
            {
            case BodyTemplateType.EmailTemplate:
                return(new EmailTemplateUserTaskMacrosHelper(userTask)
                {
                    UserConnection = userConnection,
                    UseAdminRights = useAdminRights
                });

            case BodyTemplateType.ProcessTemplate:
                return(new ProcessEmailUserTaskMacrosHelper(userTask)
                {
                    UserConnection = userConnection,
                    UseAdminRights = useAdminRights
                });

            default:
                throw new NotImplementedException();
            }
        }
        protected virtual object GetParameterValue(EmailTemplateUserTask userTask, Guid parameterUId)
        {
            var schemaElement = (IParametrizedProcessSchemaElement)userTask.GetSchemaElement();
            var parameters    = schemaElement.ForceGetParameters();
            var parameter     = parameters.GetByUId(parameterUId);

            return(userTask.GetParameterValue(parameter));
        }
Exemple #8
0
        private void InternalExecute(IEmailUserTaskMessageProvider messageProvider)
        {
            EmailTemplateUserTask userTask = messageProvider.EmailUserTask;
            EmailMessage          message  = messageProvider.GetEmailMessage();
            Activity activity = CreateActivity(message, userTask);

            userTask.ExecuteAfterActivitySaveScript(activity);
        }
Exemple #9
0
        protected virtual void LinkActivityToProcess(Activity activity, EmailTemplateUserTask userTask)
        {
            Guid   resultColumntUId = activity.Schema.Columns.GetByName("Status").UId;
            string conditionData    =
                ProcessUserTaskUtilities.GetConditionData(UserConnection, resultColumntUId, activity);

            UserConnection.IProcessEngine.AddProcessListener(activity, userTask.UId, conditionData);
            UserConnection.IProcessEngine.LinkProcessToEntity(userTask.Owner, activity.Schema.UId, activity.Id);
        }
        private string GetMacrosValue(EmailTemplateUserTask userTask, object parameterValue, string macros)
        {
            string columnUId        = GetMacrosValueByPattern(_entityColumnPattern, macros);
            var    parameterMapInfo = GetProcessParameterMapInfo(userTask.Owner, macros);
            var    parameter        = userTask.Owner.FindParameter(parameterMapInfo);
            string value            = string.IsNullOrEmpty(columnUId) || !(parameter.DataValueType is EntityDataValueType)
                                ? parameter.DataValueType.GetDisplayValue(parameterValue)
                                : GetEntityParameterDisplayValue(parameter, parameterValue, parameterMapInfo);

            return(value);
        }
Exemple #11
0
        private void FillActivityConnections(Activity activity, EmailTemplateUserTask userTask)
        {
            IEnumerable <string> activityConnections = GetActivityConnections();

            foreach (string activityConnection in activityConnections)
            {
                object propertyValue = userTask.GetPropertyValue(activityConnection);
                ProcessUserTaskUtilities.SetEntityColumnValue(activity, activityConnection, propertyValue);
            }
            ProcessUserTaskUtilities.SetEntityColumnValues(userTask, activity);
        }
        protected virtual string GetEntityPrimaryColumnDisplayName(EmailTemplateUserTask userTask,
                                                                   object parameterValue, ProcessSchemaParameter parameter)
        {
            string       result          = null;
            EntitySchema referenceSchema = parameter.ReferenceSchema;
            Entity       entity          = referenceSchema.CreateEntity(userTask.UserConnection);

            if (entity.FetchPrimaryInfoFromDB(referenceSchema.GetPrimaryColumnName(), parameterValue))
            {
                result = entity.PrimaryDisplayColumnValue;
            }
            return(result);
        }
Exemple #13
0
 private string GetActivityTitle(EmailTemplateUserTask userTask)
 {
     if (userTask.IsExecuted)
     {
         Select select =
             new Select(UserConnection).
             Column("Title").
             From("Activity").
             Where("Id").IsEqual(Column.Parameter(userTask.ActivityId)) as Select;
         return(select.ExecuteScalar <string>());
     }
     return(userTask.Subject);
 }
Exemple #14
0
        public static IEmailUserTaskMessageProvider GetEmailMessageProvider(EmailTemplateUserTask userTask)
        {
            switch ((BodyTemplateType)userTask.BodyTemplateType)
            {
            case BodyTemplateType.EmailTemplate:
                return(new EmailTemplateUserTaskMessageProvider(userTask));

            case BodyTemplateType.ProcessTemplate:
                return(new EmailProcessTemplateUserTaskMessageProvider(userTask));

            default:
                throw new NotImplementedException();
            }
        }
Exemple #15
0
        private static void SetParameterByActivity(EmailTemplateUserTask userTask, Activity activity,
                                                   string parameterName)
        {
            var column = activity.Schema.Columns.FindByName(parameterName);

            if (column != null)
            {
                object columnValue = activity.GetColumnValue(column);
                if (columnValue != null)
                {
                    userTask.SetPropertyValue(parameterName, columnValue);
                }
            }
        }
Exemple #16
0
 private static void SetActivityRemindToOwnerDate(Activity activity, EmailTemplateUserTask userTask)
 {
     if (userTask.OwnerId.IsNotEmpty())
     {
         activity.OwnerId = userTask.OwnerId;
         if (userTask.RemindBefore != 0)
         {
             activity.RemindToOwner = true;
             var      processDurationPeriod = (ProcessDurationPeriod)userTask.RemindBeforePeriod;
             DateTime remindToOwnerDate     = ProcessUserTaskUtilities.NewDate(activity.StartDate, -1 * userTask.RemindBefore,
                                                                               processDurationPeriod);
             activity.RemindToOwnerDate = remindToOwnerDate;
         }
     }
 }
Exemple #17
0
        public static IEmailUserTaskSender GetEmailSender(EmailTemplateUserTask userTask)
        {
            switch ((SendEmailType)userTask.SendEmailType)
            {
            case SendEmailType.Auto:
                return(new AutoEmailUserTaskSender {
                    UserConnection = userTask.UserConnection
                });

            case SendEmailType.Manual:
                return(new ManualEmailUserTaskSender {
                    UserConnection = userTask.UserConnection
                });

            default:
                throw new NotImplementedException();
            }
        }
        protected object GetParameterValue(EmailTemplateUserTask userTask, string macros)
        {
            // TODO CRM-40288 rewrite using userTask.Owner.GetParameterValueByMetaPath(macros) for both cases
            var    process = userTask.Owner;
            object parameterValue;

            if (userTask.CanUseFlowEngine)
            {
                var valueProvider    = process.ParameterValueProvider;
                var parameterMapInfo = GetProcessParameterMapInfo(process, macros);
                parameterValue = valueProvider.GetParameterValue(parameterMapInfo);
            }
            else
            {
                parameterValue = process.GetParameterValueByMetaPath(macros);
            }
            return(parameterValue);
        }
Exemple #19
0
        private Activity CreateActivity(EmailMessage message, EmailTemplateUserTask userTask)
        {
            var activity = new Activity(UserConnection);

            activity.SetDefColumnValues();
            activity.Id            = Guid.NewGuid();
            activity.TypeId        = ActivityConsts.EmailTypeUId;
            activity.MessageTypeId = ActivityConsts.OutgoingEmailTypeId;
            userTask.Subject       = message.Subject;
            activity.Title         = message.Subject;
            activity.StartDate     = ProcessUserTaskUtilities.NewDate(
                UserConnection.CurrentUser.GetCurrentDateTime(), userTask.StartIn,
                (ProcessDurationPeriod)userTask.StartInPeriod);
            activity.DueDate = ProcessUserTaskUtilities.NewDate(
                activity.StartDate, userTask.Duration, (ProcessDurationPeriod)userTask.DurationPeriod);
            if (userTask.ActivityCategory.IsEmpty())
            {
                userTask.ActivityCategory = ActivityConsts.EmailActivityCategoryId;
            }
            activity.ActivityCategoryId = userTask.ActivityCategory;
            activity.ShowInScheduler    = userTask.ShowInScheduler;
            activity.Recepient          = message.To.ConcatIfNotEmpty(";");
            activity.CopyRecepient      = message.Cc.ConcatIfNotEmpty(";");
            activity.BlindCopyRecepient = message.Bcc.ConcatIfNotEmpty(";");
            activity.Body       = message.Body;
            activity.IsHtmlBody = true;
            activity.Sender     = message.From;
            SetActivityRemindToOwnerDate(activity, userTask);
            FillActivityConnections(activity, userTask);
            activity.ProcessElementId = userTask.UId;
            activity.AllowedResult    = userTask.GetResultAllowedValues();
            LinkActivityToProcess(activity, userTask);
            userTask.IsActivityCompleted = false;
            userTask.ActivityId          = activity.Id;
            return(activity);
        }
 public EmailProcessTemplateUserTaskMessageProvider(EmailTemplateUserTask userTask)
     : base(userTask)
 {
 }
Exemple #21
0
 public string GetExecutionData(EmailTemplateUserTask userTask)
 {
     return(string.Empty);
 }
Exemple #22
0
 public void CancelExecuting(EmailTemplateUserTask userTask,
                             Action <object[]> callBase, params object[] parameters)
 {
     callBase(parameters);
 }
Exemple #23
0
 public bool CompleteExecuting(EmailTemplateUserTask userTask,
                               Func <object[], bool> callBase, params object[] parameters)
 {
     return(callBase(parameters));
 }
 public ProcessEmailUserTaskMacrosHelper(EmailTemplateUserTask userTask)
     : base(userTask)
 {
 }
 protected virtual bool GetIsUseFlowEngine(EmailTemplateUserTask userTask)
 {
     return(!userTask.Owner.IsEmbedded &&
            ProcessSchemaManager.GetCanUseFlowEngine(userTask.UserConnection, userTask.Owner.ProcessSchema));
 }
 protected BaseProcessEmailMessageProvider(EmailTemplateUserTask userTask)
 {
     EmailUserTask = userTask;
 }
Exemple #27
0
 protected BaseEmailUserTaskMacrosHelper(EmailTemplateUserTask userTask)
 {
     UserTask     = userTask;
     EntitySchema = FindSourceEntitySchema();
 }
 protected object GetParameterValue(EmailTemplateUserTask userTask, ProcessSchemaParameter parameter)
 {
     return(userTask.GetParameterValue(parameter));
 }