Example #1
0
 /// <inheritdoc/>
 public void Unregister(PushConnector connector)
 {
     if (_connectors.ContainsKey(connector.Id))
     {
         _logger.Information($"Unregister '{connector.Id}'");
         _connectors.TryRemove(connector.Id, out PushConnector _);
     }
     else
     {
         _logger.Warning($"Connector with id '{connector.Id}' is not registered");
     }
 }
        /// <inheritdoc/>
        public override async Task <Empty> Open(IAsyncStreamReader <grpc.PushTagDataPoints> requestStream, ServerCallContext context)
        {
            var pushConnectorIdAsString = context.RequestHeaders.SingleOrDefault(_ => string.Equals(_.Key, "pushconnectorid", StringComparison.InvariantCultureIgnoreCase))?.Value;

            if (string.IsNullOrEmpty(pushConnectorIdAsString))
            {
                throw new MissingConnectorIdentifierOnRequestHeader();
            }
            var pushConnectorName = context.RequestHeaders.SingleOrDefault(_ => string.Equals(_.Key, "pushconnectorname", StringComparison.InvariantCultureIgnoreCase))?.Value;

            if (string.IsNullOrEmpty(pushConnectorName))
            {
                throw new MissingConnectorNameOnRequestHeader();
            }
            var id = (ConnectorId)Guid.Parse(pushConnectorIdAsString);

            PushConnector pushConnector = null;

            try
            {
                _logger.Information($"Register connector : '{pushConnectorName}' with Id: '{id}'");
                pushConnector = new PushConnector(id, pushConnectorName);
                _pushConnectors.Register(pushConnector);

                while (await requestStream.MoveNext().ConfigureAwait(false))
                {
                    _tagDataPointCoordinator.Handle(pushConnector.Name, requestStream.Current.DataPoints);
                }
            }
            finally
            {
                if (pushConnector != null)
                {
                    _pushConnectors.Unregister(pushConnector);
                }
            }

            return(new Empty());
        }
Example #3
0
 /// <inheritdoc/>
 public void Register(PushConnector connector)
 {
     _logger.Information($"Register '{connector.Id}'");
     _connectors[connector.Id] = connector;
 }