public void GetAllReferences_All_Variants_With_IDataValueReferenceFactory() { var collection = new DataValueReferenceFactoryCollection(new TestDataValueReferenceFactory().Yield()); // label does not implement IDataValueReference var labelEditor = new LabelPropertyEditor(Mock.Of <ILogger>()); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(labelEditor.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi4 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var property = new Property(new PropertyType(new DataType(labelEditor)) { Variations = ContentVariation.CultureAndSegment }) { Values = new List <PropertyValue> { // Ignored (no culture) new PropertyValue { EditedValue = trackedUdi1 }, new PropertyValue { Culture = "en-US", EditedValue = trackedUdi2 }, new PropertyValue { Culture = "en-US", Segment = "A", EditedValue = trackedUdi3 }, // Ignored (no culture) new PropertyValue { Segment = "A", EditedValue = trackedUdi4 }, // duplicate new PropertyValue { Culture = "en-US", Segment = "B", EditedValue = trackedUdi3 } } }; var properties = new PropertyCollection { property }; var result = collection.GetAllReferences(properties, propertyEditors); Assert.AreEqual(2, result.Count()); Assert.AreEqual(trackedUdi2, result.ElementAt(0).Udi.ToString()); Assert.AreEqual(trackedUdi3, result.ElementAt(1).Udi.ToString()); }
public void GetAllReferences_All_Variants_With_IDataValueReferenceFactory() { var collection = new DataValueReferenceFactoryCollection(() => new TestDataValueReferenceFactory().Yield()); // label does not implement IDataValueReference var labelEditor = new LabelPropertyEditor( DataValueEditorFactory, IOHelper, EditorConfigurationParser); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => labelEditor.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi3 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi4 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var serializer = new ConfigurationEditorJsonSerializer(); var property = new Property( new PropertyType(ShortStringHelper, new DataType(labelEditor, serializer)) { Variations = ContentVariation.CultureAndSegment, }) { Values = new List <PropertyValue> { // Ignored (no culture) new() { EditedValue = trackedUdi1 }, new() { Culture = "en-US", EditedValue = trackedUdi2 }, new() { Culture = "en-US", Segment = "A", EditedValue = trackedUdi3 }, // Ignored (no culture) new() { Segment = "A", EditedValue = trackedUdi4 }, // Duplicate new() { Culture = "en-US", Segment = "B", EditedValue = trackedUdi3 }, }, }; var properties = new PropertyCollection { property }; var result = collection.GetAllReferences(properties, propertyEditors).ToArray(); Assert.AreEqual(2, result.Count()); Assert.AreEqual(trackedUdi2, result.ElementAt(0).Udi.ToString()); Assert.AreEqual(trackedUdi3, result.ElementAt(1).Udi.ToString()); }
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger) { if (!editors.TryGet(dto.EditorAlias, out var editor)) { logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label." + " The site may fail to boot and / or load data types and run.", dto.EditorAlias); //convert to label editor = new LabelPropertyEditor(logger); } var dataType = new DataType(editor); try { dataType.DisableChangeTracking(); dataType.CreateDate = dto.NodeDto.CreateDate; dataType.DatabaseType = dto.DbType.EnumParse <ValueStorageType>(true); dataType.Id = dto.NodeId; dataType.Key = dto.NodeDto.UniqueId; dataType.Level = dto.NodeDto.Level; dataType.UpdateDate = dto.NodeDto.CreateDate; dataType.Name = dto.NodeDto.Text; dataType.ParentId = dto.NodeDto.ParentId; dataType.Path = dto.NodeDto.Path; dataType.SortOrder = dto.NodeDto.SortOrder; dataType.Trashed = dto.NodeDto.Trashed; dataType.CreatorId = dto.NodeDto.UserId ?? Constants.Security.UnknownUserId; dataType.SetLazyConfiguration(dto.Configuration); // reset dirty initial properties (U4-1946) dataType.ResetDirtyProperties(false); return(dataType); } finally { dataType.EnableChangeTracking(); } }
public PropertyEditor CreateEditor(Type baseType, ProviderContext context) { PropertyEditor e = null; // Basic numeric data types if (baseType == typeof(sbyte) || baseType == typeof(byte) || baseType == typeof(short) || baseType == typeof(ushort) || baseType == typeof(int) || baseType == typeof(uint) || baseType == typeof(long) || baseType == typeof(ulong) || baseType == typeof(float) || baseType == typeof(double) || baseType == typeof(decimal)) { e = new NumericPropertyEditor(); } // Basic data type: Boolean else if (baseType == typeof(bool)) { e = new BoolPropertyEditor(); } // Basic data type: Flagged Enum else if (baseType.IsEnum && baseType.GetCustomAttributes(typeof(FlagsAttribute), true).Any()) { e = new FlaggedEnumPropertyEditor(); } // Basic data type: Other Enums else if (baseType.IsEnum) { e = new EnumPropertyEditor(); } // Basic data type: String else if (baseType == typeof(string)) { e = new StringPropertyEditor(); } // IList else if (typeof(System.Collections.IList).IsAssignableFrom(baseType)) { e = new IListPropertyEditor(); } // IDictionary else if (typeof(System.Collections.IDictionary).IsAssignableFrom(baseType)) { e = new IDictionaryPropertyEditor(); } // Unknown data type else { // Ask around if any sub-editor can handle it and choose the most specialized var availSubProviders = from p in this.subProviders where p.IsResponsibleFor(baseType, context) != EditorPriority_None orderby p.IsResponsibleFor(baseType, context) descending select p; IPropertyEditorProvider subProvider = availSubProviders.FirstOrDefault(); if (subProvider != null) { e = subProvider.CreateEditor(baseType, context); e.EditedType = baseType; return(e); } // If not, default to reflection-driven MemberwisePropertyEditor. // Except for MemberInfo types, since we can't edit them in any // meaningful anyway, and they clutter up the grid. if (typeof(MemberInfo).IsAssignableFrom(baseType)) { e = new LabelPropertyEditor(); } else { e = new MemberwisePropertyEditor(); } } e.EditedType = baseType; return(e); }