Inheritance: CoreSession
示例#1
0
        /// <summary>
        /// Performs originate. Returns ManagedSession on success, null on failure.
        /// onHangup is called as a state handler, after the channel is truly hungup (CS_REPORTING).
        /// </summary>
        public static ManagedSession OriginateHandleHangup(CoreSession aLegSession, string destination, TimeSpan timeout, Action <ManagedSession> onHangup)
        {
            var bleg = new ManagedSession();

            bleg.originate_ondestroy_delegate = bleg.originate_ondestroy_method;
            bleg.originate_onhangup_delegate  = CreateStateHandlerDelegate(bleg, sess_b => {
                if (onHangup != null)
                {
                    onHangup(sess_b);
                }
            });
            bleg.originate_table = new switch_state_handler_table();
            bleg.originate_table.on_reporting = WrapStateHandlerDelegate(bleg.originate_onhangup_delegate);
            bleg.originate_table.on_destroy   = WrapStateHandlerDelegate(bleg.originate_ondestroy_delegate);
            bleg.originate_table.flags        = (int)switch_state_handler_flag_t.SSH_FLAG_STICKY;
            var res = 0 == bleg.originate(aLegSession, destination, (int)timeout.TotalSeconds, bleg.originate_table);

            bleg.originate_keepalive_handle = GCHandle.Alloc(bleg, GCHandleType.Normal); // Prevent GC from eating the bleg
            if (res)
            {
                bleg.Initialize();
                return(bleg);
            }
            else
            {
                // Dispose to free the lock
                // The bleg lives on with its unmanaged memory freed
                // Until CS_DESTROY gets called
                bleg.Dispose();
                return(null);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VoiceQuestionnaireService"/> class.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="invalidAudioFile">The invalid audio file.</param>
 /// <param name="phraseStart">The phrase start.</param>
 /// <param name="recordingFolder">The recording folder.</param>
 public VoiceQuestionnaireService(ManagedSession session,
     string invalidAudioFile, string phraseStart, string recordingFolder)
 {
     Session = session;
     InvalidAudioFile = invalidAudioFile;
     PhraseStart = phraseStart;
     RecordingFolder = recordingFolder;
 }
示例#3
0
        // Creating these function pointers is a two-stage process.
        // The delegate needs to be stored so it doesn't get GC'd, so we can't just return GetFunctionPointerForDelegate right away.

        /// <summary>Wraps a nice handler into a delegate suitable for reverse P/Invoke. This only currently works well for hangup/reporting handlers.</summary>
        public static switch_state_handler_t_delegate CreateStateHandlerDelegate(ManagedSession sess, Action <ManagedSession> handler)
        {
            // We create a ManagedSession on top of the session so callbacks can use it "nicely"
            // Then we sort of dispose it.
            switch_state_handler_t_delegate del = ptr => {
                handler(sess);
                return(switch_status_t.SWITCH_STATUS_SUCCESS);
            };

            return(del);
        }
 private void UnParkCall(ManagedSession session)
 {
     string parkingSpace = session.GetVariable("destination_number");
     string parkedCallUuid =ParkingLot.ParkedCalls[parkingSpace];
     session.Answer();
     session.sleep(500, 0);
     session.SetTtsParameters("cepstral", "allison");
     session.Speak("Connecting you.");
     session.Execute("intercept", string.Format("{0}", parkedCallUuid));
     ParkingLot.ParkedCalls.Remove(parkingSpace);
 }
 private void ParkCall(ManagedSession session, string parkingSpace)
 {
     ParkingLot.ParkedCalls[parkingSpace] = session.uuid;
     session.HangupFunction = () => HandleHangup(parkingSpace);
     Log.WriteLine(LogLevel.Info, string.Format("Park: {0}.", parkingSpace));
     session.Answer();
     session.sleep(500, 0);
     session.SetTtsParameters("cepstral", "allison");
     session.Speak("Holding on extension " + parkingSpace+"<break time='1s' />");
     session.sleep(500, 0);
     session.StreamFile("local_stream://moh", -1);
 }
示例#6
0
        // Creating these function pointers is a two-stage process.
        // The delegate needs to be stored so it doesn't get GC'd, so we can't just return GetFunctionPointerForDelegate right away.

        /// <summary>Wraps a nice handler into a delegate suitable for reverse P/Invoke. This only currently works well for hangup/reporting handlers.</summary>
        public static switch_state_handler_t_delegate CreateStateHandlerDelegate(Action <ManagedSession> handler)
        {
            // We create a ManagedSession on top of the session so callbacks can use it "nicely"
            // Then we sort of dispose it.
            switch_state_handler_t_delegate del = ptr => {
                using (var sess = new ManagedSession(new SWIGTYPE_p_switch_core_session(ptr, false))) {
                    handler(sess);
                    return(switch_status_t.SWITCH_STATUS_SUCCESS);
                }
            };

            return(del);
        }
示例#7
0
 /// <summary>Initializes the native ManagedSession. Called after Originate completes successfully .</summary>
 internal void Initialize()
 {
     if (allocated == 0)
     {
         throw new InvalidOperationException("Cannot initialize a ManagedSession until it is allocated (originated successfully).");
     }
     // P/Invoke generated function pointers stick around until the delegate is collected
     // By sticking the delegates in fields, their lifetime won't be less than the session
     // So we don't need to worry about GCHandles and all that....
     // Info here: http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx
     this._inputCallbackRef  = inputCallback;
     this._hangupCallbackRef = hangupCallback;
     InitManagedSession(ManagedSession.getCPtr(this).Handle, this._inputCallbackRef, this._hangupCallbackRef);
     this._variables = new ChannelVariables(this);
 }
 public bool Execute(string args, IntPtr sessionHandle)
 {
     IncreaseUse();
     try {
         using (var session = new Native.ManagedSession(new Native.SWIGTYPE_p_switch_core_session(sessionHandle, false))) {
             session.Initialize();
             session.SetAutoHangup(false);
             try {
                 var plugin  = createPlugin();
                 var context = new AppContext(args, session);;
                 plugin.Run(context);
                 return(true);
             } catch (Exception ex) {
                 LogException("Run", Name, ex);
                 return(false);
             }
         }
     } finally {
         DecreaseUse();
     }
 }
        public void Run(AppContext context)
        {
            Session = context.Session;
            Session.Answer();
            Session.SetTtsParameters("flite", "kal");
            Session.sleep(1000, 0);

            var questionnaireService = new VoiceQuestionnaireService(
                                            Session, InvalidAudioFile,
                                            PhraseStart, RecordLocation);

            var phoneNumber = questionnaireService
                .AskAndVerifyQuestion(
                9, 11, 3, 10000, "#", "enter_phone_number",
                x => "you_entered_phone_number:" + x, "\\d+", _ => true);

            var nameRecordingFile = questionnaireService
                    .AskRecordAndVerifyQuestion(
                    "record_name", x => "verify_recording:" + x,
                    string.Format("{0}_{1}_{2}", Session.Uuid, DateTime.UtcNow.ToString("MMddyyyy"), phoneNumber));
        }
 internal ChannelVariables(ManagedSession session) {
     this.sess = session;
 }
        /// <summary>
        /// Performs originate. Returns ManagedSession on success, null on failure.
        /// onHangup is called as a state handler, after the channel is truly hungup (CS_REPORTING).
        /// </summary>
        public static ManagedSession OriginateHandleHangup(CoreSession aLegSession, string destination, TimeSpan timeout, Action<ManagedSession> onHangup) {
            var bleg = new ManagedSession();

            bleg.originate_ondestroy_delegate = bleg.originate_ondestroy_method;
            bleg.originate_onhangup_delegate = CreateStateHandlerDelegate(sess_b => {
                if (onHangup != null) {
                    onHangup(sess_b);
                }
            });
            bleg.originate_table = new switch_state_handler_table();
            bleg.originate_table.on_reporting = WrapStateHandlerDelegate(bleg.originate_onhangup_delegate);
            bleg.originate_table.on_destroy = WrapStateHandlerDelegate(bleg.originate_ondestroy_delegate);
            bleg.originate_table.flags = (int)switch_state_handler_flag_t.SSH_FLAG_STICKY;
            var res = 0 == bleg.originate(aLegSession, destination, (int)timeout.TotalSeconds, bleg.originate_table);
            bleg.originate_keepalive_handle = GCHandle.Alloc(bleg, GCHandleType.Normal); // Prevent GC from eating the bleg
            if (res) {
                bleg.Initialize();
                return bleg;
            } else {
                // Dispose to free the lock
                // The bleg lives on with its unmanaged memory freed 
                // Until CS_DESTROY gets called
                bleg.Dispose(); 
                return null;
            }
        }
        // Creating these function pointers is a two-stage process. 
        // The delegate needs to be stored so it doesn't get GC'd, so we can't just return GetFunctionPointerForDelegate right away.

        /// <summary>Wraps a nice handler into a delegate suitable for reverse P/Invoke. This only currently works well for hangup/reporting handlers.</summary>
        public static switch_state_handler_t_delegate CreateStateHandlerDelegate(Action<ManagedSession> handler) {
            // We create a ManagedSession on top of the session so callbacks can use it "nicely"
            // Then we sort of dispose it.
            switch_state_handler_t_delegate del = ptr => {
                using (var sess = new ManagedSession(new SWIGTYPE_p_switch_core_session(ptr, false))) {
                    handler(sess);
                    return switch_status_t.SWITCH_STATUS_SUCCESS;
                }
            };
            return del;
        }
示例#13
0
        // Creating these function pointers is a two-stage process. 
        // The delegate needs to be stored so it doesn't get GC'd, so we can't just return GetFunctionPointerForDelegate right away.

        /// <summary>Wraps a nice handler into a delegate suitable for reverse P/Invoke. This only currently works well for hangup/reporting handlers.</summary>
		public static switch_state_handler_t_delegate CreateStateHandlerDelegate(ManagedSession sess, Action<ManagedSession> handler)
		{
            // We create a ManagedSession on top of the session so callbacks can use it "nicely"
            // Then we sort of dispose it.
            switch_state_handler_t_delegate del = ptr => {
                    handler(sess);
                    return switch_status_t.SWITCH_STATUS_SUCCESS;
            };
            return del;
        }
示例#14
0
 internal ChannelVariables(ManagedSession session)
 {
     this.sess = session;
 }
示例#15
0
 public AppContext(string arguments, Native.ManagedSession session)
 {
     this.arguments = arguments;
     this.session = session;
 }
示例#16
0
 internal static HandleRef getCPtr(ManagedSession obj)
 {
     return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
示例#17
0
 public AppContext(string arguments, Native.ManagedSession session)
 {
     this.arguments = arguments;
     this.session   = session;
 }