public PartialViewResult NewPriorityLandscapeFiles(PriorityLandscapePrimaryKey priorityLandscapePrimaryKey) { Check.EnsureNotNull(priorityLandscapePrimaryKey.EntityObject); var viewModel = new NewFileViewModel(); return(ViewNewPriorityLandscapeFiles(viewModel)); }
public PartialViewResult NewGrantFiles(GrantPrimaryKey grantPrimaryKey) { Check.EnsureNotNull(grantPrimaryKey.EntityObject); var viewModel = new NewFileViewModel(); return(ViewNewGrantFiles(viewModel)); }
public PartialViewResult NewInteractionEventFiles(InteractionEventPrimaryKey interactionEventPrimaryKey) { Check.EnsureNotNull(interactionEventPrimaryKey.EntityObject); var viewModel = new NewFileViewModel(); return(ViewNewInteractionEventFiles(viewModel)); }
public void FilePath_is_Folder_with_FileName() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()) { Folder = @"C:\Example\MyFolder", FileName = "mydream.xml" }; entityUnderTest.FilePath.Should().Be(@"C:\Example\MyFolder\mydream.xml"); }
public void FilePath_if_not_ending_in_xml_appended() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()) { Folder = @"C:\Example\MyFolder", FileName = "here" }; entityUnderTest.FilePath.Should().Be(@"C:\Example\MyFolder\here.xml"); }
public void IsValid_illegal_characters_in_path_false() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()) { Folder = @"C:\Example\MyFolder", FileName = "here?" }; entityUnderTest.IsValid.Should().BeFalse(); }
public void IsValid_normal_filepath_validated() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()) { Folder = @"C:\Example\MyFolder", FileName = "here" }; entityUnderTest.IsValid.Should().BeTrue(); }
public void FilePath_with_empty_FileName_returns_default() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()) { Folder = @"C:\Example\MyFolder", FileName = "" }; entityUnderTest.FilePath.Should().Be(@"C:\Example\MyFolder\mydreams.xml"); }
public int AddFile(NewFileViewModel model, string userId, int?id) { var file = Mapper.Map <File>(model); file.UserId = userId; file.ParentFolderId = id; _context.Files.Add(file); _context.SaveChanges(); return(file.Id); }
public ActionResult NewGrantFiles(GrantPrimaryKey grantPrimaryKey, NewFileViewModel viewModel) { var grant = grantPrimaryKey.EntityObject; if (!ModelState.IsValid) { return ViewNewGrantFiles(new NewFileViewModel()); } viewModel.UpdateModel(grant, CurrentPerson); SetMessageForDisplay($"Successfully created {viewModel.FileResourcesData.Count} new files(s) for {FieldDefinition.Grant.GetFieldDefinitionLabel()} \"{grant.GrantName}\"."); return new ModalDialogFormJsonResult(); }
public void CreateNewFile_with_not_validated_path_throws_InvalidOperationException() { var mockService = Substitute.For <IDreamFileService>(); mockService.FileExists(Arg.Any <string>()).Returns(true); var entityUnderTest = new NewFileViewModel(mockService) { Folder = @"C:\Example\MyFolder", FileName = "??he" }; Action act = () => entityUnderTest.CreateNewFile(); act.Should().ThrowExactly <InvalidOperationException>().WithMessage("Unable to use a path with errors"); }
public void FileAlreadyExists_delegates_to_FileService() { var mockService = Substitute.For <IDreamFileService>(); mockService.FileExists(Arg.Any <string>()).Returns(true); var entityUnderTest = new NewFileViewModel(mockService) { Folder = @"C:\Example\MyFolder", FileName = "here" }; entityUnderTest.FileAlreadyExists.Should().BeTrue(); mockService.Received(1).FileExists(@"C:\Example\MyFolder\here.xml"); }
public async Task <IActionResult> NewFile(string appId, string siteName, string path) { var user = await GetCurrentUserAsync(); var model = new NewFileViewModel(user) { AppId = appId, SiteName = siteName, Path = path }; return(View(model)); }
public async Task OpenFromNewFile(NewFileViewModel file) { CloseModalCommand.Execute(null); if (file == null) { return; } _watcherService.IsSuspended = true; await Task.Run(() => OpenFromNewFileTask(file)).ContinueWith(async(result) => { _watcherService.IsSuspended = false; await _watcherService.RefreshAsync(ActiveProject); await RequestFileOpen(file.FullPath); }); }
public async Task <IActionResult> NewFile(NewFileViewModel model) { var user = await GetCurrentUserAsync(); var file = Request.Form.Files.First(); var app = await _dbContext.Apps.FindAsync(model.AppId); if (app.CreatorId != user.Id) { return(Unauthorized()); } string accessToken = await _appsContainer.AccessToken(app.AppId, app.AppSecret); await _storageService.SaveToProbe(file, model.SiteName, model.Path, SaveFileOptions.SourceName, accessToken); return(RedirectToAction(nameof(ViewFiles), new { appId = model.AppId, siteName = model.SiteName, path = model.Path })); }
private async static void OpenCreateNewFileWindow(WorkspaceItemViewModel workspaceItem, bool isDirectory = false) { if (!workspaceItem.IsDirectory) { throw new ArgumentException("Only directories support the new file command"); } var workspace = workspaceItem.Workspace; IWorkspaceItem newItem; if (isDirectory) { newItem = await workspaceItem.Data.CreateNewDirectory(Language.Current.Get("File.New.Folder")); } else { var window = new NewFileWindow(); var viewModel = new NewFileViewModel(); await viewModel.LoadAsync(); window.DataContext = viewModel; window.Owner = Application.Current.MainWindow; if (window.ShowDialog().Value) { var sel = viewModel.Selected; newItem = await workspaceItem.Data.CreateNewFile(viewModel.Name, "." + sel.Extension, sel.Content); } else { return; } } var vm = new WorkspaceItemViewModel(workspace, workspaceItem, newItem); if (isDirectory) { vm.IsNameChanging = true; } workspaceItem.AddChild(vm); if (!isDirectory) { workspaceItem.Workspace.SelectedItem = vm; } }
public ActionResult Create(NewFileViewModel model, int?id) { if (!ModelState.IsValid) { //filtry //dodal service do obslugi bledow //ViewBag.Message = _helperService.ModelErrorsToString(ModelState); return(Create()); } var userId = User.Identity.GetUserId(); if (id == null) { id = _foldersService.GetRootId(userId); } var id_file = _filesService.AddFile(model, userId, id); return(RedirectToAction("Details", new { Id = id_file })); }
void c_NewFile(object sender, EventArgs e) { NewFileDialog newFileDialogWindow = new NewFileDialog(); var newFileViewModel = new NewFileViewModel(); EventHandler handler = null; handler = delegate { newFileViewModel.RequestClose -= handler; newFileDialogWindow.Close(); if (newFileViewModel.Finished) { viewModel.CreateNewFile(newFileViewModel.FileName); } }; newFileViewModel.RequestClose += handler; newFileDialogWindow.DataContext = newFileViewModel; newFileDialogWindow.ShowDialog(); }
private PartialViewResult ViewNewGrantFiles(NewFileViewModel viewModel) { var viewData = new NewFileViewData(FieldDefinition.Grant.FieldDefinitionDisplayName); return(RazorPartialView <NewFile, NewFileViewData, NewFileViewModel>(viewData, viewModel)); }
public async Task OpenFromNewFileTask(NewFileViewModel file) { Stream stream = null; switch (file.SelectedFile.Type) { case EWolvenKitFile.Redscript: case EWolvenKitFile.Tweak: if (!string.IsNullOrEmpty(file.SelectedFile.Template)) { await using (var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream($"WolvenKit.App.Resources.{file.SelectedFile.Template}")) { stream = new FileStream(file.FullPath, FileMode.Create, FileAccess.Write); resource.CopyTo(stream); } } else { stream = File.Create(file.FullPath); } break; case EWolvenKitFile.Cr2w: var redType = file.SelectedFile.Name; if (redType != "") { var cr2w = new CR2WFile() { RootChunk = RedTypeManager.Create(redType) }; stream = new FileStream(file.FullPath, FileMode.Create, FileAccess.Write); using (var writer = new CR2WWriter(stream)) { writer.WriteFile(cr2w); } } break; } stream.Dispose(); //return Task.CompletedTask; // Open file //await Locator.Current.GetService<AppViewModel>().RequestFileOpen(file.FullPath); //if (file != null) //{ // _progressService.IsIndeterminate = true; // try // { // var fileViewModel = new RedDocumentViewModel(file.FileName); // await using (var stream = new MemoryStream()) // { // file.Extract(stream); // fileViewModel.OpenStream(stream, null); // } // if (!DockedViews.Contains(fileViewModel)) // DockedViews.Add(fileViewModel); // ActiveDocument = fileViewModel; // UpdateTitle(); // } // catch (Exception e) // { // _loggerService.Error(e.Message); // } // finally // { // _progressService.IsIndeterminate = false; // } //} }
private PartialViewResult ViewNewPriorityLandscapeFiles(NewFileViewModel viewModel) { var viewData = new NewFileViewData(FieldDefinition.PriorityLandscape.FieldDefinitionDisplayName); return(RazorPartialView <NewFile, NewFileViewData, NewFileViewModel>(viewData, viewModel)); }
public ActionResult NewPriorityLandscapeFiles(PriorityLandscapePrimaryKey priorityLandscapePrimaryKey, NewFileViewModel viewModel) { var priorityLandscape = priorityLandscapePrimaryKey.EntityObject; if (!ModelState.IsValid) { return(ViewNewPriorityLandscapeFiles(new NewFileViewModel())); } viewModel.UpdateModel(priorityLandscape, CurrentPerson); SetMessageForDisplay($"Successfully created {viewModel.FileResourcesData.Count} new files(s) for {FieldDefinition.PriorityLandscape.GetFieldDefinitionLabel()} \"{priorityLandscape.PriorityLandscapeName}\"."); return(new ModalDialogFormJsonResult()); }
public ActionResult NewInteractionEventFiles(InteractionEventPrimaryKey interactionEventPrimaryKey, NewFileViewModel viewModel) { var interactionEvent = interactionEventPrimaryKey.EntityObject; if (!ModelState.IsValid) { return(ViewNewInteractionEventFiles(new NewFileViewModel())); } viewModel.UpdateModel(interactionEvent, CurrentPerson); SetMessageForDisplay($"Successfully created {viewModel.FileResourcesData.Count} new files(s) for {FieldDefinition.InteractionEvent.GetFieldDefinitionLabel()} \"{interactionEvent.InteractionEventTitle}\"."); return(new ModalDialogFormJsonResult()); }
public void FileName_by_default_is_mydreams() { var entityUnderTest = new NewFileViewModel(Substitute.For <IDreamFileService>()); entityUnderTest.FileName.Should().Be("mydreams.xml"); }