public void Waiting_Invalid2 ()
		{
			Console.WriteLine ("Waiting_Invalid2");

			var download = new Download ();
			Assert.Throws<InvalidOperationException> (() => download.Retry ());
		}
		public async Task Test_ProgressDownload_Progress1 ()
		{
			Console.WriteLine ("Test_ProgressDownload_Progress1");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			ErrorEnum downloaderror = ErrorEnum.Empty;
			bus.Subscribe<DownloadError> (p => {
				downloaderror = p.Error;
			});

			var download = new Download {
				State = State.Downloading,
				Total = 0,
				Written = 0
			};
			repo.Insert (download);

			manager.ProgressDownload (new ProgressDownload {
				Id = download.Id,
				Total = 1000,
				Written = 10
			});

			Assert.AreEqual (10, download.Written, "Written");
			Assert.AreEqual (1000, download.Total, "Total");
			Assert.AreEqual (ErrorEnum.Empty, downloaderror, "Downloaderror");

		}
		public async Task Test_CancelDownloads_Multiple ()
		{
			Console.WriteLine ("Test_CancelDownloads_Multiple");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			var waiting = new Download { State = State.Waiting };
			var error = new Download { State = State.Error };
			var downloading = new Download { State = State.Downloading };
			var finished = new Download { State = State.Finished };

			repo.Insert (waiting);
			repo.Insert (downloading);
			repo.Insert (error);
			repo.Insert (finished);

			manager.CancelDownloads (new CancelDownloads {
			});

			Assert.AreEqual (State.Finished, waiting.State, "Waiting");
			Assert.AreEqual (State.Finished, downloading.State, "Downloading");
			Assert.AreEqual (State.Finished, error.State, "Error");
			Assert.AreEqual (State.Finished, finished.State, "Finished");
		}
Esempio n. 4
0
        public void Insert(DownloadManager.iOS.Bo.Download insert)
        {
            int id = Interlocked.Increment(ref _iterator);

            insert.Id = id;
            Database.Add(id, insert);
        }
		public async Task Test_DownloadError_Error3 ()
		{
			Console.WriteLine ("Test_DownloadError_Error3");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);
			var wait1 = new AutoResetEvent (false);

			ErrorEnum error = ErrorEnum.Empty;
			bus.Subscribe<DownloadError> (p => {
				error = p.Error;
				wait1.Set();
			});

			var download = new Download { Url = "url", State = State.Finished };
			repo.Insert (download);
			manager.DownloadError (new DownloadError {
				Id = download.Id,
				Error = ErrorEnum.DidCompleteWithError_Error,
			});

			wait1.WaitOne (10);
			Assert.AreEqual (ErrorEnum.Empty, error);

		}
		public async Task Test_FinishDownload_Finish1 ()
		{
			Console.WriteLine ("Test_FinishDownload_Finish1");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			ErrorEnum downloaderror = ErrorEnum.Empty;
			bus.Subscribe<DownloadError> (p => {
				downloaderror = p.Error;
			});

			var download = new Download {
				State = State.Downloading,
			};
			repo.Insert (download);

			manager.FinishedDownload (new FinishedDownload {
				Id = download.Id,
			});

			Assert.AreEqual (ErrorEnum.Empty, downloaderror, "Downloaderror");
			Assert.AreEqual (State.Finished, download.State, "Finished");

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

			var download = new Download ();
			bool paused = download.TryPause ();
			Assert.AreEqual (false, paused, "Paused");
		}
		public void Waiting_Cancel ()
		{
			Console.WriteLine ("Waiting_Cancel");

			var download = new Download ();
			download.Cancel ();
			Assert.AreEqual (State.Finished, download.State, "State");
		}
		public void Notify(Download download) {
			try {
				_changed (download);
			} catch (Exception e) {
				// disposed object crash..
				Console.WriteLine(e.ToString());
			}
		}
		private void Progress(Download download) {
			Progress progress; 
			bool hassubscriber = _progresses.TryGetValue (download.Url, out progress);
			if (hassubscriber) {
				progress.Notify (download);
			}

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

			var download = new Download ();
			bool progressed = download.TryProgress (0, 0);
			Assert.AreEqual (false, progressed, "Progressed");
		}
		public void Waiting_Invalid4 ()
		{
			Console.WriteLine ("Waiting_Invalid4");

			var download = new Download ();
			bool finished = download.TryFinish ("location");
			Assert.AreEqual (false, finished, "Finished");
		}
		public void Waiting_Resume ()
		{
			Console.WriteLine ("Waiting_Resume");

			var download = new Download ();
			bool resumed = download.TryResume ();
			Assert.AreEqual (true, resumed, "Resumed");
			Assert.AreEqual (State.Downloading, download.State, "State");
		}
		public void Waiting_Fail ()
		{
			Console.WriteLine ("Waiting_Fail");

			var download = new Download ();
			bool failed = download.TryFail (404, TaskErrorEnum.DownloadError, "Not Found");
			Assert.AreEqual (true, failed, "Failed");
			Assert.AreEqual (State.Error, download.State, "State");
		}
		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");

		}
