Пример #1
0
        /// <summary>
        /// Renders the high-level switch action instance into zero or more <see cref="SwitchExecuteAction" />
        /// instances and then adds these to the <see cref="ActionRenderingContext" />.<see cref="ActionRenderingContext.Actions" />
        /// collection.
        /// </summary>
        /// <param name="context">The action rendering context.</param>
        /// <remarks>
        /// <note>
        /// It is perfectly reasonable for an action to render no actions to the
        /// context or to render multiple actions based on its properties.
        /// </note>
        /// </remarks>
        public override void Render(ActionRenderingContext context)
        {
            var reasonString = SwitchHelper.GetSwitchHangupReasonString(reason);
            int delaySeconds = SwitchHelper.GetScheduleSeconds(delay);

            if (context.IsDialplan)
            {
                if (delaySeconds <= 0)
                {
                    context.Actions.Add(new SwitchExecuteAction("hangup", reasonString));
                }
                else
                {
                    context.Actions.Add(new SwitchExecuteAction("sched_hangup", "+{0} {1}", delaySeconds, reasonString));
                }
            }
            else
            {
                CheckCallID();

                if (delaySeconds <= 0)
                {
                    context.Actions.Add(new SwitchExecuteAction(CallID, "hangup", reasonString));
                }
                else
                {
                    context.Actions.Add(new SwitchExecuteAction(CallID, "sched_hangup", "+{0} {1}", delaySeconds, reasonString));
                }
            }
        }