public void TestGetFileStatus() { var jaypeg = SharpCrush.UploadFile("./TestFiles/jaypeg.jpg"); var stat1 = jaypeg.Status; // OR var stat2 = SharpCrush.GetFileStatus(jaypeg.FileHash); // The only way this would fail, is if they status changed with in the execution of stat1 and stat2. So about ~ 5ms // Assert.IsTrue(stat1 == stat2); // Will fail. See: https://github.com/MediaCrush/MediaCrush/issues/356 // Assert.IsTrue(stat1 == GetFileStatusResult.Done || stat1 == GetFileStatusResult.Processing); }
public void UploadFile(string file) { // Modify UI if (FileList.Count == 0) { rowCollapse1.Height = new GridLength(0); rowCollapse2.Height = new GridLength(0); rowExpand.Height = new GridLength(5, GridUnitType.Star); uploadingFilesContainer.Visibility = Visibility.Visible; uploadingFiles.ItemsSource = FileList; clearButton.Visibility = System.Windows.Visibility.Visible; } var uploadingFile = new UploadingFile(file); FileList.Add(uploadingFile); Task.Factory.StartNew(() => { var hash = SharpCrush.GetFileHash(File.ReadAllBytes(file)); uploadingFile.Hash = hash; if (SharpCrush.GetFileExists(hash)) { uploadingFile.Status = UploadingFile.FileStatus.Finished; } else { // Upload SharpCrush.UploadFileAsync(uploadingFile.File, (s, e) => uploadingFile.Progress = e.ProgressPercentage / 100.0, result => { uploadingFile.Status = UploadingFile.FileStatus.Processing; while (SharpCrush.GetFileStatus(hash) == GetFileStatusResult.Processing) { ; } uploadingFile.Status = UploadingFile.FileStatus.Finished; }); } }); }