public static async Task <Notification> GetNotificationAsync(this INotificationSearchService service, string notificationType, TenantIdentity tenant = null, string responseGroup = null) { if (service == null) { throw new ArgumentNullException(nameof(service)); } var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria.NotificationType = notificationType; //try to get with the Tenant criteria.Take = 1; criteria.ResponseGroup = responseGroup; if (tenant != null && !tenant.IsEmpty) { criteria.TenantId = tenant.Id; criteria.TenantType = tenant.Type; } var searchResult = await service.SearchNotificationsAsync(criteria); var result = searchResult?.Results.FirstOrDefault(x => x.TenantIdentity == tenant); if (result == null) { //Find first global notification (without tenant) criteria.TenantId = null; criteria.TenantType = null; searchResult = await service.SearchNotificationsAsync(criteria); result = searchResult?.Results.FirstOrDefault(x => x.TenantIdentity.IsEmpty); } return(result); }
public async Task SearchNotifications_ContainsTwitterNotification() { //Arrange var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria.Take = int.MaxValue; //Act var result = await _notificationSearchService.SearchNotificationsAsync(criteria); //Assert Assert.Contains(result.Results, n => n.Type == nameof(PostTwitterNotification) && n.IsActive.Value); }
public async Task SearchNotifications_ContainsTwitterNotification() { //Arrange var criteria = new NotificationSearchCriteria() { Take = int.MaxValue }; //Act var result = await _notificationSearchService.SearchNotificationsAsync(criteria); //Assert Assert.Contains(result.Results, n => n.Type == nameof(PostTwitterNotification) && n.IsActive); }
public async Task ExportAsync(Stream outStream, ExportImportOptions options, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); using (var sw = new StreamWriter(outStream, System.Text.Encoding.UTF8)) using (var writer = new JsonTextWriter(sw)) { writer.WriteStartObject(); progressInfo.Description = "Notifications exporting..."; progressCallback(progressInfo); var notificationsResult = await _notificationSearchService.SearchNotificationsAsync(new NotificationSearchCriteria { Take = Int32.MaxValue, ResponseGroup = NotificationResponseGroup.Default.ToString() }); writer.WritePropertyName("NotificationsTotalCount"); writer.WriteValue(notificationsResult.TotalCount); writer.WritePropertyName("Notifications"); writer.WriteStartArray(); for (var i = 0; i < notificationsResult.TotalCount; i += _batchSize) { var searchResponse = await _notificationSearchService.SearchNotificationsAsync(new NotificationSearchCriteria { Skip = i, Take = _batchSize, ResponseGroup = NotificationResponseGroup.Full.ToString() }); foreach (var notification in searchResponse.Results) { _serializer.Serialize(writer, notification); } writer.Flush(); progressInfo.Description = $"{ Math.Min(notificationsResult.TotalCount, i + _batchSize) } of { notificationsResult.TotalCount } notifications exported"; progressCallback(progressInfo); } writer.WriteEndArray(); writer.WriteEndObject(); writer.Flush(); } }
public async Task DoExportAsync(Stream outStream, Action <ExportImportProgressInfo> progressCallback, ICancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var progressInfo = new ExportImportProgressInfo { Description = "loading data..." }; progressCallback(progressInfo); using (var sw = new StreamWriter(outStream)) using (var writer = new JsonTextWriter(sw)) { await writer.WriteStartObjectAsync(); progressInfo.Description = "Notifications are started to export"; progressCallback(progressInfo); await writer.WritePropertyNameAsync("Notifications"); await writer.SerializeJsonArrayWithPagingAsync(_jsonSerializer, _batchSize, async (skip, take) => { var searchCriteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); searchCriteria.Take = take; searchCriteria.Skip = skip; searchCriteria.ResponseGroup = NotificationResponseGroup.Full.ToString(); searchCriteria.IsActive = true; var searchResult = await _notificationSearchService.SearchNotificationsAsync(searchCriteria); return((GenericSearchResult <Notification>)searchResult); }, (processedCount, totalCount) => { progressInfo.Description = $"{processedCount} of {totalCount} notifications have been exported"; progressCallback(progressInfo); }, cancellationToken); await writer.WriteEndObjectAsync(); await writer.FlushAsync(); } }
public static async Task <Notification> GetNotificationAsync(this INotificationSearchService service, string notificationType, TenantIdentity tenant = null) { if (service == null) { throw new ArgumentNullException(nameof(service)); } var criteria = AbstractTypeFactory <NotificationSearchCriteria> .TryCreateInstance(); criteria.NotificationType = notificationType; criteria.Take = int.MaxValue; var searchResult = await service.SearchNotificationsAsync(criteria); //Find first global notification (without tenant) var result = searchResult.Results.Where(x => x.TenantIdentity.IsEmpty).FirstOrDefault(); if (tenant != null) { //If tenant is specified try to find a notification belongs to concrete tenant or use default as fallback result = searchResult.Results.Where(x => x.TenantIdentity == tenant).FirstOrDefault() ?? result; } return(result); }
public async Task <IActionResult> GetNotifications(NotificationSearchCriteria searchCriteria) { var notifications = await _notificationSearchService.SearchNotificationsAsync(searchCriteria); return(Ok(notifications)); }
public async Task <ActionResult <NotificationSearchResult> > GetNotifications([FromBody] NotificationSearchCriteria searchCriteria) { var notifications = await _notificationSearchService.SearchNotificationsAsync(searchCriteria); return(Ok(notifications)); }