routercontroller.cs

来自「SQL Server 2005 Service Broker (SSB) is 」· CS 代码 · 共 60 行

CS
60
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace SSBExternalActivationRouter
{
    class RouterController
    {
        Dictionary<string, ITransactedMessageMediator> _msgMediators = new Dictionary<string,ITransactedMessageMediator>();
        Dictionary<string, ServiceMessageMapper> _msgMappers = new Dictionary<string,ServiceMessageMapper>();

        RouterControllerSignal _signal = new RouterControllerSignal();

        Thread _threadOperation;

        
        public void Init()
        {
            _msgMediators.Add("TransactedMessageMediator_MSMQ", new TransactedMessageMediator_MSMQ());
            _msgMediators.Add("TransactedMessageMediator_SQL2000", new TransactedMessageMediator_SQL2000());

            _msgMappers.Add("MSMQ", new ServiceMessageMapper("MSMQ", _msgMediators["TransactedMessageMediator_MSMQ"], _signal));
            _msgMappers.Add("SQL2000", new ServiceMessageMapper("SQL2000", _msgMediators["TransactedMessageMediator_SQL2000"], _signal));

        }

        public void Start(StartUpMode mode)
        {
            Init();

            //Spin the mappers on a thread
            switch (mode)
            {
                case StartUpMode.StartMSMQ:
                    _threadOperation = new Thread(_msgMappers["MSMQ"].Run);
                    _threadOperation.Start(); 
                    break;
                case StartUpMode.StartSQL2000:
                    _threadOperation = new Thread(_msgMappers["SQL2000"].Run);
                    _threadOperation.Start();           
                    break;
            }
            
        }

        public void Stop()
        {
            _signal.ContinueProcessing = false;
        }
    }

    enum StartUpMode
    {
        StartMSMQ,
        StartSQL2000
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?