コード例 #1
0
        public void DoExport(Stream outStream, PlatformExportManifest manifest, Action <ExportImportProgressInfo> progressCallback,
                             CancellationToken cancellationToken)
        {
            if (manifest == null)
            {
                throw new ArgumentNullException("manifest");
            }

            if (cancellationToken.IsCancellationRequested)
            {
                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 = _notificationSearchService.SearchNotifications(new NotificationSearchCriteria {
                        Take = Int32.MaxValue, ResponseGroup = NotificationResponseGroup.Default.ToString()
                    });
                    writer.WritePropertyName("NotificationsTotalCount");
                    writer.WriteValue(notificationsResult.TotalCount);

                    if (cancellationToken.IsCancellationRequested)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                    }

                    writer.WritePropertyName("Notifications");
                    writer.WriteStartArray();
                    for (var i = 0; i < notificationsResult.TotalCount; i += _batchSize)
                    {
                        var searchResponse = _notificationSearchService.SearchNotifications(new NotificationSearchCriteria {
                            Skip = i, Take = _batchSize, ResponseGroup = NotificationResponseGroup.Full.ToString()
                        });

                        foreach (var notification in searchResponse.Results)
                        {
                            GetJsonSerializer().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();
                }
        }
コード例 #2
0
        public void SearchNotifications_ContainsTwitterNotification()
        {
            //Arrange
            var criteria = new NotificationSearchCriteria()
            {
                Take = int.MaxValue
            };

            //Act
            var result = _notificationSearchService.SearchNotifications(criteria);

            //Assert
            Assert.Contains(result.Results, n => n.Type == nameof(PostTwitterNotification) && n.IsActive);
        }
コード例 #3
0
        public IActionResult GetNotifications(NotificationSearchCriteria searchCriteria)
        {
            var notifications = _notificationSearchService.SearchNotifications(searchCriteria);

            return(Ok(notifications));
        }