Example #1
0
        public AGIChannel(SocketConnection socket, bool SC511_CAUSES_EXCEPTION, bool SCHANGUP_CAUSES_EXCEPTION)
        {
            agiWriter = new AGIWriter(socket);
            agiReader = new AGIReader(socket);

            _SC511_CAUSES_EXCEPTION = SC511_CAUSES_EXCEPTION;
            _SCHANGUP_CAUSES_EXCEPTION = SCHANGUP_CAUSES_EXCEPTION;
        }
Example #2
0
        public AGIChannel(SocketConnection socket, bool SC511_CAUSES_EXCEPTION, bool SCHANGUP_CAUSES_EXCEPTION)
        {
            agiWriter = new AGIWriter(socket);
            agiReader = new AGIReader(socket);

            _SC511_CAUSES_EXCEPTION    = SC511_CAUSES_EXCEPTION;
            _SCHANGUP_CAUSES_EXCEPTION = SCHANGUP_CAUSES_EXCEPTION;
        }
Example #3
0
        public AGIChannel(AGIWriter agiWriter, AGIReader agiReader, bool SC511_CAUSES_EXCEPTION,
            bool SCHANGUP_CAUSES_EXCEPTION)
        {
            this.agiWriter = agiWriter;
            this.agiReader = agiReader;

            _SC511_CAUSES_EXCEPTION = SC511_CAUSES_EXCEPTION;
            _SCHANGUP_CAUSES_EXCEPTION = SCHANGUP_CAUSES_EXCEPTION;
        }
Example #4
0
        public AGIChannel(AGIWriter agiWriter, AGIReader agiReader, bool SC511_CAUSES_EXCEPTION,
                          bool SCHANGUP_CAUSES_EXCEPTION)
        {
            this.agiWriter = agiWriter;
            this.agiReader = agiReader;

            _SC511_CAUSES_EXCEPTION    = SC511_CAUSES_EXCEPTION;
            _SCHANGUP_CAUSES_EXCEPTION = SCHANGUP_CAUSES_EXCEPTION;
        }
        public void Run()
        {
            try
            {
                var        reader = new AGIReader(socket);
                var        writer = new AGIWriter(socket);
                AGIRequest request;
                using (var enlarger = new SocketConnectionTimeoutEnlarger(socket, 500))
                    request = reader.ReadRequest();

                //Added check for when the request is empty
                //eg. telnet to the service
                if (request.Request.Count > 0)
                {
                    var       channel = new AGIChannel(writer, reader, _SC511_CAUSES_EXCEPTION, _SCHANGUP_CAUSES_EXCEPTION);
                    AGIScript script  = mappingStrategy.DetermineScript(request);
                    Thread.SetData(_channel, channel);

                    if (script != null)
                    {
                        #if LOGGER
                        logger.Info("Begin AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name);
                        #endif
                        script.Service(request, channel);
                        #if LOGGER
                        logger.Info("End AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name);
                        #endif
                    }
                    else
                    {
                        var error = "No script configured for URL '" + request.RequestURL + "' (script '" + request.Script +
                                    "')";
                        channel.SendCommand(new VerboseCommand(error, 1));
                        #if LOGGER
                        logger.Error(error);
                        #endif
                    }
                }
                else
                {
                    var error = "A connection was made with no requests";
                    #if LOGGER
                    logger.Error(error);
                    #endif
                }
            }
            catch (AGIHangupException)
            {
            }
            catch (IOException)
            {
            }
            catch (AGIException ex)
            {
                #if LOGGER
                logger.Error("AGIException while handling request", ex);
                #else
                throw ex;
                #endif
            }
            catch (Exception ex)
            {
                #if LOGGER
                logger.Error("Unexpected Exception while handling request", ex);
                #else
                throw ex;
                #endif
            }

            Thread.SetData(_channel, null);
            try
            {
                socket.Close();
            }
            #if LOGGER
            catch (IOException ex)
            {
                logger.Error("Error on close socket", ex);
            }
            #else
            catch { }
            #endif
        }
        public void Run()
        {
            try
            {
                var reader = new AGIReader(socket);
                var writer = new AGIWriter(socket);
                AGIRequest request = reader.ReadRequest();
                var channel = new AGIChannel(writer, reader, _SC511_CAUSES_EXCEPTION, _SCHANGUP_CAUSES_EXCEPTION);
                AGIScript script = mappingStrategy.DetermineScript(request);
                Thread.SetData(_channel, channel);

                if (script != null)
                {
#if LOGGER
                    logger.Info("Begin AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name);
#endif
                    script.Service(request, channel);
#if LOGGER
                    logger.Info("End AGIScript " + script.GetType().FullName + " on " + Thread.CurrentThread.Name);
#endif
                }
                else
                {
                    var error = "No script configured for URL '" + request.RequestURL + "' (script '" + request.Script +
                                "')";
                    channel.SendCommand(new VerboseCommand(error, 1));
#if LOGGER
                    logger.Error(error);
#endif
                }
            }
            catch (AGIHangupException)
            {
            }
            catch (IOException)
            {
            }
            catch (AGIException ex)
            {
#if LOGGER
                logger.Error("AGIException while handling request", ex);
#else
				throw ex;
#endif
            }
            catch (Exception ex)
            {
#if LOGGER
                logger.Error("Unexpected Exception while handling request", ex);
#else
				throw ex;
#endif
            }

            Thread.SetData(_channel, null);
            try
            {
                socket.Close();
            }
#if LOGGER
            catch (IOException ex)
            {
                logger.Error("Error on close socket", ex);
            }
#else
			catch { }
#endif
        }