Пример #1
0
        /// <inheritdoc/>
        public override Task Connect(grpc.PullConnector request, IServerStreamWriter <grpc.PullRequest> responseStream, ServerCallContext context)
        {
            var id            = request.Id.ToGuid();
            var pullConnector = new PullConnector(id, request.Name, request.Interval);

            ITimer timer = null;

            try
            {
                _pullConnectors.Register(pullConnector);

                timer = _timers.Every(pullConnector.Interval, () =>
                {
                    var pullRequest = new grpc.PullRequest();
                    responseStream.WriteAsync(pullRequest);
                });

                context.CancellationToken.ThrowIfCancellationRequested();
                context.CancellationToken.WaitHandle.WaitOne();
            }
            finally
            {
                timer?.Stop();
                timer?.Dispose();

                _pullConnectors.Unregister(pullConnector);
            }

            return(Task.CompletedTask);
        }
Пример #2
0
 /// <inheritdoc/>
 public void Unregister(PullConnector connector)
 {
     if (_connectors.ContainsKey(connector.Id))
     {
         _logger.Information($"Unregister '{connector.Id}'");
         _connectors.TryRemove(connector.Id, out PullConnector _);
     }
     else
     {
         _logger.Warning($"Connector with id '{connector.Id}' is not registered");
     }
 }
Пример #3
0
 /// <inheritdoc/>
 public void Register(PullConnector connector)
 {
     _logger.Information($"Register '{connector.Id}'");
     _connectors[connector.Id] = connector;
 }