Esempio n. 16
0
        public bool FirstByState(DownloadManager.iOS.Bo.State state, out DownloadManager.iOS.Bo.Download result)
        {
            var download = Database
                           .Values
                           .Where(v => v.State == state)
                           .FirstOrDefault();

            result = download;
            return(download != null);
        }
		public async Task Test_CancelDownloads_Single ()
		{
			Console.WriteLine ("Test_CancelDownloads_Single");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			var download = new Download { State = State.Waiting };
			repo.Insert (download);

			manager.CancelDownloads (new CancelDownloads {
			});

			Assert.AreEqual (State.Finished, download.State, "First");
		}
		public bool TryByUrl(string url, out Download download) {
			string select = @"

				SELECT * 
	              FROM Download 
	             WHERE Url = ?
	                   ;
	";
			var results = _db.Query<Bo.Download>(select, url);
			if (!results.Any()) {
				download = null;
				return false;
			}

			download = results.First();
			return true;

		}
		public async Task Test_ResetDownloads_Single ()
		{

			Console.WriteLine ("Test_ResetDownloads_Single");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			var download = new Download { State = State.Waiting };
			repo.Insert (download);

			manager.ResetDownloads (new ResetDownloads {
			});

			var all = repo.All ();
			Assert.AreEqual (0, all.Count);
		}
        public async void QueueUrl(QueueUrl qurl)
        {
            Console.WriteLine("[Downloadanager] QueueUrl");
            Console.WriteLine("[Downloadanager] QueueUrl Url         : {0}", qurl.Url);
            Console.WriteLine("[Downloadanager] QueueUrl Description : {0}", qurl.Description);

            string   url         = qurl.Url;
            string   description = qurl.Description;
            Download result      = null;
            bool     exists      = _repo.TryByUrl(url, out result);

            if (exists)
            {
                await _bus.SendAsync <NotifyProgress> (new NotifyProgress {
                    Url      = result.Url,
                    Download = result
                });

                await _bus.SendAsync <AlreadyQueued> (new AlreadyQueued {
                    Url = url
                });

                return;
            }

            var insert = new Bo.Download {
                State            = Bo.State.Waiting,
                Url              = url,
                ErrorDescription = description,
                Written          = 0,
                Total            = 0
            };

            _repo.Insert(insert);
            await _bus.SendAsync <CheckFreeSlot> (new CheckFreeSlot());

            await _bus.SendAsync <NotifyProgress> (new NotifyProgress {
                Url      = insert.Url,
                Download = insert
            });

            return;
        }
