public static async Task <AzureFileData> UploadMedia(string file, string rebuildUrl) { return(await Task.Run(async() => { FileUploader uploader = new FileUploader(ServiceApi.PortalURL, CrossSettings.Current.GetValueOrDefault("AccessToken", ""), true, 1024000); AzureFileData azureFileData = null; bool done = false; uploader.OnError += (sender, args) => { done = true; }; uploader.OnFileComplete += (sender, args) => { azureFileData = JsonConvert.DeserializeObject <AzureFileData>(args.Result); done = true; }; uploader.UploadFiles(new List <string>() { file }, "/api/Uploads/Part", rebuildUrl); while (!done) { await Task.Delay(100); } return azureFileData; })); }
private void OnChanged(object sender, FileSystemEventArgs e) { try { System.Threading.Thread.Sleep(2000); FileUploader.UploadFiles(netSuiteService, currentTask); } catch (Exception ex) { appendLog(ex.Message, NOTIFICATION_ERROR); } }
/// <summary> /// call the upload service and config the file watcher /// </summary> private void upload() { if (null != cboTasks.SelectedItem) { try { if (sessionResponse != null && sessionResponse.status != null && sessionResponse.status.isSuccess) { btnUpload.Enabled = false; btnUpload.Cursor = Cursor.Current = Cursors.WaitCursor; currentTask = cboTasks.SelectedItem.ToString(); TaskFile[] taskFiles = FileUploader.UploadFiles(netSuiteService, currentTask); List <string> filePaths = taskFiles.Select(f => System.IO.Path.GetDirectoryName(f.Path)).Distinct().ToList(); if (chkWatchChanges.Checked) { listFileSystemWatcher = new List <FileSystemWatcher>(); foreach (string filePath in filePaths) { watch(filePath); } } else { unWatch(); } } else { appendLog("Connection closed, please restart the application", NOTIFICATION_ERROR); } } catch (Exception ex) { appendLog(ex.Message, NOTIFICATION_ERROR); } } else { appendLog("Please select a task", NOTIFICATION_ERROR); } }