public async Task <ApiResponseDto> UploadDataset(DatasetUploadDto dataset)
 {
     return(await httpClient.PostJsonAsync <ApiResponseDto>("api/file/PostDataset", dataset));
 }
        public async Task <ApiResponse> SaveDataset(ClaimsPrincipal authenticatedUser, DatasetUploadDto uploadedFile)
        {
            try
            {
                var user = await _userManager.FindByIdAsync(authenticatedUser.GetSubjectId());

                var    directory           = $"{_environment.WebRootPath}\\{user.Id}";
                var    filePath            = $"{directory}\\{ uploadedFile.Title}";
                string blazorDataFrameName = uploadedFile.Title.Insert(uploadedFile.Title.IndexOf('.'), "_blazor");

                System.IO.Directory.CreateDirectory(directory);
                var uploadedFileSave = System.IO.File.Create(filePath);

                uploadedFileSave.Write(uploadedFile.Content, 0, uploadedFile.Content.Length);
                uploadedFileSave.Close();
                var dataFrame = Frame.ReadCsv($"{directory}\\{uploadedFile.Title}");

                var shorterDataFrame = dataFrame.GetAddressRange(RangeRestriction <long> .NewStart(250));

                shorterDataFrame.SaveCsv($"{directory}\\{blazorDataFrameName}");

                var shortedFileSave = System.IO.File.Create(filePath);

                shortedFileSave.Write(uploadedFile.Content, 0, uploadedFile.Content.Length);
                shortedFileSave.Close();

                MetaDatasetFile newDatasetFile = new MetaDatasetFile
                {
                    Title       = uploadedFile.Title,
                    BlazorTitle = blazorDataFrameName,
                    Path        = directory,
                    StorageType = FileStorageType.Local,
                    Columns     = GetColumnNames(uploadedFile.Content),
                    RowCount    = GetRowCount(uploadedFile.Content),
                    CreatedBy   = user,
                    CreatedById = user.Id,
                    CreatedOn   = DateTime.Now
                };
                _persistenceManager.Context.DatasetFiles.Add(newDatasetFile);
                _persistenceManager.Context.SaveChanges();

                return(new ApiResponse(Status200OK, L["File has been uploaded successfully."]));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error while saving File to local path: {0}", ex.Message);
                return(new ApiResponse(Status400BadRequest, L["Error while uploading the file."]));
            }
        }
 public Task <ApiResponse> PostDataset(DatasetUploadDto uploadedFile)
 {
     return(_fileManager.SaveDataset(User, uploadedFile));
 }
예제 #4
0
 public Task <ApiResponse> SaveDataset(ClaimsPrincipal authenticatedUser, DatasetUploadDto uploadedFile)
 {
     throw new NotImplementedException();
 }