Пример #1
0
            public NodeHandler(Node node)
            {
                Node = node;
                var stateFactory = new StateHandlerFactory(Node);

                foreach (var messageType in stateFactory.TriggerMessageTypes)
                {
                    // Ordinarily the Repository can discover all trigger messages in the RepositoryItem
                    // but since there are multiple types of repo items in this repo, we need to give it
                    // some assistance. The factory tells the repo what triggers it can handle.
                    TriggerMessageTypes.Add(messageType);
                }
                RepoItemFactory = stateFactory.CreateHandler;
            }
        public void Publish(RoutableMessage msg)
        {
            var repoItemMessage = msg as IRoutableMessage <THashKey>;

            if (repoItemMessage != null)
            {
                var       routingHash = repoItemMessage.RoutingTarget;
                TRepoItem repoItem;
                if (RepoItems.TryGetValue(routingHash, out repoItem))
                {
                    repoItem.Publish(msg);
                }

                if (TriggerMessageTypes.Contains(msg.GetType()))
                {
                    var newRepoItem = RepoItemFactory(msg);
                    RepoItems[routingHash] = newRepoItem;
                    newRepoItem.Publish(msg);
                }
            }
        }