imprvements, fixes, etc...
This commit is contained in:
parent
72e4506ea4
commit
bf95f669a3
|
|
@ -119,6 +119,30 @@ namespace AyCode.Blazor.Components.Services
|
||||||
public object SyncRoot => _syncRoot;
|
public object SyncRoot => _syncRoot;
|
||||||
public bool IsFixedSize => false;
|
public bool IsFixedSize => false;
|
||||||
|
|
||||||
|
public bool HasWorkingReferenceList { get; private set; }
|
||||||
|
|
||||||
|
public void SetWorkingReferenceList(List<T> workingList)
|
||||||
|
{
|
||||||
|
if (workingList == null!) return; //throw new ArgumentNullException(nameof(workingList));
|
||||||
|
|
||||||
|
Monitor.Enter(_syncRoot);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
HasWorkingReferenceList = true;
|
||||||
|
if (ReferenceEquals(InnerList, workingList)) return;
|
||||||
|
|
||||||
|
if (workingList.Count == 0) workingList.AddRange(InnerList);
|
||||||
|
|
||||||
|
Clear(true);
|
||||||
|
InnerList = workingList;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Monitor.Exit(_syncRoot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private object[]? GetContextParams()
|
private object[]? GetContextParams()
|
||||||
{
|
{
|
||||||
var parameters = new List<object>();
|
var parameters = new List<object>();
|
||||||
|
|
@ -138,9 +162,9 @@ namespace AyCode.Blazor.Components.Services
|
||||||
{
|
{
|
||||||
if (SignalRCrudTags.GetAllMessageTag == AcSignalRTags.None) throw new ArgumentException($"SignalRCrudTags.GetAllMessageTag == SignalRTags.None");
|
if (SignalRCrudTags.GetAllMessageTag == AcSignalRTags.None) throw new ArgumentException($"SignalRCrudTags.GetAllMessageTag == SignalRTags.None");
|
||||||
|
|
||||||
var resultList = (await SignalRClient.GetAllAsync<List<T>>(SignalRCrudTags.GetAllMessageTag, GetContextParams())) ?? throw new NullReferenceException();
|
var responseData = (await SignalRClient.GetAllAsync<List<T>>(SignalRCrudTags.GetAllMessageTag, GetContextParams())) ?? throw new NullReferenceException();
|
||||||
|
|
||||||
await LoadDataSource(resultList);
|
await LoadDataSource(responseData, false, false, clearChangeTracking);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task LoadDataSourceAsync(bool clearChangeTracking = true)
|
public Task LoadDataSourceAsync(bool clearChangeTracking = true)
|
||||||
|
|
@ -152,28 +176,26 @@ namespace AyCode.Blazor.Components.Services
|
||||||
if (result.Status != SignalResponseStatus.Success || result.ResponseData == null)
|
if (result.Status != SignalResponseStatus.Success || result.ResponseData == null)
|
||||||
throw new NullReferenceException($"LoadDataSourceAsync; result.Status != SignalResponseStatus.Success || result.ResponseData == null; Status: {SignalResponseStatus.Success}");
|
throw new NullReferenceException($"LoadDataSourceAsync; result.Status != SignalResponseStatus.Success || result.ResponseData == null; Status: {SignalResponseStatus.Success}");
|
||||||
|
|
||||||
return LoadDataSource(result.ResponseData);
|
return LoadDataSource(result.ResponseData, false, false, clearChangeTracking);
|
||||||
}, GetContextParams());
|
}, GetContextParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LoadDataSource(IList<T> fromSource, bool clearChangeTracking = true)
|
public async Task LoadDataSource(IList<T> fromSource, bool refreshDataFromDbAsync = false, bool setSourceToWorkingReferenceList = false, bool clearChangeTracking = true)
|
||||||
{
|
{
|
||||||
Monitor.Enter(_syncRoot);
|
Monitor.Enter(_syncRoot);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Clear(clearChangeTracking);
|
if (!ReferenceEquals(InnerList, fromSource))
|
||||||
|
{
|
||||||
|
Clear(clearChangeTracking);
|
||||||
|
|
||||||
if (fromSource is List<T> fromSourceCasted) InnerList = fromSourceCasted;
|
if (setSourceToWorkingReferenceList && fromSource is List<T> fromSourceList) SetWorkingReferenceList(fromSourceList);
|
||||||
else InnerList.AddRange(fromSource);
|
else InnerList.AddRange(fromSource);
|
||||||
|
}
|
||||||
|
else if (clearChangeTracking) TrackingItems.Clear();
|
||||||
|
|
||||||
//foreach (var item in fromSource)
|
if (refreshDataFromDbAsync) LoadDataSourceAsync(false).Forget();
|
||||||
//{
|
|
||||||
// InnerList.Add(item);
|
|
||||||
|
|
||||||
// var eventArgs = new ItemChangedEventArgs<T>(item, TrackingState.GetAll);
|
|
||||||
// if (OnDataSourceItemChanged != null) await OnDataSourceItemChanged.Invoke(eventArgs);
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue