public AmoebaManager(string blocksPath, BufferManager bufferManager) { _blocksPath = blocksPath; _bufferManager = bufferManager; _clientManager = new ClientManager(_bufferManager); _serverManager = new ServerManager(_bufferManager); _cacheManager = new CacheManager(_blocksPath, _bufferManager); _connectionsManager = new ConnectionsManager(_clientManager, _serverManager, _cacheManager, _bufferManager); _downloadManager = new DownloadManager(_connectionsManager, _cacheManager, _bufferManager); _uploadManager = new UploadManager(_connectionsManager, _cacheManager, _bufferManager); _backgroundDownloadManager = new BackgroundDownloadManager(_connectionsManager, _cacheManager, _bufferManager); _backgroundUploadManager = new BackgroundUploadManager(_connectionsManager, _cacheManager, _bufferManager); _clientManager.CreateCapEvent = (object sender, string uri) => { return _createCapEvent?.Invoke(this, uri); }; _serverManager.AcceptCapEvent = (object sender, out string uri) => { uri = null; return _acceptCapEvent?.Invoke(this, out uri); }; _clientManager.CheckUriEvent = (object sender, string uri) => { return _checkUriEvent?.Invoke(this, uri) ?? true; }; _serverManager.CheckUriEvent = (object sender, string uri) => { return _checkUriEvent?.Invoke(this, uri) ?? true; }; }
public AmoebaManager(string bitmapPath, string cachePath, BufferManager bufferManager) { _bitmapPath = bitmapPath; _cachePath = cachePath; _bufferManager = bufferManager; _clientManager = new ClientManager(_bufferManager); _serverManager = new ServerManager(_bufferManager); _bitmapManager = new BitmapManager(_bitmapPath, _bufferManager); _cacheManager = new CacheManager(_cachePath, _bitmapManager, _bufferManager); _connectionsManager = new ConnectionsManager(_clientManager, _serverManager, _cacheManager, _bufferManager); _downloadManager = new DownloadManager(_connectionsManager, _cacheManager, _bufferManager); _uploadManager = new UploadManager(_connectionsManager, _cacheManager, _bufferManager); _backgroundDownloadManager = new BackgroundDownloadManager(_connectionsManager, _cacheManager, _bufferManager); _backgroundUploadManager = new BackgroundUploadManager(_connectionsManager, _cacheManager, _bufferManager); _clientManager.CreateCapEvent = (object sender, string uri) => { if (_createCapEvent != null) { return _createCapEvent(this, uri); } return null; }; _serverManager.AcceptCapEvent = (object sender, out string uri) => { uri = null; if (_acceptCapEvent != null) { return _acceptCapEvent(this, out uri); } return null; }; _clientManager.CheckUriEvent = (object sender, string uri) => { if (_checkUriEvent != null) { return _checkUriEvent(this, uri); } return true; }; _serverManager.CheckUriEvent = (object sender, string uri) => { if (_checkUriEvent != null) { return _checkUriEvent(this, uri); } return true; }; }
public BackgroundUploadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(); _watchTimer = new WatchTimer(this.WatchTimer, Timeout.Infinite); }
public DownloadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(); _threadCount = Math.Max(1, Math.Min(System.Environment.ProcessorCount, 32) / 2); _cacheManager.BlockSetEvents += this.BlockSetThread; _cacheManager.BlockRemoveEvents += this.BlockRemoveThread; }
public UploadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(); _threadCount = Math.Max(1, Math.Min(System.Environment.ProcessorCount, 32) / 2); _watchTimer = new WatchTimer(this.WatchTimer, Timeout.Infinite); _cacheManager.ShareRemoveEvents += this.ShareRemoveThread; }
public UploadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(this.ThisLock); _threadCount = Math.Max(1, Math.Min(System.Environment.ProcessorCount, 32) / 2); _connectionsManager.UploadedEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _uploadedKeys.Enqueue(key); } }; _cacheManager.RemoveKeyEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _uploadedKeys.Enqueue(key); } }; _cacheManager.RemoveShareEvent += (object sender, string path) => { _removeSharePaths.Enqueue(path); }; _uploadedThread = new Thread(() => { try { for (; ; ) { var key = _uploadedKeys.Dequeue(); while (_removeSharePaths.Count > 0) Thread.Sleep(1000); lock (this.ThisLock) { foreach (var item in _settings.UploadItems) { if (item.UploadKeys.Remove(key)) { item.UploadedKeys.Add(key); if (item.State == UploadState.Uploading) { if (item.UploadKeys.Count == 0) { item.State = UploadState.Completed; _settings.UploadedSeeds.Add(item.Seed.Clone()); } } } } } } } catch (Exception) { } }); _uploadedThread.Priority = ThreadPriority.BelowNormal; _uploadedThread.Name = "UploadManager_UploadedThread"; _uploadedThread.Start(); _removeShareThread = new Thread(() => { try { for (; ; ) { var path = _removeSharePaths.Dequeue(); lock (this.ThisLock) { List<int> ids = null; if (_shareLink.TryGetValue(path, out ids)) { foreach (var id in ids.ToArray()) { this.Remove(id); } } } } } catch (Exception) { } }); _removeShareThread.Priority = ThreadPriority.BelowNormal; _removeShareThread.Name = "UploadManager_RemoveShareThread"; _removeShareThread.Start(); }
public BackgroundUploadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(this.ThisLock); _connectionsManager.UploadedEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _uploadedKeys.Enqueue(key); } }; _cacheManager.RemoveKeyEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _uploadedKeys.Enqueue(key); } }; _uploadedThread = new Thread(() => { try { for (; ; ) { var key = _uploadedKeys.Dequeue(); lock (this.ThisLock) { foreach (var item in _settings.BackgroundUploadItems.ToArray()) { if (item.UploadKeys.Remove(key)) { item.UploadedKeys.Add(key); if (item.State == BackgroundUploadState.Uploading) { if (item.UploadKeys.Count == 0) { item.State = BackgroundUploadState.Completed; } } } } } } } catch (Exception) { } }); _uploadedThread.Priority = ThreadPriority.BelowNormal; _uploadedThread.Name = "BackgroundUploadManager_UploadedThread"; _uploadedThread.Start(); }
public BackgroundDownloadManager(ConnectionsManager connectionsManager, CacheManager cacheManager, BufferManager bufferManager) { _connectionsManager = connectionsManager; _cacheManager = cacheManager; _bufferManager = bufferManager; _settings = new Settings(this.ThisLock); _cacheManager.SetKeyEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _setKeys.Enqueue(key); } }; _cacheManager.RemoveKeyEvent += (object sender, IEnumerable<Key> keys) => { foreach (var key in keys) { _removeKeys.Enqueue(key); } }; _setThread = new Thread(() => { try { for (; ; ) { var key = _setKeys.Dequeue(); lock (this.ThisLock) { _existManager.Set(key, true); } } } catch (Exception) { } }); _setThread.Priority = ThreadPriority.BelowNormal; _setThread.Name = "BackgroundDownloadManager_SetThread"; _setThread.Start(); _removeThread = new Thread(() => { try { for (; ; ) { var key = _removeKeys.Dequeue(); lock (this.ThisLock) { _existManager.Set(key, false); } } } catch (Exception) { } }); _removeThread.Priority = ThreadPriority.BelowNormal; _removeThread.Name = "BackgroundDownloadManager_RemoveThread"; _removeThread.Start(); _connectionsManager.GetLockSignaturesEvent = (object sender) => { return this.SearchSignatures; }; }