- add AddEntry and RemoveEntry to interface

- AddEntry and RemoveEntry have INotifyGBaseEntryChanged as parameter
pull/26/head
Simon Gockner 6 years ago
parent 4939474c6e
commit da544e0b2e
  1. 37
      GBase/GBase.xml
  2. 57
      GBase/GBaseTable.cs
  3. 14
      GBase/Interfaces/IGBaseTable.cs

@ -605,6 +605,29 @@
<param name="column">The given <see cref="T:GBase.Interfaces.IGBaseColumn"/></param> <param name="column">The given <see cref="T:GBase.Interfaces.IGBaseColumn"/></param>
<returns>True if successful, false if not</returns> <returns>True if successful, false if not</returns>
</member> </member>
<member name="M:GBase.GBaseTable.AddEntry(GBase.Api.INotifyGBaseEntryChanged)">
<summary>
Add an entry that implements <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/> to this <see cref="T:GBase.Interfaces.IGBaseTable"/>
</summary>
<param name="entry">The entry implementing <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/></param>
<returns>True if successful, false if not</returns>
</member>
<member name="M:GBase.GBaseTable.RemoveEntry(GBase.Api.INotifyGBaseEntryChanged)">
<summary>
Remove an entry that implements <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/> from this <see cref="T:GBase.Interfaces.IGBaseTable"/>
</summary>
<param name="entry">The entry implementing <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/></param>
<returns>True if successful, false if not</returns>
</member>
<member name="M:GBase.GBaseTable.ModifyEntry(System.Object,System.String,System.Object)">
<summary>
Modify the property of a given entry with the given value
</summary>
<param name="entry">The entry</param>
<param name="propertyName">The name of the property</param>
<param name="value">The new value to set</param>
<returns>True if successful, false if not</returns>
</member>
<member name="M:GBase.GBaseTable.OnGBaseEntryChanged(System.Object,GBase.Api.GBaseEntryChangedEventArgs)"> <member name="M:GBase.GBaseTable.OnGBaseEntryChanged(System.Object,GBase.Api.GBaseEntryChangedEventArgs)">
<summary> <summary>
A <see cref="T:GBase.Interfaces.IGBase"/> entry changed A <see cref="T:GBase.Interfaces.IGBase"/> entry changed
@ -1011,6 +1034,20 @@
<param name="column">The given <see cref="T:GBase.Interfaces.IGBaseColumn"/></param> <param name="column">The given <see cref="T:GBase.Interfaces.IGBaseColumn"/></param>
<returns>True if successful, false if not</returns> <returns>True if successful, false if not</returns>
</member> </member>
<member name="M:GBase.Interfaces.IGBaseTable.AddEntry(GBase.Api.INotifyGBaseEntryChanged)">
<summary>
Add an entry that implements <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/> to this <see cref="T:GBase.Interfaces.IGBaseTable"/>
</summary>
<param name="entry">The entry implementing <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/></param>
<returns>True if successful, false if not</returns>
</member>
<member name="M:GBase.Interfaces.IGBaseTable.RemoveEntry(GBase.Api.INotifyGBaseEntryChanged)">
<summary>
Remove an entry that implements <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/> from this <see cref="T:GBase.Interfaces.IGBaseTable"/>
</summary>
<param name="entry">The entry implementing <see cref="T:GBase.Api.INotifyGBaseEntryChanged"/></param>
<returns>True if successful, false if not</returns>
</member>
<member name="T:GBase.Interfaces.Settings.IGBaseSettings"> <member name="T:GBase.Interfaces.Settings.IGBaseSettings">
<summary> <summary>
Settings of a <see cref="T:GBase.Interfaces.IGBase"/> instance Settings of a <see cref="T:GBase.Interfaces.IGBase"/> instance

