コード例 #1
0
            object IExpressionBuilderProvider.Evaluate(NameValueCollection arguments, Type controlType, string propertyName, string expressionPrefix)
            {
                if (string.IsNullOrEmpty(arguments.GetValueByIndexOrName(0, "Name")))
                {
                    ThrowArgumentException(propertyName, expressionPrefix, "Name={setting name} [, Default={default text}] [, Format={format string}] [, Portal={portal name}] [, CdnSettingName={setting name}]");
                }

                // retrieve the site setting value

                var settingName  = arguments.GetValueByIndexOrName(0, "Name");
                var defaultValue = arguments.GetValueByIndexOrName(1, "Default") ?? string.Empty;
                var format       = arguments.GetValueByIndexOrName(2, "Format");

                var settings = new SettingDataAdapter(new PortalConfigurationDataAdapterDependencies(), HttpContext.Current.GetWebsite());
                var selected = settings.Select(settingName);
                var setting  = selected == null ? null : selected.Entity;

                var returnType = GetReturnType(controlType, propertyName);

                if (returnType.IsA(typeof(Entity)))
                {
                    return(setting);
                }

                var url = setting == null
                                        ? defaultValue
                                        : GetEvalData(setting, "adx_value", null, format, returnType) as string;

                if (string.IsNullOrEmpty(url) || !url.Contains("~/cdn/"))
                {
                    return(url);
                }

                // retrieve the CDN hostname value

                var cdnSettingName = arguments.GetValueByIndexOrName(4, "CdnSettingName") ?? "/url/cdn";

                selected = settings.Select(cdnSettingName);
                var cdnSetting = selected == null ? null : selected.Entity;

                if (cdnSetting == null)
                {
                    return(url);
                }

                // combine the two values

                var cdnFormat = url.Replace("~/cdn/", "{0}/");

                return(GetEvalData(cdnSetting, "adx_value", null, cdnFormat, returnType));
            }
コード例 #2
0
            object IExpressionBuilderProvider.Evaluate(NameValueCollection arguments, Type controlType, string propertyName, string expressionPrefix)
            {
                if (string.IsNullOrEmpty(arguments.GetValueByIndexOrName(0, "Name")))
                {
                    ThrowArgumentException(propertyName, expressionPrefix, "Name={setting name} [, Default={default text}] [, Format={format string}] [, Portal={portal name}]");
                }

                var settingName   = arguments.GetValueByIndexOrName(0, "Name");
                var defaultString = arguments.GetValueByIndexOrName(1, "Default") ?? string.Empty;
                var format        = arguments.GetValueByIndexOrName(2, "Format");
                var returnType    = GetReturnType(controlType, propertyName);

                var settings = new SettingDataAdapter(new PortalConfigurationDataAdapterDependencies(), HttpContext.Current.GetWebsite());
                var selected = settings.Select(settingName);
                var setting  = selected == null ? null : selected.Entity;

                if (returnType.IsA(typeof(Entity)))
                {
                    return(setting);
                }

                if (returnType.IsA(typeof(EntityReference)))
                {
                    return(setting == null ? null : setting.ToEntityReference());
                }

                var value = setting == null ? null : setting.GetAttributeValue <string>("adx_value");

                object returnValue;

                if (returnType == typeof(String) && !string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(format))
                {
                    returnValue = string.Format(CultureInfo.InvariantCulture, format, value);

                    return(returnValue);
                }

                if (string.IsNullOrWhiteSpace(value))
                {
                    value = defaultString;
                }

                if (returnType == typeof(String))
                {
                    returnValue = value;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(value))
                    {
                        return(null);
                    }

                    var typeConverter = TypeDescriptor.GetConverter(returnType);
                    returnValue = typeConverter.ConvertFromString(value);
                }

                return(returnValue);
            }