Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Reverting association autoproperty code. Still need to get the locati…
Browse files Browse the repository at this point in the history
…ons right for association backing field prooperties.
  • Loading branch information
msawczyn committed Aug 26, 2020
1 parent 0f63be7 commit 2e4b5b4
Show file tree
Hide file tree
Showing 16 changed files with 729 additions and 1,117 deletions.
99 changes: 0 additions & 99 deletions src/Dsl/CustomCode/Partials/Association.cs
Expand Up @@ -235,103 +235,6 @@ private void FKPropertiesMatchIdentityProperties(ValidationContext context)
}
}

#region SourceAutoProperty tracking property

/// <summary>Storage for the SourceAutoProperty property.</summary>
private bool sourceAutoPropertyStorage;

/// <summary>Gets the storage for the SourceAutoProperty property.</summary>
/// <returns>The SourceAutoProperty value.</returns>
public bool GetSourceAutoPropertyValue()
{
if (!this.IsLoading() && IsSourceAutoPropertyTracking)
{
try
{
return Source?.AutoPropertyDefault ?? true;
}
catch (NullReferenceException)
{
return true;
}
catch (Exception e)
{
if (CriticalException.IsCriticalException(e))
throw;

return true;
}
}

return sourceAutoPropertyStorage;
}

/// <summary>Sets the storage for the SourceAutoProperty property.</summary>
/// <param name="value">The SourceAutoProperty value.</param>
public void SetSourceAutoPropertyValue(bool value)
{
sourceAutoPropertyStorage = value;

if (!Store.InUndoRedoOrRollback && !this.IsLoading())
IsSourceAutoPropertyTracking = (sourceAutoPropertyStorage == (Source?.AutoPropertyDefault ?? true));
}

internal sealed partial class IsSourceAutoPropertyTrackingPropertyHandler
{
/// <summary>
/// Called after the IsSourceAutoPropertyTracking property changes.
/// </summary>
/// <param name="element">The model element that has the property that changed. </param>
/// <param name="oldValue">The previous value of the property. </param>
/// <param name="newValue">The new value of the property. </param>
protected override void OnValueChanged(Association element, bool oldValue, bool newValue)
{
base.OnValueChanged(element, oldValue, newValue);
if (!element.Store.InUndoRedoOrRollback && newValue)
{
DomainPropertyInfo propInfo = element.Store.DomainDataDirectory.GetDomainProperty(SourceAutoPropertyDomainPropertyId);
propInfo.NotifyValueChange(element);
}
}

/// <summary>Performs the reset operation for the IsSourceAutoPropertyTracking property for a model element.</summary>
/// <param name="element">The model element that has the property to reset.</param>
internal void ResetValue(Association element)
{
object calculatedValue = null;

try
{
calculatedValue = element.Source?.AutoPropertyDefault;
}
catch (NullReferenceException) { }
catch (Exception e)
{
if (CriticalException.IsCriticalException(e))
throw;
}

if (calculatedValue != null && element.SourceAutoProperty == (bool)calculatedValue)
element.isSourceAutoPropertyTrackingPropertyStorage = true;
}

/// <summary>
/// Method to set IsSourceAutoPropertyTracking to false so that this instance of this tracking property is not
/// storage-based.
/// </summary>
/// <param name="element">
/// The element on which to reset the property value.
/// </param>
internal void PreResetValue(Association element)
{
// Force the IsSourceAutoPropertyTracking property to false so that the value
// of the SourceAutoProperty property is retrieved from storage.
element.isSourceAutoPropertyTrackingPropertyStorage = false;
}
}

#endregion

#region TargetImplementNotify tracking property

/// <summary>Storage for the TargetImplementNotify property.</summary>
Expand Down Expand Up @@ -530,7 +433,6 @@ internal virtual void PreResetIsTrackingProperties()
{
IsCollectionClassTrackingPropertyHandler.Instance.PreResetValue(this);
IsTargetImplementNotifyTrackingPropertyHandler.Instance.PreResetValue(this);
IsSourceAutoPropertyTrackingPropertyHandler.Instance.PreResetValue(this);
// same with other tracking properties as they get added
}

Expand All @@ -543,7 +445,6 @@ internal virtual void ResetIsTrackingProperties()
{
IsCollectionClassTrackingPropertyHandler.Instance.ResetValue(this);
IsTargetImplementNotifyTrackingPropertyHandler.Instance.ResetValue(this);
IsSourceAutoPropertyTrackingPropertyHandler.Instance.ResetValue(this);
// same with other tracking properties as they get added
}

