Пример #1
0
        public ExampleService(SenderLookup senderLookup, ReceiverLookup receiverLookup, IOptions <ExampleOptions> options)
        {
            if (string.IsNullOrEmpty(options.Value.Source))
            {
                throw new ArgumentException("Invalid ExampleOptions: Source must have non-empty value.", nameof(options));
            }

            _cloudEventSource = options.Value.Source;

            _userPipeSender          = senderLookup("user-pipe");
            _userPipeReceiver        = receiverLookup("user-pipe");
            _userPipeReceiver.Error += (obj, args) =>
            {
                // Do something when the receiver ecounters an error
                throw new Exception($"Error in the user-pipe receiver: {args.Exception.Message}");
            };

            _workerPipe1Sender          = senderLookup("worker-pipe-1");
            _workerPipe1Receiver        = receiverLookup("worker-pipe-1");
            _workerPipe1Receiver.Error += (obj, args) =>
            {
                // Do something when the receiver ecounters an error
                throw new Exception($"Error in the worker-pipe-1 receiver: {args.Exception.Message}");
            };

            _workerPipe2Sender          = senderLookup("worker-pipe-2");
            _workerPipe2Receiver        = receiverLookup("worker-pipe-2");
            _workerPipe2Receiver.Error += (obj, args) =>
            {
                // Do something when the receiver ecounters an error
                throw new Exception($"Error in the worker-pipe-2 receiver: {args.Exception.Message}");
            };
        }
        public ReceivingService(ReceiverLookup receiverLookup)
        {
            if (receiverLookup == null)
            {
                throw new ArgumentNullException(nameof(receiverLookup));
            }

            DataReceiver = receiverLookup(DataReceiverName)
                           ?? throw new ArgumentException("Must have an IReceiver registered with the name 'DataReceiver'.", nameof(receiverLookup));

            DataReceiver.Connected += (obj, args) =>
            {
                // Do something when the DataReceiver connects to the service
            };
            DataReceiver.Error += (obj, args) =>
            {
                // Do something when the DataReceiver ecounters an error
                throw new Exception($"Error in the DataReceiver: {args.Exception.Message}");
            };
            DataReceiver.Disconnected += (obj, args) =>
            {
                // Do something when the DataReceiver disconnects from the service
            };

            CommandReceiver = receiverLookup(CommandReceiverName)
                              ?? throw new ArgumentException("Must have an IReceiver registered with the name 'CommandReceiver'.", nameof(receiverLookup));

            CommandReceiver.Error += (obj, args) =>
            {
                // Do something when the CommandReceiver ecounters an error
                throw new Exception($"Error in the DataReceiver: {args.Exception.Message}");
            };
        }
        public ReceivingService(ReceiverLookup receiverLookup)
        {
            if (receiverLookup == null)
            {
                throw new ArgumentNullException(nameof(receiverLookup));
            }

            DataReceiver = receiverLookup(DataReceiverName)
                           ?? throw new ArgumentException("Must have an IReceiver registered with the name 'DataReceiver'.", nameof(receiverLookup));

            CommandReceiver = receiverLookup(CommandReceiverName)
                              ?? throw new ArgumentException("Must have an IReceiver registered with the name 'CommandReceiver'.", nameof(receiverLookup));
        }
Пример #4
0
        public ExampleService(SenderLookup senderLookup, ReceiverLookup receiverLookup, IOptions <ExampleOptions> options)
        {
            if (string.IsNullOrEmpty(options.Value.Source))
            {
                throw new ArgumentException("Invalid ExampleOptions: Source must have non-empty value.", nameof(options));
            }

            _cloudEventSource = new Uri(options.Value.Source, UriKind.RelativeOrAbsolute);

            _userPipeSender   = senderLookup("user-pipe");
            _userPipeReceiver = receiverLookup("user-pipe");

            _workerPipe1Sender   = senderLookup("worker-pipe-1");
            _workerPipe1Receiver = receiverLookup("worker-pipe-1");

            _workerPipe2Sender   = senderLookup("worker-pipe-2");
            _workerPipe2Receiver = receiverLookup("worker-pipe-2");
        }