public override Type GetPropertyValueType(IPublishedPropertyType propertyType) { var valueType = ConfigurationEditor.ConfigurationAs <LabelConfiguration>(propertyType.DataType.Configuration); switch (valueType.ValueType) { case ValueTypes.DateTime: case ValueTypes.Date: return(typeof(DateTime)); case ValueTypes.Time: return(typeof(TimeSpan)); case ValueTypes.Decimal: return(typeof(decimal)); case ValueTypes.Integer: return(typeof(int)); case ValueTypes.Bigint: return(typeof(long)); default: // everything else is a string return(typeof(string)); } }
// gets the tag configuration for a property // from the datatype configuration, and the editor tag configuration attribute public static TagConfiguration?GetTagConfiguration(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService) { if (property == null) { throw new ArgumentNullException(nameof(property)); } IDataEditor?editor = propertyEditors[property.PropertyType?.PropertyEditorAlias]; TagsPropertyEditorAttribute?tagAttribute = editor?.GetTagAttribute(); if (tagAttribute == null) { return(null); } var configurationObject = property.PropertyType is null ? null : dataTypeService.GetDataType(property.PropertyType.DataTypeId)?.Configuration; TagConfiguration?configuration = ConfigurationEditor.ConfigurationAs <TagConfiguration>(configurationObject); if (configuration?.Delimiter == default && configuration?.Delimiter is not null) { configuration.Delimiter = tagAttribute.Delimiter; } return(configuration); }
// gets the tag configuration for a property // from the datatype configuration, and the editor tag configuration attribute public static TagConfiguration GetTagConfiguration(this IProperty property, PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService) { if (property == null) { throw new ArgumentNullException(nameof(property)); } var editor = propertyEditors[property.PropertyType.PropertyEditorAlias]; var tagAttribute = editor.GetTagAttribute(); if (tagAttribute == null) { return(null); } var configurationObject = dataTypeService.GetDataType(property.PropertyType.DataTypeId).Configuration; var configuration = ConfigurationEditor.ConfigurationAs <TagConfiguration>(configurationObject); if (configuration.Delimiter == default) { configuration.Delimiter = tagAttribute.Delimiter; } return(configuration); }
public override void Migrate() { // get all Umbraco.Tags datatypes var dataTypeDtos = Database.Fetch <DataTypeDto>(Context.SqlContext.Sql() .Select <DataTypeDto>() .From <DataTypeDto>() .Where <DataTypeDto>(x => x.EditorAlias == Constants.PropertyEditors.Aliases.Tags)); // get a dummy editor for deserialization var editor = new TagConfigurationEditor(); foreach (var dataTypeDto in dataTypeDtos) { // need to check storageType on raw dictionary, as TagConfiguration would have a default value var dictionary = JsonConvert.DeserializeObject <JObject>(dataTypeDto.Configuration); // if missing, use TagConfiguration to properly update the configuration // due to ... reasons ... the key can start with a lower or upper 'S' if (!dictionary.ContainsKey("storageType") && !dictionary.ContainsKey("StorageType")) { var configuration = (TagConfiguration)editor.FromDatabase(dataTypeDto.Configuration); configuration.StorageType = TagsStorageType.Csv; dataTypeDto.Configuration = ConfigurationEditor.ToDatabase(configuration); Database.Update(dataTypeDto); } } }
private bool IsMultipleDataType(PublishedDataType dataType) { MediaPickerConfiguration?config = ConfigurationEditor.ConfigurationAs <MediaPickerConfiguration>(dataType.Configuration); return(config?.Multiple ?? false); }
public void Can_Perform_Add_On_DataTypeDefinitionRepository() { using (ScopeProvider.CreateScope()) { var dataTypeDefinition = new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { DatabaseType = ValueStorageType.Integer, Name = "AgeDataType", CreatorId = 0, Configuration = new LabelConfiguration { ValueType = ValueTypes.Xml } }; // Act DataTypeRepository.Save(dataTypeDefinition); bool exists = DataTypeRepository.Exists(dataTypeDefinition.Id); IDataType fetched = DataTypeRepository.Get(dataTypeDefinition.Id); // Assert Assert.That(dataTypeDefinition.HasIdentity, Is.True); Assert.That(exists, Is.True); // cannot compare 'configuration' as it's two different objects TestHelper.AssertPropertyValuesAreEqual(dataTypeDefinition, fetched, ignoreProperties: new[] { "Configuration" }); // still, can compare explicitely Assert.IsNotNull(dataTypeDefinition.Configuration); Assert.IsInstanceOf <LabelConfiguration>(dataTypeDefinition.Configuration); Assert.IsNotNull(fetched.Configuration); Assert.IsInstanceOf <LabelConfiguration>(fetched.Configuration); Assert.AreEqual(ConfigurationEditor.ConfigurationAs <LabelConfiguration>(dataTypeDefinition.Configuration).ValueType, ConfigurationEditor.ConfigurationAs <LabelConfiguration>(fetched.Configuration).ValueType); } }
public override void Migrate() { var dataTypes = GetDataTypes("Umbraco.Date"); foreach (var dataType in dataTypes) { DateTimeConfiguration config; try { config = (DateTimeConfiguration) new CustomDateTimeConfigurationEditor().FromDatabase( dataType.Configuration); } catch (Exception ex) { Logger.Error <DropDownPropertyEditorsMigration>( ex, "Invalid property editor configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared", dataType.Configuration); continue; } config.OffsetTime = false; dataType.EditorAlias = Constants.PropertyEditors.Aliases.DateTime; dataType.Configuration = ConfigurationEditor.ToDatabase(config); Database.Update(dataType); } }
/// <summary> /// Gets the configuration editor - user interface to edit the plug-in configuration file. /// </summary> /// <returns>Represents a window or dialog box that makes up an application's user interface to be used to edit configuration file.</returns> /// <exception cref="System.ArgumentNullException">Configuration Editor is unavailable.</exception> public override void EditConfiguration() { if (ConfigurationEditor == null) { throw new ArgumentNullException(nameof(ConfigurationEditor), "Configuration Editor is unavailable."); } ConfigurationEditor.EditConfiguration(CurrentConfiguration); }
private void editConfigsButton_Click(object sender, System.EventArgs e) { using (ConfigurationEditor editor = new ConfigurationEditor(project)) { this.Site.Container.Add(editor); editor.ShowDialog(); } configComboBox_Populate(); }
public void Initialize() { ProjectDocument doc = new ProjectDocument(); doc.LoadXml(NUnitProjectXml.NormalProject); model = new ProjectModel(doc); view = Substitute.For<IConfigurationEditorDialog>(); editor = new ConfigurationEditor(model, view); }
private bool Migrate(IEnumerable <DataTypeDto> dataTypes, bool isMultiple) { var refreshCache = false; ConfigurationEditor configurationEditor = null; foreach (var dataType in dataTypes) { ValueListConfiguration config; if (dataType.Configuration.IsNullOrWhiteSpace()) { continue; } // parse configuration, and update everything accordingly if (configurationEditor == null) { configurationEditor = new ValueListConfigurationEditor(_ioHelper); } try { config = (ValueListConfiguration)configurationEditor.FromDatabase(dataType.Configuration, _configurationEditorJsonSerializer); } catch (Exception ex) { Logger.LogError( ex, "Invalid configuration: \"{Configuration}\", cannot convert editor.", dataType.Configuration); continue; } // get property data dtos var propertyDataDtos = Database.Fetch <PropertyDataDto>(Sql() .Select <PropertyDataDto>() .From <PropertyDataDto>() .InnerJoin <PropertyTypeDto>().On <PropertyTypeDto, PropertyDataDto>((pt, pd) => pt.Id == pd.PropertyTypeId) .InnerJoin <DataTypeDto>().On <DataTypeDto, PropertyTypeDto>((dt, pt) => dt.NodeId == pt.DataTypeId) .Where <PropertyTypeDto>(x => x.DataTypeId == dataType.NodeId)); // update dtos var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config, isMultiple)); // persist changes foreach (var propertyDataDto in updatedDtos) { Database.Update(propertyDataDto); } UpdateDataType(dataType); refreshCache = true; } return(refreshCache); }
public void Initialize() { ProjectDocument doc = new ProjectDocument(); doc.LoadXml(NUnitProjectXml.NormalProject); model = new ProjectModel(doc); view = Substitute.For <IConfigurationEditorDialog>(); editor = new ConfigurationEditor(model, view); }
/// <summary> /// Creates automatically the instance configurations on the best effort basis. /// </summary> /// <param name="descriptors">The descriptors of nodes.</param> /// <param name="SkipOpeningConfigurationFile">if set to <c>true</c> skip opening configuration file.</param> /// <param name="CancelWasPressed">if set to <c>true</c> cancel was pressed.</param> /// <exception cref="System.ArgumentNullException">Configuration Editor is unavailable.</exception> public override void CreateInstanceConfigurations(INodeDescriptor[] descriptors, bool SkipOpeningConfigurationFile, out bool CancelWasPressed) { CancelWasPressed = false; if (ConfigurationEditor == null) { throw new ArgumentNullException(nameof(ConfigurationEditor), "Configuration Editor is unavailable."); } bool _CancelWasPressed = false; ConfigurationEditor.CreateInstanceConfigurations(descriptors, SkipOpeningConfigurationFile, x => _CancelWasPressed = x); CancelWasPressed = _CancelWasPressed; }
public static DataTypeDto BuildDto(IDataType entity, IConfigurationEditorJsonSerializer serializer) { var dataTypeDto = new DataTypeDto { EditorAlias = entity.EditorAlias, NodeId = entity.Id, DbType = entity.DatabaseType.ToString(), Configuration = ConfigurationEditor.ToDatabase(entity.Configuration, serializer), NodeDto = BuildNodeDto(entity), }; return(dataTypeDto); }
private void UpdateDataType(DataTypeDto dataType, ValueListConfiguration config, bool isMultiple) { dataType.DbType = ValueStorageType.Nvarchar.ToString(); dataType.EditorAlias = Constants.PropertyEditors.Aliases.DropDownListFlexible; var flexConfig = new DropDownFlexibleConfiguration { Items = config.Items, Multiple = isMultiple }; dataType.Configuration = ConfigurationEditor.ToDatabase(flexConfig, _configurationEditorJsonSerializer); Database.Update(dataType); }
void MainControl_Loaded(object sender, RoutedEventArgs e) { try { ConfigurableObject obj = new ConfigurableObject(); obj.SetValues(); savedConfig = Configurator.SaveConfiguration(obj); obj = new ConfigurableObject(); Configurator.LoadConfiguration(obj, savedConfig); editor = Configurator.CreateEditor(typeof(ConfigurableObject)); uiEditorContainer.Child = editor; editor.LoadConfiguration(savedConfig); } catch (Exception ex) { throw; } }
protected override void Migrate() { List <DataTypeDto> dataTypes = GetDataTypes(Constants.PropertyEditors.Legacy.Aliases.Date); foreach (DataTypeDto dataType in dataTypes) { DateTimeConfiguration config; try { config = (DateTimeConfiguration) new CustomDateTimeConfigurationEditor( _ioHelper, _editorConfigurationParser).FromDatabase( dataType.Configuration, _configurationEditorJsonSerializer); // If the Umbraco.Date type is the default from V7 and it has never been updated, then the // configuration is empty, and the format stuff is handled by in JS by moment.js. - We can't do that // after the migration, so we force the format to the default from V7. if (string.IsNullOrEmpty(dataType.Configuration)) { config.Format = "YYYY-MM-DD"; } } catch (Exception ex) { Logger.LogError( ex, "Invalid property editor configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared", dataType.Configuration); continue; } config.OffsetTime = false; dataType.EditorAlias = Constants.PropertyEditors.Aliases.DateTime; dataType.Configuration = ConfigurationEditor.ToDatabase(config, _configurationEditorJsonSerializer); Database.Update(dataType); } }
private void Prepare() { _elementTypeIds = Database.Fetch <ContentTypeDto>(Sql() .Select <ContentTypeDto>(x => x.NodeId, x => x.Alias) .From <ContentTypeDto>() .InnerJoin <NodeDto>().On <ContentTypeDto, NodeDto>(left => left.NodeId, right => right.NodeId) .Where <NodeDto>(node => node.NodeObjectType == Constants.ObjectTypes.DocumentType)) .ToDictionary(ct => ct.Alias, ct => ct.NodeId); _valueListConfigEditor = new ValueListConfigurationEditor(); _elementTypesInUse = new HashSet <int>(); _propertyTypes = new Dictionary <int, List <PropertyTypeDto> >(); _nodeIdToKey = new Lazy <Dictionary <int, NodeDto> >( () => Context.Database.Fetch <NodeDto>( Context.SqlContext.Sql() .Select <NodeDto>(x => x.NodeId, x => x.NodeObjectType, x => x.UniqueId) .From <NodeDto>() ).ToDictionary(n => n.NodeId) ); }
public void Can_Perform_Add_On_DataTypeDefinitionRepository() { var provider = TestObjects.GetScopeProvider(Logger); using (provider.CreateScope()) { var repository = CreateRepository(); var dataTypeDefinition = new DataType(new LabelPropertyEditor(Logger)) { DatabaseType = ValueStorageType.Integer, Name = "AgeDataType", CreatorId = 0, Configuration = new LabelConfiguration { ValueType = ValueTypes.Xml } }; // Act repository.Save(dataTypeDefinition); var exists = repository.Exists(dataTypeDefinition.Id); var fetched = repository.Get(dataTypeDefinition.Id); // Assert Assert.That(dataTypeDefinition.HasIdentity, Is.True); Assert.That(exists, Is.True); // cannot compare 'configuration' as it's two different objects TestHelper.AssertPropertyValuesAreEqual(dataTypeDefinition, fetched, "yyyy-MM-dd HH:mm:ss", ignoreProperties: new [] { "Configuration" }); // still, can compare explicitely Assert.IsNotNull(dataTypeDefinition.Configuration); Assert.IsInstanceOf <LabelConfiguration>(dataTypeDefinition.Configuration); Assert.IsNotNull(fetched.Configuration); Assert.IsInstanceOf <LabelConfiguration>(fetched.Configuration); Assert.AreEqual(ConfigurationEditor.ConfigurationAs <LabelConfiguration>(dataTypeDefinition.Configuration).ValueType, ConfigurationEditor.ConfigurationAs <LabelConfiguration>(fetched.Configuration).ValueType); } }
/// <summary> /// Maps the dto property values to the persisted model /// </summary> internal void MapPropertyValuesForPersistence <TPersisted, TSaved>( TSaved contentItem, ContentPropertyCollectionDto dto, Func <TSaved, Property, object> getPropertyValue, Action <TSaved, Property, object> savePropertyValue, string culture) where TPersisted : IContentBase where TSaved : IContentSave <TPersisted> { // map the property values foreach (var propertyDto in dto.Properties) { // get the property editor if (propertyDto.PropertyEditor == null) { Logger.Warn <ContentController>("No property editor found for property {PropertyAlias}", propertyDto.Alias); continue; } // get the value editor // nothing to save/map if it is readonly var valueEditor = propertyDto.PropertyEditor.GetValueEditor(); if (valueEditor.IsReadOnly) { continue; } // get the property var property = contentItem.PersistedContent.Properties[propertyDto.Alias]; // prepare files, if any matching property and culture var files = contentItem.UploadedFiles .Where(x => x.PropertyAlias == propertyDto.Alias && x.Culture == propertyDto.Culture) .ToArray(); foreach (var file in files) { file.FileName = file.FileName.ToSafeFileName(); } // create the property data for the property editor var data = new ContentPropertyData(propertyDto.Value, propertyDto.DataType.Configuration) { ContentKey = contentItem.PersistedContent.Key, PropertyTypeKey = property.PropertyType.Key, Files = files }; // let the editor convert the value that was received, deal with files, etc var value = valueEditor.FromEditor(data, getPropertyValue(contentItem, property)); // set the value - tags are special var tagAttribute = propertyDto.PropertyEditor.GetTagAttribute(); if (tagAttribute != null) { var tagConfiguration = ConfigurationEditor.ConfigurationAs <TagConfiguration>(propertyDto.DataType.Configuration); if (tagConfiguration.Delimiter == default) { tagConfiguration.Delimiter = tagAttribute.Delimiter; } var tagCulture = property.PropertyType.VariesByCulture() ? culture : null; property.SetTagsValue(value, tagConfiguration, tagCulture); } else { savePropertyValue(contentItem, property, value); } } }
private bool Migrate(IEnumerable <DataTypeDto> dataTypes) { var refreshCache = false; ConfigurationEditor configurationEditor = null; foreach (var dataType in dataTypes) { ValueListConfiguration config; if (!dataType.Configuration.IsNullOrWhiteSpace()) { // parse configuration, and update everything accordingly if (configurationEditor == null) { configurationEditor = new ValueListConfigurationEditor(); } try { config = (ValueListConfiguration)configurationEditor.FromDatabase(dataType.Configuration); } catch (Exception ex) { Logger.Error <DropDownPropertyEditorsMigration, string>( ex, "Invalid configuration: \"{Configuration}\", cannot convert editor.", dataType.Configuration); // reset config = new ValueListConfiguration(); } // get property data dtos var propertyDataDtos = Database.Fetch <PropertyDataDto>(Sql() .Select <PropertyDataDto>() .From <PropertyDataDto>() .InnerJoin <PropertyTypeDto>().On <PropertyTypeDto, PropertyDataDto>((pt, pd) => pt.Id == pd.PropertyTypeId) .InnerJoin <DataTypeDto>().On <DataTypeDto, PropertyTypeDto>((dt, pt) => dt.NodeId == pt.DataTypeId) .Where <PropertyTypeDto>(x => x.DataTypeId == dataType.NodeId)); // update dtos var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config, true)); // persist changes foreach (var propertyDataDto in updatedDtos) { Database.Update(propertyDataDto); } } else { // default configuration config = new ValueListConfiguration(); } switch (dataType.EditorAlias) { case string ea when ea.InvariantEquals("Umbraco.DropDown"): UpdateDataType(dataType, config, false); break; case string ea when ea.InvariantEquals("Umbraco.DropdownlistPublishingKeys"): UpdateDataType(dataType, config, false); break; case string ea when ea.InvariantEquals("Umbraco.DropDownMultiple"): UpdateDataType(dataType, config, true); break; case string ea when ea.InvariantEquals("Umbraco.DropdownlistMultiplePublishKeys"): UpdateDataType(dataType, config, true); break; } refreshCache = true; } return(refreshCache); }
private void SaveAppSetting(string key, string value) { Configuration manager = OpenConfigFile(); if (manager != null) { // NOTE: Most likey scenario in a production environment if (!string.IsNullOrEmpty(manager.AppSettings.Settings[key].Value)) manager.AppSettings.Settings.Remove(key); manager.AppSettings.Settings.Add(key, value); manager.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); } else { // NOTE: Alternate scenario when settings cannot be saved through a ConfigurationManager, particulary when running under the Visual Studio Web Development Server (as opposed to IIS or IIS Express). ConfigurationEditor editor = new ConfigurationEditor(Path.Combine(Server.MapPath(LocalWebConfig), "Web.config")); if (editor.KeyExists(key)) editor.UpdateKey(key, value); else editor.AddKey(key, value); editor.SaveDoc(); } }
/// <summary> /// Maps the dto property values to the persisted model /// </summary> internal void MapPropertyValuesForPersistence <TPersisted, TSaved>( TSaved contentItem, ContentPropertyCollectionDto?dto, Func <TSaved, IProperty?, object?> getPropertyValue, Action <TSaved, IProperty?, object?> savePropertyValue, string?culture) where TPersisted : IContentBase where TSaved : IContentSave <TPersisted> { if (dto is null) { return; } // map the property values foreach (ContentPropertyDto propertyDto in dto.Properties) { // get the property editor if (propertyDto.PropertyEditor == null) { _logger.LogWarning("No property editor found for property {PropertyAlias}", propertyDto.Alias); continue; } // get the value editor // nothing to save/map if it is readonly IDataValueEditor valueEditor = propertyDto.PropertyEditor.GetValueEditor(); if (valueEditor.IsReadOnly) { continue; } // get the property IProperty property = contentItem.PersistedContent.Properties[propertyDto.Alias] !; // prepare files, if any matching property and culture ContentPropertyFile[] files = contentItem.UploadedFiles .Where(x => x.PropertyAlias == propertyDto.Alias && x.Culture == propertyDto.Culture && x.Segment == propertyDto.Segment) .ToArray(); foreach (ContentPropertyFile file in files) { file.FileName = file.FileName?.ToSafeFileName(ShortStringHelper); } // create the property data for the property editor var data = new ContentPropertyData(propertyDto.Value, propertyDto.DataType?.Configuration) { ContentKey = contentItem.PersistedContent !.Key, PropertyTypeKey = property.PropertyType.Key, Files = files }; // let the editor convert the value that was received, deal with files, etc object?value = valueEditor.FromEditor(data, getPropertyValue(contentItem, property)); // set the value - tags are special TagsPropertyEditorAttribute?tagAttribute = propertyDto.PropertyEditor.GetTagAttribute(); if (tagAttribute != null) { TagConfiguration?tagConfiguration = ConfigurationEditor.ConfigurationAs <TagConfiguration>(propertyDto.DataType?.Configuration); if (tagConfiguration is not null && tagConfiguration.Delimiter == default) { tagConfiguration.Delimiter = tagAttribute.Delimiter; } var tagCulture = property?.PropertyType.VariesByCulture() ?? false ? culture : null; property?.SetTagsValue(_serializer, value, tagConfiguration, tagCulture); } else { savePropertyValue(contentItem, property, value); } } }
private void ShowConfigurationEditor() { var configEditor = new ConfigurationEditor(); configEditor.Show(); }
private static bool IsOnlyImagesDataType(PublishedDataType dataType) { var config = ConfigurationEditor.ConfigurationAs <MediaPickerConfiguration>(dataType.Configuration); return(config.OnlyImages); }
private void editConfigsButton_Click(object sender, System.EventArgs e) { ConfigurationEditor.Edit(project); configComboBox_Populate(); }
public override object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview) { var valueType = ConfigurationEditor.ConfigurationAs <LabelConfiguration>(propertyType.DataType.Configuration); switch (valueType.ValueType) { case ValueTypes.DateTime: case ValueTypes.Date: if (source is DateTime sourceDateTime) { return(sourceDateTime); } if (source is string sourceDateTimeString) { return(DateTime.TryParse(sourceDateTimeString, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dt) ? dt : DateTime.MinValue); } return(DateTime.MinValue); case ValueTypes.Time: if (source is DateTime sourceTime) { return(sourceTime.TimeOfDay); } if (source is string sourceTimeString) { return(TimeSpan.TryParse(sourceTimeString, CultureInfo.InvariantCulture, out var ts) ? ts : TimeSpan.Zero); } return(TimeSpan.Zero); case ValueTypes.Decimal: if (source is decimal sourceDecimal) { return(sourceDecimal); } if (source is string sourceDecimalString) { return(decimal.TryParse(sourceDecimalString, NumberStyles.Any, CultureInfo.InvariantCulture, out var d) ? d : 0); } if (source is double sourceDouble) { return(Convert.ToDecimal(sourceDouble)); } return((decimal)0); case ValueTypes.Integer: if (source is int sourceInt) { return(sourceInt); } if (source is string sourceIntString) { return(int.TryParse(sourceIntString, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i) ? i : 0); } return(0); case ValueTypes.Bigint: if (source is string sourceLongString) { return(long.TryParse(sourceLongString, out var i) ? i : 0); } return((long)0); default: // everything else is a string return(source?.ToString() ?? string.Empty); } }
private bool UseLabel(IPublishedPropertyType propertyType) { return(ConfigurationEditor.ConfigurationAs <ColorPickerConfiguration>(propertyType.DataType.Configuration).UseLabel); }