public Downloader ()
		{
			var personal = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
			var dbpath = Path.Combine (personal, "download.db");
			var db = new SQLiteConnection (
				dbpath, 
				SQLiteOpenFlags.ReadWrite 
				| SQLiteOpenFlags.Create 
				| SQLiteOpenFlags.FullMutex , 
				true) {
				#if DEBUG
				Trace = true
				#endif
			};

			int maxdownloads = 3;
			_bus = new InProcessBus ();
			_repository = new DownloadRepository (db);
			_manager = new DownloadManager (_bus, _repository, maxdownloads);
			_service = new NSUrlSessionManager (_bus, maxdownloads);
			_progress = new ProgressManager (_bus, _repository);
			_timer = new Timer (TimerCallback, null, 1000, 1000);
			_timer = new Timer (TimerCallback, null, 1000, 1000);

			_bus.Subscribe<DownloadError> (DownloadError_Received);
			_bus.Subscribe<TaskError> (TaskError_Received);
			_bus.Subscribe<QueueEmpty> (QueueEmpty_Received);
			_bus.Subscribe<GlobalProgress> (GlobalProgress_Received);
			_bus.Subscribe<NotifyFinish> (NotifyFinish_Received);

		}
		public void Queue_2 ()
		{
			Console.WriteLine ("Queue_2");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();

			long total = 0;
			long written = 0;
			var wait1 = new AutoResetEvent (false);

			var download = new Download {
				Url = "url",
				Total = 0,
				Written = 0
			};
			repo.Insert (download);

			var progressmanager = new ProgressManager (bus, repo);
			Action<Download> progresshandle = (d) => {
				total = d.Total;
				written = d.Written;
				wait1.Set();
			};
			progressmanager.Queue (download.Url, progresshandle);

			download.Total = 100;
			download.Written = 10;
				
			progressmanager.NotifyProgress (new NotifyProgress {
				Url = download.Url,
				Download = download
			});	

			download.Written = 50;

			progressmanager.NotifyProgress (new NotifyProgress {
				Url = download.Url,
				Download = download
			});

			download.Written = 100;

			progressmanager.NotifyProgress (new NotifyProgress {
				Url = download.Url,
				Download = download
			});

			wait1.WaitOne ();
			wait1.WaitOne ();
			wait1.WaitOne ();

			Assert.AreEqual (100, written, "Written");
			Assert.AreEqual (100, total, "Total");

		}
		public void Queue_1 ()
		{
			Console.WriteLine ("Queue_1");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();

			var progressmanager = new ProgressManager (bus, repo);
			progressmanager.Queue ("url", (download) => {

			});

		}