private async Task DisplayFile(int id) { if ((await RestService.Execute <SingleFileDto>(HttpMethod.Get, $"files/{id}", null, FileEditorAppContext.LoggedUser.JwtToken)) is SingleFileDto result) { SingleFileDto = result; } }
public void Run(bool calledFromCodeEditor = false) { var selectedItem = calledFromCodeEditor ? getCodeEditorItem() : getSelectedSolutionExplorerItem(); var filePath = selectedItem.Properties.Item("FullPath").Value.ToString(); if (!string.IsNullOrWhiteSpace(filePath)) { _projects.Clear(); var selectedProject = selectedItem.ContainingProject; var allSources = getAllProjectItems(selectedProject.ProjectItems) .Where(v => v.Name.Contains(".cs")) .Select(s => s.Properties.Item("FullPath").Value.ToString()) .Except(new[] { filePath }); var allProjects = getAllSolutionProjects(selectedProject); SingleFileDto singleFileDialog = null; Action <string, string> saveFile = (projectName, dtoFilePath) => { if (!string.IsNullOrWhiteSpace(dtoFilePath)) { try { var dtoProject = _projects[projectName]; dtoProject.ProjectItems.AddFromFile(dtoFilePath); } catch (Exception ex) { var message = ex.Message; } finally { singleFileDialog?.Close(); } } }; var viewModel = new SingleFileDtoViewModel( new SingleFileProcessor(), new CodeGenerator(), filePath, allProjects, allSources, saveFile); singleFileDialog = new SingleFileDto(viewModel); singleFileDialog.ShowModal(); } }
private async Task SaveChanges() { if (SingleFileDto.Id == 0) { return; } if (SingleFileDto.Filename.IsNullOrEmpty()) { return; } var updateFileCommand = new UpdateFileCommand { Content = SingleFileDto.Content, Filename = SingleFileDto.Filename, Id = SingleFileDto.Id }; if ((await RestService.Execute <SuccessEvent>(HttpMethod.Put, "files", updateFileCommand, FileEditorAppContext.LoggedUser.JwtToken)) is SuccessEvent @event) { SingleFileDto = new SingleFileDto { Content = "", Id = 0, Filename = "" }; await OnInitializedAsync(); } }