public void addOnCompleteListenerTest() { Debug.Log("UploadTask addOnCompleteListenerTest"); byte[] data = new byte[10]; string filename = "addOnCompleteListenerTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.addOnCompleteListener(new MyOnCompleteListener("NormalListener")) .addOnCompleteListener(new Activity(), new MyOnCompleteListener("ActivityListener")) .addOnCompleteListener(new MyExecutor("ExecutorListener"), new MyOnCompleteListener("ExecutorListener")); MyOnCompleteListener remove = new MyOnCompleteListener("remove"); task.addOnCompleteListener(remove); task.removeOnCompleteListener(remove); Debug.Log("task.isComplete status: " + task.isComplete()); Debug.Log("UploadTask addOnCompleteListenerTest success"); }
public Task <Attachment> UploadFile(FileData fileData) { TaskCompletionSource <Attachment> ResultCompletionSource = new TaskCompletionSource <Attachment>(); string fileExtension = GetExtension(fileData.FileName); string fileNameStr = fileData.FileName; string path = "userFile/" + Guid.NewGuid().ToString() + fileExtension; try { StorageReference storageReference = storage.GetReference(path); StorageMetadata storageMetadata = new StorageMetadata.Builder() .SetCustomMetadata("FileName", fileNameStr) .Build(); UploadTask uploadTask = storageReference.PutStream(fileData.GetStream(), storageMetadata); uploadTask.AddOnCompleteListener(new OnCompleteEventHandleListener((Android.Gms.Tasks.Task uploadFile) => { if (uploadFile.IsSuccessful) { var TaskResult = uploadFile.Result; var uri = ((UploadTask.TaskSnapshot)TaskResult).DownloadUrl.ToString(); Attachment attachment = new Attachment(fileNameStr, uri); ResultCompletionSource.SetResult(attachment); } })); } catch (Exception e) { ResultCompletionSource.TrySetException(e); } return(ResultCompletionSource.Task); }
private void SynchronizeExistingDirectory(Photoset set, string directory) { var localFiles = Directory.GetFiles(directory).FilterPhotos(); var photos = FlickrInstance.PhotosetsGetPhotos(set.PhotosetId); for (int i = 2; i <= Math.Ceiling((double)photos.Total / Constants.MaxPerPage); i++) { var ph = FlickrInstance.PhotosetsGetPhotos(set.PhotosetId, PhotoSearchExtras.All, PrivacyFilter.None, i, Constants.MaxPerPage); foreach (var p in ph) { photos.Add(p); } } foreach (var file in localFiles) { if (photos.FirstOrDefault(p => p.Title == Path.GetFileNameWithoutExtension(file)) == null) { var task = new UploadTask(file, set.PhotosetId, set.Title); PhotoTasks.Add(task); } } foreach (var photo in photos) { if (localFiles.FirstOrDefault(f => Path.GetFileNameWithoutExtension(f) == photo.Title) == null) { var task = new DownloadTask(photo.PhotoId, directory, set.Title); PhotoTasks.Add(task); } } }
public Task <string> UploadMoments(FileData fileData) { TaskCompletionSource <string> ResultCompletionSource = new TaskCompletionSource <string>(); string fileExtension = GetMomentExtension(fileData.FileName); string fileNameStr = fileData.FileName; string path = "moments/" + Guid.NewGuid().ToString() + fileExtension; try { StorageReference storageReference = storage.GetReference(path); UploadTask uploadTask = storageReference.PutStream(fileData.GetStream()); uploadTask.AddOnCompleteListener(new OnCompleteEventHandleListener((Android.Gms.Tasks.Task uploadFile) => { if (uploadFile.IsSuccessful) { var TaskResult = uploadFile.Result; var uri = ((UploadTask.TaskSnapshot)TaskResult).DownloadUrl.ToString(); ResultCompletionSource.SetResult(uri); } })); } catch (Exception e) { ResultCompletionSource.TrySetException(e); } return(ResultCompletionSource.Task); }
public void addOnPausedListenerTest() { Debug.Log("UploadTask addOnPausedListenerTest"); byte[] data = new byte[100]; string filename = "addOnPausedListenerTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.addOnPausedListener(new MyPausedListener("1")) .addOnPausedListener(new Activity(), new MyPausedListener("2")) .addOnPausedListener(new MyExecutor("ExecutorListener"), new MyPausedListener("3")); MyPausedListener remove = new MyPausedListener("remove"); task.addOnPausedListener(remove); task.removeOnPausedListener(remove); task.pause(); Debug.Log("task.isPaused status: " + task.isPaused()); Thread.Sleep(2000); task.resume(); Debug.Log("after task.resume status: " + task.isPaused()); task.onPaused(); Debug.Log("task.onPaused status: " + task.isPaused()); Thread.Sleep(2000); task.resume(); Debug.Log("UploadTask addOnPausedListenerTest success"); }
protected void Page_Load(object sender, EventArgs e) { var upload = Request.HttpMethod == "POST"; if (upload && !Request.GetUser().OperateFiles) { Response.StatusCode = 401; return; } var data = upload ? Request.Form : Request.QueryString; string id = data["resumableIdentifier"], path = FileHelper.Combine (RouteData.GetRelativePath(), data["resumableRelativePath"].ToValidPath(false)), filePath = FileHelper.GetFilePath(path), dataPath = FileHelper.GetDataFilePath(path), state = FileHelper.GetState(dataPath); Directory.CreateDirectory(Path.GetDirectoryName(filePath)); Directory.CreateDirectory(Path.GetDirectoryName(dataPath)); if (state != TaskType.UploadTask || state == TaskType.UploadTask && new UploadTask(path).Identifier != id) { FileHelper.Delete(path); File.WriteAllBytes(filePath, new byte[0]); try { new UploadTask(path, id, int.Parse(data["resumableTotalChunks"]), long.Parse(data["resumableTotalSize"])).Save(); } catch (IOException) { } // another save in progress } var index = int.Parse(data["resumableChunkNumber"]) - 1; if (upload) { string basePath = FileHelper.GetDataPath(path), partSuffix = ".part" + index, partPath = basePath + ".incomplete" + partSuffix; try { using (var output = new FileStream(partPath, FileMode.Create, FileAccess.Write, FileShare.Read)) Request.Files[Request.Files.AllKeys.Single()].InputStream.CopyTo(output); File.Move(partPath, basePath + ".complete" + partSuffix); } catch { FileHelper.DeleteWithRetries(partPath); // delete imcomplete file } var task = new UploadTask(path); if (task.FinishedParts != task.TotalParts) return; using (var output = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read)) for (var i = 0; i < task.TotalParts; ++i) { using (var input = new FileStream( partPath = FileHelper.GetDataPath(path + ".complete.part" + i), FileMode.Open, FileAccess.Read, FileShare.Read)) input.CopyTo(output); FileHelper.DeleteWithRetries(partPath); } task.Finish(); } else Response.StatusCode = File.Exists(FileHelper.GetDataPath(path + ".complete.part" + index)) ? 200 : 204; // test }
public void CreateTask(UploadTask task) { lock (_taskLock) { Queue.Enqueue(task); if (Queue.Count == 1) { _taskAvailable.Set(); } } }
public void uploadFile(string filename, int size) { Debug.Log("upload file start."); byte[] data = new byte[size]; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.addOnFailureListener(new MyFailureListener()) .addOnSuccessListener(new MySuccessListener()) .addOnProgressListener(new MyProgressListener()) .addOnPausedListener(new MyPausedListener()); StorageTask.ErrorResult err = new MyErrorResult(); Exception e = err.getError(); task.setResult(err.obj); err = task.getResult(); if (err == null) { Debug.Log("uploadFileTest fail, getResult err is null."); return; } StorageTask.ErrorResult timePointState = task.getTimePointState(); if (timePointState == null) { Debug.Log("uploadFileTest fail, getTimePointState result is null."); return; } Exception exp = task.getException(); if (exp == null) { Debug.Log("uploadFileTest fail, getException result is null."); return; } task.setException(exp); AndroidJavaObject ajObj = task.getResultThrowException(new AndroidJavaClass("java.lang.Exception")); if (ajObj == null) { Debug.Log("uploadFileTest fail, getException result is null."); return; } Debug.Log("upload file test success."); }
public void ConstructorTest() { Task task = new Task(delegate {}); string src = "hiahia"; string dst = "heihei"; UploadTask result = new UploadTask(task, src, dst); Assert.IsNotNull(result.Task); Assert.AreSame(task, result.Task); Assert.AreEqual(src, result.Source); Assert.AreEqual(dst, result.Destination); }
private UploadTask CreateTask(int i, ResumableContext resumableContext, FileStream fs) { UploadTask param = new UploadTask(); param.UploadFileStream = fs; param.InputStream = new FileStream(fs.Name, FileMode.Open, FileAccess.Read, FileShare.Read); param.ResumableUploadContext = resumableContext; param.ResumableUploadPartContext = resumableContext.PartContextList[i]; param.UploadProgressCallback = _uploadProgressCallback; param.ProgressUpdateInterval = _conf.ProgressUpdateInterval; param.Finished = new ManualResetEvent(false); return(param); }
private void StartPreRead(object state) { PreReadThreadParam preReadThreadParam = state as PreReadThreadParam; if (preReadThreadParam == null) { throw new ClientException("Internal error: the state must be type of PreReadThreadParam"); } int nextPart = 0; try { while (!preReadThreadParam.RequestStopPreRead && nextPart < preReadThreadParam.ResumableContext.PartContextList.Count) { MemoryStream buffer = preReadThreadParam.TakeBuffer(); if (buffer == null) { continue; } UploadTask param = new UploadTask(); param.UploadFileStream = preReadThreadParam.Fs; param.InputStream = buffer; param.ResumableUploadContext = preReadThreadParam.ResumableContext; param.ResumableUploadPartContext = preReadThreadParam.ResumableContext.PartContextList[nextPart++]; param.UploadProgressCallback = _uploadProgressCallback; param.ProgressUpdateInterval = _conf.ProgressUpdateInterval; param.Finished = new ManualResetEvent(false); int readCount = 0; while (readCount != param.ResumableUploadPartContext.Length) { int count = preReadThreadParam.Fs.Read(buffer.GetBuffer(), readCount, (int)param.ResumableUploadPartContext.Length - readCount); if (count == 0) { throw new System.IO.IOException(string.Format("Unable to read data with expected size. Expected size:{0}, actual read size: {1}", param.ResumableUploadPartContext.Length, readCount)); } readCount += count; } param.InputStream.SetLength(readCount); preReadThreadParam.CreateTask(param); } } catch (Exception e) { preReadThreadParam.PreReadError = e; } }
public static async Task <DriveItem> UploadToOneDrive(UploadTask task, string localFileName, CancellationToken token, IProgress <double> progress, TextBoxWriter logs) { if (MainWindow.Client == null) { throw new ApplicationException("OneDrive client null!"); } var name = Path.GetFileName(localFileName); var targetPath = "YEARBOOK 2019/_Uploads/" + task.TaskName + "/" + name; var sesh = await MainWindow.Client.Drives["b!ciVzyDuG1kGQJn8UlMdOl6fArqsytz1JhhwdkjwpvaP7ZUv4lIZKSL4QhaM-19bz"] .Root .ItemWithPath(targetPath) .CreateUploadSession(new DriveItemUploadableProperties() { }) .Request().PostAsync(); logs.WriteLine($"Started new sesh; timeout {sesh.ExpirationDateTime}"); using (var stream = new FileStream(localFileName, FileMode.Open)) { var maxChunkSize = 320 * 1024 * 2; var provider = new ChunkedUploadProvider(sesh, MainWindow.Client, stream, maxChunkSize); var readBuffer = new byte[maxChunkSize]; var trackedExceptions = new List <Exception>(); DriveItem item = null; int index = 0; var uploadChunkRequests = provider.GetUploadChunkRequests().ToList(); foreach (var request in uploadChunkRequests) { logs.WriteLine($"Uploading chunk {index} of {uploadChunkRequests.Count} (timeout {provider.Session.ExpirationDateTime})"); var result = await provider.GetChunkRequestResponseAsync(request, readBuffer, trackedExceptions); if (result.UploadSucceeded) { if (result.ItemResponse != null) { item = result.ItemResponse; } } index += 1; progress.Report((double)index / uploadChunkRequests.Count); } logs.WriteLine("OneDrive upload completed; new item ID " + item.Id); return(item); } }
private void Btn_Click(object sender, EventArgs e) { //upload to firebase storage for (int i = 0; i < 5; i++) { StorageReference oneRef = imagesRef.Child("one" + i + ".png"); Bitmap bitmap = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.one); MemoryStream stream = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); byte[] data = stream.ToArray(); UploadTask uploadtask = oneRef.PutBytes(data); uploadtask.AddOnSuccessListener(this); uploadtask.AddOnFailureListener(this); } }
public UploadTask TakeTask() { if (!_taskAvailable.WaitOne(1000 * 10)) { return(null); } lock (_taskLock) { UploadTask param = Queue.Dequeue(); if (Queue.Count == 0) { _taskAvailable.Reset(); } return(param); } }
async Task UploadContentAsync(IHasId book, BookContent content, UploadTask task) { var names = GetFileNames(book, content); var array = task.EnumerateFiles().ToArray(); for (var i = 0; i < array.Length; i++) { var(_, s, m) = array[i]; await _storage.WriteAsync(new StorageFile { Name = names[i], Stream = s, MediaType = m }); } }
public void addOnCanceledListenerTest() { Debug.Log("UploadTask addOnCanceledListenerTest"); byte[] data = new byte[100000]; string filename = "addOnCanceledListenerTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); Debug.Log("add addOnCanceledListener"); //task.addOnCanceledListener(new MyOnCanceledListener("MyOnCanceledListener")); MyOnCanceledListener actitvity_listener = new MyOnCanceledListener("ActivityListener"); task.addOnCanceledListener(new Activity(), actitvity_listener); MyOnCanceledListener executor_listener = new MyOnCanceledListener("ExecutorListener"); task.addOnCanceledListener(new MyExecutor("ExecutorListener"), executor_listener); MyOnCanceledListener listener = new MyOnCanceledListener("NormalListener"); task.addOnCanceledListener(listener); Debug.Log("remove addOnCanceledListener"); MyOnCanceledListener remove = new MyOnCanceledListener("remove"); task.addOnCanceledListener(new Activity(), remove); task.removeOnCanceledListener(remove); // UnityEngine.Debug.Log("cancel"); Debug.Log("task.isCanceled status: " + task.isCanceled()); if (!task.isCanceled()) { task.pause(); task.cancel(); } Debug.Log("after cancel: task.isCanceled status: " + task.isCanceled()); Debug.Log("UploadTask addOnCanceledListenerTest success"); }
public void uploadFile(string path) { Debug.Log("upload file start."); File file = new File(path); if (!System.IO.File.Exists(path)) { Debug.Log("upload file does not exists: " + path); return; } StorageReference storageReference = mAGCStorageManagement.getStorageReference(path); UploadTask task = storageReference.putFile(file); task.addOnFailureListener(new MyFailureListener()).addOnSuccessListener(new MySuccessListener()); Debug.Log("upload file end."); }
public async Task Error_IfCredentialsAreInvalidAndThrowExceptionOnErrorResponseIsFalse() { var input = new UploadInput { FileMask = "TestFile1.csv", FilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../../../TestData/"), S3Directory = @"\" }; var options = new UploadOptions { ReturnListOfObjectKeys = true, ThrowErrorIfNoMatch = true }; var param = new Parameters { // Invalid AwsAccesKeyId. AwsAccessKeyId = "fnvfdvfkdjvn", // Invalid AwsSecretAccessKey. AwsSecretAccessKey = "bvfjhbvdjhvbjdhf", BucketName = Environment.GetEnvironmentVariable("HiQ_AWSS3Test_BucketName"), Region = (Regions)int.Parse(Environment.GetEnvironmentVariable("HiQ_AWSS3Test_Region")), ThrowExceptionOnErrorResponse = false }; async Task <List <string> > UploadThatThrows() { var response = await UploadTask.UploadFiles(input, param, options, new CancellationToken()); return(response); } try { await UploadThatThrows(); } catch (Exception ex) { Assert.Fail("Expected no exception, but got: " + ex.Message); } }
public static void GET(string Url, Action <UploadTask> UploadingAction) { string url = Url + "?{?}"; Handle.GET(url, (string parameters, Request request) => { if (!ResolveUploadParameters( parameters, out string sessionId, out string fileName, out long fileSize, out string error)) { return(new Response() { StatusCode = (ushort)System.Net.HttpStatusCode.BadRequest, Body = error }); } if (!request.WebSocketUpgrade) { return(404); } WebSocket ws = request.SendUpgrade(WebSocketGroupName); var task = new UploadTask(sessionId, fileName, fileSize, parameters); task.StateChange += (s, a) => UploadingAction(s as UploadTask); if (!Uploads.TryAdd(ws.ToUInt64(), task)) { return(new Response() { StatusCode = (ushort)System.Net.HttpStatusCode.BadRequest, Body = "Unable to create upload task" }); } return(HandlerStatus.Handled); }, new HandlerOptions()
public async Task <string> UploadAnImageToFireBase(string fileURL, string fileNameWithOutExtension = "", string folderStructureName = "") { string response = ""; try { Stream streamResponse = new MemoryStream(); FileStream fs = new FileStream(fileURL, FileMode.Open, FileAccess.Read); using (System.IO.Stream stream = new FileStream(fileURL, FileMode.Open, FileAccess.Read)) { streamResponse = stream; var firebaseStorageReference = FirebaseStorage.GetInstance(FirebaseAppInstance).Reference; StorageReference storageFilesReference; if (string.IsNullOrEmpty(fileNameWithOutExtension)) { string fileNameWithExtension = Path.GetFileName(fileURL); storageFilesReference = firebaseStorageReference.Child(folderStructureName + fileNameWithExtension);// ("TemporaryTestFiles/" + fileNameWithExtension); } else { string fileExtension = Path.GetExtension(fileURL); storageFilesReference = firebaseStorageReference.Child(folderStructureName + fileNameWithOutExtension + fileExtension);// ("TemporaryTestFiles/" + fileNameWithOutExtension + fileExtension); } AndroidConversionService androidConversionService = new AndroidConversionService(); var urlBytes = await androidConversionService.GetBytesFromStream(streamResponse); if (urlBytes != null) { UploadTask uploadTask = storageFilesReference.PutBytes(urlBytes); //uploadTask.AddOnCompleteListener() } } } catch (System.Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(response); }
public void continueWithTest() { byte[] data = new byte[100]; string filename = "continueWithTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.continueWith(new MyExecutor("continueWithTestExecutor"), new MyContinuation("MyExecutor&MyContinuation")); task.continueWith(new MyContinuation("MyContinuation")); task.continueWithTask(new MyContinuation("MyContinuation&Task")); task.continueWithTask(new MyExecuteResult("continueWithTestExecuteResult")); task.continueWithTask(new MyExecutor("continueWithTestExecutor&Task"), new MyContinuation("MyExecutor&MyContinuation&Task")); task.onSuccessTask(new MyExecutor("onSuccessTask"), new MySuccessContinuation("onSuccessTask")); task.onSuccessTask(new MySuccessContinuation("onSuccessTaskSingle")); Debug.Log("continueWithTest Success"); }
public static async Task <string> LocalCopy(UploadTask task, string sourceFileName, bool doNotCheckOverwrite = false) { var name = Path.GetFileName(sourceFileName); var targetPath = task.LocalBackupPath + Path.DirectorySeparatorChar + name; var overwrite = doNotCheckOverwrite || task.OverwriteAll; if (File.Exists(targetPath) && !overwrite) { if (MessageBox.Show($"File {name} exists in target directory {task.LocalBackupPath}. Are you sure you want to overwrite it?", "Overwrite?", MessageBoxButton.YesNo) == MessageBoxResult.No) { throw new ServiceFailureException(); } else { overwrite = true; } } await IOHelpers.CopyFileAsync(sourceFileName, targetPath, overwrite); return(targetPath); }
public void Error_IfSourcePathIsInvalid() { var input = new UploadInput { FileMask = @"*.test", FilePath = @"c:\there_is_no_folder_like_this\" }; var options = new UploadOptions { ReturnListOfObjectKeys = true, ThrowErrorIfNoMatch = true }; void UploadThatThrows() { UploadTask.UploadFiles(input, _param, options, new CancellationToken()); } Assert.That(UploadThatThrows, Throws.TypeOf <ArgumentException>() .With.Message.StartsWith("Source path not found.")); }
public BuildUpload() { Action start = StartBuildGet; Action end = EndBuildGet; UploadTask task = new UploadTask(start, end); m_TaskList.Add(task); start = new Action(this.StartBuildCreate); end = new Action(this.EndBuildCreate); task = new UploadTask(start, end); m_TaskList.Add(task); start = new Action(this.StartArtifactCreate); end = new Action(this.EndArtifactCreate); task = new UploadTask(start, end); m_TaskList.Add(task); start = new Action(this.StartFileUpload); end = new Action(this.EndFileUpload); task = new UploadTask(start, end); m_TaskList.Add(task); m_Timer.Start(); }
/// <summary> /// Encapsulate Card into a single file for uploading and sharing to Firebase /// </summary> private void uploadCardMedia(StorageReference sr_cardMedias, Card card) { // Upload media to cloud foreach (AbMediaContent media in card.mediaList) { string mediaFileName = Path.GetFileName(media.filePath); StorageReference sr_curCardMedia = sr_cardMedias.Child(mediaFileName); FileStream fs = new FileStream(media.filePath, FileMode.Open); //StorageMetadata metadata = new StorageMetadata.Builder() // .SetCustomMetadata("MediaContentType", media.mediaType.ToString()).Build(); UploadTask uploadTask = sr_curCardMedia.PutStream(fs); UploadListener uploadListener = new UploadListener(fs); uploadTask.AddOnFailureListener(uploadListener); uploadTask.AddOnSuccessListener(uploadListener); } // TODO add upload failure and success handling? }
public static async Task UploadSingleFile(UploadTask task, string path, IProgress <double> progress, TextBoxWriter logs) { progress.Report(0); await logs.WriteLineAsync($"Starting upload of {path}"); var localCopyAttempts = 0; var checkedOverwrite = false; while (true) { var targetPath = await LocalCopyService.LocalCopy(task, path, checkedOverwrite); if (ChecksumService.VerifyChecksum(path, targetPath)) { await logs.WriteLineAsync("Local copy successful"); break; } else { await logs.WriteLineAsync($"Local copy attempt {localCopyAttempts} failed"); localCopyAttempts += 1; checkedOverwrite = true; if (localCopyAttempts == MAX_LOCAL_COPY_ATTEMPTS) { throw new Exception($"Tried {MAX_LOCAL_COPY_ATTEMPTS} times to copy file {path}"); } CancellationToken.Token.ThrowIfCancellationRequested(); } } CancellationToken.Token.ThrowIfCancellationRequested(); await logs.WriteLineAsync($"Starting upload to OneDrive for {path}"); await OneDriveUploadService.UploadToOneDrive(task, path, CancellationToken.Token, progress, logs); logs.WriteLine("Job's done!"); }
public static async Task Upload(UploadTask task, IProgress <double> totalProgress, IProgress <double> fileProgress, TextBoxWriter logs) { totalProgress.Report(0); CancellationToken = new CancellationTokenSource(); var files = Directory.EnumerateFiles(task.Folder).OrderBy(x => x).ToList(); var indexOfFirst = files.IndexOf(task.FirstFileName); var indexOfLast = files.IndexOf(task.LastFileName); IEnumerable <string> filesToUpload = files.Where((_, index) => index >= indexOfFirst && index <= indexOfLast); var fileIndex = 0; var filesForUpload = filesToUpload.ToList(); foreach (var file in filesForUpload) { var index = fileIndex; await UploadSingleFile(task, file, new Progress <double>(x => { totalProgress.Report((index + x) / filesForUpload.Count); fileProgress.Report(x); }), logs); fileIndex += 1; } }
public void addOnProgressListenerTest() { Debug.Log("UploadTask addOnProgressListenerTest"); byte[] data = new byte[100]; string filename = "addOnProgressListenerTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); task.addOnProgressListener(new MyProgressListener("1")) .addOnProgressListener(new Activity(), new MyProgressListener("2")) .addOnProgressListener(new MyExecutor("addOnProgressListenerTest"), new MyProgressListener("3")); MyProgressListener remove = new MyProgressListener("remove"); task.addOnProgressListener(remove); task.removeOnProgressListener(remove); bool isInProgress = task.isInProgress(); Debug.Log("UploadTask addOnProgressListenerTest success, is InProgress status: " + isInProgress); }
public void Error_IfCredentialsAreInvalidAndThrowExceptionOnErrorResponseIsTrue() { var input = new UploadInput { FileMask = "TestFile1.csv", FilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../../../TestData/"), S3Directory = @"\", CannedACL = S3CannedACLs.Private }; var options = new UploadOptions { ReturnListOfObjectKeys = true, ThrowErrorIfNoMatch = true }; var param = new Parameters { // Invalid AwsAccesKeyId. AwsAccessKeyId = "fnvfdvfkdjvn", // Invalid AwsSecretAccessKey. AwsSecretAccessKey = "bvfjhbvdjhvbjdhf", BucketName = Environment.GetEnvironmentVariable("HiQ_AWSS3Test_BucketName"), Region = (Regions)int.Parse(Environment.GetEnvironmentVariable("HiQ_AWSS3Test_Region")), ThrowExceptionOnErrorResponse = true }; async Task <List <string> > UploadThatThrows() { var response = await UploadTask.UploadFiles(input, param, options, new CancellationToken()); return(response); } Assert.That(UploadThatThrows, Throws.TypeOf <SecurityException>().With.Message.StartsWith("Invalid Amazon S3 Credentials - data was not uploaded.")); }
private Task Upload(UploadTask uploadTask, IProgress <IUploadState>?progress = null, CancellationToken cancellationToken = default, PauseToken pauseToken = default) { var tcs = new TaskCompletionSource <bool>(); uploadTask.AddOnCompleteListener(new OnCompleteHandlerListener(task => { if (task.IsSuccessful) { tcs.SetResult(true); } else { tcs.SetException(ExceptionMapper.Map(task.Exception)); } })); if (progress != null) { uploadTask.AddOnProgressListener(new OnProgressHandlerListener(snapshot => { var uploadTaskSnapshot = snapshot.JavaCast <UploadTask.TaskSnapshot>(); progress.Report(new UploadTaskSnapshotWrapper(uploadTaskSnapshot !)); })); } if (cancellationToken != default) { cancellationToken.Register(() => uploadTask.Cancel()); } if (pauseToken != default) { pauseToken.SetStorageTask(new StorageTaskWrapper(uploadTask)); } return(tcs.Task); }
public void timePointStateBaseTest() { byte[] data = new byte[100]; string filename = "timePointStateBaseTest.data"; StorageReference storageReference = mAGCStorageManagement.getStorageReference(filename); UploadTask task = storageReference.putBytes(data, new FileMetadata()); StorageTask.ErrorResult err = task.getTimePointState(); StorageTask.TimePointStateBase timePoint = HmsUtil.GetHmsBase <StorageTask.TimePointStateBase>(err.obj); Exception e = timePoint.getError(); if (e == null) { Debug.Log("timePointStateBaseTest fail, error result is null"); return; } StorageReference timeRef = timePoint.getStorage(); if (timeRef == null) { Debug.Log("timePointStateBaseTest fail, timeRef is null"); return; } StorageTask storageTask = timePoint.getTask(); if (storageTask == null) { Debug.Log("timePointStateBaseTest fail, storageTask is null"); return; } Debug.Log("timePointStateBaseTest success"); }
public static void GET(string Url, Action<UploadTask> UploadingAction) { string url = Url + "?{?}"; Handle.GET(url, (string parameters, Request request) => { string sessionId; string fileName; long fileSize; string error; if (!ResolveUploadParameters(parameters, out sessionId, out fileName, out fileSize, out error)) { return new Response() { StatusCode = (ushort) System.Net.HttpStatusCode.BadRequest, Body = error }; } if (!request.WebSocketUpgrade) { return 404; } WebSocket ws = request.SendUpgrade(WebSocketGroupName); UploadTask task = new UploadTask(sessionId, fileName, fileSize, parameters); task.StateChange += (s, a) => { UploadingAction(s as UploadTask); }; if (!Uploads.TryAdd(ws.ToUInt64(), task)) { return new Response() { StatusCode = (ushort) System.Net.HttpStatusCode.BadRequest, Body = "Unable to create upload task" }; } return HandlerStatus.Handled; }, new HandlerOptions() {SkipRequestFilters = true}); Handle.WebSocket(WebSocketGroupName, (byte[] data, WebSocket ws) => { if (!Uploads.ContainsKey(ws.ToUInt64())) { ws.Disconnect("Could not find correct socket to handle the incoming data.", WebSocket.WebSocketCloseCodes.WS_CLOSE_CANT_ACCEPT_DATA); return; } UploadTask task = Uploads[ws.ToUInt64()]; task.Write(data); if (task.FileSize > 0) { ws.Send(task.Progress.ToString()); } }); Handle.WebSocketDisconnect(WebSocketGroupName, (ws) => { UploadTask task; if (Uploads.TryRemove(ws.ToUInt64(), out task)) { task.Close(); } }); }
private bool NextTask(ref UploadTask task) { lock (_localSync) { if (_uploadTasks.Count > 0) { task = _uploadTasks[0]; _uploadTasks.RemoveAt(0); } else { _executionTask = null; task = null; } return task != null; } }