public object this[object lineID, object key] { get { ALPLine _line = this[lineID]; if (_line != null) { return(_line[key]); } else { return(null); } } set { ALPLine _line = this[lineID]; if (_line != null) { _line[key] = value; if ((key is string) && key.Equals(USER_DATA)) { AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(this.ControlLocationID, (int)(ALPCmdID.APC_SET_DATA)); ac[0] = new AltiLinkPlus.ALPParameter((int)lineID); ac[1] = new AltiLinkPlus.ALPParameter((int)ALPInfoType.APC_DATATYPE_USER); ac[2] = new AltiLinkPlus.ALPParameter((string)value); ac[3] = new AltiLinkPlus.ALPParameter(0); base.SendALPCommand(ac); } } } }
public void Redirect(object lineID, string number, int callID) { AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand((int)(lineID), (int)(ALPCmdID.REDIRECT)); ac[0] = new AltiLinkPlus.ALPParameter(callID); ac[1] = new AltiLinkPlus.ALPParameter(number); ac[2] = new AltiLinkPlus.ALPParameter(1); ac[3] = new AltiLinkPlus.ALPParameter(String.Empty); base.SendALPCommandAndWait(ac, 0); }
public void Call(object lineID, string number) { AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand((int)(lineID), (int)(ALPCmdID.MAKECALL)); ac[0] = new AltiLinkPlus.ALPParameter(number); ac[1] = new AltiLinkPlus.ALPParameter(1); ac[2] = new AltiLinkPlus.ALPParameter(String.Empty); ac[3] = new AltiLinkPlus.ALPParameter(String.Empty); ac[4] = new AltiLinkPlus.ALPParameter(1); base.SendALPCommandAndWait(ac, 0); }
/// <summary> /// Checks the connection status. /// </summary> /// <param name="data">Data for check (not used).</param> private void CheckConnection(object data) { if (!this.ConnectionIsAlive) { RaiseEvent(SPStatus.ERROR_CONNECTION, "Connection Timer expired"); } this.ConnectionIsAlive = false; AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(this.ControlLocationID, Convert.ToInt32(ALPCmdID.PING)); ac[0] = new AltiLinkPlus.ALPParameter(1); this.SendALPCommand(ac); TraceOut.Put("[Timer] Checking connection(" + this.ConnectionIsAlive.ToString() + ")..."); }
protected override void ProcessEvent(Diacom.AltiGen.AltiLinkPlus.ALPEvent altiEvent) { switch ((ALPEvID)(altiEvent.CommandId)) { case ALPEvID.RING: CallInfo rInfo = new CallInfo(altiEvent[0]); AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(rInfo.lineID, (int)(ALPCmdID.GET_EXTRACALLINFO)); ac[0] = new AltiLinkPlus.ALPParameter(rInfo.SessionHandle); RingInfo.Add(ac.SequenceId, rInfo); base.SendALPCommand(ac); break; case ALPEvID.STCHG: Diacom.ExtensionManager.StateChangedEventHandler ehsc = this.StateChanged; if (ehsc != null) { SPLineState state = ((SPLineState)(altiEvent[0].ReadInt32())); Diacom.ExtensionManager.LineStateInfoEventArgs si = new Diacom.ExtensionManager.LineStateInfoEventArgs(state); ehsc(GetLine(altiEvent.LocationId), si); } break; } base.ProcessEvent(altiEvent); }
/// <summary> /// Processes all events. /// </summary> /// <param name="altiEvent">Block of data to process.</param> /// <returns>An object whith the event.</returns> protected override void ProcessEvent(AltiLinkPlus.ALPEvent altiEvent) { // Getting information only if event is for our SP control line. TraceOut.Put("AltiGenSP::ProcessEvent LocId=" + altiEvent.LocationId + " EventId=" + ((ALPEvID)altiEvent.CommandId).ToString()); if (altiEvent.LocationId == ControlLocationID) { switch ((ALPEvID)(altiEvent.CommandId)) { // Event Ev.Ring. case ALPEvID.APC_CALLPRESENT: { CallInfo rInfo = new CallInfo(((AltiLinkPlus.ALPParameter)(altiEvent[0]))); ALPLine _line = this[rInfo.lineID]; if (!_line.IsUnderAPCControl) { AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(ControlLocationID, (int)(ALPCmdID.APC_GET_DATA)); ac[0] = new AltiLinkPlus.ALPParameter(rInfo.lineID); ac[1] = new AltiLinkPlus.ALPParameter((int)Diacom.AltiGen.ALPInfoType.APC_DATATYPE_USER); ac[2] = new AltiLinkPlus.ALPParameter(0); StoredRingInfo.Add(ac.SequenceId, rInfo); base.SendALPCommand(ac); _line.InfoState = ALPLine.CallInfoState.CALL_INFO_REQ_SENT; _line.Digits.Clear(); TraceOut.Put("AltiGenSP::APC_CALLPRESENT from :" + rInfo.callerID + " - requested extra info"); } break; } // Event Ev.RingBack. case ALPEvID.APC_RINGBACK: { CallInfo rbInfo = new CallInfo(((AltiLinkPlus.ALPParameter)(altiEvent[0]))); // Getting current line from hashtable. ALPLine _line = this[rbInfo.lineID]; if (_line != null) { // Updating line information. if (_line.SPLineInfo.Type == "T") { _line.SPLineInfo.CalledNumber = _line.SPLineInfo.AccessCode + rbInfo.calleeID; _line.SPLineInfo.CalledName = rbInfo.calleeName; } else { _line.SPLineInfo.CalledNumber = rbInfo.callerID; _line.SPLineInfo.CalledName = rbInfo.callerName; } _line.SPLineInfo.DNISNumber = rbInfo.DNISID; _line.SPLineInfo.DNISName = rbInfo.DNISName; _line.SPLineInfo.CIDNumber = rbInfo.ANIID; _line.SPLineInfo.CIDName = rbInfo.ANIName; _line.SPLineInfo.DIDNumber = rbInfo.calleeID; _line.SPLineInfo.DIDName = rbInfo.calleeName; TraceOut.Put("AltiGenSP::APC_RINGBACK"); if (!_line.IsUnderAPCControl) { this.SendSpEvent(new Ev.RingBack(rbInfo.lineID, (SPLine)_line.SPLineInfo.Clone())); } } break; } // Event Ev.Connect. case ALPEvID.STCHG: { // Getting parameters. ALPLineState state = ((ALPLineState)(altiEvent[0].ReadInt32())); int lineID = altiEvent[1].ReadInt32(); // Getting current line from hashtable. ALPLine _line = this[lineID]; TraceOut.Put("AltiGenSP::Line State=" + ((ALPLineState)state).ToString()); if ((_line != null) && (state == ALPLineState.APC)) { if (_line.IsUnderAPCControl && (_line.InfoState == ALPLine.CallInfoState.SNATCHED_SLAVE_LINE)) { this.SendSpEvent(new Ev.CommandStatus(_line.ConnectedLine.SPLineInfo.ID, Cmd.CommandID.DISCONNECT_LINE, Diacom.Ev.CmdStatus.OK)); } else if (!_line.IsUnderAPCControl) { if (_line.InfoState == ALPLine.CallInfoState.CALL_INFO_RECEIVED) { // Have new connected line. Creating and sending event. TraceOut.Put("AltiGenSP:: Line is APC controlled now"); _line.IsUnderAPCControl = true; this.SendSpEvent(new Ev.Connect(lineID)); foreach (string _digit in _line.Digits) { this.SendSpEvent(new Ev.Digit(lineID, _digit[0])); } } else { _line.InfoState = ALPLine.CallInfoState.CONNECT_DELAYED; } } } break; } // Event Ev.Digit. case ALPEvID.APC_DIGIT: { // Getting parameters. AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0]; int lineID = param.ReadInt32(); char digit = Convert.ToChar(param.ReadByte()); // Creating and sending event. ALPLine _line = this[lineID]; if (_line.IsUnderAPCControl) { this.SendSpEvent(new Ev.Digit(lineID, digit)); } else { _line.Digits.Add(digit.ToString()); } break; } // Event Ev.Disconnect. case ALPEvID.APC_CALLDROP: { // Getting parameters. int lineID = altiEvent[0].ReadInt32(); ALPLine _line = this[lineID]; break; } // Event Ev.CommandStatus. case ALPEvID.APC_STATUS: { // Creating new StateInfo object. LineStateInfo sInfo = new LineStateInfo((AltiLinkPlus.ALPParameter)(altiEvent[0])); ALPCmdStatus lastCmdStatus = (ALPCmdStatus)sInfo.cmdStatus; TraceOut.Put("AltiGenSP::APC Status Line=" + sInfo.lineID + " CmdId=" + ((ALPCmdID)sInfo.commandID).ToString() + " Status=" + lastCmdStatus.ToString()); // Getting current line from hashtable. ALPLine _line = this[sInfo.lineID]; if (_line == null) { break; } // Save the last status _line.LastCommand.Status = lastCmdStatus; // What was the command issued? switch ((ALPCmdID)(sInfo.commandID)) { // Status of APC_PLAY_DTMF command. case ALPCmdID.APC_PLAY_DTMF: if (lastCmdStatus == ALPCmdStatus.FAILED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_DTMF, Ev.CmdStatus.ERROR)); } else { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_DTMF, Ev.CmdStatus.OK)); } break; // Status of APC_PLAY_VOICE command. case ALPCmdID.APC_PLAY_VOICE: if (lastCmdStatus == ALPCmdStatus.FINISHED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_FILE, Ev.CmdStatus.OK)); } else if (lastCmdStatus == ALPCmdStatus.FAILED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.PLAY_FILE, Ev.CmdStatus.ERROR)); } break; // Status of APC_RECORD_VOICE command. case ALPCmdID.APC_RECORD_VOICE: if (lastCmdStatus == ALPCmdStatus.FINISHED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.RECORD_FILE, Ev.CmdStatus.OK)); } else if (lastCmdStatus == ALPCmdStatus.FAILED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.RECORD_FILE, Ev.CmdStatus.ERROR)); } break; // Status of APC_CONNECT_CALL command. case ALPCmdID.APC_CONNECT_CALL: if (lastCmdStatus == ALPCmdStatus.SUCCEED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.CONNECT_LINES, Ev.CmdStatus.OK)); } else { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.CONNECT_LINES, Ev.CmdStatus.ERROR)); } break; // Status of APC_TRANSFER_CALL command. case ALPCmdID.APC_TRANSFER_CALL: if (lastCmdStatus != ALPCmdStatus.SUCCEED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.TRANSFER, Ev.CmdStatus.ERROR)); } break; // Status of APC_DROP_CALL command. case ALPCmdID.APC_DROP_CALL: if (lastCmdStatus == ALPCmdStatus.SUCCEED) { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.DROP_CALL, Ev.CmdStatus.OK)); } else { this.SendSpEvent(new Ev.CommandStatus(sInfo.lineID, Cmd.CommandID.DROP_CALL, Ev.CmdStatus.ERROR)); } break; } break; } default: { base.ProcessEvent(altiEvent); break; } } } // Getting information for ALL line PADs - just want to know that is going on. switch ((ALPEvID)(altiEvent.CommandId)) { case ALPEvID.STCHG: { if (altiEvent.LocationId == ControlLocationID) { break; // We already processed this above } // Saving line state. ALPLineState state = (ALPLineState)(altiEvent[0].ReadInt32()); ALPLine _line = this[altiEvent.LocationId]; TraceOut.Put("AltiGenSP::Line State=" + ((SPLineState)state).ToString()); if (_line != null) { // Rasing event the line is disconnected if status is DISCONNECT. if (state == ALPLineState.IDLE) { if (_line.IsUnderAPCControl) { TraceOut.Put("AltiGenSP:: Line is not APC controlled"); _line.IsUnderAPCControl = false; _line.InfoState = ALPLine.CallInfoState.INITIAL; this.SendSpEvent(new Ev.Disconnect(_line.SPLineInfo.ID)); } } else if ((state == ALPLineState.CONNECTED) && (_line.LastCommand.ID == ALPCmdID.APC_TRANSFER_CALL)) { this.SendSpEvent(new Ev.CommandStatus(_line.SPLineInfo.ID, Cmd.CommandID.TRANSFER, Ev.CmdStatus.OK)); } _line.SPLineInfo.State = (SPLineState)state; // Rasing event state of the line changed. this.SendSpEvent(new Ev.LineStateChanged(_line.SPLineInfo.ID, (SPLineState)state)); } break; } // Event Ev.Tone. case ALPEvID.TONE: { // Getting parameters. AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0]; int lineID = param.ReadInt32(); param = (AltiLinkPlus.ALPParameter)altiEvent[1]; int tone = Convert.ToChar(param.ReadInt32()); // Creating and sending event. this.SendSpEvent(new Ev.Tone(lineID, ((Ev.ToneType)(tone)))); break; } // Line information changed. case ALPEvID.CONFIG_CHG: { const int CONFIG_CHANGED_TYPE_LINEINFO = 0x8000; AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0]; int type = param.ReadInt32(); if (type == CONFIG_CHANGED_TYPE_LINEINFO) { // Command to Get Lines Information. this.SendALPCommand(new Diacom.AltiGen.AltiLinkPlus.ALPCommand(altiEvent.LocationId, Convert.ToInt32(ALPCmdID.GET_LINEINFO))); } break; } // System configuration changed. case ALPEvID.SYSCONFIG_CHG: { AltiLinkPlus.ALPParameter param = (AltiLinkPlus.ALPParameter)altiEvent[0]; SystemConfigChangeCodes type = ((SystemConfigChangeCodes)(param.ReadInt32())); switch (type) { // Line added. case SystemConfigChangeCodes.LINEADD: { // Issue command to Get Line Information. When we get the response - then the code there will send an event. this.SendALPCommand(new Diacom.AltiGen.AltiLinkPlus.ALPCommand(altiEvent.LocationId, Convert.ToInt32(ALPCmdID.GET_LINEINFO))); break; } // Line removed. case SystemConfigChangeCodes.LINEREMOVE: { this.SendSpEvent(new Ev.LineStateChanged(altiEvent.LocationId, SPLineState.LINE_REMOVE)); break; } } break; } default: { if (altiEvent.LocationId != ControlLocationID) { base.ProcessEvent(altiEvent); } break; } } }
/// <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> /// Process all responses. /// </summary> /// <param name="altiResponse">Block of data to process.</param> /// <returns>An object with the response.</returns> protected virtual void ProcessResponse(AltiLinkPlus.ALPResponse altiResponse) { TraceOut.Put("AltiGenSPCore::ProcessResponse SeqId=" + altiResponse.SequenceId + " LocId=" + altiResponse.LocationId + " CmdId=" + ((ALPCmdID)altiResponse.CommandId).ToString() + " code=" + ((ALPRespID)altiResponse.ResponseCode).ToString()); WaitingCommandInfo wci; lock (this.waitingCommands) { wci = this.waitingCommands[altiResponse.SequenceId]; } switch ((ALPCmdID)(altiResponse.CommandId)) { case ALPCmdID.REGISTER_APPID: if (wci != null) { wci.respCode = altiResponse.ResponseCode; wci.errorOccured = (altiResponse.ResponseCode == 0) ? false : true; wci.cmdReady.Set(); } break; // Logon. case ALPCmdID.LOGON: { if (altiResponse.ResponseCode == 0) { TraceOut.Put("Logon saccessfull..."); // Getting our control line PAD. if (this.logonType == SPLogonType.ADMINISTRATOR) { this.ControlLocationID = altiResponse.LocationId; } } if (wci != null) { wci.respCode = altiResponse.ResponseCode; wci.errorOccured = (altiResponse.ResponseCode == 0) ? false : true; wci.cmdReady.Set(); } break; } case ALPCmdID.GET_VERSION: if (altiResponse.ResponseCode == 0) { this.VersionID = altiResponse[0].ReadInt32(); TraceOut.Put("GetVersion successful. Version = " + VersionID.ToString("X")); bool enableOptionPack = Convert.ToBoolean(altiResponse[1].ReadByte()); } if (wci != null) { wci.errorOccured = (altiResponse.ResponseCode == 0) ? false : true; wci.respCode = altiResponse.ResponseCode; wci.cmdReady.Set(); } break; // Get lines info. case ALPCmdID.GET_LINEINFO: if (altiResponse.ResponseCode == 0) { // First parameter in response is number of entries. int linesCount = altiResponse[0].ReadInt32(); // Second parameter holds lines information. AltiLinkPlus.ALPParameter param = altiResponse[1]; // Filling lines hashtable. for (int i = 0; i < linesCount; i++) { LineInfo _li = new LineInfo(param, this.VersionID); this[_li.lineHandle] = new ALPLine(_li); // If there is no command waiting - send the event that new line was added if (wci == null) { this.SendSpEvent(new Ev.LineStateChanged(_li.lineHandle, SPLineState.LINE_ADD)); } } TraceOut.Put(linesCount.ToString() + " lines added..."); } else if (altiResponse.ResponseCode == (int)Diacom.AltiGen.ALPRespID.LIST_END) { // We received "No more Data" response TraceOut.Put("All lines received."); if (wci != null) { wci.errorOccured = false; wci.cmdReady.Set(); } } else { TraceOut.Put("Failed to get lines info : " + ((ALPRespID)(altiResponse.ResponseCode)).ToString()); if (wci != null) { wci.errorOccured = true; wci.respCode = altiResponse.ResponseCode; wci.cmdReady.Set(); } } break; case ALPCmdID.PING: TraceOut.Put("PING response received."); this.ConnectionIsAlive = true; break; } }
/// <summary> /// Connects to server with given parameters. /// </summary> /// <param name="serverIP">IP address of server.</param> /// <param name="serverPort">Port to connect.</param> /// <param name="logonType">Type of logon.</param> /// <param name="account">Account.</param> /// <param name="password">Password.</param> /// <param name="timeout">Timeout interval.</param> /// <remarks> /// <para>Creates new TCP socket, connects to server with given IP address and port, /// tries to logon as "logonType" to "account" with given "password".</para> /// <para>Blocks the current thread until initialization is finished. /// Waits for connection "timeout" miliseconds.</para> /// </remarks> public void Connect(string serverIP, int serverPort, SPLogonType logonType, string account, string password, int timeout) { try { // Connect to the AltiWare server. this.tcpc.Connect(serverIP, serverPort); this.ConnectionIsAlive = true; // Assign network stream. this.st = tcpc.GetStream(); // To Binaryreader. this.bw = new BinaryWriter(st); // To BinaryWriter. this.br = new BinaryReader(st); this.lines = new Hashtable(); // Starting threads. this.outALPThreadHandle.Start(); this.outThreadHandle.Start(); this.inThreadHandle.Start(); if (timeout == 0) { timeout = System.Threading.Timeout.Infinite; } else if (timeout < 1000) { timeout *= 1000; } // Command to Register Application. AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand(0, Convert.ToInt32(ALPCmdID.REGISTER_APPID)); // AltiGen SDK application. ac[0] = new AltiLinkPlus.ALPParameter("GATORS11"); this.SendALPCommandAndWait(ac, timeout); // Command to Logon ac = new AltiLinkPlus.ALPCommand(0, Convert.ToInt32(ALPCmdID.LOGON)); ac[0] = new AltiLinkPlus.ALPParameter((int)logonType); ac[1] = new AltiLinkPlus.ALPParameter(account); ac[2] = new AltiLinkPlus.ALPParameter(password); ac[3] = new AltiLinkPlus.ALPParameter(0); ac[4] = new AltiLinkPlus.ALPParameter(0); ac[5] = new AltiLinkPlus.ALPParameter(0); ac[6] = new AltiLinkPlus.ALPParameter(0); this.SendALPCommandAndWait(ac, timeout); // Get version this.SendALPCommandAndWait(new AltiLinkPlus.ALPCommand(0, Convert.ToInt32(ALPCmdID.GET_VERSION)), timeout); // Issue command to Get Lines Information. this.SendALPCommandAndWait(new Diacom.AltiGen.AltiLinkPlus.ALPCommand(0, Convert.ToInt32(ALPCmdID.GET_LINEINFO)), timeout); // Have a bad response on REGISTER_APPID, LOGON or GET_LINES command. if ((lines == null) || (ControlLocationID == 0)) { TraceOut.Put("Logon unsuccessful"); RaiseEvent(SPStatus.ERROR_LOGON, "Logon Error"); return; } this.ConnectionChecker = new System.Threading.Timer(new System.Threading.TimerCallback(this.CheckConnection), null, 30000, 30000); spStatus = SPStatus.OK; RaiseEvent(SPStatus.OK, "Logon Success"); } catch (Exception _x) { TraceOut.Put("Connect Exception"); TraceOut.Put("_x.Message"); RaiseEvent(SPStatus.ERROR_LOGON, _x.Message); } }
public void Drop(object lineID) { AltiLinkPlus.ALPCommand ac = new AltiLinkPlus.ALPCommand((int)(lineID), (int)(ALPCmdID.DROPCALL)); ac[0] = new AltiLinkPlus.ALPParameter(1); base.SendALPCommandAndWait(ac, 0); }