Compare commits
No commits in common. "74d679a5a9cde89371002662105a926b75973b48" and "4f979eec969d3c1e9d5230dcea97ce04c79323b6" have entirely different histories.
74d679a5a9
...
4f979eec96
|
|
@ -6,13 +6,10 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AyCode.Core.Enums
|
namespace AyCode.Core.Enums
|
||||||
{
|
{
|
||||||
public enum TrackingState : byte
|
public enum DataChangeMode
|
||||||
{
|
{
|
||||||
None = 0,
|
Add = 1,
|
||||||
Get = 1,
|
Update = 2,
|
||||||
GetAll = 2,
|
Remove = 3,
|
||||||
Add = 3,
|
|
||||||
Update = 4,
|
|
||||||
Remove = 5,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,9 +6,8 @@ namespace AyCode.Core.Extensions
|
||||||
{
|
{
|
||||||
public static class CollectionExtensions
|
public static class CollectionExtensions
|
||||||
{
|
{
|
||||||
public static TrackingState UpdateCollection<TDataItem>(this IList<TDataItem> source, TDataItem dataItem, bool isRemove) where TDataItem : IId<Guid>
|
public static DataChangeMode 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);
|
||||||
|
|
@ -17,17 +16,17 @@ namespace AyCode.Core.Extensions
|
||||||
{
|
{
|
||||||
if (transferIndex > -1) source.RemoveAt(transferIndex);
|
if (transferIndex > -1) source.RemoveAt(transferIndex);
|
||||||
|
|
||||||
return TrackingState.Remove;
|
return DataChangeMode.Remove;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transferIndex > -1)
|
if (transferIndex > -1)
|
||||||
{
|
{
|
||||||
source[transferIndex] = dataItem;
|
source[transferIndex] = dataItem;
|
||||||
return TrackingState.Update;
|
return DataChangeMode.Update;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.Add(dataItem);
|
source.Add(dataItem);
|
||||||
return TrackingState.Add;
|
return DataChangeMode.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,6 +1,4 @@
|
||||||
using AyCode.Core.Enums;
|
namespace AyCode.Services.SignalRs;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -10,17 +8,4 @@ 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