Esempio n. 1
0
        private async Task BroadcastOperationAsync(
            ChangeStreamOperationType operationType,
            RecordedEventDocument document
            )
        {
            switch (operationType)
            {
            case ChangeStreamOperationType.Insert:
            {
                var recordedEvent = RecordedEvent.FromDocument(document);
                Console.WriteLine("Broadcasting insert:");
                Console.WriteLine(Encoding.UTF8.GetString(recordedEvent.Data));
                await _hub.Clients.All.EventRecorded(recordedEvent);

                break;
            }

            case ChangeStreamOperationType.Update:
            case ChangeStreamOperationType.Replace:
            case ChangeStreamOperationType.Delete:
            case ChangeStreamOperationType.Invalidate:
            case ChangeStreamOperationType.Rename:
            case ChangeStreamOperationType.Drop:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(operationType), operationType, null);
            }
        }
Esempio n. 2
0
        public static RecordedEvent FromDocument(RecordedEventDocument document)
        {
            var recordedEvent = new RecordedEvent(
                document.Id,
                document.Stream,
                document.EventId,
                document.EventType,
                document.EventNumber,
                document.Created,
                document.Data,
                document.Metadata
                );

            return(recordedEvent);
        }