public virtual async Task <Stack <ICollection <string> > > Seek(string start, string target, ConcurrentHashSet <string> source, CancellationToken cancellationToken = default) { source.Remove(start); _log.LogDebug("Started seeking with start {start} and target {target}.", start, target); var similarityGroups = new ConcurrentDictionary <string, ICollection <string> >(); bool foundTarget = await SeekTarget(start, target, source, similarityGroups); var researchResult = new Stack <ICollection <string> >(); if (!foundTarget) { _log.LogDebug("Target was not found. No results to be shown."); source.Dispose(); return(researchResult); } _log.LogDebug("Target found. Getting all paths next."); var paths = new List <string> { start }; SeekAllShortestPaths(start, target, similarityGroups.ToDictionary(kv => kv.Key, kv => kv.Value.ToList()), researchResult, paths); _log.LogDebug("Finalized seek."); source.Dispose(); return(researchResult); }
protected virtual void Dispose(bool disposing) { if (disposing) { content?.Dispose(); fileExtenthionFilter?.Dispose(); } }
public void FirstOrDefault(int expected, int input) { // Arrange var list = new ConcurrentHashSet <int>(); // Act var actual = list.FirstOrDefault(x => x == input); // Assert Assert.Equal(expected, actual); list.Dispose(); }
public void GetEnumerator() { // Arrange var list = new ConcurrentHashSet <int>(); // Act var actual = list.GetEnumerator(); // Assert Assert.Equal(0, actual.Current); list.Dispose(); }
public void Clear() { // Arrange var list = new ConcurrentHashSet <int>(); // Act list.Clear(); // Assert Assert.Empty(list); list.Dispose(); }
public void Contains(bool expected, int input) { // Arrange var list = new ConcurrentHashSet <int>(); // Act var actual = list.Contains(input); // Assert Assert.Equal(expected, actual); list.Dispose(); }
protected override void Dispose(bool disposing) { if (m_disposed) { return; } m_assemblyResolver.Dispose(); m_downloadedUris.Dispose(); base.Dispose(disposing); }
/// <inheritdoc/> public void Dispose() { if (!_stopped) { Stop(); } try { _listenerTask.GetAwaiter().GetResult(); } catch (TaskCanceledException) { // Ignorieren - alles ist OK } BackgroundTransferWorker.Dispose(); _cancellationTokenSource.Dispose(); _connections.Dispose(); }
public Task Run() { var backupDir = Core.Instance.Config.BackupDirectory; Core.Instance.Log.InfoFormat("Starting LookUpProtocol: '{0}'", backupDir); return(Task.Factory.StartNew(() => { // get array with all the fileId's associated with the backed up chunks var fileIds = Util.GetLocalFileChunks() .Select(chunk => chunk.FileId) .Distinct().ToList(); if (fileIds.Count == 0) { Core.Instance.Log.Info("LookUpProtocol: got no files, no lookup required"); return; } // remove duplicates, transform the collection into a ConcurrentHashSet var backedUpFilesId = new ConcurrentHashSet <FileId>(fileIds); var waitPeriod = 1000; for (int retry = 0; retry < MaxRetries; ++retry) { // perform a lookup for each fileId var subscriptions = backedUpFilesId.Select(id => { Core.Instance.MCChannel.Send(new LookupMessage(id)); return Core.Instance.MCChannel.Received .Where(message => message.MessageType == MessageType.Got) .Cast <GotMessage>() .Where(message => message.FileId == id) // ReSharper disable once AccessToDisposedClosure .Subscribe(msg => backedUpFilesId.Remove(msg.FileId)); }).ToList(); // wait Task.Delay(waitPeriod).Wait(); foreach (var subscription in subscriptions) { subscription.Dispose(); } // if we got a Got for all the files we don't need to wait longer if (backedUpFilesId.Count == 0) { break; } waitPeriod *= 2; } // delete all the unused chunks foreach (var unusedFileId in backedUpFilesId) { var fileList = Directory.GetFiles(backupDir, unusedFileId + "_*"); foreach (var backedUpChunk in fileList) { File.Delete(backedUpChunk); } Core.Instance.ChunkPeers.RemoveAllChunkPeer(unusedFileId); } backedUpFilesId.Clear(); backedUpFilesId.Dispose(); })); }