private void Refresh()
{
if (_isRefreshing) return;
_isRefreshing = true;
try
{
var tempDictionary = new ConcurrentDictionary<Seed, SearchState>();
{
foreach (var seed in _amoebaManager.CacheSeeds)
{
tempDictionary[seed] = SearchState.Cache;
}
foreach (var information in _amoebaManager.UploadingInformation)
{
if (information.Contains("Seed") && ((UploadState)information["State"]) != UploadState.Completed)
{
var seed = (Seed)information["Seed"];
tempDictionary.AddOrUpdate(seed, SearchState.Uploading, (_, orignalState) => orignalState | SearchState.Uploading);
}
}
foreach (var information in _amoebaManager.DownloadingInformation)
{
if (information.Contains("Seed") && ((DownloadState)information["State"]) != DownloadState.Completed)
{
var seed = (Seed)information["Seed"];
tempDictionary.AddOrUpdate(seed, SearchState.Downloading, (_, orignalState) => orignalState | SearchState.Downloading);
}
}
foreach (var seed in _amoebaManager.UploadedSeeds)
{
tempDictionary.AddOrUpdate(seed, SearchState.Uploaded, (_, orignalState) => orignalState | SearchState.Uploaded);
}
foreach (var seed in _amoebaManager.DownloadedSeeds)
{
tempDictionary.AddOrUpdate(seed, SearchState.Downloaded, (_, orignalState) => orignalState | SearchState.Downloaded);
}
}
lock (_thisLock)
{
_seedsDictionary = tempDictionary;
}
}
catch (Exception)
{
}
finally
{
_isRefreshing = false;
}
}