Esempio n. 21
0
        public bool TryById(int id, out Bo.Download download)
        {
            var downloads = _db.Query <Bo.Download> (@"

				SELECT * 
                  FROM Download 
				 WHERE Id = ?
                     ;

			"            , id);

            if (!downloads.Any())
            {
                download = null;
                return(false);
            }

            download = downloads.First();
            return(true);
        }
		public bool FirstByState(State state, out Download result) {
		
			string query = @"
			
	SELECT * 
      FROM Download 
     WHERE DownloadState = ?
  ORDER BY LastModified DESC
     LIMIT 1
           ;
";
			var downloads = _db.Query<Bo.Download> (query, state);
			if (!downloads.Any()) {
				result = null;
				return false;
			}

			result = downloads.First ();
			return true;

		}
		public async void QueueUrl(QueueUrl qurl) {

			Console.WriteLine("[Downloadanager] QueueUrl");
			Console.WriteLine("[Downloadanager] QueueUrl Url         : {0}", qurl.Url);
			Console.WriteLine("[Downloadanager] QueueUrl Description : {0}", qurl.Description);

			string url = qurl.Url;
			string description = qurl.Description;
			Download result = null;
			bool exists = _repo.TryByUrl (url, out result);
			if (exists) {

				await _bus.SendAsync<NotifyProgress> (new NotifyProgress {
					Url = result.Url,
					Download = result
				});

				await _bus.SendAsync<AlreadyQueued> (new AlreadyQueued { 
					Url = url
				});

				return;
			}

			var insert = new Bo.Download {
				State = Bo.State.Waiting,
				Url = url,
				ErrorDescription = description,
				Written = 0,
				Total = 0
			};
			_repo.Insert(insert);
			await _bus.SendAsync<CheckFreeSlot> (new CheckFreeSlot ());
			await _bus.SendAsync<NotifyProgress> (new NotifyProgress {
				Url = insert.Url,
				Download = insert
			});

			return;
		}
		public async Task Test_ResetDownloads_Multiple ()
		{
			Console.WriteLine ("Test_ResetDownloads_Multiple");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			var waiting = new Download { State = State.Waiting };
			var error = new Download { State = State.Error };
			var downloading = new Download { State = State.Downloading };
			var finished = new Download { State = State.Finished };

			repo.Insert (waiting);
			repo.Insert (downloading);
			repo.Insert (error);
			repo.Insert (finished);

			manager.ResetDownloads (new ResetDownloads {
			});

			var all = repo.All ();
			Assert.AreEqual (0, all.Count);
		}
		public void Update (Download download)
		{
			_db.Update (download);
		}
		public void Insert (Download insert)
		{
			_db.Insert (insert);
		}
		public bool TryDetail (string url, out Download result)
		{
			return _repository.TryByUrl (url, out result);
		}
		public async Task Test_DownloadError_Error500 ()
		{

			Console.WriteLine ("Test_DownloadError_Error500");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);
			var wait1 = new AutoResetEvent (false);

			ErrorEnum error = ErrorEnum.Empty;
			bus.Subscribe<DownloadError> (p => {
				error = p.Error;
				wait1.Set();
			});

			var download = new Download { Url = "url", State = State.Downloading };
			repo.Insert (download);

			manager.TaskError (new TaskError {
				Id = download.Id,
				Error = TaskErrorEnum.InvalidResponse,
				StatusCode = 500
			});

			Assert.AreEqual (State.Error, download.State);
			Assert.AreEqual (500, download.StatusCode);

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

			var download = new Download ();
			bool failed = download.TryFail (404, TaskErrorEnum.DownloadError, "Not Found");
			Assert.AreEqual (true, failed, "Failed");
			bool progressed = download.TryProgress (0,0);
			Assert.AreEqual (false, progressed, "Progressed");
		}
