예제 #1
0
        public void GetUploadEvent_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);

            var args = item.GetUploadEvent();

            Assert.AreEqual(item, args.UploadItem);
        }
예제 #2
0
        public void Cancel_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);

            item.SetResumeAction(() => { });

            var args = item.GetUploadEvent();

            args.BeginUpload();

            // Act
            item.Cancel();

            Assert.AreEqual(FileUploadStatus.Canceled, item.Status);
        }
예제 #3
0
        public override void Execute(object parameter)
        {
            // TODO: replace with FileInfoBase
            FileInfo[] files = (FileInfo[])parameter;
            foreach (FileInfo info in files)
            {
                if (info.Exists) // TODO: not testable
                {
                    FileInfoBase fileInfoWrapper = new FileInfoWrapper(info);
                    UploadItem item = new UploadItem(fileInfoWrapper);
                    UploadItemViewModel model = new UploadItemViewModel(item);
                    _model.ItemsSource.Add(model);

                    var task = Vinco.Uploader.Tasks.ScheduledTasks.Instance.CreateTask(UploadController.Instance.GetHandler(), item);
                    Vinco.Uploader.Tasks.ScheduledTasks.Instance.Add(task);
                }
            }
        }
예제 #4
0
        public void OnBeginUpload_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);
            var called = false;

            item.SetResumeAction(() =>
                {
                    called = true;
                });

            var args = item.GetUploadEvent();
            var date = DateTime.Now;

            // Act
            args.BeginUpload();

            Assert.AreEqual(date, item.StartDate);
            Assert.AreEqual(FileUploadStatus.Uploading, item.Status);
            Assert.IsTrue(called);
        }
예제 #5
0
        public void Constructor_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);

            Assert.AreNotEqual(Guid.Empty, item.Id);
            Assert.AreEqual(file.Name, item.Name);
            Assert.AreEqual(file.Length, item.Length);
            Assert.AreEqual(null, item.Eta);
            Assert.AreEqual(default(TimeSpan), item.Elapsed);
            Assert.AreEqual(null, item.UploadSpeed);
            Assert.AreEqual(0, item.TotalBytesUploaded);
            Assert.AreEqual(null, item.StartDate);
            Assert.AreEqual(null, item.EndDate);
            Assert.AreEqual(null, item.Message);
            Assert.AreEqual(null, item.AverageChunkUpload);
            Assert.AreEqual(FileUploadStatus.Pending, item.Status);
            Assert.AreEqual(file, item.FileInfo);
            Assert.AreEqual(0, item.FailedRetries);
            Assert.AreEqual(file.Name, item.ToString());
        }
예제 #6
0
        private void UploadFiles()
        {
            // Find files
            IList<string> files = files = GetFiles(_uploadFromPath).ToList();

            _totalFilesCount = files.Count();

            Console.WriteLine("Found total files : {0}", _totalFilesCount);

            // Start uploader
            ScheduledTasks.Instance.Run();

            int runningUploads = 0;
            while (runningUploads < _totalFilesCount)
            {
                int batch = runningUploads - _uploadedFilesCount;

                if (batch < 50)
                {
                    string file = files[runningUploads];
                    try
                    {
                        // Get file to upload
                        var info = new FileInfo(file);
                        var fileWrapper = new FileInfoWrapper(info);

                        // Create upload item
                        var uploadItem = new UploadItem(fileWrapper);
                        uploadItem.ProgressChanged += UploadItem_ProgressChanged;
                        uploadItem.UploadCompleted += UploadItem_UploadCompleted;

                        // Create upload handler
                        var handler = new ChunkedHttpUploader(0)
                        {
                            UploadUri = _uploadUri,
                            CancelUri = _cancelUri
                        };

                        // Create upload task
                        var task = ScheduledTasks.Instance.CreateTask(handler, uploadItem);

                        // Add task into schedules
                        ScheduledTasks.Instance.Add(task);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    runningUploads++;
                }
            }
        }
예제 #7
0
        public void OnUploadCompleted_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);

            item.SetResumeAction(() => { });

            var args = item.GetUploadEvent();
            var date = DateTime.Now;

            // Act
            args.BeginUpload();
            args.UploadCompleted(null);

            // Assert
            Assert.AreEqual(FileUploadStatus.Complete, item.Status);
            Assert.IsNull(item.UploadSpeed);
            Assert.AreEqual(date, item.EndDate);
            Assert.IsNull(item.AverageChunkUpload);
        }
예제 #8
0
        public void Resume_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);
            var progress = false;

            item.SetResumeAction(() => { progress = true; });

            var args = item.GetUploadEvent();

            args.BeginUpload();

            // Act
            item.Pause();
            item.Resume();

            // Assert
            Assert.AreEqual(FileUploadStatus.Uploading, item.Status);
            Assert.IsTrue(progress);
        }
예제 #9
0
        public void OnUploadProgressChanged_Test()
        {
            var file = new MemoryFileInfo("Uploader test...");
            var item = new UploadItem(file);

            item.SetResumeAction(() => { });

            var args = item.GetUploadEvent();

            // Act
            args.BeginUpload();
            Thread.Sleep(1000);
            args.UploadProgressChanged(10, new TimeSpan(0, 0, 0, 1));

            // Assert
            Assert.AreEqual(10, item.TotalBytesUploaded, "TotalBytesUploaded");
            Assert.AreEqual(1, item.Elapsed.Seconds, "Elapsed");
            Assert.AreEqual(1, item.UploadSpeed, "UploadSpeed");
            Assert.AreEqual(new TimeSpan(0, 0, 0, 0, 601), item.Eta, "Eta");
            Assert.AreEqual(new TimeSpan(0, 0, 0, 1), item.AverageChunkUpload, "AverageChunkUpload");
        }