Skip to content

Commit

Permalink
Move lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 14, 2021
1 parent 07f912c commit 168a326
Showing 1 changed file with 52 additions and 55 deletions.
107 changes: 52 additions & 55 deletions Server/Components/Devices/DevicesFrame.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ public void Dispose()

public void Refresh()
{
lock (_devicesLock)
{
LoadDevices();
InvokeAsync(StateHasChanged);
}
LoadDevices();
InvokeAsync(StateHasChanged);
}

protected override async Task OnInitializedAsync()
Expand All @@ -116,21 +113,15 @@ protected override async Task OnInitializedAsync()

_sortableProperties.AddRange(sortableProperties);

lock (_devicesLock)
{
LoadDevices();
}
LoadDevices();
}

protected override bool ShouldRender()
{
var shouldRender = base.ShouldRender();
if (shouldRender)
{
lock (_devicesLock)
{
FilterDevices();
}
FilterDevices();
}
return shouldRender;
}
Expand Down Expand Up @@ -226,67 +217,73 @@ private string GetSortIcon()

private void LoadDevices()
{
_allDevices.Clear();
lock (_devicesLock)
{
_allDevices.Clear();

var devices = DataService.GetDevicesForUser(Username)
.OrderByDescending(x => x.IsOnline)
.ToList();
var devices = DataService.GetDevicesForUser(Username)
.OrderByDescending(x => x.IsOnline)
.ToList();

_allDevices.AddRange(devices);
_allDevices.AddRange(devices);

HighestVersion = _allDevices.Max(x => Version.TryParse(x.AgentVersion, out var result) ? result : default);
HighestVersion = _allDevices.Max(x => Version.TryParse(x.AgentVersion, out var result) ? result : default);
}

FilterDevices();
}

private void FilterDevices()
{
_filteredDevices.Clear();
_filteredDevices.AddRange(_allDevices);

if (!string.IsNullOrWhiteSpace(_selectedSortProperty))
lock (_devicesLock)
{
var direction = _sortDirection == ListSortDirection.Ascending ? 1 : -1;
_filteredDevices.Sort((a, b) =>
_filteredDevices.Clear();
_filteredDevices.AddRange(_allDevices);

if (!string.IsNullOrWhiteSpace(_selectedSortProperty))
{
if (a.IsOnline != b.IsOnline)
var direction = _sortDirection == ListSortDirection.Ascending ? 1 : -1;
_filteredDevices.Sort((a, b) =>
{
return b.IsOnline.CompareTo(a.IsOnline);
}
if (a.IsOnline != b.IsOnline)
{
return b.IsOnline.CompareTo(a.IsOnline);
}
var propInfo = _sortableProperties.Find(x => x.Name == _selectedSortProperty);
var propInfo = _sortableProperties.Find(x => x.Name == _selectedSortProperty);
var valueA = propInfo.GetValue(a);
var valueB = propInfo.GetValue(b);
var valueA = propInfo.GetValue(a);
var valueB = propInfo.GetValue(b);
return Comparer.Default.Compare(valueA, valueB) * direction;
});
}
return Comparer.Default.Compare(valueA, valueB) * direction;
});
}


if (_hideOfflineDevices)
{
_filteredDevices.RemoveAll(x => !x.IsOnline);
}
if (_hideOfflineDevices)
{
_filteredDevices.RemoveAll(x => !x.IsOnline);
}

if (_selectedGroupId == _deviceGroupNone)
{
_filteredDevices.RemoveAll(x => !string.IsNullOrWhiteSpace(x.DeviceGroupID));
}
else if (_selectedGroupId != _deviceGroupAll)
{
_filteredDevices.RemoveAll(x => x.DeviceGroupID != _selectedGroupId);
}
if (_selectedGroupId == _deviceGroupNone)
{
_filteredDevices.RemoveAll(x => !string.IsNullOrWhiteSpace(x.DeviceGroupID));
}
else if (_selectedGroupId != _deviceGroupAll)
{
_filteredDevices.RemoveAll(x => x.DeviceGroupID != _selectedGroupId);
}

if (!string.IsNullOrWhiteSpace(_filter))
{
_filteredDevices.RemoveAll(x =>
x.Alias?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.CurrentUser?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.DeviceName?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Notes?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Platform?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Tags?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true);
if (!string.IsNullOrWhiteSpace(_filter))
{
_filteredDevices.RemoveAll(x =>
x.Alias?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.CurrentUser?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.DeviceName?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Notes?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Platform?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true &&
x.Tags?.Contains(_filter, StringComparison.OrdinalIgnoreCase) != true);
}
}
}

Expand Down

0 comments on commit 168a326

Please sign in to comment.