/// <summary> /// The is multiple data type. /// </summary> /// <param name="dataTypeId"> /// The data type id. /// </param> /// <param name="propertyEditorAlias"></param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool IsMultipleDataType(int dataTypeId, string propertyEditorAlias) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, // better to cache here + trigger refresh in DataTypeCacheRefresher return(Storages.GetOrAdd(dataTypeId, id => { var preVals = _dataTypeService.GetPreValuesCollectionByDataTypeId(id).PreValuesAsDictionary; if (preVals.ContainsKey("multiPicker")) { var preValue = preVals .FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase)) .Value; return preValue != null && preValue.Value.TryConvertTo <bool>().Result; } //in some odd cases, the pre-values in the db won't exist but their default pre-values contain this key so check there var propertyEditor = PropertyEditorResolver.Current.GetByAlias(propertyEditorAlias); if (propertyEditor != null) { var preValue = propertyEditor.DefaultPreValues .FirstOrDefault(x => string.Equals(x.Key, "multiPicker", StringComparison.InvariantCultureIgnoreCase)) .Value; return preValue != null && preValue.TryConvertTo <bool>().Result; } return false; })); }
/// <summary> /// Discovers if the tags data type is storing its data in a Json format /// </summary> /// <param name="dataTypeId"> /// The data type id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool JsonStorageType(int dataTypeId) { // GetDataType(id) is cached at repository level; still, there is some // deep-cloning involved (expensive) - better cache here + trigger // refresh in DataTypeCacheRefresher return(Storages.GetOrAdd(dataTypeId, id => { var configuration = _dataTypeService.GetDataType(id).ConfigurationAs <TagConfiguration>(); return configuration.StorageType == TagsStorageType.Json; })); }
/// <summary> /// Discovers if the slider is set to range mode. /// </summary> /// <param name="dataTypeId"> /// The data type id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool IsRangeDataType(int dataTypeId) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, // better to cache here + trigger refresh in DataTypeCacheRefresher // fixme wtf this should NOT be expensive! return(Storages.GetOrAdd(dataTypeId, id => { var dataType = _dataTypeService.GetDataType(id); var configuration = dataType.ConfigurationAs <SliderConfiguration>(); return configuration.EnableRange; })); }
/// <summary> /// Discovers if the slider is set to range mode. /// </summary> /// <param name="dataTypeId"> /// The data type id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool IsRangeDataType(int dataTypeId) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, // better to cache here + trigger refresh in DataTypeCacheRefresher // TODO: this is cheap now, remove the caching return(Storages.GetOrAdd(dataTypeId, id => { var dataType = _dataTypeService.GetDataType(id); var configuration = dataType?.ConfigurationAs <SliderConfiguration>(); return configuration?.EnableRange ?? false; })); }
/// <summary> /// Discovers if the slider is set to range mode. /// </summary> /// <param name="dataTypeId"> /// The data type id. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> private bool IsRangeDataType(int dataTypeId) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, // better to cache here + trigger refresh in DataTypeCacheRefresher return(Storages.GetOrAdd(dataTypeId, id => { var preValue = _dataTypeService.GetPreValuesCollectionByDataTypeId(id) .PreValuesAsDictionary .FirstOrDefault(x => string.Equals(x.Key, "enableRange", StringComparison.InvariantCultureIgnoreCase)) .Value; return preValue != null && preValue.Value.TryConvertTo <bool>().Result; })); }
private bool IsMultipleDataType(int dataTypeId, out int maxNumber) { // GetPreValuesCollectionByDataTypeId is cached at repository level; // still, the collection is deep-cloned so this is kinda expensive, // better to cache here + trigger refresh in DataTypeCacheRefresher maxNumber = Storages.GetOrAdd(dataTypeId, id => { var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(id).PreValuesAsDictionary; return(preValues.TryGetValue("maxNumber", out var maxNumberPreValue) ? maxNumberPreValue.Value.TryConvertTo <int>().Result : 0); }); return(maxNumber != 1); }