Beispiel #1
0
        public object Clone()
        {
            var attributes = new List <NetworkEntityAttributeValue>();

            attributes.AddRange(AttributeValues.Select(a => a.Clone() as NetworkEntityAttributeValue));

            var obj = this.MemberwiseClone() as NetworkDataEntity;

            obj.AttributeValues = attributes;

            return(obj);
        }
Beispiel #2
0
        public virtual object this[object key]
        {
            get
            {
                var keyString = key.ToStringSafe();

                if (keyString == "AttributeValues")
                {
                    return(AttributeValues.Select(a => a.Value).ToList());
                }

                var propInfo = GetType().GetProperty(key.ToStringSafe());
                if (propInfo != null && !propInfo.GetCustomAttributes(typeof(LavaIgnoreAttribute)).Any())
                {
                    var propValue = propInfo.GetValue(this, null);
                    return((propValue as Guid? )?.ToString() ?? propValue);
                }

                // The remainder of this method is only necessary to support the old way of getting attribute
                // values in liquid templates (e.g. {{ Person.BaptismData }} ).  Once support for this method is
                // deprecated ( in v4.0 ), and only the new method of using the Attribute filter is
                // supported (e.g. {{ Person | Attribute:'BaptismDate' }} ), the remainder of this method
                // can be removed

                if (Attributes == null)
                {
                    return(null);
                }

                var unformatted = false;
                var url         = false;

                var attributeKey = key.ToStringSafe();
                if (attributeKey.EndsWith("_unformatted"))
                {
                    attributeKey = attributeKey.Replace("_unformatted", string.Empty);
                    unformatted  = true;
                }
                else if (attributeKey.EndsWith("_url"))
                {
                    attributeKey = attributeKey.Replace("_url", string.Empty);
                    url          = true;
                }

                if (!Attributes.ContainsKey(attributeKey))
                {
                    return(null);
                }

                var attribute = Attributes[attributeKey];
                if (!attribute.IsAuthorized(Authorization.VIEW, null))
                {
                    return(null);
                }

                var field = attribute.FieldType.Field;
                var value = GetAttributeValue(attribute.Key);

                if (unformatted)
                {
                    return(value);
                }

                if (url && field is Field.ILinkableFieldType)
                {
                    return(((Field.ILinkableFieldType)field).UrlLink(value, attribute.QualifierValues));
                }

                return(field.FormatValue(null, attribute.EntityTypeId, Id, value, attribute.QualifierValues, false));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the <see cref="System.Object"/> with the specified key.
        /// </summary>
        /// <remarks>
        /// This method is necessary to support getting AttributeValues in Lava templates and
        /// to support the old way of getting attribute values in Lava templates
        /// (e.g. {{ Person.BaptismData }} ).  Once support for this method is
        /// removed and only the new method of using the Attribute filter is
        /// supported (e.g. {{ Person | Attribute:'BaptismDate' }} ), this method can be
        /// trimmed to only support the AttributeValues key.
        /// </remarks>
        /// <value>
        /// The <see cref="System.Object"/>.
        /// </value>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public override object this[object key]
        {
            get
            {
                string keyString = key.ToStringSafe();

                object item = base[key];
                if (item == null)
                {
                    var lavaSupportLevel = GlobalAttributesCache.Get().LavaSupportLevel;

                    if (this.Attributes == null)
                    {
                        this.LoadAttributes();
                    }

                    if (keyString == "AttributeValues")
                    {
                        return(AttributeValues.Select(a => a.Value).ToList());
                    }

                    // The remainder of this method is only necessary to support the old way of getting attribute
                    // values in liquid templates (e.g. {{ Person.BaptismData }} ).  Once support for this method is
                    // deprecated ( in v4.0 ), and only the new method of using the Attribute filter is
                    // supported (e.g. {{ Person | Attribute:'BaptismDate' }} ), the remainder of this method
                    // can be removed

                    if (lavaSupportLevel == Lava.LavaSupportLevel.NoLegacy)
                    {
                        return(null);
                    }

                    if (this.Attributes != null)
                    {
                        string attributeKey = keyString;
                        bool   unformatted  = false;
                        bool   url          = false;

                        if (attributeKey.EndsWith("_unformatted"))
                        {
                            attributeKey = attributeKey.Replace("_unformatted", "");
                            unformatted  = true;
                        }
                        else if (attributeKey.EndsWith("_url"))
                        {
                            attributeKey = attributeKey.Replace("_url", "");
                            url          = true;
                        }

                        if (this.Attributes.ContainsKey(attributeKey))
                        {
                            var attribute = this.Attributes[attributeKey];
                            if (attribute.IsAuthorized(Authorization.VIEW, null))
                            {
                                Rock.Model.ExceptionLogService.LogException(new Rock.Lava.LegacyLavaSyntaxDetectedException(this.GetType().GetFriendlyTypeName(), attributeKey), System.Web.HttpContext.Current);

                                if (unformatted)
                                {
                                    return(GetAttributeValueAsType(attribute.Key));
                                }

                                var    field = attribute.FieldType.Field;
                                string value = GetAttributeValue(attribute.Key);

                                if (url && field is Rock.Field.ILinkableFieldType)
                                {
                                    return(((Rock.Field.ILinkableFieldType)field).UrlLink(value, attribute.QualifierValues));
                                }

                                return(field.FormatValue(null, attribute.EntityTypeId, this.Id, value, attribute.QualifierValues, false));
                            }
                        }
                    }
                }

                return(item);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the <see cref="System.Object"/> with the specified key.
        /// </summary>
        /// <remarks>
        /// This method is only neccessary to support the old way of getting attribute values in
        /// liquid templates (e.g. {{ Person.BaptismData }} ).  Once support for this method is
        /// deprecated ( in v4.0 ), and only the new method of using the Attribute filter is
        /// suported (e.g. {{ Person | Attribute:'BaptismDate' }} ), this method can be removed
        /// </remarks>
        /// <value>
        /// The <see cref="System.Object"/>.
        /// </value>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public override object this[object key]
        {
            get
            {
                string keyString = key.ToStringSafe();

                object item = base[key];
                if (item == null)
                {
                    if (this.Attributes == null)
                    {
                        this.LoadAttributes();
                    }

                    if (keyString == "AttributeValues")
                    {
                        return(AttributeValues.Select(a => a.Value).ToList());
                    }

                    // The remainder of this method is only neccessary to support the old way of getting attribute
                    // values in liquid templates (e.g. {{ Person.BaptismData }} ).  Once support for this method is
                    // deprecated ( in v4.0 ), and only the new method of using the Attribute filter is
                    // suported (e.g. {{ Person | Attribute:'BaptismDate' }} ), the remainder of this method
                    // can be removed

                    if (this.Attributes != null)
                    {
                        string attributeKey = keyString;
                        bool   unformatted  = false;
                        bool   url          = false;

                        if (attributeKey.EndsWith("_unformatted"))
                        {
                            attributeKey = attributeKey.Replace("_unformatted", "");
                            unformatted  = true;
                        }
                        else if (attributeKey.EndsWith("_url"))
                        {
                            attributeKey = attributeKey.Replace("_url", "");
                            url          = true;
                        }

                        if (this.Attributes.ContainsKey(attributeKey))
                        {
                            var attribute = this.Attributes[attributeKey];
                            if (attribute.IsAuthorized(Authorization.VIEW, null))
                            {
                                if (unformatted)
                                {
                                    return(GetAttributeValueAsType(attribute.Key));
                                }

                                var    field = attribute.FieldType.Field;
                                string value = GetAttributeValue(attribute.Key);

                                if (url && field is Rock.Field.ILinkableFieldType)
                                {
                                    return(((Rock.Field.ILinkableFieldType)field).UrlLink(value, attribute.QualifierValues));
                                }

                                return(field.FormatValue(null, value, attribute.QualifierValues, false));
                            }
                        }
                    }
                }

                return(item);
            }
        }