Exemple #1
0
        public TslResult SendPrepareCommand(string number)
        {
            LogService.Logger.Debug(string.Format("SendPrepareCommand {0}", number));
            var tslResult = new TslResult();

            try
            {
                this.Modem.Dial(number);

                if (this.Modem.Connection != null)
                {
                    if (!this.IsCanceled)
                    {
                        tslResult.Connected = true;
                        var msg = new TSL_Message()
                        {
                            Control = eControl.TSL_Prepare
                        };

                        var ret = this.Modem.SendTSLMessageAndWaitForResult(msg, TSL_WaitTime);
                        tslResult.Responsed = ret != null && ret is TSL_Message && ((TSL_Message)ret).Control == eControl.ACK;
                    }

                    SendMessage(eControl.TSL_EOT);
                    this.Modem.HangUp();
                }
            }
            catch (Exception ex)
            {
                LogService.Logger.Error(ex);
            }

            return(tslResult);
        }
Exemple #2
0
        public TslResult SendAndReceiveResult(string number, int phoneNumberId, Action <int, ResultData> saveFunc)
        {
            var tslResult = new TslResult();

            try
            {
                this.Modem.Dial(number);

                if (this.Modem.Connection != null)
                {
                    if (!this.IsCanceled)
                    {
                        tslResult.Connected = true;
                        var done = false;
                        var msg  = new TSL_Message()
                        {
                            Control = eControl.TSL_ResultRequest
                        };
                        var ret = this.Modem.SendTSLMessageAndWaitForResult(msg, TSL_WaitTime);

                        while (ret != null && !done && !this.IsCanceled)
                        {
                            if (ret is TSL_Message)
                            {
                                var r_msg = ret as TSL_Message;

                                if (r_msg.Control == eControl.TSL_ResultEnd)
                                {
                                    SendMessage(eControl.TSL_EOT);
                                    done = true;
                                }
                            }
                            else if (ret is ResultData)
                            {
                                var result = ret as ResultData;
                                if (saveFunc != null)
                                {
                                    saveFunc(phoneNumberId, result);
                                }
                                ret = this.Modem.SendTSLMessageAndWaitForResult(msg, TSL_WaitTime);
                            }
                        }

                        tslResult.Responsed = done;
                    }
                }

                this.Modem.HangUp();
                this.Modem.ClearBuffer();
            }
            catch (Exception ex)
            {
                LogService.Logger.Error(ex);
            }

            return(tslResult);
        }