示例#1
0
        public XNodeEventService(ILogger <SystemService> logger,
                                 string agentId,
                                 XNodeConfiguration nodeConfig,
                                 DataStorageConfiguration dataStorageConfig,
                                 AgentConfiguration agentConfiguration,
                                 IXNodeConnectionRepository xNodeConnectionRepository,
                                 TenantIOService tenantIOService,
                                 ProducerIOService producerIOService,
                                 ConsumerIOService consumerIOService,
                                 MessageIOService messageIOService)
        {
            this.logger = logger;
            this.xNodeConnectionRepository = xNodeConnectionRepository;
            this.tenantIOService           = tenantIOService;
            this.producerIOService         = producerIOService;
            this.consumerIOService         = consumerIOService;
            this.messageIOService          = messageIOService;
            this.agentId    = agentId;
            this.nodeConfig = nodeConfig;

            var provider = new XNodeConnectionProvider(nodeConfig, dataStorageConfig, agentConfiguration, agentId);

            _connection = provider.GetHubConnection();

            _connection.On <AgentConnectedArgs>("StorageConnected", connectedArgs => StorageConnected?.Invoke(connectedArgs));
            _connection.On <AgentDisconnectedArgs>("StorageDisconnected", disconnectedArgs => StorageDisconnected?.Invoke(disconnectedArgs));

            _connection.On <TenantCreatedArgs>("TenantCreated", tenantCreated => TenantCreated?.Invoke(tenantCreated));
            _connection.On <TenantUpdatedArgs>("TenantUpdated", tenantUpdated => TenantUpdated?.Invoke(tenantUpdated));

            _connection.On <ProductCreatedArgs>("ProductCreated", productCreated => ProductCreated?.Invoke(productCreated));
            _connection.On <ProductUpdatedArgs>("ProductUpdated", productUpdated => ProductUpdated?.Invoke(productUpdated));

            _connection.On <ComponentCreatedArgs>("ComponentCreated", componentCreated => ComponentCreated?.Invoke(componentCreated));
            _connection.On <ComponentUpdatedArgs>("ComponentUpdated", componentUpdated => ComponentUpdated?.Invoke(componentUpdated));

            _connection.On <TopicCreatedArgs>("TopicCreated", topicCreated => TopicCreated?.Invoke(topicCreated));
            _connection.On <TopicUpdatedArgs>("TopicUpdated", topicUpdated => TopicUpdated?.Invoke(topicUpdated));

            _connection.On <ProducerConnectedArgs>("ProducerConnected", producerConnected => ProducerConnected?.Invoke(producerConnected));
            _connection.On <ProducerDisconnectedArgs>("ProducerDisconnected", producerDisconnected => ProducerDisconnected?.Invoke(producerDisconnected));

            _connection.On <ConsumerConnectedArgs>("ConsumerConnected", consumerConnected => ConsumerConnected?.Invoke(consumerConnected));
            _connection.On <ConsumerDisconnectedArgs>("ConsumerDisconnected", consumerDisconnected => ConsumerDisconnected?.Invoke(consumerDisconnected));
            _connection.On <ConsumerConnectedArgs>("ConsumerUnacknowledgedMessagesRequested", consumerConnected => ConsumerUnacknowledgedMessagesRequested?.Invoke(consumerConnected));
            _connection.On <MessageAcknowledgedArgs>("MessageAcknowledged", messageAcked => MessageAcknowledged?.Invoke(messageAcked));

            _connection.On <MessageStoredArgs>("MessageStored", msgStored => MessageStored?.Invoke(msgStored));

            InitializeEventHandlers();

            ConnectAsync();

            xNodeConnectionRepository.AddService(nodeConfig.ServiceUrl, agentId, this);
        }
示例#2
0
        /// <summary>
        /// Method for updating an existing <see cref="Topic"/>.
        /// </summary>
        /// <param name="topicId">The Id of the topic.</param>
        /// <param name="subject">The updated subject.</param>
        /// <param name="text">The updated text.</param>
        /// <param name="type">The updated type.</param>
        /// <param name="state">The updated state.</param>
        /// <returns>The updated topic.</returns>
        /// <exception cref="ArgumentNullException">If the topicId or subject arguments are null/empty.</exception>
        /// <exception cref="PermissionException">If the current user does not have access.</exception>
        public Topic Update(String topicId, String subject, String text, TopicType?type = default(TopicType?), TopicState?state = default(TopicState?))
        {
            if (String.IsNullOrWhiteSpace(topicId))
            {
                throw new ArgumentNullException(nameof(topicId));
            }
            if (String.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentNullException(nameof(subject));
            }

            this.loggingService.Application.DebugWriteFormat("Update called on TopicService, topicId: {0}", topicId);

            IAuthenticatedUser currentUser = this.userProvider.CurrentUser;

            if (currentUser == null /* TODO !currentUser.Can(this.permissionService)*/)
            {
                this.loggingService.Application.DebugWriteFormat("User does not have permissions to update the topic, topicId: {0}", topicId);
                throw new PermissionException("update topic", currentUser);
            }

            Topic topic = this.FindById(topicId);

            topic = this.Update(currentUser.Id, topicId, subject, text, type.HasValue ? type.Value : topic.Type, topic.State);

            // TODO:
            TopicUpdated afterEvent = new TopicUpdated {
                //Subject = output.Subject,
                //Text = output.Text,
                //Type = output.
                //ForumId = output.Id,
                //Author = this.userProvider.CurrentUser
            };

            this.eventPublisher.Publish <TopicUpdated>(afterEvent);

            return(topic);
        }