Skip to content

Commit

Permalink
Add the Element.RetriveDetails property and rename related members ac…
Browse files Browse the repository at this point in the history
…cordingly

RetrieveDetails and RetrieveDetailsChangeStatus will later be implemented to observe the values of both IsOnline and ChildrenRetrievalPolicy.

References #21
  • Loading branch information
andreashuber-lawo committed Apr 25, 2016
1 parent de4a77c commit 4dfd3a1
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<Compile Include="Model\IResult.cs" />
<Compile Include="Model\IInvocationResult.cs" />
<Compile Include="Model\InvocationFailedException.cs" />
<Compile Include="Model\IsOnlineChangeStatus.cs" />
<Compile Include="Model\RetrieveDetailsChangeStatus.cs" />
<Compile Include="Model\IValueReader.cs" />
<Compile Include="Model\MatrixAddressingMode.cs" />
<Compile Include="Model\MatrixParameters.cs" />
Expand Down
10 changes: 5 additions & 5 deletions Lawo.EmberPlusSharp/Model/CollectionNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ internal sealed override Element ReadNewChildContents(
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal sealed override bool ChangeOnlineStatus(IElement child)
internal sealed override bool ChangeVisibility(Element child)
{
base.ChangeOnlineStatus(child);
base.ChangeVisibility(child);

if (child.IsOnline)
if (child.RetrieveDetails)
{
this.children.Add((TElement)child);
this.children.Add((TElement)(IElement)child);
}
else
{
this.children.Remove((TElement)child);
this.children.Remove((TElement)(IElement)child);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/DynamicFieldNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public ReadOnlyObservableCollection<IElement> DynamicChildren

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal sealed override bool ChangeOnlineStatus(IElement child)
internal sealed override bool ChangeVisibility(Element child)
{
return DynamicNodeHelper.ChangeOnlineStatus(base.ChangeOnlineStatus, this.dynamicChildren, child);
return DynamicNodeHelper.ChangeVisibility(base.ChangeVisibility, this.dynamicChildren, child);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/DynamicNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ internal static Element ReadDynamicChildContents(
}
}

internal static bool ChangeOnlineStatus(
Func<IElement, bool> baseImpl, ObservableCollection<IElement> dynamicChildren, IElement child)
internal static bool ChangeVisibility(
Func<Element, bool> baseImpl, ObservableCollection<IElement> dynamicChildren, Element child)
{
if (!baseImpl(child))
{
if (child.IsOnline)
if (child.RetrieveDetails)
{
dynamicChildren.Add(child);
}
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/DynamicRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ internal sealed override Element ReadNewDynamicChildContents(
return DynamicNodeHelper.ReadDynamicChildContents(reader, actualType, context, out childRetrievalState);
}

internal sealed override bool ChangeOnlineStatus(IElement child)
internal sealed override bool ChangeVisibility(Element child)
{
return DynamicNodeHelper.ChangeOnlineStatus(base.ChangeOnlineStatus, this.dynamicChildren, child);
return DynamicNodeHelper.ChangeVisibility(base.ChangeVisibility, this.dynamicChildren, child);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
24 changes: 17 additions & 7 deletions Lawo.EmberPlusSharp/Model/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public abstract class Element : NotifyPropertyChanged, IElement
private string identifier;
private string description;
private bool isOnline = true;
private object tag;
private bool hasChanges;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -75,20 +76,24 @@ internal set
{
// We're deliberately not simply setting this to Changed here, because we want to correctly handle
// the case when IsOnline is changed twice without being observed between the changes.
if (this.IsOnlineChangeStatus == IsOnlineChangeStatus.Unchanged)
if (this.RetrieveDetailsChangeStatus == RetrieveDetailsChangeStatus.Unchanged)
{
this.IsOnlineChangeStatus = IsOnlineChangeStatus.Changed;
this.RetrieveDetailsChangeStatus = RetrieveDetailsChangeStatus.Changed;
}
else if (this.IsOnlineChangeStatus == IsOnlineChangeStatus.Changed)
else if (this.RetrieveDetailsChangeStatus == RetrieveDetailsChangeStatus.Changed)
{
this.IsOnlineChangeStatus = IsOnlineChangeStatus.Unchanged;
this.RetrieveDetailsChangeStatus = RetrieveDetailsChangeStatus.Unchanged;
}
}
}
}

/// <inheritdoc/>
public object Tag { get; set; }
public object Tag
{
get { return this.tag; }
set { this.SetValue(ref this.tag, value); }
}

/// <inheritdoc/>
public string GetPath()
Expand All @@ -115,8 +120,6 @@ internal int[] NumberPath
get { return this.numberPath; }
}

internal IsOnlineChangeStatus IsOnlineChangeStatus { get; set; }

internal bool HasChanges
{
get
Expand All @@ -138,6 +141,13 @@ internal bool HasChanges
}
}

internal virtual bool RetrieveDetails
{
get { return this.IsOnline; }
}

internal RetrieveDetailsChangeStatus RetrieveDetailsChangeStatus { get; set; }

internal virtual RetrievalState RetrievalState
{
get { return RetrievalState.Complete; }
Expand Down
22 changes: 11 additions & 11 deletions Lawo.EmberPlusSharp/Model/ElementWithSchemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class ElementWithSchemas<TMostDerived> : Element<TMostDerived>,
where TMostDerived : ElementWithSchemas<TMostDerived>
{
/// <summary>See <see cref="RetrievalState"/> for more information.</summary>
/// <remarks>This field and its sibling <see cref="offlineRetrievalState"/> are modified by the following
/// <remarks>This field and its sibling <see cref="noDetailsRetrievalState"/> are modified by the following
/// methods, which are directly or indirectly called from
/// <see cref="Consumer{T}.CreateAsync(Lawo.EmberPlusSharp.S101.S101Client)"/>:
/// <list type="number">
Expand All @@ -40,8 +40,8 @@ public abstract class ElementWithSchemas<TMostDerived> : Element<TMostDerived>,
/// are changed at once in a large tree.</item>
/// </list>
/// </remarks>
private RetrievalState offlineRetrievalState = RetrievalState.Complete;
private RetrievalState onlineRetrievalState;
private RetrievalState noDetailsRetrievalState = RetrievalState.Complete;
private RetrievalState detailsRetrievalState;

private IReadOnlyList<string> schemaIdentifiers;

Expand All @@ -56,38 +56,38 @@ public IReadOnlyList<string> SchemaIdentifiers

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal ElementWithSchemas(RetrievalState onlineRetrievalState)
internal ElementWithSchemas(RetrievalState detailsRetrievalState)
{
this.onlineRetrievalState = onlineRetrievalState;
this.detailsRetrievalState = detailsRetrievalState;
}

/// <summary>Gets or sets the retrieval state.</summary>
/// <remarks>This implementation has nothing to do with schemas. However, it so happens that this member has the
/// same behavior for all subclasses (parameters, nodes and matrices). If this fact ever changes, it probably
/// makes sense to move this member to its own base class (named e.g. RequestedElement).</remarks>
internal override RetrievalState RetrievalState
internal sealed override RetrievalState RetrievalState
{
get
{
return this.IsOnline ? this.onlineRetrievalState : this.offlineRetrievalState;
return this.RetrieveDetails ? this.detailsRetrievalState : this.noDetailsRetrievalState;
}

set
{
if (this.IsOnline)
if (this.RetrieveDetails)
{
this.onlineRetrievalState = value;
this.detailsRetrievalState = value;
}
else
{
this.offlineRetrievalState = value;
this.noDetailsRetrievalState = value;
}
}
}

internal override RetrievalState UpdateRetrievalState(bool throwForMissingRequiredChildren)
{
if (!this.IsOnline || (this.RetrievalState.Equals(RetrievalState.Complete) &&
if (!this.RetrieveDetails || (this.RetrievalState.Equals(RetrievalState.Complete) &&
this.AreRequiredChildrenAvailable(throwForMissingRequiredChildren)))
{
this.RetrievalState = base.UpdateRetrievalState(throwForMissingRequiredChildren);
Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/FieldNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ internal virtual Element ReadNewDynamicChildContents(
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal override bool ChangeOnlineStatus(IElement child)
internal override bool ChangeVisibility(Element child)
{
base.ChangeOnlineStatus(child);
base.ChangeVisibility(child);
MetaElement metaChild;
var result = MetaChildren.TryGetValue(child.Identifier, out metaChild);

if (result)
{
metaChild.ChangeOnlineStatus(this, child);
metaChild.ChangeVisibility(this, child);
}

return result;
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/MetaElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal abstract Element ReadContents(

internal abstract bool IsAvailable(IParent parent, bool throwIfMissing);

internal abstract void ChangeOnlineStatus(IParent parent, IElement element);
internal abstract void ChangeVisibility(IParent parent, Element element);

////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/MetaElement1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ internal sealed override bool IsAvailable(IParent parent, bool throwIfMissing)
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal sealed override void ChangeOnlineStatus(IParent parent, IElement element)
internal sealed override void ChangeVisibility(IParent parent, Element element)
{
if (!this.IsOptional && !element.IsOnline)
if (!this.IsOptional && !element.RetrieveDetails)
{
const string Format =
"The required property {0}.{1} in the node with the path {2} has been set offline by the provider.";
throw CreateRequiredPropertyException(parent, Format);
}

this.set((TMostDerived)parent, (TProperty)(element.IsOnline ? element : null));
this.set((TMostDerived)parent, (TProperty)(element.RetrieveDetails ? element : null));
parent.OnPropertyChanged(new PropertyChangedEventArgs(this.Property.Name));
}

Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ internal virtual bool GetIsRoot()
}

[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal override bool ChangeOnlineStatus(IElement child)
internal override bool ChangeVisibility(Element child)
{
if (child.IsOnline)
if (child.RetrieveDetails)
{
this.observableChildren.Add(child);
}
Expand All @@ -82,7 +82,7 @@ internal override bool ChangeOnlineStatus(IElement child)
this.observableChildren.Remove(child);
}

return base.ChangeOnlineStatus(child);
return base.ChangeVisibility(child);
}

internal sealed override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
Expand Down
19 changes: 10 additions & 9 deletions Lawo.EmberPlusSharp/Model/NodeBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ internal virtual bool ReadChildrenCore(EmberReader reader)
return isEmpty;
}

/// <summary>Changes the online status of <paramref name="child"/>.</summary>
/// <param name="child">The child to change the online status for.</param>
/// <returns><c>true</c> if the online status has been changed; otherwise, <c>false</c>.</returns>
internal virtual bool ChangeOnlineStatus(IElement child)
/// <summary>Changes the visibility of <paramref name="child"/>.</summary>
/// <param name="child">The child to change the visibility for.</param>
/// <returns><c>true</c> if the visibility has been changed; otherwise, <c>false</c>.</returns>
internal virtual bool ChangeVisibility(Element child)
{
return false;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ internal sealed override RetrievalState ReadQualifiedChild(

internal sealed override RetrievalState UpdateRetrievalState(bool throwForMissingRequiredChildren)
{
if (!this.IsOnline || (this.children.Count == 0))
if (!this.RetrieveDetails || (this.children.Count == 0))
{
return base.UpdateRetrievalState(throwForMissingRequiredChildren);
}
Expand All @@ -226,12 +226,13 @@ internal sealed override RetrievalState UpdateRetrievalState(bool throwForMissin
var childRetrievalState = child.UpdateRetrievalState(throwForMissingRequiredChildren);
accumulatedChildRetrievalState &= childRetrievalState;

if (child.IsOnlineChangeStatus != IsOnlineChangeStatus.Unchanged)
if (child.RetrieveDetailsChangeStatus != RetrieveDetailsChangeStatus.Unchanged)
{
if ((child.IsOnline && childRetrievalState.Equals(RetrievalState.Verified)) || !child.IsOnline)
if ((child.RetrieveDetails && childRetrievalState.Equals(RetrievalState.Verified)) ||
!child.RetrieveDetails)
{
child.IsOnlineChangeStatus = IsOnlineChangeStatus.Unchanged;
this.ChangeOnlineStatus(child);
child.RetrieveDetailsChangeStatus = RetrieveDetailsChangeStatus.Unchanged;
this.ChangeVisibility(child);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Lawo.EmberPlusSharp/Model/ParameterBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ internal override RetrievalState ReadContents(EmberReader reader, ElementType ac
break;
case GlowParameterContents.IsOnline.OuterNumber:
this.IsOnline = reader.AssertAndReadContentsAsBoolean();
var send = (this.IsOnlineChangeStatus == IsOnlineChangeStatus.Changed) &&
this.IsOnline && this.StreamIdentifier.HasValue;
var send = (this.RetrieveDetailsChangeStatus == RetrieveDetailsChangeStatus.Changed) &&
this.RetrieveDetails && this.StreamIdentifier.HasValue;
this.RetrievalState &= send ? RetrievalState.None : RetrievalState.Complete;
break;
case GlowParameterContents.Formula.OuterNumber:
Expand Down Expand Up @@ -359,7 +359,7 @@ private int? StreamIdentifier
{
this.streamIdentifier = value;

if (value.HasValue && this.IsOnline)
if (value.HasValue && this.RetrieveDetails)
{
this.RetrievalState = RetrievalState.None;
}
Expand Down Expand Up @@ -429,7 +429,7 @@ private void SetFinalTytpe(ParameterType? valueType, ParameterType? enumType, Pa
}
else
{
if (this.IsOnline)
if (this.RetrieveDetails)
{
const string Format =
"No enumeration, enumMap, value or type field is available for the parameter with the path {0}.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

namespace Lawo.EmberPlusSharp.Model
{
internal enum IsOnlineChangeStatus
internal enum RetrieveDetailsChangeStatus
{
/// <summary><see cref="Element.IsOnline"/> has the value set during initialization or first read operation.
/// <summary><see cref="Element.RetrieveDetails"/> has the value set during initialization or first read operation.
/// </summary>
Initialized,

/// <summary><see cref="Element.IsOnline"/> has not been changed since
/// <see cref="Element.IsOnlineChangeStatus"/> has been reset.</summary>
/// <summary><see cref="Element.RetrieveDetails"/> has not been changed since
/// <see cref="Element.RetrieveDetailsChangeStatus"/> has been reset.</summary>
Unchanged,

/// <summary><see cref="Element.IsOnline"/> has been changed since
/// <see cref="Element.IsOnlineChangeStatus"/> has been reset.</summary>
/// <summary><see cref="Element.RetrieveDetails"/> has been changed since
/// <see cref="Element.RetrieveDetailsChangeStatus"/> has been reset.</summary>
Changed
}
}
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/ShadowNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class ShadowNode : NodeBase<ShadowNode>
{
internal ShadowNode()
{
this.IsOnlineChangeStatus = IsOnlineChangeStatus.Unchanged;
this.RetrieveDetailsChangeStatus = RetrieveDetailsChangeStatus.Unchanged;
}

[SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", Justification = "Official Glow name.")]
Expand Down

0 comments on commit 4dfd3a1

Please sign in to comment.