|
|
|
|
@ -5,6 +5,7 @@ |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.IO; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Reflection; |
|
|
|
|
using System.Threading; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
@ -35,8 +36,6 @@ namespace GBase |
|
|
|
|
|
|
|
|
|
Columns = new List<IGBaseColumn>(); |
|
|
|
|
Entries = new List<object>(); |
|
|
|
|
|
|
|
|
|
INotifyGBaseEntryChanged.GBaseEntryChanged += OnGBaseEntryChanged; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -119,30 +118,47 @@ namespace GBase |
|
|
|
|
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); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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)) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
entry.GBaseEntryChanged -= OnGBaseEntryChanged; |
|
|
|
|
|
|
|
|
|
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> |
|
|
|
|
/// A <see cref="IGBase"/> entry changed |
|
|
|
|
/// </summary> |
|
|
|
|
@ -151,13 +167,7 @@ namespace GBase |
|
|
|
|
private void OnGBaseEntryChanged(object entry, GBaseEntryChangedEventArgs args) |
|
|
|
|
{ |
|
|
|
|
//TODO: Might change, depending on #23 |
|
|
|
|
bool success; |
|
|
|
|
if (args == null) |
|
|
|
|
success = RemoveEntry(entry); |
|
|
|
|
else if (!Entries.Contains(entry)) |
|
|
|
|
success = AddEntry(entry); |
|
|
|
|
else |
|
|
|
|
success = ModifyEntry(entry, args.ColumnName, args.Value); |
|
|
|
|
bool success = ModifyEntry(entry, args.ColumnName, args.Value); |
|
|
|
|
|
|
|
|
|
if (!success) |
|
|
|
|
throw new Exception("Failed to handle EntryChanged"); //TODO: Decide what to do here |
|
|
|
|
@ -177,6 +187,13 @@ namespace GBase |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Columns.Clear(); |
|
|
|
|
|
|
|
|
|
foreach (var entry in Entries.OfType<INotifyGBaseEntryChanged>().ToList()) |
|
|
|
|
{ |
|
|
|
|
RemoveEntry(entry); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Entries.Clear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |