public async Task <FileInfoViewModel> SaveFile(FileInfoViewModel fileInfoViewModel)
        {
            var signedURL = generatePreSignedURL(fileInfoViewModel.FormFile.FileName);

            using (var httpClient = _httpClientFactory.CreateClient())
                using (var fileStream = fileInfoViewModel.FormFile.OpenReadStream())
                {
                    var putResponseMessage = await httpClient.PutAsync(signedURL, new StreamContent(fileStream));

                    putResponseMessage.EnsureSuccessStatusCode();
                }

            FileInfo fileInfo;

            try
            {
                var signedUri = new Uri(signedURL);
                var fileS3URL = signedURL.Substring(0, signedURL.IndexOf(signedUri.Query));
                fileInfoViewModel.URL = fileS3URL;
                fileInfo = fileInfoViewModel.ToFileInfo();
                this._applicationDbContext.Entry(fileInfo).State = EntityState.Added;
                await this._applicationDbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                using (var httpClient = _httpClientFactory.CreateClient())
                {
                    await httpClient.DeleteAsync(signedURL);
                }
                throw;
            }
            return(fileInfo.ToFileInfoViewModel());
        }
Exemple #2
0
        private void SetViewModel(IEnumerable <IFileInfo> fileInfos)
        {
            FileInfoList = new List <FileInfoViewModel>();

            foreach (var fileInfo in fileInfos)
            {
                var fileInfoViewModel = new FileInfoViewModel()
                {
                    IsDirectory    = fileInfo.IsDirectory,
                    Icon           = "fas fa-file",
                    FileType       = "file",
                    Length         = fileInfo.Length + " bytes",
                    FileName       = fileInfo.Name,
                    LastUpdateTime = fileInfo.LastModified.LocalDateTime
                };

                if (fileInfo.IsDirectory)
                {
                    fileInfoViewModel.Icon     = "fas fa-folder";
                    fileInfoViewModel.FileType = "folder";
                    fileInfoViewModel.Length   = "/";
                    fileInfoViewModel.FileName = $"<a href='{Url.Content("~/")}VirtualFileExplorer?path={fileInfo.PhysicalPath}'>{fileInfo.Name}</a>";
                }
                else
                {
                    fileInfoViewModel.FilePath = ((EmbeddedResourceFileInfo)fileInfo).VirtualPath;
                }

                FileInfoList.Add(fileInfoViewModel);
            }
        }
Exemple #3
0
 public void Visit(FileInfoViewModel current)
 {
     if (this.current != null)
     {
         this.backList.Push(this.current);
     }
     this.nextList.Clear();
     this.current = current;
 }
 public void PrintFileInfo(FileInfoViewModel fileInfoViewModel)
 {
     Console.WriteLine($"\n- file name: '{fileInfoViewModel.FileName}'");
     Console.WriteLine($"- extension: '{fileInfoViewModel.Extension}'");
     Console.WriteLine($"- file size: '{fileInfoViewModel.FileSize}'");
     Console.WriteLine($"- creation date: '{fileInfoViewModel.CreationDate}'");
     Console.WriteLine($"- downloads number: '{fileInfoViewModel.DownloadsNumber}'");
     Console.WriteLine($"- login: '******'\n");
 }
Exemple #5
0
        /// <summary>
        /// ファイル一覧で選択中のファイルを削除します。
        /// </summary>
        /// <param name="fileInfoViewModel"></param>
        private void DeleteFileListItem(FileInfoViewModel fileInfoViewModel)
        {
            this.ViewModel.DeleteFileListItemCommand(fileInfoViewModel, () =>
                                                     MessageBox.Show($"「{fileInfoViewModel.Name}」を削除します。よろしいですか?", "ファイルの削除", MessageBoxButton.YesNo) == MessageBoxResult.Yes
                                                     );



            this.SetFocusFileList();
        }
Exemple #6
0
        async Task ShowFileInfo()
        {
            foreach (var file in await fileReaderReference.EnumerateFilesAsync())
            {
                var fileInfo = await file.ReadFileInfoAsync();

                AvatarFileInfoVM      = new FileInfoViewModel();
                AvatarFileInfoVM.Name = fileInfo.Name;
                AvatarFileInfoVM.Size = fileInfo.Size;
                AvatarFileInfoVM.Type = fileInfo.Type;
            }
        }
Exemple #7
0
        private void _fileExplorer_OnOpenFileRequest(object sender, FileInfoViewModel viewModel)
        {
            var content = _fileExplorer.GetFileContent(viewModel);

            if (content is string text)
            {
                var textView = new TextBlock {
                    Text = text, TextWrapping = TextWrapping.Wrap
                };
                ContentViewer.Content = textView;
            }
        }