Expand Down
99 changes: 0 additions & 99 deletions src/Dsl/CustomCode/Partials/BidirectionalAssociation.cs
Expand Up @@ -135,103 +135,6 @@ internal void PreResetValue(BidirectionalAssociation element)

#endregion

#region TargetAutoProperty tracking property

/// <summary>Storage for the TargetAutoProperty property.</summary>
private bool targetAutoPropertyStorage;

/// <summary>Gets the storage for the TargetAutoProperty property.</summary>
/// <returns>The TargetAutoProperty value.</returns>
public bool GetTargetAutoPropertyValue()
{
if (!this.IsLoading() && IsTargetAutoPropertyTracking)
{
try
{
return Source?.AutoPropertyDefault ?? true;
}
catch (NullReferenceException)
{
return true;
}
catch (Exception e)
{
if (CriticalException.IsCriticalException(e))
throw;

return true;
}
}

return targetAutoPropertyStorage;
}

/// <summary>Sets the storage for the TargetAutoProperty property.</summary>
/// <param name="value">The TargetAutoProperty value.</param>
public void SetTargetAutoPropertyValue(bool value)
{
targetAutoPropertyStorage = value;

if (!Store.InUndoRedoOrRollback && !this.IsLoading())
IsTargetAutoPropertyTracking = (targetAutoPropertyStorage == (Source?.AutoPropertyDefault ?? true));
}

internal sealed partial class IsTargetAutoPropertyTrackingPropertyHandler
{
/// <summary>
/// Called after the IsTargetAutoPropertyTracking property changes.
/// </summary>
/// <param name="element">The model element that has the property that changed. </param>
/// <param name="oldValue">The previous value of the property. </param>
/// <param name="newValue">The new value of the property. </param>
protected override void OnValueChanged(BidirectionalAssociation element, bool oldValue, bool newValue)
{
base.OnValueChanged(element, oldValue, newValue);
if (!element.Store.InUndoRedoOrRollback && newValue)
{
DomainPropertyInfo propInfo = element.Store.DomainDataDirectory.GetDomainProperty(TargetAutoPropertyDomainPropertyId);
propInfo.NotifyValueChange(element);
}
}

/// <summary>Performs the reset operation for the IsTargetAutoPropertyTracking property for a model element.</summary>
/// <param name="element">The model element that has the property to reset.</param>
internal void ResetValue(BidirectionalAssociation element)
{
object calculatedValue = null;

try
{
calculatedValue = element.Source?.AutoPropertyDefault;
}
catch (NullReferenceException) { }
catch (Exception e)
{
if (CriticalException.IsCriticalException(e))
throw;
}

if (calculatedValue != null && element.TargetAutoProperty == (bool)calculatedValue)
element.isTargetAutoPropertyTrackingPropertyStorage = true;
}

/// <summary>
/// Method to set IsTargetAutoPropertyTracking to false so that this instance of this tracking property is not
/// storage-based.
/// </summary>
/// <param name="element">
/// The element on which to reset the property value.
/// </param>
internal void PreResetValue(BidirectionalAssociation element)
{
// Force the IsTargetAutoPropertyTracking property to false so that the value
// of the TargetAutoProperty property is retrieved from storage.
element.isTargetAutoPropertyTrackingPropertyStorage = false;
}
}

#endregion

/// <summary>
/// Calls the pre-reset method on the associated property value handler for each
/// tracking property of this model element.
Expand All @@ -241,7 +144,6 @@ internal override void PreResetIsTrackingProperties()
{
base.PreResetIsTrackingProperties();
IsSourceImplementNotifyTrackingPropertyHandler.Instance.PreResetValue(this);
IsTargetAutoPropertyTrackingPropertyHandler.Instance.PreResetValue(this);
// same with other tracking properties as they get added
}

