예제 #1
0
        public AGIScript DetermineScript(AGIRequest request)
        {
            AGIScript script = null;

            if (mapping != null)
            {
                lock (mapping.SyncRoot)
                {
                    if (mapping.Contains(request.Script))
                    {
                        script = (AGIScript)mapping[request.Script];
                    }
                }
            }
            return(script);
        }
예제 #2
0
        public void Run()
        {
            try
            {
                AGIReader  reader  = new AGIReader(socket);
                AGIWriter  writer  = new AGIWriter(socket);
                AGIRequest request = reader.ReadRequest();
                AGIChannel channel = new AGIChannel(writer, reader);
                AGIScript  script  = mappingStrategy.DetermineScript(request);
                Thread.SetData(AGIConnectionHandler.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
                {
                    string error;
                    error = "No script configured for URL '" + request.RequestURL + "' (script '" + request.Script + "')";
                    channel.SendCommand(new Command.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(AGIConnectionHandler.channel, null);
            try
            {
                socket.Close();
            }
#if LOGGER
            catch (IOException ex)
            {
                logger.Error("Error on close socket", ex);
            }
#else
            catch { }
#endif
        }