Example #1
0
        /// <summary>
        /// Converts object into AltiLink Plus v2.0 format and returns it.
        /// </summary>
        /// <param name="obj">Command to convert (of "object" type).</param>
        /// <returns>Command in AltiLink Plus v2.0 format (or null).</returns>
        protected override AltiLinkPlus.ALPCommand ProcessCommand(Cmd.CmdBase obj)
        {
            AltiLinkPlus.ALPCommand cmd = null;
            ALPLine _line = null;

            if (obj == null)
            {
                return(null);
            }

            _line = this[obj.Line];
            // Check if the line exists.
            if (_line == null)
            {
                SendSpEvent(new Ev.CommandStatus(obj.Line, obj.ID, Ev.CmdStatus.ERROR));
                return(null);
            }

            // Answer the call.
            if (obj is Cmd.AnswerCall)
            {
                Cmd.AnswerCall _cmd = ((Cmd.AnswerCall)(obj));
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_ANSWER_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_ANSWER_CALL, _cmd.Sender);
                return(cmd);
            }

            // Reject the call.
            if (obj is Cmd.RejectCall)
            {
                Cmd.RejectCall _cmd = ((Cmd.RejectCall)(obj));
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_REJECT_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.rejectReasonCode);
                cmd[2] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_REJECT_CALL, _cmd.Sender);
                return(cmd);
            }

            // Pass the call.
            if (obj is Cmd.PassCall)
            {
                Cmd.PassCall _cmd = ((Cmd.PassCall)(obj));
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_PASS_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_PASS_CALL, _cmd.Sender);
                return(cmd);
            }

            // Connect lines command.
            if (obj is Cmd.Connect)
            {
                Cmd.Connect _cmd   = ((Cmd.Connect)obj);
                ALPLine     _line1 = this[_cmd.LineOne];
                ALPLine     _line2 = this[_cmd.LineTwo];
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_CONNECT_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.LineOne));
                cmd[1] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.LineTwo));
                cmd[2] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line1.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_CONNECT_CALL, _cmd.Sender);
                return(cmd);
            }

            // Disconnect.
            if (obj is Cmd.Disconnect)
            {
                Cmd.Disconnect _cmd = ((Cmd.Disconnect)obj);
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_SNATCH_LINE)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_SNATCH_LINE, _cmd.Sender);
                return(cmd);
            }

            // Dial the number.
            if (obj is Cmd.Dial)
            {
                Cmd.Dial _cmd          = ((Cmd.Dial)obj);
                string   _numberToDial = _line.SPLineInfo.AccessCode + _cmd.Destination;
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_MAKE_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(_numberToDial);
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.Account);
                cmd[2] = new AltiLinkPlus.ALPParameter(_cmd.Tone);
                cmd[3] = new AltiLinkPlus.ALPParameter(_cmd.Source);
                cmd[4] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command.
                OutcallCommandStruct odc = new OutcallCommandStruct(_cmd.Sender, _cmd.Line, Cmd.CommandID.DIAL);
                outcallNumbersDialingCommands.Add(cmd.SequenceId, odc);
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_MAKE_CALL, _cmd.Sender);
                return(cmd);
            }

            // Drop Call.
            if (obj is Cmd.DropCall)
            {
                Cmd.DropCall _cmd = ((Cmd.DropCall)obj);
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_DROP_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_DROP_CALL, _cmd.Sender);
                return(cmd);
            }

            // Play DTMF.
            if (obj is Cmd.PlayDTMF)
            {
                Cmd.PlayDTMF _cmd = ((Cmd.PlayDTMF)obj);
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_PLAY_DTMF)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.DTMFCode);
                cmd[2] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_PLAY_DTMF, _cmd.Sender);
                return(cmd);
            }

            // Play file.
            if (obj is Cmd.PlayFile)
            {
                Cmd.PlayFile _cmd = ((Cmd.PlayFile)obj);
                // Creating command.
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_PLAY_VOICE)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.CutOffString);
                cmd[2] = new AltiLinkPlus.ALPParameter(_cmd.FilePath);
                cmd[3] = new AltiLinkPlus.ALPParameter(0);
                cmd[4] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_PLAY_VOICE, _cmd.Sender);
                return(cmd);
            }

            // Record file.
            if (obj is Cmd.RecordFile)
            {
                Cmd.RecordFile _cmd = ((Cmd.RecordFile)obj);
                // Creating command.
                cmd = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_RECORD_VOICE)));
                // Adding parameters.
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.CutOffString);
                cmd[2] = new AltiLinkPlus.ALPParameter(_cmd.FilePath);
                cmd[3] = new AltiLinkPlus.ALPParameter(0);
                cmd[4] = new AltiLinkPlus.ALPParameter(_cmd.AppendMode);
                cmd[5] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_RECORD_VOICE, _cmd.Sender);
                return(cmd);
            }

            // Reset.
            if (obj is Cmd.Reset)
            {
                Cmd.Reset _cmd = ((Cmd.Reset)obj);
                switch (_line.LastCommand.ID)
                {
                case ALPCmdID.APC_PLAY_VOICE:
                {
                    cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, Convert.ToInt32(ALPCmdID.APC_STOP_PLAY_VOICE));
                    cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                    // Type (0 - stop play current, 1 - stop play all).
                    cmd[1] = new AltiLinkPlus.ALPParameter(1);
                    cmd[2] = new AltiLinkPlus.ALPParameter(0);
                    break;
                }

                case ALPCmdID.APC_RECORD_VOICE:
                {
                    cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, Convert.ToInt32(ALPCmdID.APC_STOP_RECORD_VOICE));
                    cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                    // Type (0 - stop record current, 1 - stop record all).
                    cmd[1] = new AltiLinkPlus.ALPParameter(1);
                    cmd[2] = new AltiLinkPlus.ALPParameter(0);
                    break;
                }
                }
                return(cmd);
            }

            // Ring extension.
            if (obj is Cmd.RingExtension)
            {
                Cmd.RingExtension _cmd          = ((Cmd.RingExtension)obj);
                string            _numberToRing = _line.SPLineInfo.AccessCode + _cmd.Extension;
                // Creating command.
                cmd = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_RING_EXT)));
                // Adding parameters.
                cmd[0] = new AltiLinkPlus.ALPParameter(_cmd.RingType);
                cmd[1] = new AltiLinkPlus.ALPParameter(_numberToRing);
                cmd[2] = new AltiLinkPlus.ALPParameter(0);
                OutcallCommandStruct odc = new OutcallCommandStruct(_cmd.Sender, _cmd.Line, Cmd.CommandID.RING_EXTENSION);
                outcallNumbersDialingCommands.Add(cmd.SequenceId, odc);
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_RING_EXT, _cmd.Sender);
                return(cmd);
            }

            // Snatch line.
            if (obj is Cmd.Disconnect)
            {
                Cmd.Disconnect _cmd = ((Cmd.Disconnect)obj);
                // Creating command.
                cmd = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_SNATCH_LINE)));
                // Adding parameters.
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_SNATCH_LINE, _cmd.Sender);
                return(cmd);
            }

            // Switch music.
            if (obj is Cmd.SwitchMusic)
            {
                Cmd.SwitchMusic _cmd = ((Cmd.SwitchMusic)obj);
                // Creating command.
                cmd = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_SWITCH_MUSIC)));
                // Adding parameters.
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(_cmd.MusicMode);
                cmd[2] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_SWITCH_MUSIC, _cmd.Sender);
                return(cmd);
            }

            // Transfer call.
            if (obj is Cmd.TransferCall)
            {
                const int        TRANSFER_CALL_TIMEOUT = 45;
                Cmd.TransferCall _cmd    = ((Cmd.TransferCall)obj);
                ALPLine          _target = this[_cmd.Target];

                string _numberToRing = _target.SPLineInfo.AccessCode + _cmd.Destination;
                cmd    = new AltiLinkPlus.ALPCommand(ControlLocationID, (Convert.ToInt32(ALPCmdID.APC_TRANSFER_CALL)));
                cmd[0] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Line));
                cmd[1] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Type));
                switch (_cmd.Type)
                {
                case Cmd.TransferCallType.EXTENSION:
                case Cmd.TransferCallType.EXTENSION_VOICE_MESSAGE:
                {
                    cmd[2] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_numberToRing));
                    cmd[3] = new AltiLinkPlus.ALPParameter("");
                    break;
                }

                case Cmd.TransferCallType.AUTOATEDDANT:
                {
                    if (_cmd.Destination == string.Empty)
                    {
                        cmd[2] = new AltiLinkPlus.ALPParameter(1);
                    }
                    else
                    {
                        cmd[2] = new AltiLinkPlus.ALPParameter(Convert.ToInt32(_cmd.Destination));
                    }
                    cmd[3] = new AltiLinkPlus.ALPParameter("");
                    break;
                }

                case Cmd.TransferCallType.OPERATOR:
                {
                    cmd[2] = new AltiLinkPlus.ALPParameter(0);
                    cmd[3] = new AltiLinkPlus.ALPParameter(_cmd.Destination);
                    break;
                }

                case Cmd.TransferCallType.TRUNK:
                {
                    _numberToRing += (_cmd.Destination == string.Empty) ?  "**5" : string.Empty;
                    cmd[2]         = new AltiLinkPlus.ALPParameter(0);
                    cmd[3]         = new AltiLinkPlus.ALPParameter(_numberToRing);
                    break;
                }
                }
                cmd[4] = new AltiLinkPlus.ALPParameter(TRANSFER_CALL_TIMEOUT);
                cmd[5] = new AltiLinkPlus.ALPParameter(0);
                // Saving information about the command in line's Line class.
                _line.LastCommand.Set(cmd.SequenceId, ALPCmdID.APC_TRANSFER_CALL, _cmd.Sender);
                return(cmd);
            }
            return(null);
        }
 /// <summary>
 /// Converts object into AltiLink Plus v2.0 format and returns it.
 /// </summary>
 /// <param name="cmd">Command to convert (of "object" type).</param>
 /// <returns>Command in AltiLink Plus v2.0 format (or null).</returns>
 protected virtual AltiLinkPlus.ALPCommand ProcessCommand(Cmd.CmdBase cmd)
 {
     return(null);
 }