Пример #1
0
        void  timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timer.Stop();

            if (initializationAttempted == false)
            {
                //#region WaitForStartupNotificaton
                //String waitForStartup = ConfigurationSettings.AppSettings["WaitForStartup"];
                //String startupKey = ConfigurationSettings.AppSettings["StartupKey"];
                //String startupValue = ConfigurationSettings.AppSettings["StartupValue"];
                //double startupWaitPeriod = Convert.ToDouble(ConfigurationSettings.AppSettings["StartupWaitPeriod"]);
                
                //if (waitForStartup == "Yes")
                //{
                //    if (waitingForStartup == false)
                //    {
                //        addMsg("Waiting For Startup ");
                //        waitingForStartup = true;
                //    }
                //    String status = dataAccess.getConfigValue(startupKey);
                //    if (status != startupValue)
                //    {
                //        timer.Interval = startupWaitPeriod;
                //        timer.Start();
                //        return;

                //    }
                    
                //    addMsg("Received Startup");

                //}
                //#endregion

                if (gsmPort == String.Empty)
                {
                    addMsg("Attempting Initialzation....");
                }
                else
                {
                    addMsg("Attempting Initialization on Port: " + gsmPort);
                }

                sms = new SMS(addMsg);

                bool result = sms.initialize(gsmPort);

                if (result == false)
                {
                    addMsg("Initialization Failed !! ");
                }
                else
                {
                    addMsg("Initialization Successful");
                    
                    //timer.Interval = timerTick * 1000;
                    timer.Start();

                }
                initializationAttempted = true;
            }
            else
            {
                DataTable dt = dataAccess.getOpenSMSAlerts();

                if (dt.Rows.Count > 0)
                {
                    Dictionary<String, ArrayList> smsList = new Dictionary<string, ArrayList>();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        String message = (String)dt.Rows[i]["message"];
                        String receiver = (String)dt.Rows[i]["receiver"];
                        if (smsList.ContainsKey(message))
                        {
                            smsList[message].Add(receiver);
                        }
                        else
                        {
                            ArrayList receiverList = new ArrayList();
                            receiverList.Add(receiver);
                            smsList.Add(message, receiverList);
                        }
                    }

                    foreach (KeyValuePair<String, ArrayList> smsMsg in smsList)
                    {
                        sms.send(smsMsg.Key, smsMsg.Value);
                    }


                }
                timer.Start(); 
            }
	        
        }