private static object GetFieldValue(IDynamicObject source, string fieldName)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            var property = source.GetPropertyByName(fieldName);
            if (property == null)
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Could not find the property '{0}' in type '{1}'.",
                        fieldName,
                        source.GetType().AssemblyQualifiedName),
                    "fieldName");

            return source.GetValueByPropertyName(fieldName);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the source property information.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <param name="referencePropertyName">Name of the reference property.</param>
        /// <returns>PropertyInfo.</returns>
        public PropertyInfo GetSourcePropertyInfo(IDynamicObject obj, string referencePropertyName)
        {
            var prop = obj.GetPropertyByName(referencePropertyName);
            if (prop == null || prop.Name == Constants.IdColumnName)
                return prop;

            var refAttr = prop.GetCustomAttributes(typeof(ReferenceDisplayFieldAttribute), false).FirstOrDefault() as ReferenceDisplayFieldAttribute;
            if (refAttr == null) return null;

            var sourceType = TheDynamicTypeManager.GetEditableRootType(refAttr.DefinedIn);

            if (sourceType == null) return null;

            var sourceProp = sourceType.GetPropertyByName(refAttr.SystemName);

            if (sourceProp == null) return null;

            var sourceAttrs = sourceProp.GetCustomAttributes(false);

            var isFinal = !sourceAttrs.Any(a => a is CrossRefFieldAttribute || a is ReverseCrossRefFieldAttribute);

            if (isFinal)
            {
                return sourceProp;
            }

            var crAttr = sourceAttrs.FirstOrDefault(a => a is CrossRefFieldAttribute) as CrossRefFieldAttribute;

            if (crAttr != null)
            {
                return GetSourcePropertyInfo(crAttr.ReferenceTableName, crAttr.RefFieldName);
            }

            var reverseCrAttr = sourceAttrs.FirstOrDefault(a => a is ReverseCrossRefFieldAttribute) as ReverseCrossRefFieldAttribute;

            if (reverseCrAttr != null)
            {
                return GetSourcePropertyInfo(reverseCrAttr.ReferenceTableName, reverseCrAttr.CrossReferenceFieldName);
            }

            return null;
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces the fields with values.
        /// </summary>
        /// <param name="templ">The templ.</param>
        /// <param name="item">The item.</param>
        /// <param name="isHtml">if set to <c>true</c> [is HTML].</param>
        /// <returns>System.String.</returns>
        public string ReplaceFieldsWithValues(string templ, IDynamicObject item, bool isHtml = false)
        {
            return ReplaceRegex.Replace(
                templ,
                match =>
                    {
                        var prop = item.GetPropertyByName(match.Groups[1].Value);

                        return prop == null ? match.Value : GetValue(item, prop, isHtml);
                    });
        }
        private static IDynamicObject GetReferencedItem(IDynamicObject item, string propertyName)
        {
            var property = item.GetPropertyByName(propertyName);
            if (property == null)
                return null;

            var crAttribute = property.GetCustomAttribute<CrossRefFieldAttribute>();
            if (crAttribute != null && !crAttribute.AllowMultiple)
            {
                return item.GetValueByPropertyName(propertyName + "Member");
            }

            return item.GetValueByPropertyName(propertyName) as IDynamicObject;
        }
Esempio n. 5
0
        /// <summary>
        /// Determines whether this instance can execute the specified item.
        /// </summary>
        /// <param name="item">The target item.</param>
        /// <param name="oldItem">The old item.</param>
        /// <returns><c>true</c> if this instance can execute the specified item; otherwise, <c>false</c>.</returns>
        public override bool CanExecute(IDynamicObject item, IDynamicObject oldItem)
        {
            if (item == null)
                return false;

            if (string.IsNullOrWhiteSpace(ApprovalFieldName))
                return false;

            var prop = item.GetPropertyByName(ApprovalFieldName);

            if (prop == null)
                return false;

            var approval = item.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName);

            if (approval == null)
                return false;

            var oldApproval = oldItem != null
                                  ? oldItem.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName)
                                  : null;

            return approval.GetApprovalState() == ApprovalStates.ReadyForApproval
                   && (oldApproval == null
                       || (approval.CurrentLevel != oldApproval.CurrentLevel || approval.GetApprovalState() != oldApproval.GetApprovalState()));
        }
