TrackingState, etc
This commit is contained in:
parent
4f979eec96
commit
bd565146e6
|
|
@ -6,10 +6,12 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace AyCode.Core.Enums
|
||||
{
|
||||
public enum DataChangeMode
|
||||
public enum TrackingState : byte
|
||||
{
|
||||
Add = 1,
|
||||
Update = 2,
|
||||
Remove = 3,
|
||||
None = 0,
|
||||
Get = 1,
|
||||
Add = 2,
|
||||
Update = 3,
|
||||
Remove = 4,
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@ namespace AyCode.Core.Extensions
|
|||
{
|
||||
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 (dataItem.Id.IsNullOrEmpty()) throw new ArgumentNullException(nameof(dataItem), "UpdateCollection->dataItem.Id.IsNullOrEmpty()");
|
||||
|
||||
|
|
@ -16,17 +16,17 @@ namespace AyCode.Core.Extensions
|
|||
{
|
||||
if (transferIndex > -1) source.RemoveAt(transferIndex);
|
||||
|
||||
return DataChangeMode.Remove;
|
||||
return TrackingState.Remove;
|
||||
}
|
||||
|
||||
if (transferIndex > -1)
|
||||
{
|
||||
source[transferIndex] = dataItem;
|
||||
return DataChangeMode.Update;
|
||||
return TrackingState.Update;
|
||||
}
|
||||
|
||||
source.Add(dataItem);
|
||||
return DataChangeMode.Add;
|
||||
return TrackingState.Add;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -8,4 +10,16 @@ public sealed class SignalRCrudTags(int getAllTag, int getItemTag, int addTag, i
|
|||
public int UpdateMessageTag { get; } = updateTag;
|
||||
public int RemoveMessageTag { get; } = removeTag;
|
||||
|
||||
public int GetMessageTagByTrackingState(TrackingState trackingState)
|
||||
{
|
||||
return trackingState switch
|
||||
{
|
||||
TrackingState.None => 0,
|
||||
TrackingState.Get => GetItemMessageTag,
|
||||
TrackingState.Add => AddMessageTag,
|
||||
TrackingState.Update => UpdateMessageTag,
|
||||
TrackingState.Remove => RemoveMessageTag,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue