コード例 #1
0
        /// <summary>
        /// Send Mail
        /// </summary>
        /// <returns></returns>
        public NotifyComResponse Send(INotifyObject notifyObject)
        {
            notifyComResponse = new NotifyComResponse();
            try
            {
                _snppServer     = notifyObject.NotifierSettings["SNPPServer"].ToStr();
                _snppPort       = notifyObject.NotifierSettings["SNPPPort"].ToInt();
                _pagerSubject   = notifyObject.NotifierSettings["PagerSubject"].ToStr();
                _pagerToAddress = notifyObject.NotifierSettings["ToAddress"].ToStr();
                _name           = notifyObject.NotifierSettings["Name"].ToStr();
                _pagerBody      = notifyObject.NotificationData.ToStr();



                /*Send notification to Pager using SNPP Server*/
                try
                {
                    if (notifyObject.NotifierSettings["DeliveryMethod"].ToInt() != 1)
                    {
                        string phone        = notifyObject.NotifierSettings["ToAddress"].ToStr();
                        int    pagerDelay   = notifyObject.NotifierSettings["PagerDelay"].ToInt();
                        string pagerMessage = notifyObject.NotifierSettings["PagerMessage"].ToStr();
                        string comPortId    = notifyObject.NotifierSettings["PagerComPort"].ToStr();

                        Int16 attemptCount = notifyObject.NotifierSettings["AttemptCount"].ToInt16();
                        attemptCount++;
                        notifyObject.NotifierSettings["AttemptCount"] = attemptCount;
                        notifyObject.NotifierSettings["LastSentTime"] = DateTime.Now;

                        Message = " Attempt: " + attemptCount.ToString();

                        sendPageTime = DateTime.Now;

                        /*
                         * "2400,n,8,1"
                         * 1st baud rate
                         * 2nd parity
                         * 3rd data bits
                         * 4th stop bit*/


                        IOPort.ComSettings comSettings = new IOPort.ComSettings();
                        comSettings.BaudRate  = 2400;
                        comSettings.ParityBit = System.IO.Ports.Parity.Even;
                        comSettings.DataBits  = 8;
                        comSettings.StopBit   = System.IO.Ports.StopBits.One;



                        int n = 0;
                        //COMcmds[n++] = "1~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        //COMcmds[n++] = ".3~+~.1";

                        //COMcmds[n++] = ".5~ATH~3";          // Hang-up if connected
                        COMcmds[n++] = ".5~ATH~3";          // Hang-up if connected
                        COMcmds[n++] = ".5~ATZ~3";          // Reset modem
                        COMcmds[n++] = ".5~ATL0M0~3";       // Disable modem speaker / sounds
                        COMcmds[n++] = ".5~ATE0~3";         //Turn off echoing

                        if (notifyObject.NotifierSettings["COMportInitString"].ToStr().Length > 0)
                        {
                            COMcmds[n++] = ".5~" + notifyObject.NotifierSettings["COMportInitString"].ToStr() + "~1";
                        }

                        //If Len(InitString) Then COMcmds[n] = ".5~" & InitString & "~1";
                        COMcmds[n++] = ".5~ATDT" + phone + new System.Text.StringBuilder().Append(',', pagerDelay).ToString() + pagerMessage + "~40";
                        //COMcmds[n++] = "0~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        //COMcmds[n++] = ".3~+~.1";
                        COMcmds[n++] = ".5~ATH~3";
                        nCOMcmds     = n;

                        comPort = new IOPort();//for COMM port


                        //ping the com port
                        comPort.Handshake("COM" + comPortId, comSettings, DataRecieveFromCom);


                        SendCommand();
                    }
                    else
                    {
                        //snnpObj = new KTGUtil.SNPP();
                        using (SNPPWrapper snppObj = new SNPPWrapper())
                        {
                            /*SNPP Host*/
                            snppObj.Host = _snppServer;

                            /*SNPP Port Number*/
                            snppObj.Port = _snppPort;

                            /*Subject*/
                            snppObj.Subject = _pagerSubject;

                            /*Body*/
                            snppObj.Body = _pagerBody;

                            /*Pager To Address*/
                            snppObj.SendTo = _pagerToAddress;

                            /*Send information to pager*/
                            int res = snppObj.Send();
                            ProcessCompleted = true;



                            if (res == 0)
                            {
                                /*Record notify response*/
                                notifyComResponse.IsError         = false;
                                notifyComResponse.IsSucceeded     = true;
                                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", sent successfully.";
                            }
                            else
                            {
                                notifyComResponse.IsError         = true;
                                notifyComResponse.IsSucceeded     = false;
                                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Error:." + snppObj.LastErrorText;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    /*Record notify response*/
                    notifyComResponse.IsError         = true;
                    notifyComResponse.IsSucceeded     = false;
                    notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                    Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                    ProcessCompleted = true;
                    /*Debug Object values for reference*/
                    LogBook.Debug(notifyComResponse, this);

                    /*Write exception log*/
                    LogBook.Write("Error has occurred while sending pager to ." + _pagerToAddress, ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
                }
            }
            catch (Exception ex)
            {
                /*Record notify response*/
                notifyComResponse.IsError         = true;
                notifyComResponse.IsSucceeded     = true;
                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                ProcessCompleted = true;
                /*Debug Object values for reference*/
                LogBook.Debug(notifyComResponse, this);

                /*Write exception log*/
                LogBook.Write("Error has occurred while preparing SNPP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
            }
            return(notifyComResponse);
        }
コード例 #2
0
        public NotifyComResponse Send()
        {
            notifyComResponse = new NotifyComResponse();
            try
            {
                /*Send notification to Pager using SNPP Server*/
                try
                {
                    //snnpObj = new KTGUtil.SNPP();
                    using (SNPPWrapper snppObj = new SNPPWrapper())
                    {
                        /*SNPP Host*/
                        snppObj.Host = _snppServer;

                        /*SNPP Port Number*/
                        snppObj.Port = _snppPort;

                        /*Subject*/
                        snppObj.Subject = _pagerSubject;

                        /*Body*/
                        snppObj.Body = _pagerBody;

                        /*Pager To Address*/
                        snppObj.SendTo = _pagerToAddress;

                        /*Send information to pager*/
                        int res = snppObj.Send();
                        ProcessCompleted = true;



                        if (res == 0)
                        {
                            /*Record notify response*/
                            notifyComResponse.IsError         = false;
                            notifyComResponse.IsSucceeded     = true;
                            notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", sent successfully.";
                        }
                        else
                        {
                            notifyComResponse.IsError         = true;
                            notifyComResponse.IsSucceeded     = false;
                            notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Error:." + snppObj.LastErrorText;
                        }
                    }
                }

                catch (Exception ex)
                {
                    /*Record notify response*/
                    notifyComResponse.IsError         = true;
                    notifyComResponse.IsSucceeded     = false;
                    notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                    Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                    ProcessCompleted = true;
                    /*Debug Object values for reference*/
                    LogBook.Debug(notifyComResponse, this);

                    /*Write exception log*/
                    LogBook.Write("Error has occurred while sending pager to ." + _pagerToAddress, ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
                }
            }
            catch (Exception ex)
            {
                /*Record notify response*/
                notifyComResponse.IsError         = true;
                notifyComResponse.IsSucceeded     = true;
                notifyComResponse.ResponseContent = "Page to [" + _name + "] " + _pagerToAddress + ", Failed.";
                Message         += "Page to [" + _name + "] " + _pagerToAddress + ", Failed (" + ex.Message + ").";
                ProcessCompleted = true;
                /*Debug Object values for reference*/
                LogBook.Debug(notifyComResponse, this);

                /*Write exception log*/
                LogBook.Write("Error has occurred while preparing SNPP setting.", ex, "CooperAtkins.NotificationServer.NotifyEngine.PagerHelper");
            }
            return(notifyComResponse);
        }