private async Task <int> CreateNote(string noteId, string textToWrite) { if (string.IsNullOrWhiteSpace(noteId)) { mLogger.LogError("No task id given to create note"); return(1); } if (textToWrite == null) { textToWrite = string.Empty; } NoteResource noteResource = new NoteResource { NotePath = noteId, Text = textToWrite, PossibleNotes = null }; using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, TaskerUris.NotesUri) { Content = new StringContent(JsonConvert.SerializeObject(noteResource), Encoding.UTF8, PostMediaType) }; NoteResource noteResourceResponse = await HttpMessageRequester.SendHttpRequestMessage <NoteResource>( mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false); if (noteResourceResponse != null) { mLogger.LogInformation($"Created new note {noteResourceResponse.NotePath}"); } return(0); }
public async Task GetPrivateNoteAsync_ValidNoteIdentifier_CorrectNoteTextIsGiven(string noteIdentifier, string expectedText) { using TestServer testServer = ApiTestHelper.CreateTestServerWithFakeDatabaseConfig(); using HttpClient httpClient = testServer.CreateClient(); using HttpResponseMessage response = await httpClient.GetAsync($"{MainRoute}/note/{noteIdentifier}").ConfigureAwait(false); response.EnsureSuccessStatusCode(); NoteResource noteResource = JsonConvert.DeserializeObject <NoteResource>( await response.Content.ReadAsStringAsync().ConfigureAwait(false)); Assert.Equal(expectedText, noteResource.Text); }
public Note MapResourceToEntity(NoteResource <NewNoteAttributes> resource) { if (resource == null) { return(null); } var attributes = resource.Attributes ?? new NewNoteAttributes(); return(new Note() { Text = attributes.Text, Creator = attributes.Creator, CreatedOn = DateTime.Now }); }
public async Task <IActionResult> PutNoteAsync([FromBody] NoteResource noteResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } if (noteResource == null) { return(BadRequest($"Parameter {nameof(noteResource)} is null")); } IEnumerable <IWorkTask> workTasks = await mWorkTaskService.FindWorkTasksByConditionAsync(task => task.ID == noteResource.NotePath) .ConfigureAwait(false); if (!workTasks.Any()) { return(StatusCode(StatusCodes.Status405MethodNotAllowed, $"Could not find work task {noteResource.NotePath}")); } mLogger.LogDebug($"Requesting putting new note {noteResource.NotePath}"); IWorkTask firstWorkTask = workTasks.First(); string noteName = $"{firstWorkTask.ID}-{firstWorkTask.Description}{AppConsts.NoteExtension}"; try { IResponse <NoteResourceResponse> result = await mNoteService.CreatePrivateNote(noteName, noteResource.Text).ConfigureAwait(false); NoteResource noteResourceResult = mMapper.Map <NoteResourceResponse, NoteResource>(result.ResponseObject); if (!result.IsSuccess) { return(StatusCode(StatusCodes.Status405MethodNotAllowed, result.Message)); } return(Ok(noteResourceResult)); } catch (Exception ex) { mLogger.LogError(ex, "Put operation failed with error"); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
private bool Open(NoteResource note) { ProcessStartInfo startInfo = new ProcessStartInfo(mNoteClientViewer) { UseShellExecute = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden, Arguments = $"\"{note.NotePath}\"", }; using Process process = new Process { StartInfo = startInfo, }; process.Start(); return(true); }
private async Task PrintNoteText(string noteName, bool isPrivateNote) { NoteResource noteResource = await NotesProvider.GetNoteResource(mHttpClient, noteName, isPrivateNote, mLogger) .ConfigureAwait(false); if (noteResource == null) { mLogger.LogError($"Could not find note {noteName}"); return; } if (noteResource.IsMoreThanOneNoteFound()) { mConsolePrinter.Print(noteResource.PossibleNotes, "Found the next possible notes"); return; } mConsolePrinter.Print(noteResource.Text, $"NotePath: {Environment.NewLine}{noteResource.NotePath}{Environment.NewLine}"); }
public async Task <IActionResult> GetPrivateNoteAsync(string noteIdentifier) { if (string.IsNullOrEmpty(noteIdentifier)) { return(BadRequest("Note is null or empty")); } noteIdentifier = GetFixedNotePath(noteIdentifier); mLogger.LogDebug($"Requesting text of private note {noteIdentifier}"); try { IResponse <NoteResourceResponse> result = await mNoteService.GetTaskNote(noteIdentifier).ConfigureAwait(false); mLogger.LogDebug($"Get result {(result.IsSuccess ? "succeeded" : "failed")}"); if (!result.IsSuccess) { return(StatusCode(StatusCodes.Status404NotFound, result.Message)); } NoteResource noteResource = mMapper.Map <NoteResourceResponse, NoteResource>(result.ResponseObject); if (noteResource.IsMoreThanOneNoteFound) { mLogger.LogDebug($"Found more than one note for {noteIdentifier}"); } else { mLogger.LogDebug($"Found note at path {result.ResponseObject.Note.NotePath}"); } return(Ok(noteResource)); } catch (Exception ex) { mLogger.LogError(ex, "Update operation failed with error"); return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
private async Task <int> OpenNote(string noteName, bool isPrivateNote) { if (string.IsNullOrWhiteSpace(noteName)) { mLogger.LogError($"{nameof(noteName)} is null or whitespace. Invalid note name."); return(1); } NoteResource noteResource = await NotesProvider.GetNoteResource( mHttpClient, noteName, isPrivateNote, mLogger).ConfigureAwait(false); if (noteResource == null) { mLogger.LogError($"Could not find note {noteName}"); return(1); } if (noteResource.IsMoreThanOneNoteFound()) { StringBuilder stringBuilder = new StringBuilder(); noteResource.PossibleNotes.ToList().ForEach(note => stringBuilder.AppendLine(note)); mLogger.LogInformation($"Found the next possible notes: {stringBuilder}"); return(0); } bool isOpenSuccess = Open(noteResource); if (!isOpenSuccess) { mLogger.LogError($"Could not open note {noteResource.NotePath}"); } mLogger.LogInformation($"Note {noteResource.NotePath} opened"); return(0); }