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;
             });
         }
     });
 }
Exemplo n.º 2
0
        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;
                    });
                }
            });
        }