Exemple #8
0
        public FileInfoViewModel Next()
        {
            if (!this.EnableNext)
            {
                return(null);
            }

            var result = this.nextList.Pop();

            this.backList.Push(this.current);
            this.current = result;

            return(result);
        }
Exemple #9
0
        /// <summary>
        /// ファイル一覧の項目を選択します。
        /// </summary>
        /// <param name="fileInfoViewModel"></param>
        private void SelectFileListItem(FileInfoViewModel fileInfoViewModel)
        {
            this.ViewModel.SelectFileListItemCommand(fileInfoViewModel);

            this.ScrollFileListToSelectedItem();

            if (fileInfoViewModel.FileType == FileInfoViewModel.FileInfoType.File)
            {
                this.SetFocusImage();
            }
            else
            {
                this.SetFocusFileList();
            }
        }
        public async Task WhenExceptionThenUploadFileReturnsInternalServerError()
        {
            // Arrange
            var fileInfoViewModel   = new FileInfoViewModel {
            };
            var fileInfoServiceMock = new Mock <IFileInfoService>();
            var fileInfoController  = new FileInfoController(fileInfoServiceMock.Object);

            // Act
            var contentResult = (ContentResult)await fileInfoController.UploadFile(fileInfoViewModel);

            // Assert
            contentResult.ShouldNotBeNull();
            contentResult.StatusCode.ShouldBe((int)HttpStatusCode.InternalServerError);
        }
Exemple #11
0
        public static CreateFileRequest ConvertToCreateFileRequest(FileInfoViewModel file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }
            var createFileRequest = new CreateFileRequest
            {
                Id          = file.Id,
                ContentType = file.ContentType,
                Name        = file.Name,
                SizeKB      = file.SizeKB
            };

            return(createFileRequest);
        }
        public async Task WhenErrorInUploadToS3ThenSaveFileThrowsException()
        {
            // Arrange
            var formFileMock = new Mock <IFormFile>();

            const string testQuery       = "?testquery";
            const string urlWithoutQuery = "http://signed_Url/test.png";
            string       s3SignedURL     = $"{urlWithoutQuery}{testQuery}";

            var fileInfoViewModel = new FileInfoViewModel {
            };
            var fileInfoService   = getFileInfoService(s3SignedURL, formFileMock, null);

            // Act, Assert
            await fileInfoService.SaveFile(fileInfoViewModel).ShouldThrowAsync <Exception>();
        }
        private async Task ExecuteConsoleCommandFileInfo(Options options)
        {
            var fileInfoQuery         = new GetFileInfoQuery(options);
            var fileInfoResponseModel = await _mediator.Send(fileInfoQuery);

            FileInfoViewModel fileInfoViewModel = new FileInfoViewModel
            {
                FileName        = fileInfoResponseModel.FileName,
                Extension       = fileInfoResponseModel.Extension,
                CreationDate    = ConvertingHelper.GetDateString(fileInfoResponseModel.CreationDate),
                FileSize        = ConvertingHelper.GetSizeString(fileInfoResponseModel.FileSize),
                DownloadsNumber = fileInfoResponseModel.DownloadsNumber,
                Login           = fileInfoResponseModel.Login
            };

            _consolePrinter.PrintFileInfo(fileInfoViewModel);
        }
Exemple #14
0
        public static FileInfoDTO ConvertToFileInfoDTO(FileInfoViewModel file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var fileInfoDTO = new FileInfoDTO()
            {
                Id          = file.Id,
                Name        = file.Name,
                ContentType = file.ContentType,
                SizeKB      = file.SizeKB
            };

            return(fileInfoDTO);
        }
Exemple #15
0
        public async Task <IActionResult> UploadFile([FromForm] FileInfoViewModel fileInfoViewModel)
        {
            try
            {
                var fileInfoViewModelDB = await this._fileInfoService.SaveFile(fileInfoViewModel);

                var routeValues = new {
                    fileInfoViewModelDB.Id
                };
                return(new CreatedAtActionResult(actionName: "", controllerName: "FileInfo",
                                                 routeValues: routeValues, value: fileInfoViewModelDB));
            }
            catch (Exception)
            {
                return(_internalServerError);

                throw;
            }
        }
        public async Task WhenNoErrorThenSaveFileTestReturnsFileInfoViewModel()
        {
            // Arrange
            var formFileMock = new Mock <IFormFile>();

            const string testQuery         = "?testquery";
            const string urlWithoutQuery   = "http://signed_Url/test.png";
            string       s3SignedURL       = $"{urlWithoutQuery}{testQuery}";
            var          fileInfoViewModel = getFileInfoViewModel(formFileMock);

            var fileInfoService = getFileInfoService(s3SignedURL, formFileMock, getApplicationDbContext());

            // Act
            FileInfoViewModel fileInfoViewModelResult = await fileInfoService.SaveFile(fileInfoViewModel);

            // Assert
            fileInfoViewModelResult.ShouldSatisfyAllConditions(
                () => fileInfoViewModelResult.Id.ShouldBeGreaterThan(0),
                () => fileInfoViewModelResult.URL.ShouldBe(urlWithoutQuery),
                () => fileInfoViewModelResult.Type.ShouldBe(fileInfoViewModel.Type),
                () => fileInfoViewModelResult.SizeInBytes.ShouldBe(fileInfoViewModel.SizeInBytes),
                () => fileInfoViewModelResult.Description.ShouldBe(fileInfoViewModel.Description));
        }
