/// <summary>
 /// Configure specific routes for each component.  This method must be updated for each routing configuration change.
 /// The publish nodes are for testing the simulation and documenting the expected interconnections.
 /// The subscribe nodes configure expected topics for this node.
 /// 
 /// Each subscriptions is a separate binding to the component's internal queue.
 /// </summary>
 /// <remarks>
 ///                         [To]          [From]
 /// 
 /// Controller Publish:     [Memory]     .[Controller]
 /// Memory Publish:         [Controller] .[Memory]
 ///                                                   
 /// Controller Subscribe:   [Controller] .[*]
 /// Memory Subscribe:       [Memory]     .[*]
 /// </remarks>
 /// <param name="service">host service to facilitate access to all properties</param>
 /// <returns></returns>
 public static NodeInterface BuildNode(NodeServiceBase service)
 {
     NodeInterface node = new NodeInterface(service);
     switch (service.thisComponent)
     {
         case SystemNode.Controller:
             node.Publish.Add(node.RouteKey(service.thisComponent, SystemNode.Environment));
             node.Publish.Add(node.RouteKey(service.thisComponent,SystemNode.Memory));
             node.Subscribe.Add(node.RouteKey(SystemNode.Environment, service.thisComponent));
             node.Subscribe.Add(node.RouteKey(SystemNode.Memory, service.thisComponent));
             break;
         case SystemNode.Environment:
             node.Publish.Add(node.RouteKey(service.thisComponent,SystemNode.Controller));
             node.Subscribe.Add(node.RouteKey(SystemNode.Controller,service.thisComponent));
             break;
         case SystemNode.Memory:
             node.Publish.Add(node.RouteKey(service.thisComponent,SystemNode.Controller));
             node.Subscribe.Add(node.RouteKey(SystemNode.Controller,service.thisComponent));
             break;
         default:
             break;
     }
     node.QueueConfiguration(service);       //  define the queue subscription topics
     return (node);
 }
 /// <summary>
 /// 
 /// </summary>
 public void QueueConfiguration(NodeServiceBase _service)
 {
     try
     {
         Func<IMessage<NodeMessage>, MessageReceivedInfo, Task> msghandler =
             new Func<IMessage<NodeMessage>, MessageReceivedInfo, Task>(_service.ServiceMessageHandler);
                                         //  (3) Mailbox/Queue Declarations for subscribing to messages
         IQueue queue =  Queue.DeclareTransient("Q_" + this.thisComponent.ToString());
         queue.BindTo(this.memoryExchange,  this.Subscribe.ToArray());        //  (3a) Bind Mailbox(s) to MTA - declaring the RoutingKey/routing pattern to accept for this queue
         MQNetwork.mqQueue(queue, msghandler);   //  (3b) Create Queue to memory Client Bus
     }
     catch (Exception)
     {
     }
 }
        /// <summary>
        /// Default Constructor-connect to service bus
        /// <list type="bullet">Memory Exchange Construction
        ///     <item>Start the publishing task</item>
        ///     <item>Topic Routing - requires node based RouteKey</item>
        ///     <item>Auto-delete (exchange andQueues are deleted when all queues have closed)</item>
        /// </list>
        /// <list type="bullet">Local Persistent Exchange Construction
        ///     <item>Topic Routing - requires node based RouteKey</item>
        ///     <item>Durable (exchange & Queues persist)</item>
        /// </list>
        /// <list type="bullet">Queue Construction
        ///     <item>Instantiate uniquely named transient queue</item>
        ///     <item>Bind the queue to the exchange</item>
        /// </list>
        /// </summary>
        /// 
        /// <param name="_service">
        /// <list type="bullet">Host service for this node interface, for directly accessing following:
        ///     <item>Cancellation token for process control by owning process</item>
        ///     <item>Message handler to be invoked by the incoming topic queue</item>
        ///     <item>Service component type for queue naming and topic routing identification</item>
        /// </list>
        /// </param>
        /// <param name="_topology">Define Exchange type to be used by this node  </param>
        public NodeInterface(NodeServiceBase _service)
        {
            #region Node Overhead
            this.m_cancellation = _service.m_nodetoken;                              //  cancellation token
            this.m_outgoingqueue = new BlockingCollection<IMessage<NodeMessage>>(this.m_outgoingqueuebase);

            m_messaging[1] = new Task(() => { this.PublishQueuedMessage(); }, TaskCreationOptions.LongRunning);
            m_messaging[1].Start();        //  asynchronous start
            #endregion
            #region Exchange Configuration
            this.thisComponent = _service.thisComponent;   //  this node identifier
            this.SubscriptionTopics.Add(this.thisComponent.ToString() + MQNetwork.Wildcard);
            this.memoryExchange =               //  (2) Instantiate Topic Only MTA - routes on a routing pattern and is deleted when all references close.
                Exchange.DeclareTopic(ConfigurationManager.AppSettings["SBmemoryExchange"]);
            #endregion
        }