private void AddToPanelPickerAllowedEditors() { var panelPickerDataType = _dataTypeService.GetDataTypeDefinitionByName(PanelsInstallationConstants.DataTypeNames.PanelPicker); var preValuesDictionary = _dataTypeService.GetPreValuesCollectionByDataTypeId(panelPickerDataType.Id).PreValuesAsDictionary; AddAllowedEditor(preValuesDictionary, TableEditor); _dataTypeService.SavePreValues(panelPickerDataType, preValuesDictionary); }
private void AddToDefaultGridAllowedEditors() { var defaultGridDataType = _dataTypeService.GetDataTypeDefinitionByName(CoreInstallationConstants.DataTypeNames.ContentGrid); var preValuesDictionary = _dataTypeService.GetPreValuesCollectionByDataTypeId(defaultGridDataType.Id).PreValuesAsDictionary; GridInstallationHelper.AddAllowedEditorForOneColumnRow(preValuesDictionary, UserListAlias); _dataTypeService.SaveDataTypeAndPreValues(defaultGridDataType, preValuesDictionary); }
public PreValueCollection GetDataTypeOptions(string dataTypeName) { var dataType = _dataTypeService.GetDataTypeDefinitionByName(dataTypeName); if (dataType == null) { return(null); } return(_dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id)); }
public void RegisterNtextType <T, Tconverter>(string dataTypeName) where Tconverter : IDataTypeConverter <string, T> { DataTypeRegistration reg = new DataTypeRegistration(); reg.ClrType = typeof(T); reg.CodeFirstControlled = false; //no real definition so don't sync reg.DataTypeInstanceName = dataTypeName; reg.ConverterType = typeof(Tconverter); reg.DbType = DatabaseType.Ntext; reg.UmbracoDatabaseType = DataTypeDatabaseType.Ntext; reg.Definition = _service.GetDataTypeDefinitionByName(dataTypeName); reg.PropertyEditorAlias = reg.Definition.PropertyEditorAlias; _registerController.Register(typeof(T), reg); }
/// <summary> /// Convert archetype data types with the given name /// /// Creates new data types, including a content type to represent the Archetype /// Then converts the content from one json format to the other /// This searches inside other nested contents as well as just standard content /// Finally swaps the data type itself over /// </summary> /// <param name="name"></param> public void Convert(string name) { var archetypeDataType = _dataTypeService.GetDataTypeDefinitionByName(name); var nestedContentDataType = CreateNestedContentDataTypeBasedOnArchetype(archetypeDataType); var allContentTypes = _contentTypeService.GetAllContentTypes(); var archetypeContentTypes = allContentTypes .Where(c => c.PropertyTypes.Any(a => a.DataTypeDefinitionId == archetypeDataType.Id) || c.CompositionPropertyTypes.Any(a => a.DataTypeDefinitionId == archetypeDataType.Id)); ConvertContent(archetypeContentTypes, archetypeDataType); ConvertDataType(archetypeContentTypes, archetypeDataType, nestedContentDataType); }
internal DataTypeInfo ResolveDataType(FluidityEditorFieldConfig fieldConfig, bool isReadOnly = false) { var dtdKey = !fieldConfig.DataTypeName.IsNullOrWhiteSpace() ? fieldConfig.DataTypeName : fieldConfig.GetOrCalculateDefinititionId().ToString(); dtdKey += $"_{isReadOnly}"; return(_cacheProvider.GetCacheItem <DataTypeInfo>($"fluidity_datatypeinfo_{dtdKey}", () => { IDataTypeDefinition dataTypeDefinition = null; if (!fieldConfig.DataTypeName.IsNullOrWhiteSpace()) { dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(fieldConfig.DataTypeName); } if (dataTypeDefinition == null) { var dataTypeId = fieldConfig.DataTypeId == 0 && isReadOnly ? -92 // If readonly and no explicit datatype defined, default to label : fieldConfig.GetOrCalculateDefinititionId(); dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeId); } var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); var propEditor = _propertyEditorResolver.GetByAlias(dataTypeDefinition.PropertyEditorAlias); return new DataTypeInfo(dataTypeDefinition, propEditor, preValues); })); }
/// <summary> /// Convert ContentPickerAlias data types with the given name /// /// Converts the content from ids to UDIs /// Swaps the data type alias itself over /// </summary> /// <param name="name"></param> public void Convert(string name) { var oldDataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(name); oldDataTypeDefinition.Name = oldDataTypeDefinition.Name + " (Obsolete)"; _dataTypeService.Save(oldDataTypeDefinition); var oldPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(oldDataTypeDefinition.Id); var newDataTypeDefinition = new DataTypeDefinition(_newDataTypeAlias); newDataTypeDefinition.Name = name; _dataTypeService.SaveDataTypeAndPreValues(newDataTypeDefinition, _preValueConversion == null ? new Dictionary <string, PreValue>() : _preValueConversion(oldPreValues.PreValuesAsDictionary)); var allContentTypes = _contentTypeService.GetAllContentTypes(); var contentTypesToConvert = allContentTypes .Where(c => c.PropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id) || c.CompositionPropertyTypes.Any(a => a.DataTypeDefinitionId == oldDataTypeDefinition.Id)) .ToArray(); AddReplacementDataType(contentTypesToConvert, oldDataTypeDefinition, newDataTypeDefinition); ConvertContent(contentTypesToConvert, oldDataTypeDefinition); DeleteOldDataType(oldDataTypeDefinition); }
internal DataTypeInfo ResolveDataType(FluidityEditorFieldConfig fieldConfig) { var dtdKey = !fieldConfig.DataTypeName.IsNullOrWhiteSpace() ? fieldConfig.DataTypeName : fieldConfig.GetOrCalculateDefinititionId().ToString(); return(_cacheProvider.GetCacheItem <DataTypeInfo>($"fluidity_datatypeinfo_{dtdKey}", () => { IDataTypeDefinition dataTypeDefinition = null; if (!fieldConfig.DataTypeName.IsNullOrWhiteSpace()) { dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(fieldConfig.DataTypeName); } if (dataTypeDefinition == null) { var dataTypeId = fieldConfig.GetOrCalculateDefinititionId(); dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeId); } var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id); var propEditor = _propertyEditorResolver.GetByAlias(dataTypeDefinition.PropertyEditorAlias); return new DataTypeInfo(dataTypeDefinition, propEditor, preValues); })); }
private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model) { var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault(); if (dataType == null) { // Create new data type. dataType = CreateDataType(model); _dataTypeService.SaveDataTypeAndPreValues(dataType, GetPreValues(model)); } else { // Update the data type and its pre-values. _dataTypeService.Save(UpdateDataTypeDefinition(dataType, model)); var existingPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id).FormatAsDictionary(); var preValuesToSave = existingPreValues.Any() ? GetUpdatedPreValues(existingPreValues, model.PreValues) : GetPreValues(model); _dataTypeService.SavePreValues(dataType.Id, preValuesToSave); } // We get the data type once more to refresh it after saving it. dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name); // Set/update tracking. SetDataTypeId(model, dataType); }
public void Convert(string name) { var archetypeDataType = _dataTypeService.GetDataTypeDefinitionByName(name); var nestedContentDataType = CreateNestedContentDataType(archetypeDataType); var archetypeContentTypes = ArchetypeContentTypes(archetypeDataType); foreach (var archetypeContentType in archetypeContentTypes) { ConvertInsideNestedContents(archetypeContentType.Alias, Alias(archetypeDataType.Name + "nc")); ConvertArchetypeValuesToNestedContent(archetypeContentType.Id, archetypeDataType.Id, Alias(archetypeDataType.Name + "nc")); } foreach (var archetypeContentType in archetypeContentTypes) { foreach (var composition in archetypeContentType.ContentTypeComposition) { if (Archetypes(composition.PropertyTypes, archetypeDataType).Any()) { var compositionContentType = _contentTypeService.GetContentType(composition.Id); var propertyTypes = Archetypes(compositionContentType.PropertyTypes, archetypeDataType).ToArray(); foreach (var propType in propertyTypes) { propType.DataTypeDefinitionId = nestedContentDataType.Id; propType.PropertyEditorAlias = NestedContentAlias; } _contentTypeService.Save(compositionContentType); } } if (Archetypes(archetypeContentType.PropertyTypes, archetypeDataType).Any()) { var propertyTypes = Archetypes(archetypeContentType.PropertyTypes, archetypeDataType).ToArray(); foreach (var propType in propertyTypes) { propType.DataTypeDefinitionId = nestedContentDataType.Id; propType.PropertyEditorAlias = NestedContentAlias; } _contentTypeService.Save(archetypeContentType); } } _dataTypeService.Delete(archetypeDataType); }
public void Convert(string name) { var nestedContentDataType = _dataTypeService.GetDataTypeDefinitionByName(name); var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(nestedContentDataType.Id).FormatAsDictionary(); nestedContentDataType.PropertyEditorAlias = "Umbraco.NestedContent"; _dataTypeService.SaveDataTypeAndPreValues(nestedContentDataType, preValues); }
private SyncAttempt <IDataTypeDefinition> DeserializeItem(XElement node, IDataTypeDefinition item) { // pre import var mappedNode = DeserializeGetMappedValues(node); Guid key = node.Attribute("Key").ValueOrDefault(Guid.Empty); var name = node.Attribute("Name").ValueOrDefault(string.Empty); var editorAlias = node.Attribute("Id").ValueOrDefault(string.Empty); var dbType = node.Attribute("DatabaseType").ValueOrDefault(string.Empty); var databaseType = !string.IsNullOrEmpty(dbType) ? dbType.EnumParse <DataTypeDatabaseType>(true) : DataTypeDatabaseType.Ntext; if (item == null && !string.IsNullOrEmpty(name)) { // lookup by alias. LogHelper.Debug <DataTypeSerializer>("Looking up datatype by name: {0}", () => name); item = _dataTypeService.GetDataTypeDefinitionByName(name); } if (item == null) { // create item = new DataTypeDefinition(editorAlias) { Key = key, Name = name, DatabaseType = databaseType }; } if (item.Name != name) { item.Name = name; } if (item.Key != key) { item.Key = key; } if (item.PropertyEditorAlias != editorAlias) { item.PropertyEditorAlias = editorAlias; } if (item.DatabaseType != databaseType) { item.DatabaseType = databaseType; } _dataTypeService.Save(item); DeserializeUpdatePreValues(item, mappedNode); _dataTypeService.Save(item); return(SyncAttempt <IDataTypeDefinition> .Succeed(item.Name, item, ChangeType.Import)); }
public static int?getPrevalueId(string dataTypeName, string dataTypeValue) { // Instantiate datatype service IDataTypeService dtService = ApplicationContext.Current.Services.DataTypeService; // Obtain prevalue collection from datatypes IDataTypeDefinition dtDefinition = dtService.GetDataTypeDefinitionByName(dataTypeName); PreValueCollection pvCollection = dtService.GetPreValuesCollectionByDataTypeId(dtDefinition.Id); return(pvCollection.PreValuesAsDictionary.FirstOrDefault(preValue => string.Equals(preValue.Value.Value, dataTypeValue)).Value.Id); }
private void UpdateDatatypePreValues(IDataTypeService dataTypeService, string dataTypeName, string assemblyFullNamePreValue, string enumFullNamePreValue) { var dataType = dataTypeService.GetDataTypeDefinitionByName(dataTypeName); if (dataType != null) { var preValues = dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id); var dictionary = preValues.FormatAsDictionary(); dictionary[FolderConstants.PreValueAssemblyAlias].Value = assemblyFullNamePreValue; dictionary[FolderConstants.PreValueEnumAlias].Value = enumFullNamePreValue; dataTypeService.SaveDataTypeAndPreValues(dataType, dictionary); } }
private void Synchronize(IDataTypeDefinition[] dataTypes, DataType model) { var dataType = _dataTypeFinder.Find(model, dataTypes).SingleOrDefault(); dataType = dataType == null ? CreateDataType(model) : UpdateDataTypeDefinition(dataType, model); _dataTypeService.Save(dataType); // We get the data type once more to refresh it after saving it. dataType = _dataTypeService.GetDataTypeDefinitionByName(dataType.Name); // Set the pre-values, if any. SetDataTypePreValues(dataType, model); // Set/update tracking. SetDataTypeId(model, dataType); }
private MediaType CreateSearchMediaComposition() { var compositionFolder = GetMediaCompositionFolder(); var composition = new MediaType(compositionFolder.Id) { Alias = MediaAliases.SearchMediaCompositionAlias, Name = MediaAliases.SearchMediaCompositionName, SortOrder = 2 }; InstallationStepsHelper.CreateTrueFalseDataType("TrueFalse"); var trueFalseEditor = _dataTypeService.GetDataTypeDefinitionByName("TrueFalse"); var property = new PropertyType(trueFalseEditor, MediaAliases.UseInSearch) { Name = "Use in search", }; composition.AddPropertyType(property, MediaAliases.CompositionTabName); _contentTypeService.Save(composition); return(composition); }
private void CreateProperties(ContentType item, IEnumerable <ContentTypeTab> tabs) { foreach (var tab in tabs) { foreach (var property in tab.Properties) { LogHelper.Info <ContentTypeBuilder>("Looking for DocType: {0}", () => property.DataType); var dataType = _dataTypeService.GetDataTypeDefinitionByName(property.DataType); var itemProperty = item.PropertyTypes.SingleOrDefault(x => x.Alias == property.Alias); if (itemProperty == null) { // create it. itemProperty = new PropertyType(dataType, property.Alias) { Name = property.Name }; if (!property.Description.IsNullOrWhiteSpace()) { itemProperty.Description = property.Description; } if (!property.Validation.IsNullOrWhiteSpace()) { itemProperty.ValidationRegExp = property.Validation; } itemProperty.Mandatory = property.Mandatory; itemProperty.SortOrder = property.SortOrder; itemProperty.PropertyEditorAlias = dataType.PropertyEditorAlias; item.AddPropertyType(itemProperty, tab.TabName); } } } }
private void RemoveFromPreValues(IEnumerable <string> editorsToRemove) { const string itemsKey = "items"; var defaultGridDataType = _dataTypeService.GetDataTypeDefinitionByName(CoreInstallationConstants.DataTypeNames.DefaultGrid); var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(defaultGridDataType.Id); var preValuesDictionary = preValues.FormatAsDictionary(); var items = preValuesDictionary[itemsKey].Value.Pipe(Json.Decode); var availableEditors = items.layouts[0].areas[0].allowed; var availableEditorsList = new List <string>(); foreach (var editor in availableEditors) { availableEditorsList.Add((string)editor); } var actualEditors = availableEditorsList.Except(editorsToRemove); items.layouts[0].areas[0].allowed = JArray.FromObject(actualEditors).ToDynamic(); preValuesDictionary[itemsKey].Value = JsonConvert.SerializeObject(items); _dataTypeService.SaveDataTypeAndPreValues(defaultGridDataType, preValuesDictionary); }
public bool Exists(string name) { var datatype = _dataTypeService.GetDataTypeDefinitionByName(name); return(datatype != null); }
protected override IDataTypeDefinition FindExisting() { return(dataTypeService.GetDataTypeDefinitionByName(Configuration.Name)); }
/// <summary> /// Adds the container (listview) tab to the document /// </summary> /// <typeparam name="TPersisted"></typeparam> /// <param name="display"></param> /// <param name="entityType">This must be either 'content' or 'media'</param> /// <param name="dataTypeService"></param> /// <param name="localizedTextService"></param> internal static void AddListView <TPersisted>(TabbedContentItem <ContentPropertyDisplay, TPersisted> display, string entityType, IDataTypeService dataTypeService, ILocalizedTextService localizedTextService) where TPersisted : IContentBase { int dtdId; var customDtdName = Constants.Conventions.DataTypes.ListViewPrefix + display.ContentTypeAlias; switch (entityType) { case "content": dtdId = Constants.System.DefaultContentListViewDataTypeId; break; case "media": dtdId = Constants.System.DefaultMediaListViewDataTypeId; break; case "member": dtdId = Constants.System.DefaultMembersListViewDataTypeId; break; default: throw new ArgumentOutOfRangeException("entityType does not match a required value"); } //first try to get the custom one if there is one var dt = dataTypeService.GetDataTypeDefinitionByName(customDtdName) ?? dataTypeService.GetDataTypeDefinitionById(dtdId); if (dt == null) { throw new InvalidOperationException("No list view data type was found for this document type, ensure that the default list view data types exists and/or that your custom list view data type exists"); } var preVals = dataTypeService.GetPreValuesCollectionByDataTypeId(dt.Id); var editor = PropertyEditorResolver.Current.GetByAlias(dt.PropertyEditorAlias); if (editor == null) { throw new NullReferenceException("The property editor with alias " + dt.PropertyEditorAlias + " does not exist"); } var listViewTab = new Tab <ContentPropertyDisplay>(); listViewTab.Alias = Constants.Conventions.PropertyGroups.ListViewGroupName; listViewTab.Label = localizedTextService.Localize("content/childItems"); listViewTab.Id = display.Tabs.Count() + 1; listViewTab.IsActive = true; var listViewConfig = editor.PreValueEditor.ConvertDbToEditor(editor.DefaultPreValues, preVals); //add the entity type to the config listViewConfig["entityType"] = entityType; //Override Tab Label if tabName is provided if (listViewConfig.ContainsKey("tabName")) { var configTabName = listViewConfig["tabName"]; if (configTabName != null && string.IsNullOrWhiteSpace(configTabName.ToString()) == false) { listViewTab.Label = configTabName.ToString(); } } var listViewProperties = new List <ContentPropertyDisplay>(); listViewProperties.Add(new ContentPropertyDisplay { Alias = string.Format("{0}containerView", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = "", Value = null, View = editor.ValueEditor.View, HideLabel = true, Config = listViewConfig }); listViewTab.Properties = listViewProperties; SetChildItemsTabPosition(display, listViewConfig, listViewTab); }