Exemple #17
0
        public ActionResult <ApiResult <string> > SaveFileInfo([FromForm] FileInfoViewModel model)
        {
            CheckInitData(model.Id);
            JsonResult errorResult = base.ValidateModel(model.Id);

            if (errorResult != null)
            {
                return(errorResult);
            }
            var saveObject = base.mapper.Map <FileInfo>(model);
            var result     = new ApiResult <string>();

            model.Name = model.Name.Trim();
            ValidateFileInfo(saveObject);
            saveObject.IsDeleted = false;
            var x = Db.Storageable(saveObject).ToStorage();

            x.AsUpdateable.ExecuteCommand();
            x.AsInsertable.ExecuteCommand();
            result.Data      = x.InsertList.Any()? Pubconst.MESSAGEADDSUCCESS:Pubconst.MESSAGESAVESUCCESS;
            result.IsSuccess = true;
            return(result);
        }
        public async Task WhenNoExceptionThenUploadFileReturnsCreated()
        {
            // Arrange
            var fileInfoViewModel         = new FileInfoViewModel {
            };
            var fileInfoViewModelFromSave = new FileInfoViewModel {
            };
            var fileInfoServiceMock       = new Mock <IFileInfoService>();
            var fixture = new Fixture();

            fileInfoServiceMock.Setup(fileInfoService => fileInfoService.SaveFile(fileInfoViewModel))
            .ReturnsAsync(new FileInfoViewModel
            {
                Id = fixture.Create <int>()
            });
            var fileInfoController = new FileInfoController(fileInfoServiceMock.Object);

            // Act
            var createdAtActionResult = (CreatedAtActionResult)await fileInfoController.UploadFile(fileInfoViewModel);

            // Assert
            createdAtActionResult.ShouldNotBeNull();
            createdAtActionResult.StatusCode.ShouldBe((int)HttpStatusCode.Created);
        }
Exemple #19
0
        private void HandleGridViewModelPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            var vm = (IFileSystemCollectionViewModel <TFile, TFolder>)sender;

            if (e.PropertyName == "SelectedItem")
            {
                var file = vm.SelectedItem;
                if (file != null && file.IsNot <IFolder>())
                {
                    var br = BusyStatusReceiver;
                    br.AutoReset("Loading file info...", () => _loadFileInfoHandler.ExecuteAsync(ct => FileInfoViewModel.LoadFileInfoAsync(file, ct, br), Timeout))
                    .ConfigureAwait(true);
                }
            }
        }
Exemple #20
0
 public static FileInfo ToFileInfo(this FileInfoViewModel fileInfoViewModel)
 {
     return(expFileInfoViewModelToFileInfo.Compile()(fileInfoViewModel));
 }
Exemple #21
0
 async Task ClearFileInfo()
 {
     AvatarFileInfoVM = null;
     await fileReaderReference.ClearValue();
 }
Exemple #22
0
        public ActionResult <ApiResult <TableModel <FileInfoGridViewModel> > > GetFileInfoList([FromForm] FileInfoViewModel model)
        {
            var result = new ApiResult <TableModel <FileInfoGridViewModel> >();

            result.Data = new TableModel <FileInfoGridViewModel>();
            int count = 0;
            var list  = Db.Queryable <FileInfo>()
                        .WhereIF(!string.IsNullOrEmpty(model.Name), it => it.Name.Contains(model.Name))
                        .OrderBy(it => new { it.Name })
                        .Select <FileInfoGridViewModel>()
                        .ToPageList(model.PageIndex, model.PageSize, ref count);

            result.Data.Rows       = list;
            result.Data.Total      = count;
            result.Data.PageSize   = model.PageSize;
            result.Data.PageNumber = model.PageIndex;
            result.IsSuccess       = true;
            return(result);
        }