示例#1
0
        public List <Message> Read()
        {
            try
            {
                List <Message>            list = new List <Message>();
                CS.SMS.ListMessageCommand lmc  = new CS.SMS.ListMessageCommand(_adaptor, CS.SMS.MessageStateType.All, CS.SMS.MessageFormatType.PDU);
                if (lmc.Execute())
                {
                    foreach (CS.SMS.ShortMessage item in lmc.MessageCollection)
                    {
                        CS.SMS.DeleteMessageCommand dmc = new CS.SMS.DeleteMessageCommand(_adaptor, item.Index);
                        if (dmc.Execute())
                        {
                            list.Add(new Message(item));
                        }
                    }
                    return(list);
                }

                throw new ModemException("ListMessageCommand.Execute() failed.");
            }
            catch (Exception p)
            {
                logger.Error(p);
                return(null);
            }
        }
        private void ExecuteReader()
        {
            try
            {
                OnReaderStarted(EventArgs.Empty);

                CS.SMS.ListMessageCommand lmc = new CS.SMS.ListMessageCommand(_adaptor, CS.SMS.MessageStateType.All, CS.SMS.MessageFormatType.PDU);

                if (lmc.Execute())
                {
                    foreach (CS.SMS.ShortMessage item in lmc.MessageCollection)
                    {
                        Thread.BeginCriticalRegion();
                        CS.SMS.DeleteMessageCommand dmc = new CS.SMS.DeleteMessageCommand(_adaptor, item.Index);
                        if (dmc.Execute())
                        {
                            _ReaderQ.Enqueue(new Message(item));
                        }
                        Thread.EndCriticalRegion();

                        OnItemRead(new ItemReadEventArgs(new Message(item)));

                        if (_Stopped)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    throw new ModemException("ListMessageCommand.Execute() Failed.");
                }

                OnReaderStopped(EventArgs.Empty);
            }
            catch (Exception p)
            {
                logger.Error(p);
            }
        }
        /// <summary>
        ///
        /// </summary>
        private bool Check()
        {
            try
            {
                OnExecute(new ExecutionEventArgs("Setting Code Suppression..."));
                using (Command command = new CS.CodeSuppressionCommand(_adaptor))
                {
                    ((CS.CodeSuppressionCommand)command).Type = CS.CodeSuppressionType.TransmitCodes;
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting Command Echo..."));
                using (Command command = new CS.CommandEchoCommand(_adaptor))
                {
                    ((CS.CommandEchoCommand)command).Type = CS.CommandEchoType.NoEcho;
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting Response Format..."));
                using (Command command = new CS.ResponseFormatCommand(_adaptor))
                {
                    ((CS.ResponseFormatCommand)command).Type = CS.ResponseFormatType.Verbose;
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting Message Format..."));
                using (Command command = new CS.SMS.MessageFormatCommand(_adaptor))
                {
                    ((CS.SMS.MessageFormatCommand)command).FormatType = CS.SMS.MessageFormatType.PDU;
                    if (((CS.SMS.MessageFormatCommand)command).FormatType != CS.SMS.MessageFormatType.PDU)
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting Report Error..."));
                using (Command command = new CS.ReportMEErrorCommand(_adaptor))
                {
                    ((CS.ReportMEErrorCommand)command).ReportType = CS.ReportMEErrorType.ReportOK;
                    if (((CS.ReportMEErrorCommand)command).ReportType != CS.ReportMEErrorType.ReportOK)
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting Preferred Message Storage..."));
                using (Command command = new CS.SMS.PreferredMessageStorage(_adaptor))
                {
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Setting New Message Indications..."));
                using (Command command = new CS.SMS.NewMessageIndications(_adaptor))
                {
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                }

                OnExecute(new ExecutionEventArgs("Fetching Service Centre Address..."));
                using (Command command = new CS.SMS.ServiceCentreAddress(_adaptor))
                {
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }
                    _SMSC = ((CS.SMS.ServiceCentreAddress)command).Address;
                }

                OnExecute(new ExecutionEventArgs("Clearing Incoming Message Queue..."));
                using (Command command = new CS.SMS.ListMessageCommand(_adaptor, CS.SMS.MessageStateType.All, CS.SMS.MessageFormatType.PDU))
                {
                    if (!command.Execute())
                    {
                        throw new ModemException();
                    }

                    foreach (CS.SMS.ShortMessage item in ((CS.SMS.ListMessageCommand)command).MessageCollection)
                    {
                        CS.SMS.DeleteMessageCommand dmc = new CS.SMS.DeleteMessageCommand(_adaptor, item.Index);
                        if (!dmc.Execute())
                        {
                            throw new ModemException("DeleteMessageCommand Execute Failed.");
                        }
                        if (_Stopped)
                        {
                            break;
                        }
                    }
                }

                OnExecute(new ExecutionEventArgs("Initializing Completed."));

                return(true);
            }
            catch (Exception p)
            {
                logger.Error(p);
                return(false);
            }
        }