public void ReadRecordForDeletedResourceTest() { PrivateApiResponse <RecordsHandlingComponent.DataContract.RecordsCreateOrDeleteResponseItem> recordResponse = null; var recordHandler = new RecordManager(); var fieldHandler = new FieldManager(); var fields = fieldHandler.GetFieldGuid(new[] { "P_Name", "P_Owner" }, new[] { Porters.TestCoreFramework.Enums.ResourceType.Client }) .Result.Result.ToDictionary(x => $"{char.ToUpper(x.Resource[0]) + x.Resource.Substring(1)}.{x.Alias}", x => (int)UuidUtil.GetId(x.Id)); var request = RecordRequestComposer.ComposeCreateRequest() .Append(item => item.ForResource(Porters.TestCoreFramework.Enums.ResourceType.Client) .WithField(fields["Client.P_Name"], "TestName") .WithField(fields["Client.P_Owner"], 1)); recordResponse = recordHandler.WriteRecords(request.Result); PrAssume.That(recordResponse, PrIs.SuccessfulResponse()); var fileHandler = new FileStorageManager(); var fileRecordUploadResponse = fileHandler.Upload(GenerateUploadFileRequest(recordId: recordResponse.Result.Ids[0][0].ToString())); PrAssume.That(fileRecordUploadResponse, PrIs.SuccessfulResponse()); var recordDeleteResponse = recordHandler.DeleteRecords(RecordRequestComposer.ComposeDeleteRequest(Porters.TestCoreFramework.Enums.ResourceType.Client, recordResponse.Result.Ids.SelectMany(x => x))); PrAssume.That(recordDeleteResponse, PrIs.SuccessfulResponse()); var fileRecordReadResponse = fileHandler.Read(fileRecordUploadResponse.Result.Id); PrAssert.That(fileRecordReadResponse, PrIs.ErrorResponse()); }
public void HappyPathTest(ResourceId resource, FileType fileType) { var fileInfo = CommonConstants.Files[fileType]; var path = Path.Combine(Util.GetTestDirectory(), fileInfo.Location); var base64string = Util.ReadFileAsBase64String(path); var recordInfo = RecordsCreator.Data[resource]; var handler = new FileStorageManager(); var request = GenerateUploadFileRequest(fileName: fileInfo.Location.Split('/').Last(), recordId: recordInfo.Id.ToString(), resourceId: ((int)resource).ToString(), sublist: "1", contentType: fileInfo.MimeType); request.Content = base64string; var uploadResponse = handler.Upload(request); PrAssert.That(uploadResponse, PrIs.SuccessfulResponse()); //send request as string, not as object, to make sure we receive string as is, without json.NET formatting. using (LogHelper.LoggerForCurrentTest.EnterReproStep("Sending request to read file content.")) using (var readResponse = PrivateApiConnection.GetConnectionForCurrentTest().SendAsync(FileStorageManager.EndPoint, new Dictionary <string, string> { ["id"] = uploadResponse.Result.Id }, System.Net.Http.HttpMethod.Get).Result) { var receivedContent = readResponse.Content.ReadAsByteArrayAsync().Result; PrAssert.That((int)readResponse.StatusCode, PrIs.LessThan(300)); PrAssert.That(receivedContent, PrIs.EqualTo(File.ReadAllBytes(path))); } var deleteResponse = handler.Delete(uploadResponse.Result.Id); PrAssert.That(deleteResponse, PrIs.SuccessfulResponse()); }
public void UploadSeveralFilesToSameRecordTest() { const int filesNumber = 50; var fileIdsList = new List <string>(); var handler = new FileStorageManager(); using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Uploading {filesNumber} files")) { for (var i = 0; i < filesNumber; i++) { //upload a file of 1MB size var response = handler.Upload(GenerateUploadFileRequest(content: TestContext.CurrentContext.Random.GetString(1 << 20))); PrAssume.That(response, PrIs.SuccessfulResponse(), $"File #{i} was not uploaded successfully"); fileIdsList.Add(response.Result.Id); } } using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Reading {filesNumber} files")) { foreach (var id in fileIdsList) { var response = handler.Read(id); PrAssert.That(response, PrIs.SuccessfulResponse()); } } using (LogHelper.LoggerForCurrentTest.EnterReproStep($"Deleting {filesNumber} files")) { foreach (var id in fileIdsList) { var response = handler.Delete(id); PrAssert.That(response, PrIs.SuccessfulResponse()); } } }
protected async void FormSubmit() { int.TryParse(ParentId, out int parentId); model.ParentId = parentId; #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { fileName = file.Name; fileSize = Convert.ToInt32(file.Size); // 첨부 파일 삭제 await FileStorageManager.DeleteAsync(model.FileName, ""); // 다시 업로드 fileName = await FileStorageManager.UploadAsync(file.Data, file.Name, "", true); model.FileName = fileName; model.FileSize = fileSize; } } #endregion await UploadRepositoryAsyncReference.EditAsync(model); NavigationManagerReference.NavigateTo("/Uploads"); }
public void UploadFileWihtoutParameterInMetadataTest(string parameterName, bool isRequiredParameter) { var handler = new FileStorageManager(); var response = handler.Upload(GenerateUploadFileRequest(fileSize: defaultContent.Length.ToString()), (o) => { (o["metadata"] as JObject).Property(parameterName).Remove(); return(o); }); try { if (isRequiredParameter) { PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(116)); } else { PrAssert.That(response, PrIs.SuccessfulResponse()); } } finally { handler.Delete(response?.Result?.Id); } }
protected async void FormSubmit() { int.TryParse(ParentId, out int parentId); model.ParentId = parentId; #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { fileName = file.Name; fileSize = Convert.ToInt32(file.Size); fileName = await FileStorageManager.UploadAsync(file.Data, file.Name, "", true); model.FileName = fileName; model.FileSize = fileSize; } } #endregion foreach (var m in Models) { m.FileName = model.FileName; m.FileSize = model.FileSize; await UploadRepositoryAsyncReference.AddAsync(m); } NavigationManagerReference.NavigateTo("/BriefingLogs"); }
/// <summary> /// default constructor /// </summary> /// <param name="applicationLogTools"></param> /// <param name="fileStorageManager"></param> /// <param name="mapper"></param> public FileStorageController(IApplicationLogTools applicationLogTools , FileStorageManager fileStorageManager , IMapper mapper) { _applicationLogTools = applicationLogTools; _fileStorageManager = fileStorageManager; _mapper = mapper; }
async void OnNewModelFromNetwork(object sender, NewModelOnNetworkEventArgs e) { var acceptDownload = await MessageDialogHelper.AskYesNoQuestionAsync( "New Model Available", "Someone on the network has opened a new model, do you want to access it?"); if (acceptDownload) { this.ShowBusy("Downloading model files..."); var modelFilePath = await this.DownloadModelToLocalStorageAsync( e.ModelIdentifier, e.IPAddress); if (!string.IsNullOrEmpty(modelFilePath)) { // Open the model from the file as we would if the user had selected // it via a dialog. var modelDetails = await this.ImportGLTFModelFromFileAsync(modelFilePath); var newModel = modelDetails.GameObject; // Flag that the ID of this model came from over the network, we didn't // open it ourselves. var modelIdentifier = newModel.AddComponent <ModelIdentifier>(); modelIdentifier.AssignExistingFromNetworkedShare(e.ModelIdentifier); // Add positioning. var positioningManager = newModel.AddComponent <ModelPositioningManager>(); positioningManager.InitialiseSizeAndPositioning( this.RootParentProvider.RootParent); // And updates (this handles incoming transformation messages along // with removal messages too) newModel.AddComponent <ModelUpdatesManager>(); // With this model coming from the network, we want to import // the anchor onto the parent to put it into the same place within // the space as on the device it originated from. var worldAnchorBits = await FileStorageManager.LoadExportedWorldAnchorAsync(modelIdentifier.Identifier); if (worldAnchorBits != null) { var anchorManager = newModel.AddComponent <AnchorManager>(); // TODO: if this fails then?... await anchorManager.ImportAnchorToModelParent(worldAnchorBits); } // Let the user know about what to expect with their first shared model. this.AudioManager.PlayClipOnceOnly(AudioClipType.FirstSharedModelOpened); } else { this.AudioManager.PlayClip(AudioClipType.ErrorDownloadingModel); } this.HideBusy(); } }
public void DeleteFileContentForIdTest(string id, int errorCode) { var handler = new FileStorageManager(); using (LogHelper.LoggerForCurrentTest.EnterReproStep("Running the test -- sending a read request with the specified id")) { var readResponse = handler.Delete(id); PrAssert.That(readResponse, PrIs.ErrorResponse().And.ErrorCode(errorCode)); } }
protected async void CreateOrEditClick() { #region 일 업로드 관련 추가 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { //file.Name = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}{file.Name}"; fileName = file.Name; fileSize = Convert.ToInt32(file.Size); //await FileUploadServiceReference.UploadAsync(file); //[A] 바이트 형태 //var ms = new MemoryStream(); //await file.Data.CopyToAsync(ms); // 파일 데이터를 메모리스트림으로 변환 //// upload 하기전 memorystream을 byte 배열로 다시변환 //await FileStorageManager.UploadAsync(ms.ToArray(), file.Name, "", true); //[B] Stream형태 //string folderPath = Path.Combine(WebHostEnvironment.WebRootPath, "files"); await FileStorageManager.UploadAsync(file.Data, file.Name, "", true); Model.FileName = fileName; Model.FileSize = fileSize; } #endregion if (!int.TryParse(parentId, out int newParentId)) { newParentId = 0; } Model.ParentId = newParentId; //Model.ParentKey = Model.ParentKey; if (Model.Id == 0) { // Create await NoticeRepositoryAsyncReference.AddAsync(Model); CreateCallback?.Invoke(); // -> EditCallback } else { // Edit await NoticeRepositoryAsyncReference.EditAsync(Model); await EditCallback.InvokeAsync(true); } //IsShow = false; }
public async Task <string> DownloadModelToLocalStorageAsync() { var worked = false; var mainFilePath = string.Empty; #if ENABLE_WINMD_SUPPORT // Grab the list of Uris/Files that make up the remote model. Note that there // is an assumption that the first file here will be the actual GLB/GLTF file // otherwise the code below which sets mainFilePath will not work. var remoteUrisForModel = await DownloadRemoteUriListForModelAsync(); if (remoteUrisForModel.Count > 0) { worked = true; // Add into that the URI for the anchor file so that we download this too var remoteAnchorFileUri = FileStorageManager.GetAnchorFileRelativeUri( this.modelIdentifier); remoteUrisForModel.Add(remoteAnchorFileUri); // Iterate through and download each one of those files if we need to. for (int i = 0; ((i < remoteUrisForModel.Count) && worked); i++) { // Recurse down & make sure we have a file in the right folder to store // this locally. var localFile = await FileStorageManager.GetStorageFileForRelativeUriAsync( remoteUrisForModel[i]); // Store off the first local file path as we assume that will be the .GLB or // GLTF file. if (i == 0) { mainFilePath = localFile.Path; } // We want the size of that file. var properties = await localFile.GetBasicPropertiesAsync(); // If the file was already there with > 0 size then we will not overwrite it. // (as a cheap form of caching) if (properties.Size == 0) { // Go grab the file from the remote HoloLens web server and store // the bits locally. worked = await DownloadToStorageFileAsync(remoteUrisForModel[i], localFile); } } } #endif // ENABLE_WINMD_SUPPORT return(worked ? mainFilePath : string.Empty); }
protected async void CreateOrEditClick() { #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { //file.Name = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}{file.Name}"; fileName = file.Name; fileSize = Convert.ToInt32(file.Size); //[A] byte[] 형태 //var ms = new MemoryStream(); //await file.Data.CopyToAsync(ms); //await FileStorageManager.UploadAsync(ms.ToArray(), file.Name, "", true); //[B] Stream 형태 //string folderPath = Path.Combine(WebHostEnvironment.WebRootPath, "files"); await FileStorageManager.UploadAsync(file.Data, file.Name, "", true); Model.FileName = fileName; Model.FileSize = fileSize; } } #endregion if (!int.TryParse(parentId, out int newParentId)) { newParentId = 0; } Model.ParentId = newParentId; Model.ParentKey = Model.ParentKey; if (Model.Id == 0) { // Create await UploadRepositoryAsyncReference.AddAsync(Model); CreateCallback?.Invoke(); } else { // Edit await UploadRepositoryAsyncReference.EditAsync(Model); await EditCallback.InvokeAsync(true); } //IsShow = false; // this.Hide() }
public static IStorageManager GetGameStorageManager() { if (g_gameStorageManager == null) { var folder = EnsureFolder(Platform.Instance.UserDataPath, "gameData"); g_gameStorageManager = Platform.Instance.UseEncryption ? new EncryptedFileStorageManager(folder) : new FileStorageManager(folder); } return(g_gameStorageManager); }
public static IStorageManager GetAppStorageManager() { if (g_appStorageManager == null) { var folder = EnsureFolder(Platform.Instance.AppDataPath); g_appStorageManager = Platform.Instance.UseEncryption ? new EncryptedFileStorageManager(folder) : new FileStorageManager(folder); } return(g_appStorageManager); }
private void PerformTestWithPreparedData(Action <string> testAction) { var manager = new FileStorageManager(); var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); try { testAction(result.Result.Id); } finally { manager.Delete(result.Result.Id); } }
public void Upload() { using (FileStorageManager fsm = new FileStorageManager(_fsBaseAddress, _productsBaseAddress, Convert.ToInt32(_bufferSize), Convert.ToInt32(_taskCount))) { fsm.CurrentStateChanged += s => _currentMessage = s; var md5 = StartCoroutine(fsm.UploadBuild(_folderPath, "04b79864-c61b-4540-9885-51a8bdd15552", _startFileName, 2) .AsEnumerator()); } }
protected async void DownloadBy(LibraryModel model) { if (!string.IsNullOrEmpty(model.FileName)) { byte[] fileBytes = await FileStorageManager.DownloadAsync(model.FileName, ""); if (fileBytes != null) { // DownCount model.DownCount = model.DownCount + 1; await UploadRepositoryAsyncReference.EditAsync(model); await FileUtil.SaveAs(JSRuntime, model.FileName, fileBytes); } } }
private void PerformTestForFileStatus(bool isDeleted, Func <string, FileStorageManager, PrivateApiResponse <object> > testFunc) { var manager = new FileStorageManager(); var id = nonExistingRecordId; if (isDeleted) { var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); manager.Delete(result.Result.Id); id = result.Result.Id; } var response = testFunc(id, manager); PrAssert.That(response, PrIs.WithErrorCode(100).And.HttpCode(400)); }
async Task <List <string> > DownloadRemoteUriListForModelAsync() { // We first download the file list which tells us which files make up the model. var fileListUri = FileStorageManager.GetFileListRelativeUri(this.modelIdentifier); // Get a local storage file within the 3D objects folder to store that into. var fileListLocalFile = await FileStorageManager.GetStorageFileForRelativeUriAsync( fileListUri); // Download the remote file list. await DownloadToStorageFileAsync(fileListUri, fileListLocalFile); // Read the bill of materials - the files that make up the model. var remoteFileUris = await FileIO.ReadLinesAsync(fileListLocalFile); return(remoteFileUris.ToList()); }
private void PerformTestWithoutAuthorisationWithDataPreparation(bool doDeauth, Func <PrivateApiConnection, string, object> responseProvider) { var manager = new FileStorageManager(); var result = manager.Upload(GenerateUploadFileRequest()); PrAssume.That(result, PrIs.SuccessfulResponse()); PrivateApiConnection.GetConnectionForCurrentTest().DeAuthenticate(); try { PerformTestWithoutAuthorisation(doDeauth, responseProvider, result.Result.Id); } finally { PrivateApiConnection.GetConnectionForCurrentTest().Authenticate(); manager.Delete(result.Result.Id); } }
public void UploadFileWihtoutContentParameterTest() { var handler = new FileStorageManager(); var response = handler.Upload(GenerateUploadFileRequest(fileSize: defaultContent.Length.ToString()), (o) => { (o as JObject).Property("content").Remove(); return(o); }); try { PrAssert.That(response, PrIs.ErrorResponse().And.ErrorCode(116)); } finally { handler.Delete(response?.Result?.Id); } }
static void Main() { var folderRoot = @"C:\development\CHDAV2\Web\"; var cloudStorage = true; log4net.Config.BasicConfigurator.Configure(); var log = LogManager.GetLogger(typeof(Program)); var fileStorageManager = new FileStorageManager(folderRoot, cloudStorage, log); var doc = new Document { IsAzure = true, FileName = "test.txt" }; fileStorageManager.Exists() }
protected async void DeleteClick() { bool isDelete = await JSRuntime.InvokeAsync <bool>("confirm", $"{Id}번 글을 정말로 삭제하시겠습니까?"); if (isDelete) { if (!string.IsNullOrEmpty(model?.FileName)) { // 첨부 파일 삭제 await FileStorageManager.DeleteAsync(model.FileName, "Libraries"); } await UploadRepositoryAsyncReference.DeleteAsync(Id); // 삭제 NavigationManagerReference.NavigateTo("/Libraries"); // 리스트 페이지로 이동 } else { await JSRuntime.InvokeAsync <object>("alert", "취소되었습니다."); } }
async void OnOpenSpeechCommand() { var filePath = await this.PickFileFrom3DObjectsFolderAsync(); if (!string.IsNullOrEmpty(filePath)) { var modelDetails = await this.ImportGLTFModelFromFileAsync(filePath); if (modelDetails != null) { // Our new model comes out of the file load. var newModel = modelDetails.GameObject; // Give the new model a new identity. var modelIdentifier = newModel.AddComponent <ModelIdentifier>(); // Make it focusable. newModel.AddComponent <FocusWatcher>(); // Add positioning. var positioningManager = newModel.AddComponent <ModelPositioningManager>(); positioningManager.InitialiseSizeAndPositioning( this.RootParentProvider.RootParent); // Add manipulations to the new model so it can be moved around. var manipManager = newModel.AddComponent <ModelUpdatesManager>(); manipManager.AddHandManipulationsToModel(); // Add an anchor to the new model's parent such that we can then // anchor the parent while moving the model around within it // (anchored components can't move). var anchorManager = newModel.AddComponent <AnchorManager>(); anchorManager.AddAnchorToModelParent(); // Write out all the files that were part of loading this model // into a file in case they need sharing in future. await FileStorageManager.StoreFileListAsync( (Guid)modelIdentifier.Identifier, modelDetails.FileLoader); // And export the anchor into the file system as well. // TODO: this will currently wait "for ever" for the world anchor to be // located which might be wildly optimistic, we should probably add some // notion of a timeout on that here too. var exportedAnchorBits = await anchorManager.ExportAnchorAsync(); if (exportedAnchorBits != null) { // Store that into the file system so that the web server can later // serve it up on request. await FileStorageManager.StoreExportedWorldAnchorAsync( (Guid)modelIdentifier.Identifier, exportedAnchorBits); // Message out to the network that we have a new model that they // can optionally grab if they want to. NetworkMessagingProvider.SendNewModelMessage( (Guid)modelIdentifier.Identifier); } } } }