Compare commits
2 Commits
4f979eec96
...
74d679a5a9
| Author | SHA1 | Date |
|---|---|---|
|
|
74d679a5a9 | |
|
|
bd565146e6 |
|
|
@ -6,10 +6,13 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AyCode.Core.Enums
|
namespace AyCode.Core.Enums
|
||||||
{
|
{
|
||||||
public enum DataChangeMode
|
public enum TrackingState : byte
|
||||||
{
|
{
|
||||||
Add = 1,
|
None = 0,
|
||||||
Update = 2,
|
Get = 1,
|
||||||
Remove = 3,
|
GetAll = 2,
|
||||||
|
Add = 3,
|
||||||
|
Update = 4,
|
||||||
|
Remove = 5,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,8 +6,9 @@ namespace AyCode.Core.Extensions
|
||||||
{
|
{
|
||||||
public static class CollectionExtensions
|
public static class CollectionExtensions
|
||||||
{
|
{
|
||||||
public static DataChangeMode UpdateCollection<TDataItem>(this IList<TDataItem> source, TDataItem dataItem, bool isRemove) where TDataItem : IId<Guid>
|
public static TrackingState UpdateCollection<TDataItem>(this IList<TDataItem> source, TDataItem dataItem, bool isRemove) where TDataItem : IId<Guid>
|
||||||
{
|
{
|
||||||
|
if (source == null) throw new ArgumentNullException(nameof(source), $"source == null");
|
||||||
if (dataItem.Id.IsNullOrEmpty()) throw new ArgumentNullException(nameof(dataItem), "UpdateCollection->dataItem.Id.IsNullOrEmpty()");
|
if (dataItem.Id.IsNullOrEmpty()) throw new ArgumentNullException(nameof(dataItem), "UpdateCollection->dataItem.Id.IsNullOrEmpty()");
|
||||||
|
|
||||||
var transferIndex = source.FindIndex(x => x.Id == dataItem.Id);
|
var transferIndex = source.FindIndex(x => x.Id == dataItem.Id);
|
||||||
|
|
@ -16,17 +17,17 @@ namespace AyCode.Core.Extensions
|
||||||
{
|
{
|
||||||
if (transferIndex > -1) source.RemoveAt(transferIndex);
|
if (transferIndex > -1) source.RemoveAt(transferIndex);
|
||||||
|
|
||||||
return DataChangeMode.Remove;
|
return TrackingState.Remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transferIndex > -1)
|
if (transferIndex > -1)
|
||||||
{
|
{
|
||||||
source[transferIndex] = dataItem;
|
source[transferIndex] = dataItem;
|
||||||
return DataChangeMode.Update;
|
return TrackingState.Update;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.Add(dataItem);
|
source.Add(dataItem);
|
||||||
return DataChangeMode.Add;
|
return TrackingState.Add;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int FindIndex<T>(this IList<T> list, Predicate<T> predicate)
|
public static int FindIndex<T>(this IList<T> list, Predicate<T> predicate)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
namespace AyCode.Services.SignalRs;
|
using AyCode.Core.Enums;
|
||||||
|
|
||||||
|
namespace AyCode.Services.SignalRs;
|
||||||
|
|
||||||
public sealed class SignalRCrudTags(int getAllTag, int getItemTag, int addTag, int updateTag, int removeTag)
|
public sealed class SignalRCrudTags(int getAllTag, int getItemTag, int addTag, int updateTag, int removeTag)
|
||||||
{
|
{
|
||||||
|
|
@ -8,4 +10,17 @@ public sealed class SignalRCrudTags(int getAllTag, int getItemTag, int addTag, i
|
||||||
public int UpdateMessageTag { get; } = updateTag;
|
public int UpdateMessageTag { get; } = updateTag;
|
||||||
public int RemoveMessageTag { get; } = removeTag;
|
public int RemoveMessageTag { get; } = removeTag;
|
||||||
|
|
||||||
|
public int GetMessageTagByTrackingState(TrackingState trackingState)
|
||||||
|
{
|
||||||
|
return trackingState switch
|
||||||
|
{
|
||||||
|
TrackingState.None => 0,
|
||||||
|
TrackingState.Get => GetItemMessageTag,
|
||||||
|
TrackingState.GetAll => GetAllMessageTag,
|
||||||
|
TrackingState.Add => AddMessageTag,
|
||||||
|
TrackingState.Update => UpdateMessageTag,
|
||||||
|
TrackingState.Remove => RemoveMessageTag,
|
||||||
|
_ => throw new ArgumentOutOfRangeException()
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue