Cleans up the IPropertyType interface, cleans up how it is constructed
This commit is contained in:
@@ -33,14 +33,9 @@ namespace Umbraco.Core.Models
|
||||
/// </summary>
|
||||
void SetValue(object value, string culture = null, string segment = null);
|
||||
|
||||
/// <summary>
|
||||
/// Resets the entity identity.
|
||||
/// </summary>
|
||||
void ResetIdentity();
|
||||
|
||||
int PropertyTypeId { get; }
|
||||
void PublishValues(string culture = "*", string segment = "*");
|
||||
void UnpublishValues(string culture = "*", string segment = "*");
|
||||
void FactorySetValue(string culture, string segment, bool published, object value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Umbraco.Core.Models
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
// TODO: Change this to ObservableDictionary so we can reduce the INotifyCollectionChanged implementation details
|
||||
public class PropertyTypeCollection : KeyedCollection<string, IPropertyType>, INotifyCollectionChanged, IDeepCloneable
|
||||
public class PropertyTypeCollection : KeyedCollection<string, IPropertyType>, INotifyCollectionChanged, IDeepCloneable, ICollection<IPropertyType>
|
||||
{
|
||||
[IgnoreDataMember]
|
||||
private readonly ReaderWriterLockSlim _addLocker = new ReaderWriterLockSlim();
|
||||
@@ -83,8 +83,7 @@ namespace Umbraco.Core.Models
|
||||
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
|
||||
}
|
||||
|
||||
// TODO: Instead of 'new' this should explicitly implement one of the collection interfaces members
|
||||
public new void Add(IPropertyType item)
|
||||
void ICollection<IPropertyType>.Add(IPropertyType item)
|
||||
{
|
||||
item.SupportsPublishing = SupportsPublishing;
|
||||
|
||||
|
||||
@@ -47,6 +47,54 @@ namespace Umbraco.Core.Models
|
||||
PropertyType = propertyType;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Property"/> instance for existing <see cref="IProperty"/>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="propertyType"></param>
|
||||
/// <param name="values">
|
||||
/// Generally will contain a published and an unpublished property values
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static Property CreateWithValues(int id, IPropertyType propertyType, params InitialPropertyValue[] values)
|
||||
{
|
||||
var property = new Property(propertyType);
|
||||
try
|
||||
{
|
||||
property.DisableChangeTracking();
|
||||
property.Id = id;
|
||||
foreach(var value in values)
|
||||
{
|
||||
property.FactorySetValue(value.Culture, value.Segment, value.Published, value.Value);
|
||||
}
|
||||
property.ResetDirtyProperties(false);
|
||||
return property;
|
||||
}
|
||||
finally
|
||||
{
|
||||
property.EnableChangeTracking();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used for constructing a new <see cref="Property"/> instance
|
||||
/// </summary>
|
||||
public class InitialPropertyValue
|
||||
{
|
||||
public InitialPropertyValue(string culture, string segment, bool published, object value)
|
||||
{
|
||||
Culture = culture ?? throw new ArgumentNullException(nameof(culture));
|
||||
Segment = segment ?? throw new ArgumentNullException(nameof(segment));
|
||||
Published = published;
|
||||
Value = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
public string Culture { get; }
|
||||
public string Segment { get; }
|
||||
public bool Published { get; }
|
||||
public object Value { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a property value.
|
||||
/// </summary>
|
||||
@@ -284,7 +332,7 @@ namespace Umbraco.Core.Models
|
||||
}
|
||||
|
||||
// bypasses all changes detection and is the *only* way to set the published value
|
||||
public void FactorySetValue(string culture, string segment, bool published, object value)
|
||||
private void FactorySetValue(string culture, string segment, bool published, object value)
|
||||
{
|
||||
var (pvalue, _) = GetPValue(culture, segment, true);
|
||||
|
||||
|
||||
@@ -16,31 +16,21 @@ namespace Umbraco.Core.Persistence.Factories
|
||||
|
||||
foreach (var propertyType in propertyTypes)
|
||||
{
|
||||
var property = new Property(propertyType);
|
||||
var values = new List<Property.InitialPropertyValue>();
|
||||
int propertyId = default;
|
||||
|
||||
try
|
||||
// see notes in BuildDtos - we always have edit+published dtos
|
||||
if (xdtos.TryGetValue(propertyType.Id, out var propDtos))
|
||||
{
|
||||
property.DisableChangeTracking();
|
||||
|
||||
// see notes in BuildDtos - we always have edit+published dtos
|
||||
|
||||
if (xdtos.TryGetValue(propertyType.Id, out var propDtos))
|
||||
foreach (var propDto in propDtos)
|
||||
{
|
||||
foreach (var propDto in propDtos)
|
||||
{
|
||||
property.Id = propDto.Id;
|
||||
property.FactorySetValue(languageRepository.GetIsoCodeById(propDto.LanguageId), propDto.Segment, propDto.VersionId == publishedVersionId, propDto.Value);
|
||||
}
|
||||
|
||||
propertyId = propDto.Id;
|
||||
values.Add(new Property.InitialPropertyValue(languageRepository.GetIsoCodeById(propDto.LanguageId), propDto.Segment, propDto.VersionId == publishedVersionId, propDto.Value));
|
||||
}
|
||||
}
|
||||
|
||||
property.ResetDirtyProperties(false);
|
||||
properties.Add(property);
|
||||
}
|
||||
finally
|
||||
{
|
||||
property.EnableChangeTracking();
|
||||
}
|
||||
var property = Property.CreateWithValues(propertyId, propertyType, values.ToArray());
|
||||
properties.Add(property);
|
||||
}
|
||||
|
||||
return properties;
|
||||
|
||||
Reference in New Issue
Block a user