Esempio n. 1
0
        public virtual GlobalSetting GetByKey(String key)
        {
            var query = from o in Context.CreateQuery(EntityName)
                        where o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)) == key
                        select new
            {
                Id            = o.GetAttributeValue <Guid>(GlobalSettingEntity.IdFieldName(_prefix)),
                Name          = o.GetAttributeValue <String>(Common.CustomNameFieldName(_prefix)),
                Key           = o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)),
                Value         = o.GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix)),
                Type          = o.GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix)),
                ReferenceType = o.GetAttributeValue <String>(GlobalSettingEntity.ReferenceTypeFieldName(_prefix))
            };

            var array = query.ToArray();

            return(array.Any() ? new GlobalSetting(_prefix)
            {
                Id = array[0].Id,
                Key = array[0].Key,
                Name = array[0].Name,
                Value = array[0].Value,
                Type = array[0].Type.ToEnum <GlobalSettingType>() ?? GlobalSettingType.String,
                ReferenceType = array[0].ReferenceType
            } : null);
        }
Esempio n. 2
0
        public virtual IEnumerable <GlobalSetting> GetAll()
        {
            var query = from o in Context.CreateQuery(EntityName)
                        select new
            {
                Id            = o.GetAttributeValue <Guid>(GlobalSettingEntity.IdFieldName(_prefix)),
                Name          = o.GetAttributeValue <String>(Common.CustomNameFieldName(_prefix)),
                Key           = o.GetAttributeValue <String>(GlobalSettingEntity.KeyFieldName(_prefix)),
                Value         = o.GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix)),
                Type          = o.GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix)),
                ReferenceType = o.GetAttributeValue <String>(GlobalSettingEntity.ReferenceTypeFieldName(_prefix))
            };

            var array = query.ToArray();

            return(array
                   .Select(o => new GlobalSetting(_prefix)
            {
                Id = o.Id,
                Key = o.Key,
                Name = o.Name,
                Value = o.Value,
                Type = o.Type.ToEnum <GlobalSettingType>() ?? GlobalSettingType.String,
                ReferenceType = o.ReferenceType
            }).ToArray());
        }
        private void SanitizeValue(Entity target, GlobalSettingType type, String value)
        {
            if (value == null)
            {
                return;
            }

            if (type == GlobalSettingType.String)
            {
                return;
            }

            target.AddOrUpdateAttribute(GlobalSettingEntity.ValueFieldName(_prefix), value.Trim().ToLower());
        }
        protected override void Execute(IPluginContext context)
        {
            this.EnsureNotNull(context, nameof(context));

            context.EnsureTargetLogicalName(GlobalSettingEntity.TypeName(_prefix));

            var target = context
                         .GetTargetEntity();
            var image = context
                        .GetEntityImage(EntityImageType.PreImage, throwIfNull: context.IsUpdateMessage());

            var type = target
                       .GetAttributeValue <OptionSetValue>(GlobalSettingEntity.TypeFieldName(_prefix), image)?
                       .ToEnum <GlobalSettingType>() ?? GlobalSettingType.String;
            var value = target
                        .GetAttributeValue <String>(GlobalSettingEntity.ValueFieldName(_prefix), image);

            ValidateValue(type, value);
            SanitizeValue(target, type, value);
        }
        private ISetting loadSetting(SettingAttribute attribute)
        {
            ISetting setting = null;
            switch (attribute.SettingType)
            {
                case SettingType.Global:
                case SettingType.Forum:
                    {
                        setting = new GlobalSettingEntity(attribute);
                        break;
                    }

                case SettingType.Office:
                    {
                        setting = new office();
                        break;
                    }
            }

            // TODO:
            ((BasePlainObject)setting).LoadByReference(setting.KeyColumnName, attribute.SettingName);
            return setting;
        }