private void RaiseUploadRequest() { if (ParentItem.Parent == null) { CommonNotifyRequest.Raise(new Notification { Content = "Can not upload files to the root. Please select a folder first.".Localize(), Title = "Error".Localize(null, LocalizationScope.DefaultCategory) }); return; } IEnumerable<FileType> fileTypes = new[] { new FileType("all files".Localize(), ".*"), new FileType("jpg image".Localize(), ".jpg"), new FileType("bmp image".Localize(), ".bmp"), new FileType("png image".Localize(), ".png"), new FileType("Report".Localize(), ".rld"), new FileType("Report".Localize(), ".rldc") }; if (fileDialogService == null) fileDialogService = new System.Waf.VirtoCommerce.ManagementClient.Services.FileDialogService(); var result = fileDialogService.ShowOpenFileDialog(this, fileTypes); if (result.IsValid) { var delimiter = !string.IsNullOrEmpty(ParentItem.InnerItemID) && !ParentItem.InnerItemID.EndsWith(NamePathDelimiter) ? NamePathDelimiter : string.Empty; // construct new FolderItemId var fileInfo = new FileInfo(result.FileName); var fileName = string.Format("{0}{1}{2}", ParentItem.InnerItemID, delimiter, fileInfo.Name); var canUpload = true; var fileExists = SelectedFolderItems.OfType<IFileSearchViewModel>().Any(x => x.InnerItem.FolderItemId.EndsWith(NamePathDelimiter + fileInfo.Name, StringComparison.OrdinalIgnoreCase)); if (fileExists) { CommonConfirmRequest.Raise(new ConditionalConfirmation { Title = "Upload file".Localize(), Content = string.Format("There is already a file with the same name in this location.\nDo you want to overwrite and replace the existing file '{0}'?".Localize(), fileInfo.Name) }, (x) => { canUpload = x.Confirmed; }); } if (canUpload) { ShowLoadingAnimation = true; var worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { var id = o.GetHashCode().ToString(); var item = new StatusMessage { ShortText = "File upload in progress".Localize(), StatusMessageId = id }; EventSystem.Publish(item); using (var info = new UploadStreamInfo()) using (var fileStream = new FileStream(result.FileName, FileMode.Open, FileAccess.Read)) { info.FileName = fileName; info.FileByteStream = fileStream; info.Length = fileStream.Length; _assetRepository.Upload(info); } }; worker.RunWorkerCompleted += (o, ea) => { ShowLoadingAnimation = false; var item = new StatusMessage { StatusMessageId = o.GetHashCode().ToString() }; if (ea.Cancelled) { item.ShortText = "File upload was canceled!".Localize(); item.State = StatusMessageState.Warning; } else if (ea.Error != null) { item.ShortText = string.Format("Failed to upload file: {0}".Localize(), ea.Error.Message); item.Details = ea.Error.ToString(); item.State = StatusMessageState.Error; } else { item.ShortText = "File uploaded".Localize(); item.State = StatusMessageState.Success; RefreshCommand.Execute(); } EventSystem.Publish(item); }; worker.RunWorkerAsync(); } } }
/// <summary> /// Uploads the specified stream. /// </summary> /// <param name="info">The info.</param> public void Upload(UploadStreamInfo info) { BlobStorageProvider.Upload(info); }
/// <summary> /// Uploads the specified stream. /// </summary> /// <param name="info">The info.</param> public void Upload(UploadStreamInfo info) { BlobStorageProvider.Upload(info); }
private string Upload(string fileName, Stream source) { string retVal = null; using (var info = new UploadStreamInfo()) { Folder folder = null; try { folder = _assetProvider.GetFolderById("export"); } catch (Exception e) { retVal = e.Message; } finally { folder = folder ?? _assetProvider.CreateFolder("export", null); } if (folder != null) { retVal = null; info.FileName = string.Format("{0}{1}{2}", folder.FolderId, "/", Path.GetFileName(fileName)); info.FileByteStream = source; info.Length = source.Length; try { _assetProvider.Upload(info); } catch (Exception e) { retVal = string.Format("Couldn't upload exported file: {0}", e.Message); } } else { retVal = string.Format("Export folder not found and can't be created: {0}", retVal); } } return retVal; }