@ -5,6 +5,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -35,8 +36,6 @@ namespace GBase
Columns = new List<IGBaseColumn>(); Columns = new List<IGBaseColumn>();
Entries = new List<object>(); Entries = new List<object>();
INotifyGBaseEntryChanged.GBaseEntryChanged += OnGBaseEntryChanged;
} }
@ -119,30 +118,47 @@ namespace GBase
return Columns.Remove(column); return Columns.Remove(column);
} }
private bool AddEntry(object entry) //TODO: Write to file /// <summary>
/// Add an entry that implements <see cref="INotifyGBaseEntryChanged"/> to this <see cref="IGBaseTable"/>
/// </summary>
/// <param name="entry">The entry implementing <see cref="INotifyGBaseEntryChanged"/></param>
/// <returns>True if successful, false if not</returns>
public bool AddEntry(INotifyGBaseEntryChanged entry) //TODO: Write to file
{ {
Entries.Add(entry); Entries.Add(entry);
return true; entry.GBaseEntryChanged += OnGBaseEntryChanged;
}
private bool ModifyEntry(object entry, string propertyName, object value) //TODO: Write to file
{
PropertyInfo property = entry.GetType().GetProperty(propertyName);
if (property == null)
return false;
property.SetValue(entry, value);
return true; return true;
} }
private bool RemoveEntry(object entry) //TODO: remove from file /// <summary>
/// Remove an entry that implements <see cref="INotifyGBaseEntryChanged"/> from this <see cref="IGBaseTable"/>
/// </summary>
/// <param name="entry">The entry implementing <see cref="INotifyGBaseEntryChanged"/></param>
/// <returns>True if successful, false if not</returns>
public bool RemoveEntry(INotifyGBaseEntryChanged entry) //TODO: remove from file
{ {
if (!Entries.Contains(entry)) if (!Entries.Contains(entry))
return false; return false;
entry.GBaseEntryChanged -= OnGBaseEntryChanged;
return Entries.Remove(entry); return Entries.Remove(entry);
} }
/// <summary>
/// Modify the property of a given entry with the given value
/// </summary>
/// <param name="entry">The entry</param>
/// <param name="propertyName">The name of the property</param>
/// <param name="value">The new value to set</param>
/// <returns>True if successful, false if not</returns>
private bool ModifyEntry(object entry, string propertyName, object value) //TODO: Write to file
{
//don't need to change value of property in `Entries` list, the instance is saved there, any property change is already changed there as well
return true;
}
/// <summary> /// <summary>
/// A <see cref="IGBase"/> entry changed /// A <see cref="IGBase"/> entry changed
/// </summary> /// </summary>
@ -151,13 +167,7 @@ namespace GBase
private void OnGBaseEntryChanged(object entry, GBaseEntryChangedEventArgs args) private void OnGBaseEntryChanged(object entry, GBaseEntryChangedEventArgs args)
{ {
//TODO: Might change, depending on #23 //TODO: Might change, depending on #23
bool success; bool success = ModifyEntry(entry, args.ColumnName, args.Value);
if (args == null)
success = RemoveEntry(entry);
else if (!Entries.Contains(entry))
success = AddEntry(entry);
else
success = ModifyEntry(entry, args.ColumnName, args.Value);
if (!success) if (!success)
throw new Exception("Failed to handle EntryChanged"); //TODO: Decide what to do here throw new Exception("Failed to handle EntryChanged"); //TODO: Decide what to do here
@ -177,6 +187,13 @@ namespace GBase
} }
Columns.Clear(); Columns.Clear();
foreach (var entry in Entries.OfType<INotifyGBaseEntryChanged>().ToList())
{
RemoveEntry(entry);
}
Entries.Clear();
} }
} }
} }

@ -6,6 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using GBase.Api;
namespace GBase.Interfaces namespace GBase.Interfaces
{ {
@ -58,5 +59,18 @@ namespace GBase.Interfaces
/// <returns>True if successful, false if not</returns> /// <returns>True if successful, false if not</returns>
bool RemoveColumn(IGBaseColumn column); bool RemoveColumn(IGBaseColumn column);
/// <summary>
/// Add an entry that implements <see cref="INotifyGBaseEntryChanged"/> to this <see cref="IGBaseTable"/>
/// </summary>
/// <param name="entry">The entry implementing <see cref="INotifyGBaseEntryChanged"/></param>
/// <returns>True if successful, false if not</returns>
bool AddEntry(INotifyGBaseEntryChanged entry);
/// <summary>
/// Remove an entry that implements <see cref="INotifyGBaseEntryChanged"/> from this <see cref="IGBaseTable"/>
/// </summary>
/// <param name="entry">The entry implementing <see cref="INotifyGBaseEntryChanged"/></param>
/// <returns>True if successful, false if not</returns>
bool RemoveEntry(INotifyGBaseEntryChanged entry);
} }
} }
Loading…
Cancel
Save