Ejemplo n.º 1
0
        public async Task SubscribeConnectionToModel(string connectionId, string modelId)
        {
            logger.Trace();
            if (_modelSubscriptions.ContainsKey(modelId))
            {
                if (_modelSubscriptions[modelId].Contains(connectionId))
                {
                    logger.Warn($"Tried to subscribe {connectionId} to {modelId} but subscription already existed");
                }
                else
                {
                    _modelSubscriptions[modelId].Add(new ConnectionSubscription()
                    {
                        ConnectionId = connectionId,
                        ModelId      = modelId
                    });
                    logger.Trace($"Added {connectionId} to subscriptions for {modelId}");
                }
            }
            else
            {
                await AppendKnownModel(modelId);

                _modelSubscriptions[modelId].Add(new ConnectionSubscription()
                {
                    ConnectionId = connectionId,
                    ModelId      = modelId
                });
                logger.Trace($"Added {connectionId} to subscriptions for an as of yet unknown model {modelId}");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Endpoint URL for Service Bus
        /// </summary>
        private void Amqc_LineTopicMessage(object sender, OnMessageEventArgs e)
        {
            logger.Trace(sender.ToString() + "Amqc_LineTopicMessage called");
            //OldRouterCode(e.Content, e.Properties["ContentType"] as string);

            //Changes for Configurator DTO.
            var contentType = e.Properties["ContentType"] as string;

            if (contentType.CompareTo(BrokerCommands.CONFIGURE_ROUTES) == 0)
            {
                var isOk = BreanosConnectors.SerializationHelper.TryUnpack(e.Content, out RoutingRequest registrationRequest);
                if (!isOk)
                {
                    logger.Warn($"Unpack not successfull in Amqc_LineTopicMessage");
                }
                if (_router == null)
                {
                    logger.Debug($"_router was initialized in Amqc_LineTopicMessage");
                    _router = new ConfigurableContentTypeRouter();//new ContentTypeRouter(JsonDirectory);
                }

                (_router as ConfigurableContentTypeRouter).Config(registrationRequest);
            }
            RouterCode(e.Content, e.Properties["ContentType"] as string, e.Properties);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handler for AssistentQueue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _activeMqConnector_Message(object sender, BreanosConnectors.Interface.OnMessageEventArgs e)
        {
            logger.Trace();
            if (e == null)
            {
                logger.Error($"Received null message from ActiveMq");
                return;
            }
            if (e.Properties == null)
            {
                logger.Error($"Received message with null properties from ActiveMq");
            }
            if (!e.Properties.ContainsKey("ContentType"))
            {
                logger.Error($"Received a message from amq but did not contain ContentType");
                return;
            }
            logger.Trace($"Message from the AMQ: ContentType: {e.Properties["ContentType"]}; Content: {e.Content}");

            switch (e.Properties["ContentType"])
            {
            case BrokerCommands.KPU_REGISTRATION:
                var isUnpackSuccessful = BreanosConnectors.SerializationHelper.TryUnpack(e.Content, out KpuRegistrationRequest registrationRequest);
                if (isUnpackSuccessful)
                {
                    IncomingKpuRegistration(registrationRequest);
                    SendKpuRegistrationRequestToSecurityService(registrationRequest);
                }
                else
                {
                    logger.Warn($"Could not unpack KpuRegistrationRequest");
                }
                break;

            case BrokerCommands.MODEL_UPDATE:
                var IsUpdate = BreanosConnectors.SerializationHelper.TryUnpack(e.Content, out ModelUpdate[] updates);
                if (IsUpdate)
                {
                    UpdateModelValue(updates);
                }
                else
                {
                    logger.Error($"Could not unpack modelupdate from kpu");
                }
                break;

            case BrokerCommands.PACKAGE:
                var packageKpuId = (string)e.Properties["KpuId"];
                if (_currentKpuPackageRequests.ContainsKey(packageKpuId) && _currentKpuPackageRequests[packageKpuId].Count > 0)
                {
                    foreach (var connection in _currentKpuPackageRequests[packageKpuId])
                    {
                        SendKpuPackage(connection, packageKpuId, e.Content);
                    }
                    _currentKpuPackageRequests[packageKpuId].Clear();
                }
                break;

            case BrokerCommands.REQUESTKPUID:
                logger.Error($"BrokerCommands.REQUESTKPUID has been called. Please hold the line!");
                HandleRequestKPUIdRequest(e.Content);
                break;

            default:
                break;
            }
        }