Esempio n. 30
0
 public void Update(DownloadManager.iOS.Bo.Download download)
 {
 }
		public void Finished_Invalid1 ()
		{
			Console.WriteLine ("Finished_Invalid1");

			var download = new Download ();
			bool resumed = download.TryResume ();
			Assert.AreEqual (true, resumed, "Resumed");
			bool finished = download.TryFinish ("location");
			Assert.AreEqual (true, finished, "Finished");
			Assert.AreEqual ("location", download.Temporary, "Temporary");
			Assert.Throws<InvalidOperationException> (() => download.Cancel());
		}
		public void Finished_Invalid2 ()
		{
			Console.WriteLine ("Finished_Invalid2");

			var download = new Download ();
			bool resumed = download.TryResume ();
			Assert.AreEqual (true, resumed, "Resumed");
			bool finished = download.TryFinish ("location");
			Assert.AreEqual (true, finished, "Finished");
			Assert.AreEqual ("location", download.Temporary, "Temporary");
			bool failed = download.TryFail (404, TaskErrorEnum.DownloadError, "Not Found");
			Assert.AreEqual (false, failed, "Failed");
		}
Esempio n. 33
0
        public bool TryByUrl(string url, out DownloadManager.iOS.Bo.Download result)
        {
            var urls = Database.Values.ToDictionary <Download, string> (v => v.Url);

            return(urls.TryGetValue(url, out result));
        }
		public async Task Test_ProgressDownload_ErrorNotFound2 ()
		{
			Console.WriteLine ("Test_ProgressDownload_ErrorNotFound2");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);
			var wait1 = new AutoResetEvent (false);

			ErrorEnum downloaderror = ErrorEnum.Empty;
			bus.Subscribe<DownloadError> (p => {
				downloaderror = p.Error;
				wait1.Set();
			});

			var download = new Download {
				State = State.Downloading,
				Total = 0,
				Written = 0
			};
			repo.Insert (download);

			manager.ProgressDownload (new ProgressDownload {
				Id = 666,
				Total = 1000,
				Written = 10
			});

			wait1.WaitOne ();

			Assert.AreEqual (0, download.Written, "Written");
			Assert.AreEqual (0, download.Total, "Total");
			Assert.AreEqual (ErrorEnum.ProgressDownload_IdentifierNotFound, downloaderror, "Downloaderror");

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

			var download = new Download ();
			bool resumed = download.TryResume ();
			Assert.AreEqual (true, resumed, "Resumed");
			bool finished = download.TryFinish ("location");
			Assert.AreEqual (true, finished, "Finished");
			Assert.AreEqual ("location", download.Temporary, "Temporary");
			bool resumed2 = download.TryResume ();
			Assert.AreEqual (false, resumed2, "Resumed2");
		}
		public async Task Test_CancelDownloads_Multiple2 ()
		{
			Console.WriteLine ("Test_CancelDownloads_Multiple2");

			var bus = new InProcessBus ();
			var repo = new DownloadRepositoryMock ();
			var manager = new DownloadManager.iOS.DownloadManager (bus, repo, 3);

			var waiting1 = new Download { State = State.Waiting };
			var waiting2 = new Download { State = State.Waiting };
			var waiting3 = new Download { State = State.Waiting };
			var waiting4 = new Download { State = State.Waiting };
			var waiting5 = new Download { State = State.Waiting };

			repo.Insert (waiting1);
			repo.Insert (waiting2);
			repo.Insert (waiting3);
			repo.Insert (waiting4);
			repo.Insert (waiting5);

			manager.CancelDownloads (new CancelDownloads {
			});

			Assert.AreEqual (State.Finished, waiting1.State, "Waiting1");
			Assert.AreEqual (State.Finished, waiting2.State, "Waiting2");
			Assert.AreEqual (State.Finished, waiting3.State, "Waiting3");
			Assert.AreEqual (State.Finished, waiting4.State, "Waiting4");
			Assert.AreEqual (State.Finished, waiting5.State, "Waiting5");
		}
Esempio n. 37
0
 public bool TryById(int id, out DownloadManager.iOS.Bo.Download result)
 {
     return(Database.TryGetValue(id, out result));
 }