コード例 #1
0
        public static List<EmailVariable> GetAndSetVariablesFromTemplate(string strInput, SPListItem sourceListItem, SPListItem taskItem, SPUser user)
        {
            List<EmailVariable> list = new List<EmailVariable>();
            List<string> variables = new List<string>();
            variables = extractVariables(strInput);

            foreach (string variable in variables)
            {
                EmailVariable var = new EmailVariable(variable);
                SetVariableValuesFromItem(var, sourceListItem, taskItem, user);
                list.Add(var);
            }

            return list;
        }
コード例 #2
0
 public static void ProcessGlobalVariables(EmailVariable variable, SPListItem sourceListItem, SPListItem taskItem)
 {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
         using (SPWeb web = sourceListItem.ParentList.ParentWeb)
         {
             SPList globalVariableList = Utility.GetListFromURL(web.Site.RootWeb.Url + "/Lists/CMappGlobalVariables");
             if (globalVariableList == null)
                 return;
             SPQuery query = new SPQuery(globalVariableList.DefaultView);
             query.Query = "<Where><And><Eq><FieldRef Name='Title' /><Value Type='Text'>" + variable.Name + "</Value></Eq>";
             query.Query += "<Eq><FieldRef Name='Type' /><Value Type='Text'>Global Variable</Value></Eq></And></Where>";
             SPListItemCollection items = globalVariableList.GetItems(query);
             if (items != null && items.Count > 0)
             {
                 SPListItem item = items[0];
                 if (item[new Guid("23250978-D4C9-4677-AEE5-C9A318740B1C")] != null)
                     variable.Value = item[new Guid("23250978-D4C9-4677-AEE5-C9A318740B1C")].ToString();
                 if (!string.IsNullOrEmpty(variable.Value) && !variable.Value.Contains("%" + variable.Type + ":" + variable.Name + "%"))
                 {
                     List<EmailVariable> newVariable = GetAndSetVariablesFromTemplate(variable.Value, item, taskItem);
                     variable.Value = SetValuesToContent(variable.Value, newVariable, new List<EmailVariable>());
                 }
                 else
                 {
                     if (item[new Guid("40BB5B9B-B29A-42e0-98BF-B0255441C53F")] != null)
                         variable.Value = item[new Guid("40BB5B9B-B29A-42e0-98BF-B0255441C53F")].ToString();
                 }
             }
         }
     });
 }
コード例 #3
0
        public static List<EmailVariable> GetVariablesFromDesigner(string strInput)
        {
            List<EmailVariable> list = new List<EmailVariable>();

            return list;

            if (string.IsNullOrEmpty(strInput))
                return list;

            Regex regex = new Regex("%(?<NAME>[^%\r\n]+)*%:(?<VALUE>[^%]+)");
            MatchCollection mats = regex.Matches(strInput);
            foreach (Match mat in mats)
            {
                EmailVariable var = new EmailVariable(mat.Groups["NAME"].Value, mat.Groups["VALUE"].Value);
                list.Add(var);
            }
            return list;
        }
コード例 #4
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;
            }
        }
コード例 #5
0
 public static void SetVariableValuesFromItem(EmailVariable variable, SPListItem sourceListItem, SPListItem taskItem)
 {
     SetVariableValuesFromItem(variable, sourceListItem, taskItem, null);
 }
コード例 #6
0
        public static void SetVariableValues(EmailVariable variable, SPListItem item)
        {
            if (item == null)
            {
                variable.Value = string.Empty;
                return;
            }
            SPField varField = item.Fields.Cast<SPField>().
                FirstOrDefault(p => string.Compare(p.Title, variable.Name, true) == 0 || string.Compare(p.InternalName, variable.Name, true) == 0);

            if (varField != null)
            {
                switch (varField.Type)
                {
                    case SPFieldType.User:
                    case SPFieldType.Lookup:
                        SetLookupValueFieldType(variable, item, varField);
                        break;
                    case SPFieldType.Invalid:
                        if (string.Compare(varField.TypeAsString, Constants.LOOKUP_WITH_PICKER_TYPE_NAME, true) == 0)
                        {
                            SetLookupValueFieldType(variable, item, varField);
                        }

                        if (string.Compare(varField.TypeAsString, Constants.LINK_TO_ITEM_TYPE_NAME, true) == 0)
                        {
                            //SetLookupValueFieldType(variable, item, varField);
                            variable.Value = item[varField.Id] != null ? item[varField.Id].ToString() : string.Empty;
                        }

                        break;
                    case SPFieldType.DateTime:
                        variable.Value = item[varField.Id] != null ? Convert.ToDateTime(item[varField.Id]).ToString("dd/MM/yyyy") : string.Empty;
                        break;
                    default:
                        variable.Value = item[varField.Id] != null ? item[varField.Id].ToString() : string.Empty;
                        break;
                }
            }
        }
コード例 #7
0
        public static void SetVariableValues(EmailVariable variable, SPList list)
        {
            if (list == null)
            {
                variable.Value = string.Empty;
                return;
            }

            if (string.Compare(variable.Name, "name", true) == 0)
            {
                variable.Value = list.Title;
            }

            if (string.Compare(variable.Name, "id", true) == 0)
            {
                variable.Value = list.ID.ToString();
            }
        }
コード例 #8
0
 public static void SetLookupValueFieldType(EmailVariable variable, SPListItem item, SPField varField)
 {
     if (item[varField.Id] == null) return;
     SPFieldLookup lookupField = (SPFieldLookup)varField;
     SPFieldLookupValue itemFieldValue = (SPFieldLookupValue)lookupField.GetFieldValue(item[varField.Id].ToString());
     variable.Value = itemFieldValue.LookupValue;
 }