Expand All @@ -254,7 +156,6 @@ internal override void ResetIsTrackingProperties()
{
base.ResetIsTrackingProperties();
IsSourceImplementNotifyTrackingPropertyHandler.Instance.ResetValue(this);
IsTargetAutoPropertyTrackingPropertyHandler.Instance.ResetValue(this);
// same with other tracking properties as they get added
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/Dsl/CustomCode/Partials/ModelClass.cs
Expand Up @@ -861,14 +861,6 @@ protected virtual void OnAutoPropertyDefaultChanged(bool oldValue, bool newValue
Attributes,
ModelAttribute.AutoPropertyDomainPropertyId,
ModelAttribute.IsAutoPropertyTrackingDomainPropertyId);
TrackingHelper.UpdateTrackingCollectionProperty(Store,
Store.GetAll<Association>().Where(a => a.Source?.FullName == FullName),
Association.SourceAutoPropertyDomainPropertyId,
Association.IsSourceAutoPropertyTrackingDomainPropertyId);
TrackingHelper.UpdateTrackingCollectionProperty(Store,
Store.GetAll<BidirectionalAssociation>().Where(a => a.Target?.FullName == FullName),
BidirectionalAssociation.TargetAutoPropertyDomainPropertyId,
BidirectionalAssociation.IsTargetAutoPropertyTrackingDomainPropertyId);
}

internal sealed partial class AutoPropertyDefaultPropertyHandler
Expand Down
38 changes: 8 additions & 30 deletions src/Dsl/CustomCode/Type Descriptors/AssociationTypeDescriptor.cs
Expand Up @@ -38,7 +38,7 @@ private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
&& association.SourceMultiplicity != Multiplicity.ZeroMany
&& association.TargetMultiplicity != Multiplicity.ZeroMany)
propertyDescriptors.Remove("FKPropertyName");

// only display roles for 1..1 and 0-1..0-1 associations
if ((association.SourceMultiplicity != Multiplicity.One || association.TargetMultiplicity != Multiplicity.One)
&& (association.SourceMultiplicity != Multiplicity.ZeroOne || association.TargetMultiplicity != Multiplicity.ZeroOne))
Expand All @@ -58,19 +58,18 @@ private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
if (association.SourceMultiplicity != Multiplicity.ZeroMany || association.TargetMultiplicity != Multiplicity.ZeroMany)
propertyDescriptors.Remove("JoinTableName");

// don't display BackingField or PropertyAccessMode unless AutoProperty is false
if (association.SourceAutoProperty)
{
propertyDescriptors.Remove("SourceBackingFieldName");
propertyDescriptors.Remove("SourcePropertyAccessMode");
}

if (bidirectionalAssociation?.TargetAutoProperty != false)
// only show backing field and property access mode for EFCore5+ non-collection associations
if (!association.Source.ModelRoot.IsEFCore5Plus || association.TargetMultiplicity == Multiplicity.ZeroMany)
{
propertyDescriptors.Remove("TargetBackingFieldName");
propertyDescriptors.Remove("TargetPropertyAccessMode");
}

if (!association.Source.ModelRoot.IsEFCore5Plus || bidirectionalAssociation?.SourceMultiplicity == Multiplicity.ZeroMany)
{
propertyDescriptors.Remove("SourceBackingFieldName");
propertyDescriptors.Remove("SourcePropertyAccessMode");
}
/********************************************************************************/

//Add the descriptors for the tracking properties
Expand All @@ -97,17 +96,6 @@ private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
+ "Only valid for non-collection targets.")
, new CategoryAttribute("End 2")
}));


propertyDescriptors.Add(new TrackingPropertyDescriptor(association
, storeDomainDataDirectory.GetDomainProperty(Association.SourceAutoPropertyDomainPropertyId)
, storeDomainDataDirectory.GetDomainProperty(Association.IsSourceAutoPropertyTrackingDomainPropertyId)
, new Attribute[]
{
new DisplayNameAttribute("Source AutoProperty")
, new DescriptionAttribute("Overrides default autoproperty setting")
, new CategoryAttribute("End 1")
}));
}

if (bidirectionalAssociation?.SourceMultiplicity == Multiplicity.One || bidirectionalAssociation?.SourceMultiplicity == Multiplicity.ZeroOne)
Expand All @@ -122,16 +110,6 @@ private PropertyDescriptorCollection GetCustomProperties(Attribute[] attributes)
+ "Only valid for non-collection targets.")
, new CategoryAttribute("End 1")
}));

propertyDescriptors.Add(new TrackingPropertyDescriptor(association
, storeDomainDataDirectory.GetDomainProperty(BidirectionalAssociation.TargetAutoPropertyDomainPropertyId)
, storeDomainDataDirectory.GetDomainProperty(BidirectionalAssociation.IsTargetAutoPropertyTrackingDomainPropertyId)
, new Attribute[]
{
new DisplayNameAttribute("Target AutoProperty")
, new DescriptionAttribute("Overrides default autoproperty setting")
, new CategoryAttribute("End 2")
}));
}

}
Expand Down

0 comments on commit 2e4b5b4

Please sign in to comment.