public async Task HandleAsync(CreateNoteInSqliteCommand command) { using (var context = _factory.CreateContext()) { var note = _mapper.MapTo <Note>(command); note.Id = Guid.NewGuid(); note.NeedSynchronization = true; note.StatusSynchronization = SynchronizationStatusEnum.NeedInsert; try { var(lot, lat) = await _geolocationService.GeLocationAsync(); note.Latitude = lat; note.Longitude = lot; } catch (PermissionException) { } note.CreatedAt = DateTime.UtcNow; await context.AddAsync(note); await context.SaveChangesAsync(); NPublisher.PublishIt(new NewNotesMessage(note)); } }
public async Task HandleAsync(LoginCommand command) { var result = await _apiWebService.SendAsync <JwtDto>(HttpMethod.Post, Endpoints.Login, command); _apiWebSettings.JwtDto = result; NPublisher.PublishIt <LoggedMessage>(); }
private async Task FetchAllResultsAsync(Domain.Synchronization.Synchronization synchronization, NoteMeContext context, CancellationToken cts) { cts.ThrowIfCancellationRequested(); var syncDate = synchronization.LastSynchronization; var hasMore = false; var allNotes = new List <Note>(); do { var filterBy = $@"{nameof(Note.CreatedAt)} > ""{syncDate}"""; var orderBy = $"{nameof(Note.CreatedAt)}-desc"; var query = new GetNotesQuery() .SetNormalWhere(filterBy) .SetNormalOrderBy(orderBy); var notes = await _webService.SendAsync <PaginationDto <NoteDto> >(HttpMethod.Get, Endpoints.Notes._ + query.ToUri()); if (!notes.Data.Any() && !allNotes.Any()) { return; } hasMore = notes.Data.Count == query.PageSize; foreach (var noteDto in notes.Data) { var note = await context.Notes.FirstOrDefaultAsync(x => x.Id == noteDto.Id, cts); if (note != null) { note.Content = noteDto.Content; note.Tags = noteDto.Tags; note.Name = noteDto.Name; } else { note = _mapper.MapTo <Note>(noteDto); if (note.Status == StatusEnum.Normal) { allNotes.Add(note); } await context.AddRangeAsync(note); } } } while (hasMore); await context.SaveChangesAsync(cts); NPublisher.PublishIt(new NewNotesMessage(allNotes)); }
public async Task NPubilsher_Static_Should_SubscribeTypeOfMessage() { var ts = new TaskCompletionSource <TestMessage>(); var ok = false; var subscription = NPublisher.SubscribeIt <TestMessage>(x => { ok = true; ts.SetResult(x); }); NPublisher.PublishIt <TestMessage>(); await ts.Task; ok.Should().BeTrue(); }
public async Task NPubilsher_Static_Should_Unsubscribe() { var ts = new TaskCompletionSource <TestMessageForUnsubscribe>(); var ok = false; var subscription = NPublisher.SubscribeIt <TestMessageForUnsubscribe>(x => { ok = !ok; ts.SetResult(x); }); NPublisher.PublishIt <TestMessageForUnsubscribe>(); var result = await ts.Task; NPublisher.UnsubscribeIt(subscription); NPublisher.PublishIt <TestMessageForUnsubscribe>(); ok.Should().Be(true); }
public async Task NPubilsher_Static_Should_SubscribeTypeOfMessageWithContent() { var ts = new TaskCompletionSource <TestMessageWithContent>(); var ok = false; var message = new TestMessageWithContent("sample_data"); var subscription = NPublisher.SubscribeIt <TestMessageWithContent>(x => { ok = true; ts.SetResult(x); x.Should().Be(message); }); NPublisher.PublishIt(message); var result = await ts.Task; result.Content.Should().Be(message.Content); result.Should().Be(message); }
private void LogoutMenuItem_OnClicked(object sender, EventArgs e) { NPublisher.PublishIt <LogoutMessage>(); }
public async Task HandleAsync(LogoutUserCommand command) { NPublisher.PublishIt <LogoutMessage>(); }
public LogoutView() { NPublisher.PublishIt <LogoutMessage>(); InitializeComponent(); }