예제 #1
0
 //public RequestManager(DBLocator _dbLocator, MsmqConfigInfo _MsmqConfigInfo, List<ssCredentialInfo> _Credentials)
 public RequestManager(DBLocator _dbLocator,string _RequestQ, string _ResponseQ, string _AbandonQ, List<CredentialInfo> _Credentials)
 {
     myDBLocator = _dbLocator;
     //myMSMQConfig = _MsmqConfigInfo;
     myMSMQConfig = new MsmqConfigInfo(_RequestQ, _ResponseQ, _AbandonQ);
     myCredentials = _Credentials;
     //use the logger from our DBContext instance
     m_logger = myDBLocator.GetDBContext().Logger;
 }
예제 #2
0
        static void Main(string[] args)
        {
            //We are going to process the configuration 
            Logger myLogger = new Logger();
            SendMsgToConsole("Message Processor Started", myLogger);

            //get connection string
            AppSettingsReader reader = new AppSettingsReader();
            string connectionString = (string)reader.GetValue("SharingSocialDB", typeof(string)); 
            //set up locator
            DBLocator myDBLocator = new DBLocator(connectionString);

            //MSMQ Values used for ssServiceRequest and Message Processor(s)
            MsmqConfigInfo myMsmqInfo = new MsmqConfigInfo();
            try
            {
                //all or nothing, either we get all these from web.config or we use the default set
                myMsmqInfo.RequestQ = ((string)(reader.GetValue("MSMQ.Request.Q", typeof(string))));
                myMsmqInfo.ResponseQ = ((string)(reader.GetValue("MSMQ.Response.Q", typeof(string))));
                myMsmqInfo.AbandonQ = ((string)(reader.GetValue("MSMQ.Abandon.Q", typeof(string))));
                myMsmqInfo.RequestQFB = ((string)(reader.GetValue("MSMQ.Request.Q.FB", typeof(string))));
            }
            catch
            {
                //get the from default in code
                myMsmqInfo.RequestQ = Common.Constants.DEF_MSMQ_REQUEST_QUEUE;
                myMsmqInfo.ResponseQ = Common.Constants.DEF_MSMQ_RESPONSE_QUEUE;
                myMsmqInfo.AbandonQ = Common.Constants.DEF_MSMQ_ABANDON_QUEUE;
            }
            //create queues if not there.
            if (!MessageQueue.Exists(myMsmqInfo.RequestQ))
            {
                SendMsgToConsole(string.Format("Attempting to create queue {0}",myMsmqInfo.RequestQ), myLogger);
                MessageQueue.Create(myMsmqInfo.RequestQ);
            }
            if (!MessageQueue.Exists(myMsmqInfo.ResponseQ))
            {
                SendMsgToConsole(string.Format("Attempting to create queue {0}", myMsmqInfo.ResponseQ), myLogger);
                MessageQueue.Create(myMsmqInfo.ResponseQ);
            }
            if (!MessageQueue.Exists(myMsmqInfo.AbandonQ))
            {
                SendMsgToConsole(string.Format("Attempting to create queue {0}", myMsmqInfo.AbandonQ), myLogger);
                MessageQueue.Create(myMsmqInfo.AbandonQ);
            }
            if (!MessageQueue.Exists(myMsmqInfo.RequestQFB))
            {
                SendMsgToConsole(string.Format("Attempting to create queue {0}", myMsmqInfo.RequestQFB), myLogger);
                MessageQueue.Create(myMsmqInfo.RequestQFB);
            }

            SendMsgToConsole("Processed Configuration", myLogger);
            //echo config MasterDB
            CredentialInfoSqlServer sqlServerInfo = new CredentialInfoSqlServer(myDBLocator.myMasterDBConnStr);
            SendMsgToConsole(string.Format("Pointing To Server={0}, db={1}", sqlServerInfo.ServerName, sqlServerInfo.DatabaseName), myLogger);

            //read credentials
            List<CredentialInfo> myCredentials = GetCredentials();

            //Start Request wrapper
            string processQ = myMsmqInfo.RequestQ;
            try
            {
                if (args[0] == "fb")
                    processQ = myMsmqInfo.RequestQFB;
                else
                    processQ = myMsmqInfo.RequestQ;
            }
            catch
            {
                processQ = myMsmqInfo.RequestQ;
            }

            //start the manager, each manager will have a different dbcontext generated here.
            RequestManager ReqMgr = new RequestManager(myDBLocator, processQ, myMsmqInfo.ResponseQ, myMsmqInfo.AbandonQ, myCredentials);
            SendMsgToConsole("Request Manager started", myLogger);
            //open queue
            ReqMgr.OpenQueue();
            //listen for messages
            ReqMgr.Start();
            SendMsgToConsole("Request Manager now listening for messages on " + processQ, myLogger);
            string consoleInputStr = string.Empty;
            while (consoleInputStr.ToLower() != "x" && consoleInputStr.ToLower() != "e")
            {
                consoleInputStr = Console.ReadLine();
                if (consoleInputStr.ToLower() == "x" || consoleInputStr.ToLower() == "e")
                {
                    Console.WriteLine("[{0}]-[{1}]", DateTime.Now, "Press the Y to confirm"); 
                    if (Console.ReadLine().ToLower() == "y")
                    {
                        while (ReqMgr.IsProcessing)
                        {
                            SendMsgToConsole("Waiting for Request to complete processing", myLogger);
                            Thread.Sleep(1500);
                        }
                        SendMsgToConsole("Processing has been completed, now terminating", myLogger);
                    }
                    else
                        consoleInputStr = string.Empty;
                }
            }
            ReqMgr.Stop();
            SendMsgToConsole("Processor Terminated", myLogger);
        }