Esempio n. 6
0
        private Document CreateGlobalSearchDoc(int id, string processSystemName, string processDisplayName, IEnumerable<string> otherFieldsName, IDynamicObject self, bool isGsUpdate = false)
        {
            var selfHasBusinessRules = self as IHasBusinessRules;
            if (selfHasBusinessRules == null)
            {
                return null;
            }

            try
            {
                selfHasBusinessRules.DisableBusinessRules();
                var doc = new Document();
                doc.Add(
                    new Field("ItemId", id.ToString(CultureInfo.InvariantCulture), Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.YES));
                doc.Add(new Field("ProcessSystemName", processSystemName, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.YES));
                doc.Add(new Field("ProcessDisplayName", processDisplayName, Field.Store.YES, Field.Index.NOT_ANALYZED, Field.TermVector.NO));

                foreach (var field in otherFieldsName)
                {
                    var property = self.GetPropertyByName(field);
                    if (property == null)
                    {
                        continue;
                    }

                    if (property.GetCustomAttribute<AllowLocalizedDataAttribute>() != null)
                    {
                        foreach (var localization in property.DeclaringType.GetCustomAttributes<LocalizationInfoAttribute>())
                        {
                            CultureInfo culture;

                            try
                            {
                                culture = CultureHelper.GetCultureInfo(localization.CultureName);
                            }
                            catch (CultureNotFoundException)
                            {
                                continue;
                            }

                            using (new CultureContext(culture))
                            {
                                var documentField = GetField(processSystemName, property, self, isGsUpdate, culture);
                                if (documentField != null)
                                    doc.Add(documentField);
                            }
                        }
                    }
                    else
                    {
                        var documentField = GetField(processSystemName, property, self, isGsUpdate);
                        if (documentField != null)
                            doc.Add(documentField);
                    }
                }

                return doc.GetFields().Count <= 3 ? null : doc;
            }
            catch (Exception ex)
            {
                Logger.Log(LogSeverity.Error, "Global Search Error", "Error on Creating Lucene Document : " + ex.Message);
                _error = "Global Search Error : " + ex.Message;
                return null;
            }
            finally
            {
                selfHasBusinessRules.EnableBusinessRules();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Determines whether [is person field match] [the specified item].
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="sc">The sc.</param>
        /// <param name="personIds">The person ids.</param>
        /// <returns><c>true</c> if [is person field match] [the specified item]; otherwise, <c>false</c>.</returns>
        private static bool IsPersonFieldMatch(IDynamicObject item, IStateConnectorSecurityConfiguration sc, IDictionary<string, int> personIds)
        {
            if (string.IsNullOrEmpty(sc.PersonFieldName) || sc.PersonFieldName == Constants.AllPersonFieldsSystemName)
                return false;

            var prop = item.GetPropertyByName(sc.PersonFieldName);

            if (prop == null)
                return false;

            var crAttr =
                (CrossRefFieldAttribute)
                prop.GetCustomAttributes(typeof(CrossRefFieldAttribute), false).FirstOrDefault();

            if (crAttr == null)
                return false;

            int personId;

            if (!personIds.TryGetValue(crAttr.ReferenceTableName, out personId))
                return false;

            if (crAttr.AllowMultiple)
            {
                var list = item.ReadValueByPropertyName<IList>(prop.Name);

                if (list == null)
                    return false;

                return list.Cast<ICrossRefItemInfo>().Any(x => x.Id == personId);
            }

            var value = item.ReadValueByPropertyName<int?>(prop.Name);

            return value == personId;
        }