Esempio n. 1
0
        public static void SetVariableValuesFromItem(EmailVariable variable, SPListItem sourceListItem, SPListItem taskItem, SPUser user)
        {
            PropertyInfo property;
            switch (variable.Type.ToLower())
            {
                case Constants.Workflow.ITEM:
                    SetVariableValues(variable, sourceListItem);
                    break;

                case Constants.Workflow.TASK:
                    if (taskItem == null) break;
                    SetVariableValues(variable, taskItem);

                    if (string.IsNullOrEmpty(variable.Value)
                        && string.Compare("Comment", variable.Name, true) == 0)
                    {
                        Hashtable properties = SPWorkflowTask.GetExtendedPropertiesAsHashtable(taskItem);
                        if (properties.ContainsKey(Constants.Workflow.CCI_COMMENT))
                        {
                            variable.Value = properties[Constants.Workflow.CCI_COMMENT].ToString();
                        }
                    }
                    break;

                case Constants.Workflow.TASK_LIST:
                    if (taskItem == null) break;
                    SetVariableValues(variable, taskItem.ParentList);
                    break;

                case Constants.Workflow.CURRENT_USER:
                    if (user == null) break;
                    Type type = user.GetType();
                    property = type.GetProperties().FirstOrDefault(p => string.Compare(p.Name, variable.Name, true) == 0);
                    if (property == null)
                        break;
                    object value1 = property.GetValue(user, null);
                    variable.Value = value1 == null ? string.Empty : value1.ToString();
                    break;

                case Constants.Workflow.GLOBAL:
                    ProcessGlobalVariables(variable, sourceListItem, taskItem);
                    break;

                case Constants.Workflow.NONE:
                    break;
            }
        }